[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Common code for standard field types which store lists of PHIDs. 5 */ 6 abstract class PhabricatorStandardCustomFieldPHIDs 7 extends PhabricatorStandardCustomField { 8 9 public function buildFieldIndexes() { 10 $indexes = array(); 11 12 $value = $this->getFieldValue(); 13 if (is_array($value)) { 14 foreach ($value as $phid) { 15 $indexes[] = $this->newStringIndex($phid); 16 } 17 } 18 19 return $indexes; 20 } 21 22 public function readValueFromRequest(AphrontRequest $request) { 23 $value = $request->getArr($this->getFieldKey()); 24 $this->setFieldValue($value); 25 } 26 27 public function getValueForStorage() { 28 $value = $this->getFieldValue(); 29 if (!$value) { 30 return null; 31 } 32 33 return json_encode(array_values($value)); 34 } 35 36 public function setValueFromStorage($value) { 37 $result = array(); 38 if ($value) { 39 $value = json_decode($value, true); 40 if (is_array($value)) { 41 $result = array_values($value); 42 } 43 } 44 $this->setFieldValue($value); 45 } 46 47 public function readApplicationSearchValueFromRequest( 48 PhabricatorApplicationSearchEngine $engine, 49 AphrontRequest $request) { 50 return $request->getArr($this->getFieldKey()); 51 } 52 53 public function applyApplicationSearchConstraintToQuery( 54 PhabricatorApplicationSearchEngine $engine, 55 PhabricatorCursorPagedPolicyAwareQuery $query, 56 $value) { 57 if ($value) { 58 $query->withApplicationSearchContainsConstraint( 59 $this->newStringIndex(null), 60 $value); 61 } 62 } 63 64 public function getRequiredHandlePHIDsForApplicationSearch($value) { 65 if ($value) { 66 return $value; 67 } 68 return array(); 69 } 70 71 public function getRequiredHandlePHIDsForPropertyView() { 72 $value = $this->getFieldValue(); 73 if ($value) { 74 return $value; 75 } 76 return array(); 77 } 78 79 public function renderPropertyViewValue(array $handles) { 80 $value = $this->getFieldValue(); 81 if (!$value) { 82 return null; 83 } 84 85 $handles = mpull($handles, 'renderLink'); 86 $handles = phutil_implode_html(', ', $handles); 87 return $handles; 88 } 89 90 public function getRequiredHandlePHIDsForEdit() { 91 $value = $this->getFieldValue(); 92 if ($value) { 93 return $value; 94 } else { 95 return array(); 96 } 97 } 98 99 public function getApplicationTransactionRequiredHandlePHIDs( 100 PhabricatorApplicationTransaction $xaction) { 101 102 $old = json_decode($xaction->getOldValue()); 103 if (!is_array($old)) { 104 $old = array(); 105 } 106 107 $new = json_decode($xaction->getNewValue()); 108 if (!is_array($new)) { 109 $new = array(); 110 } 111 112 $add = array_diff($new, $old); 113 $rem = array_diff($old, $new); 114 115 return array_merge($add, $rem); 116 } 117 118 public function getApplicationTransactionTitle( 119 PhabricatorApplicationTransaction $xaction) { 120 $author_phid = $xaction->getAuthorPHID(); 121 122 $old = json_decode($xaction->getOldValue()); 123 if (!is_array($old)) { 124 $old = array(); 125 } 126 127 $new = json_decode($xaction->getNewValue()); 128 if (!is_array($new)) { 129 $new = array(); 130 } 131 132 $add = array_diff($new, $old); 133 $rem = array_diff($old, $new); 134 135 if ($add && !$rem) { 136 return pht( 137 '%s updated %s, added %d: %s.', 138 $xaction->renderHandleLink($author_phid), 139 $this->getFieldName(), 140 new PhutilNumber(count($add)), 141 $xaction->renderHandleList($add)); 142 } else if ($rem && !$add) { 143 return pht( 144 '%s updated %s, removed %d: %s.', 145 $xaction->renderHandleLink($author_phid), 146 $this->getFieldName(), 147 new PhutilNumber(count($rem)), 148 $xaction->renderHandleList($rem)); 149 } else { 150 return pht( 151 '%s updated %s, added %d: %s; removed %d: %s.', 152 $xaction->renderHandleLink($author_phid), 153 $this->getFieldName(), 154 new PhutilNumber(count($add)), 155 $xaction->renderHandleList($add), 156 new PhutilNumber(count($rem)), 157 $xaction->renderHandleList($rem)); 158 } 159 } 160 161 public function shouldAppearInHerald() { 162 return true; 163 } 164 165 public function getHeraldFieldConditions() { 166 return array( 167 HeraldAdapter::CONDITION_INCLUDE_ALL, 168 HeraldAdapter::CONDITION_INCLUDE_ANY, 169 HeraldAdapter::CONDITION_INCLUDE_NONE, 170 HeraldAdapter::CONDITION_EXISTS, 171 HeraldAdapter::CONDITION_NOT_EXISTS, 172 ); 173 } 174 175 }
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 |