[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/macro/controller/ -> PhabricatorMacroViewController.php (source)

   1  <?php
   2  
   3  final class PhabricatorMacroViewController
   4    extends PhabricatorMacroController {
   5  
   6    private $id;
   7  
   8    public function willProcessRequest(array $data) {
   9      $this->id = $data['id'];
  10    }
  11  
  12    public function shouldAllowPublic() {
  13      return true;
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $user = $request->getUser();
  19  
  20      $macro = id(new PhabricatorMacroQuery())
  21        ->setViewer($user)
  22        ->withIDs(array($this->id))
  23        ->needFiles(true)
  24        ->executeOne();
  25      if (!$macro) {
  26        return new Aphront404Response();
  27      }
  28  
  29      $file = $macro->getFile();
  30  
  31      $title_short = pht('Macro "%s"', $macro->getName());
  32      $title_long  = pht('Image Macro "%s"', $macro->getName());
  33  
  34      $actions = $this->buildActionView($macro);
  35  
  36      $crumbs = $this->buildApplicationCrumbs();
  37      $crumbs->setActionList($actions);
  38      $crumbs->addTextCrumb(
  39        $title_short,
  40        $this->getApplicationURI('/view/'.$macro->getID().'/'));
  41  
  42      $properties = $this->buildPropertyView($macro, $actions);
  43      if ($file) {
  44        $file_view = new PHUIPropertyListView();
  45        $file_view->addImageContent(
  46          phutil_tag(
  47            'img',
  48            array(
  49              'src'     => $file->getViewURI(),
  50              'class'   => 'phabricator-image-macro-hero',
  51            )));
  52      }
  53  
  54      $xactions = id(new PhabricatorMacroTransactionQuery())
  55        ->setViewer($request->getUser())
  56        ->withObjectPHIDs(array($macro->getPHID()))
  57        ->execute();
  58  
  59      $engine = id(new PhabricatorMarkupEngine())
  60        ->setViewer($user);
  61      foreach ($xactions as $xaction) {
  62        if ($xaction->getComment()) {
  63          $engine->addObject(
  64            $xaction->getComment(),
  65            PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT);
  66        }
  67      }
  68      $engine->process();
  69  
  70      $timeline = id(new PhabricatorApplicationTransactionView())
  71        ->setUser($user)
  72        ->setObjectPHID($macro->getPHID())
  73        ->setTransactions($xactions)
  74        ->setMarkupEngine($engine);
  75  
  76      $header = id(new PHUIHeaderView())
  77        ->setUser($user)
  78        ->setPolicyObject($macro)
  79        ->setHeader($title_long);
  80  
  81      if ($macro->getIsDisabled()) {
  82        $header->addTag(
  83          id(new PHUITagView())
  84            ->setType(PHUITagView::TYPE_STATE)
  85            ->setName(pht('Macro Disabled'))
  86            ->setBackgroundColor(PHUITagView::COLOR_BLACK));
  87      }
  88  
  89      $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
  90  
  91      $comment_header = $is_serious
  92        ? pht('Add Comment')
  93        : pht('Grovel in Awe');
  94  
  95      $draft = PhabricatorDraft::newFromUserAndKey($user, $macro->getPHID());
  96  
  97      $add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
  98        ->setUser($user)
  99        ->setObjectPHID($macro->getPHID())
 100        ->setDraft($draft)
 101        ->setHeaderText($comment_header)
 102        ->setAction($this->getApplicationURI('/comment/'.$macro->getID().'/'))
 103        ->setSubmitButtonName(pht('Add Comment'));
 104  
 105      $object_box = id(new PHUIObjectBoxView())
 106        ->setHeader($header)
 107        ->addPropertyList($properties);
 108  
 109      if ($file_view) {
 110        $object_box->addPropertyList($file_view);
 111      }
 112  
 113      return $this->buildApplicationPage(
 114        array(
 115          $crumbs,
 116          $object_box,
 117          $timeline,
 118          $add_comment_form,
 119        ),
 120        array(
 121          'title' => $title_short,
 122        ));
 123    }
 124  
 125    private function buildActionView(PhabricatorFileImageMacro $macro) {
 126      $can_manage = $this->hasApplicationCapability(
 127        PhabricatorMacroManageCapability::CAPABILITY);
 128  
 129      $request = $this->getRequest();
 130      $view = id(new PhabricatorActionListView())
 131        ->setUser($request->getUser())
 132        ->setObject($macro)
 133        ->setObjectURI($request->getRequestURI())
 134        ->addAction(
 135          id(new PhabricatorActionView())
 136          ->setName(pht('Edit Macro'))
 137          ->setHref($this->getApplicationURI('/edit/'.$macro->getID().'/'))
 138          ->setDisabled(!$can_manage)
 139          ->setWorkflow(!$can_manage)
 140          ->setIcon('fa-pencil'));
 141  
 142      $view->addAction(
 143        id(new PhabricatorActionView())
 144          ->setName(pht('Edit Audio'))
 145          ->setHref($this->getApplicationURI('/audio/'.$macro->getID().'/'))
 146          ->setDisabled(!$can_manage)
 147          ->setWorkflow(!$can_manage)
 148          ->setIcon('fa-music'));
 149  
 150      if ($macro->getIsDisabled()) {
 151        $view->addAction(
 152          id(new PhabricatorActionView())
 153            ->setName(pht('Restore Macro'))
 154            ->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
 155            ->setWorkflow(true)
 156            ->setDisabled(!$can_manage)
 157            ->setIcon('fa-check-circle-o'));
 158      } else {
 159        $view->addAction(
 160          id(new PhabricatorActionView())
 161            ->setName(pht('Disable Macro'))
 162            ->setHref($this->getApplicationURI('/disable/'.$macro->getID().'/'))
 163            ->setWorkflow(true)
 164            ->setDisabled(!$can_manage)
 165            ->setIcon('fa-ban'));
 166      }
 167  
 168      return $view;
 169    }
 170  
 171    private function buildPropertyView(
 172      PhabricatorFileImageMacro $macro,
 173      PhabricatorActionListView $actions) {
 174  
 175      $view = id(new PHUIPropertyListView())
 176        ->setUser($this->getRequest()->getUser())
 177        ->setObject($macro)
 178        ->setActionList($actions);
 179  
 180      switch ($macro->getAudioBehavior()) {
 181        case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
 182          $view->addProperty(pht('Audio Behavior'), pht('Play Once'));
 183          break;
 184        case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
 185          $view->addProperty(pht('Audio Behavior'), pht('Loop'));
 186          break;
 187      }
 188  
 189      $audio_phid = $macro->getAudioPHID();
 190      if ($audio_phid) {
 191        $this->loadHandles(array($audio_phid));
 192        $view->addProperty(
 193          pht('Audio'),
 194          $this->getHandle($audio_phid)->renderLink());
 195      }
 196  
 197      $view->invokeWillRenderEvent();
 198  
 199      return $view;
 200    }
 201  
 202  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1