[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class HeraldManiphestTaskAdapter extends HeraldAdapter { 4 5 private $task; 6 private $ccPHIDs = array(); 7 private $assignPHID; 8 private $projectPHIDs = array(); 9 private $emailPHIDs = array(); 10 11 public function getEmailPHIDs() { 12 return $this->emailPHIDs; 13 } 14 15 public function getAdapterApplicationClass() { 16 return 'PhabricatorManiphestApplication'; 17 } 18 19 public function getAdapterContentDescription() { 20 return pht('React to tasks being created or updated.'); 21 } 22 23 public function getRepetitionOptions() { 24 return array( 25 HeraldRepetitionPolicyConfig::EVERY, 26 HeraldRepetitionPolicyConfig::FIRST, 27 ); 28 } 29 30 public function supportsRuleType($rule_type) { 31 switch ($rule_type) { 32 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 33 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 34 return true; 35 case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 36 default: 37 return false; 38 } 39 } 40 41 public function setTask(ManiphestTask $task) { 42 $this->task = $task; 43 return $this; 44 } 45 public function getTask() { 46 return $this->task; 47 } 48 49 public function getObject() { 50 return $this->task; 51 } 52 53 private function setCcPHIDs(array $cc_phids) { 54 $this->ccPHIDs = $cc_phids; 55 return $this; 56 } 57 public function getCcPHIDs() { 58 return $this->ccPHIDs; 59 } 60 61 public function setAssignPHID($assign_phid) { 62 $this->assignPHID = $assign_phid; 63 return $this; 64 } 65 public function getAssignPHID() { 66 return $this->assignPHID; 67 } 68 69 public function setProjectPHIDs(array $project_phids) { 70 $this->projectPHIDs = $project_phids; 71 return $this; 72 } 73 public function getProjectPHIDs() { 74 return $this->projectPHIDs; 75 } 76 77 public function getAdapterContentName() { 78 return pht('Maniphest Tasks'); 79 } 80 81 public function getFields() { 82 return array_merge( 83 array( 84 self::FIELD_TITLE, 85 self::FIELD_BODY, 86 self::FIELD_AUTHOR, 87 self::FIELD_ASSIGNEE, 88 self::FIELD_CC, 89 self::FIELD_CONTENT_SOURCE, 90 self::FIELD_PROJECTS, 91 self::FIELD_TASK_PRIORITY, 92 self::FIELD_TASK_STATUS, 93 self::FIELD_IS_NEW_OBJECT, 94 ), 95 parent::getFields()); 96 } 97 98 public function getActions($rule_type) { 99 switch ($rule_type) { 100 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 101 return array_merge( 102 array( 103 self::ACTION_ADD_CC, 104 self::ACTION_EMAIL, 105 self::ACTION_ASSIGN_TASK, 106 self::ACTION_ADD_PROJECTS, 107 self::ACTION_NOTHING, 108 ), 109 parent::getActions($rule_type)); 110 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 111 return array_merge( 112 array( 113 self::ACTION_ADD_CC, 114 self::ACTION_EMAIL, 115 self::ACTION_FLAG, 116 self::ACTION_ASSIGN_TASK, 117 self::ACTION_NOTHING, 118 ), 119 parent::getActions($rule_type)); 120 } 121 } 122 123 public function getPHID() { 124 return $this->getTask()->getPHID(); 125 } 126 127 public function getHeraldName() { 128 return 'T'.$this->getTask()->getID(); 129 } 130 131 public function getHeraldField($field) { 132 switch ($field) { 133 case self::FIELD_TITLE: 134 return $this->getTask()->getTitle(); 135 case self::FIELD_BODY: 136 return $this->getTask()->getDescription(); 137 case self::FIELD_AUTHOR: 138 return $this->getTask()->getAuthorPHID(); 139 case self::FIELD_ASSIGNEE: 140 return $this->getTask()->getOwnerPHID(); 141 case self::FIELD_CC: 142 return $this->getTask()->getCCPHIDs(); 143 case self::FIELD_PROJECTS: 144 return PhabricatorEdgeQuery::loadDestinationPHIDs( 145 $this->getTask()->getPHID(), 146 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 147 case self::FIELD_TASK_PRIORITY: 148 return $this->getTask()->getPriority(); 149 case self::FIELD_TASK_STATUS: 150 return $this->getTask()->getStatus(); 151 } 152 153 return parent::getHeraldField($field); 154 } 155 156 public function applyHeraldEffects(array $effects) { 157 assert_instances_of($effects, 'HeraldEffect'); 158 159 $result = array(); 160 foreach ($effects as $effect) { 161 $action = $effect->getAction(); 162 switch ($action) { 163 case self::ACTION_NOTHING: 164 $result[] = new HeraldApplyTranscript( 165 $effect, 166 true, 167 pht('Great success at doing nothing.')); 168 break; 169 case self::ACTION_ADD_CC: 170 foreach ($effect->getTarget() as $phid) { 171 $this->ccPHIDs[] = $phid; 172 } 173 $result[] = new HeraldApplyTranscript( 174 $effect, 175 true, 176 pht('Added addresses to cc list.')); 177 break; 178 case self::ACTION_EMAIL: 179 foreach ($effect->getTarget() as $phid) { 180 $this->emailPHIDs[] = $phid; 181 } 182 $result[] = new HeraldApplyTranscript( 183 $effect, 184 true, 185 pht('Added addresses to email list.')); 186 break; 187 case self::ACTION_FLAG: 188 $result[] = parent::applyFlagEffect( 189 $effect, 190 $this->getTask()->getPHID()); 191 break; 192 case self::ACTION_ASSIGN_TASK: 193 $target_array = $effect->getTarget(); 194 $assign_phid = reset($target_array); 195 $this->setAssignPHID($assign_phid); 196 $result[] = new HeraldApplyTranscript( 197 $effect, 198 true, 199 pht('Assigned task.')); 200 break; 201 case self::ACTION_ADD_PROJECTS: 202 foreach ($effect->getTarget() as $phid) { 203 $this->projectPHIDs[] = $phid; 204 } 205 $result[] = new HeraldApplyTranscript( 206 $effect, 207 true, 208 pht('Added projects.')); 209 break; 210 default: 211 $custom_result = parent::handleCustomHeraldEffect($effect); 212 if ($custom_result === null) { 213 throw new Exception(pht( 214 "No rules to handle action '%s'.", 215 $action)); 216 } 217 218 $result[] = $custom_result; 219 break; 220 } 221 } 222 return $result; 223 } 224 225 protected function getCustomFieldTemplateObject() { 226 return new ManiphestTask(); 227 } 228 229 }
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 |