[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioMockThumbGridView extends AphrontView { 4 5 private $mock; 6 7 public function setMock(PholioMock $mock) { 8 $this->mock = $mock; 9 return $this; 10 } 11 12 public function render() { 13 $mock = $this->mock; 14 15 $all_images = $mock->getAllImages(); 16 $all_images = mpull($all_images, null, 'getPHID'); 17 18 $history = mpull($all_images, 'getReplacesImagePHID', 'getPHID'); 19 20 $replaced = array(); 21 foreach ($history as $phid => $replaces_phid) { 22 if ($replaces_phid) { 23 $replaced[$replaces_phid] = true; 24 } 25 } 26 27 // Figure out the columns. Start with all the active images. 28 $images = mpull($mock->getImages(), null, 'getPHID'); 29 30 // Now, find deleted images: obsolete images which were not replaced. 31 foreach ($mock->getAllImages() as $image) { 32 if (!$image->getIsObsolete()) { 33 // Image is current. 34 continue; 35 } 36 37 if (isset($replaced[$image->getPHID()])) { 38 // Image was replaced. 39 continue; 40 } 41 42 // This is an obsolete image which was not replaced, so it must be 43 // a deleted image. 44 $images[$image->getPHID()] = $image; 45 } 46 47 $cols = array(); 48 $depth = 0; 49 foreach ($images as $image) { 50 $phid = $image->getPHID(); 51 52 $col = array(); 53 54 // If this is a deleted image, null out the final column. 55 if ($image->getIsObsolete()) { 56 $col[] = null; 57 } 58 59 $col[] = $phid; 60 while ($phid && isset($history[$phid])) { 61 $col[] = $history[$phid]; 62 $phid = $history[$phid]; 63 } 64 65 $cols[] = $col; 66 $depth = max($depth, count($col)); 67 } 68 69 $grid = array(); 70 $jj = $depth; 71 for ($ii = 0; $ii < $depth; $ii++) { 72 $row = array(); 73 if ($depth == $jj) { 74 $row[] = phutil_tag( 75 'th', 76 array( 77 'valign' => 'middle', 78 'class' => 'pholio-history-header', 79 ), 80 pht('Current Revision')); 81 } else { 82 $row[] = phutil_tag('th', array(), null); 83 } 84 foreach ($cols as $col) { 85 if (empty($col[$ii])) { 86 $row[] = phutil_tag('td', array(), null); 87 } else { 88 $thumb = $this->renderThumbnail($all_images[$col[$ii]]); 89 $row[] = phutil_tag('td', array(), $thumb); 90 } 91 } 92 $grid[] = phutil_tag('tr', array(), $row); 93 $jj--; 94 } 95 96 $grid = phutil_tag( 97 'table', 98 array( 99 'id' => 'pholio-mock-thumb-grid', 100 'class' => 'pholio-mock-thumb-grid', 101 ), 102 $grid); 103 104 $grid = id(new PHUIBoxView()) 105 ->addClass('pholio-mock-thumb-grid-container') 106 ->appendChild($grid); 107 108 return id(new PHUIObjectBoxView()) 109 ->setHeaderText(pht('Mock History')) 110 ->appendChild($grid); 111 } 112 113 114 private function renderThumbnail(PholioImage $image) { 115 $thumbfile = $image->getFile(); 116 117 if ($image->getFile()->isViewableImage()) { 118 $dimensions = PhabricatorImageTransformer::getPreviewDimensions( 119 $thumbfile, 120 100); 121 } else { 122 // If this is a PDF or a text file or something, we'll end up using a 123 // generic thumbnail which is always sized correctly. 124 $dimensions = array( 125 'sdx' => 100, 126 'sdy' => 100, 127 ); 128 } 129 130 $tag = phutil_tag( 131 'img', 132 array( 133 'width' => $dimensions['sdx'], 134 'height' => $dimensions['sdy'], 135 'src' => $thumbfile->getPreview100URI(), 136 'class' => 'pholio-mock-thumb-grid-image', 137 'style' => 'top: '.floor((100 - $dimensions['sdy'] ) / 2).'px', 138 )); 139 140 $classes = array('pholio-mock-thumb-grid-item'); 141 if ($image->getIsObsolete()) { 142 $classes[] = 'pholio-mock-thumb-grid-item-obsolete'; 143 } 144 145 $inline_count = null; 146 if ($image->getInlineComments()) { 147 $inline_count[] = phutil_tag( 148 'span', 149 array( 150 'class' => 'pholio-mock-thumb-grid-comment-count', 151 ), 152 pht('%s', new PhutilNumber(count($image->getInlineComments())))); 153 } 154 155 return javelin_tag( 156 'a', 157 array( 158 'sigil' => 'mock-thumbnail', 159 'class' => implode(' ', $classes), 160 'href' => '#', 161 'meta' => array( 162 'imageID' => $image->getID(), 163 ), 164 ), 165 array( 166 $tag, 167 $inline_count, 168 )); 169 } 170 171 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |