Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentBrowseController.php
- This file was added.
| <?php | |||||
| final class PhragmentBrowseController extends PhragmentController { | |||||
| private $dblob; | |||||
| public function willProcessRequest(array $data) { | |||||
| $this->dblob = idx($data, "dblob", ""); | |||||
| } | |||||
| public function processRequest() { | |||||
| $request = $this->getRequest(); | |||||
| $viewer = $request->getUser(); | |||||
| $parents = $this->loadParentFragments($this->dblob); | |||||
| if ($parents === null) { | |||||
| return new Aphront404Response(); | |||||
| } | |||||
| $current = nonempty(last($parents), null); | |||||
epriestley: Equivalent to `last($parents)`? (Except I don't remember if `last()` returns `false` or `null`… | |||||
Not Done Inline ActionsWill fix. hach-que: Will fix. | |||||
Not Done Inline ActionsIt's literally a wrapper around end(), so it will return false on an empty array. hach-que: It's literally a wrapper around `end()`, so it will return false on an empty array. | |||||
| $path = ''; | |||||
| if ($current !== null) { | |||||
| $path = $current->getPath(); | |||||
| } | |||||
| $crumbs = $this->buildApplicationCrumbsWithPath($parents); | |||||
| $crumbs->addAction( | |||||
| id(new PHUIListItemView()) | |||||
| ->setName(pht('Create Fragment')) | |||||
| ->setHref($this->getApplicationURI('/create/'.$path)) | |||||
| ->setIcon('create')); | |||||
| $current_box = $this->createCurrentFragmentView($current); | |||||
| $list = id(new PHUIObjectItemListView()) | |||||
| ->setUser($viewer); | |||||
| $fragments = null; | |||||
| if ($current === null) { | |||||
| // Find all root fragments. | |||||
| $fragments = id(new PhragmentFragmentQuery()) | |||||
| ->setViewer($this->getRequest()->getUser()) | |||||
| ->needLatestVersion(true) | |||||
| ->withDepths(array(1)) | |||||
| ->execute(); | |||||
| } else { | |||||
| // Find all child fragments. | |||||
| $fragments = id(new PhragmentFragmentQuery()) | |||||
| ->setViewer($this->getRequest()->getUser()) | |||||
| ->needLatestVersion(true) | |||||
| ->withLeadingPath($current->getPath().'/') | |||||
| ->withDepths(array($current->getDepth() + 1)) | |||||
| ->execute(); | |||||
| } | |||||
| foreach ($fragments as $fragment) { | |||||
| $item = id(new PHUIObjectItemView()); | |||||
| $item->setHeader($fragment->getName()); | |||||
| $item->setHref($this->getApplicationURI('/browse/'.$fragment->getPath())); | |||||
| $item->addAttribute(pht( | |||||
| 'Last Updated %s', | |||||
| phabricator_datetime( | |||||
| $fragment->getLatestVersion()->getDateCreated(), | |||||
| $viewer))); | |||||
| $item->addAttribute(pht( | |||||
Not Done Inline Actionspht epriestley: pht | |||||
| 'Latest Version %s', | |||||
| $fragment->getLatestVersion()->getSequence())); | |||||
| $list->addItem($item); | |||||
| } | |||||
| return $this->buildApplicationPage( | |||||
| array( | |||||
| $crumbs, | |||||
| $current_box, | |||||
| $list), | |||||
| array( | |||||
| 'title' => pht('Browse Phragments'), | |||||
| 'device' => true)); | |||||
Not Done Inline ActionsYou should be abel to do this with $header->setPolicyObject($fragment) epriestley: You should be abel to do this with $header->setPolicyObject($fragment) | |||||
| } | |||||
| private function createCurrentFragmentView($fragment) { | |||||
| if ($fragment === null) { | |||||
| return null; | |||||
| } | |||||
| $viewer = $this->getRequest()->getUser(); | |||||
| $header = id(new PHUIHeaderView()) | |||||
| ->setHeader($fragment->getName()) | |||||
| ->setPolicyObject($fragment) | |||||
| ->setUser($viewer); | |||||
| $properties = new PHUIPropertyListView(); | |||||
| $phids = array(); | |||||
| $phids[] = $fragment->getLatestVersionPHID(); | |||||
| $this->loadHandles($phids); | |||||
| $properties->addProperty( | |||||
| pht('Latest Version'), | |||||
| $this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); | |||||
| return id(new PHUIObjectBoxView()) | |||||
| ->setHeader($header) | |||||
| ->addPropertyList($properties); | |||||
| } | |||||
| } | |||||
Equivalent to last($parents)? (Except I don't remember if last() returns false or null; it's probably false for consistency with end()).