[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/pholio/view/ -> PholioMockImagesView.php (source)

   1  <?php
   2  
   3  final class PholioMockImagesView extends AphrontView {
   4  
   5    private $mock;
   6    private $imageID;
   7    private $requestURI;
   8    private $commentFormID;
   9  
  10    public function setCommentFormID($comment_form_id) {
  11      $this->commentFormID = $comment_form_id;
  12      return $this;
  13    }
  14  
  15    public function getCommentFormID() {
  16      return $this->commentFormID;
  17    }
  18  
  19    public function setRequestURI(PhutilURI $request_uri) {
  20      $this->requestURI = $request_uri;
  21      return $this;
  22    }
  23  
  24    public function getRequestURI() {
  25      return $this->requestURI;
  26    }
  27  
  28    public function setImageID($image_id) {
  29      $this->imageID = $image_id;
  30      return $this;
  31    }
  32  
  33    public function getImageID() {
  34      return $this->imageID;
  35    }
  36  
  37    public function setMock(PholioMock $mock) {
  38      $this->mock = $mock;
  39      return $this;
  40    }
  41  
  42    public function render() {
  43      if (!$this->mock) {
  44        throw new Exception('Call setMock() before render()!');
  45      }
  46  
  47      $mock = $this->mock;
  48  
  49      require_celerity_resource('javelin-behavior-pholio-mock-view');
  50  
  51      $images = array();
  52      $panel_id = celerity_generate_unique_node_id();
  53      $viewport_id = celerity_generate_unique_node_id();
  54  
  55      $ids = mpull($mock->getImages(), 'getID');
  56      if ($this->imageID && isset($ids[$this->imageID])) {
  57        $selected_id = $this->imageID;
  58      } else {
  59        $selected_id = head_key($ids);
  60      }
  61  
  62      // TODO: We could maybe do a better job with tailoring this, which is the
  63      // image shown on the review stage.
  64      $nonimage_uri = celerity_get_resource_uri(
  65        'rsrc/image/icon/fatcow/thumbnails/default.p100.png');
  66  
  67      $engine = id(new PhabricatorMarkupEngine())
  68        ->setViewer($this->getUser());
  69      foreach ($mock->getAllImages() as $image) {
  70        $engine->addObject($image, 'default');
  71      }
  72      $engine->process();
  73      $current_set = 0;
  74      foreach ($mock->getAllImages() as $image) {
  75        $file = $image->getFile();
  76        $metadata = $file->getMetadata();
  77        $x = idx($metadata, PhabricatorFile::METADATA_IMAGE_WIDTH);
  78        $y = idx($metadata, PhabricatorFile::METADATA_IMAGE_HEIGHT);
  79  
  80        $is_obs = (bool)$image->getIsObsolete();
  81        if (!$is_obs) {
  82          $current_set++;
  83        }
  84  
  85        $history_uri = '/pholio/image/history/'.$image->getID().'/';
  86        $images[] = array(
  87          'id' => $image->getID(),
  88          'fullURI' => $file->getBestURI(),
  89          'stageURI' => ($file->isViewableImage()
  90            ? $file->getBestURI()
  91            : $nonimage_uri),
  92          'pageURI' => $this->getImagePageURI($image, $mock),
  93          'downloadURI' => $file->getDownloadURI(),
  94          'historyURI' => $history_uri,
  95          'width' => $x,
  96          'height' => $y,
  97          'title' => $image->getName(),
  98          'descriptionMarkup' => $engine->getOutput($image, 'default'),
  99          'isObsolete' => (bool)$image->getIsObsolete(),
 100          'isImage' => $file->isViewableImage(),
 101          'isViewable' => $file->isViewableInBrowser(),
 102        );
 103      }
 104  
 105      $navsequence = array();
 106      foreach ($mock->getImages() as $image) {
 107        $navsequence[] = $image->getID();
 108      }
 109  
 110      $full_icon = array(
 111        javelin_tag('span', array('aural' => true), pht('View Raw File')),
 112        id(new PHUIIconView())->setIconFont('fa-file-image-o'),
 113      );
 114  
 115      $download_icon = array(
 116        javelin_tag('span', array('aural' => true), pht('Download File')),
 117        id(new PHUIIconView())->setIconFont('fa-download'),
 118      );
 119  
 120      $login_uri = id(new PhutilURI('/login/'))
 121        ->setQueryParam('next', (string) $this->getRequestURI());
 122      $config = array(
 123        'mockID' => $mock->getID(),
 124        'panelID' => $panel_id,
 125        'viewportID' => $viewport_id,
 126        'commentFormID' => $this->getCommentFormID(),
 127        'images' => $images,
 128        'selectedID' => $selected_id,
 129        'loggedIn' => $this->getUser()->isLoggedIn(),
 130        'logInLink' => (string) $login_uri,
 131        'navsequence' => $navsequence,
 132        'fullIcon' => hsprintf('%s', $full_icon),
 133        'downloadIcon' => hsprintf('%s', $download_icon),
 134        'currentSetSize' => $current_set,
 135      );
 136      Javelin::initBehavior('pholio-mock-view', $config);
 137  
 138      $mockview = '';
 139  
 140      $mock_wrapper = javelin_tag(
 141        'div',
 142        array(
 143          'id' => $viewport_id,
 144          'sigil' => 'mock-viewport',
 145          'class' => 'pholio-mock-image-viewport',
 146        ),
 147        '');
 148  
 149      $image_header = javelin_tag(
 150        'div',
 151        array(
 152          'id' => 'mock-image-header',
 153          'class' => 'pholio-mock-image-header',
 154        ),
 155        '');
 156  
 157      $mock_wrapper = javelin_tag(
 158        'div',
 159        array(
 160          'id' => $panel_id,
 161          'sigil' => 'mock-panel touchable',
 162          'class' => 'pholio-mock-image-panel',
 163        ),
 164        array(
 165          $image_header,
 166          $mock_wrapper,
 167        ));
 168  
 169      $inline_comments_holder = javelin_tag(
 170        'div',
 171        array(
 172          'id' => 'mock-image-description',
 173          'sigil' => 'mock-image-description',
 174          'class' => 'mock-image-description',
 175        ),
 176        '');
 177  
 178      $mockview[] = phutil_tag(
 179        'div',
 180          array(
 181            'class' => 'pholio-mock-image-container',
 182            'id' => 'pholio-mock-image-container',
 183          ),
 184        array($mock_wrapper, $inline_comments_holder));
 185  
 186      return $mockview;
 187    }
 188  
 189    private function getImagePageURI(PholioImage $image, PholioMock $mock) {
 190      $uri = '/M'.$mock->getID().'/'.$image->getID().'/';
 191      return $uri;
 192    }
 193  }


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