[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSettingsPanelEmailPreferences 4 extends PhabricatorSettingsPanel { 5 6 public function getPanelKey() { 7 return 'emailpreferences'; 8 } 9 10 public function getPanelName() { 11 return pht('Email Preferences'); 12 } 13 14 public function getPanelGroup() { 15 return pht('Email'); 16 } 17 18 public function processRequest(AphrontRequest $request) { 19 $user = $request->getUser(); 20 21 $preferences = $user->loadPreferences(); 22 23 $pref_no_mail = PhabricatorUserPreferences::PREFERENCE_NO_MAIL; 24 $pref_no_self_mail = PhabricatorUserPreferences::PREFERENCE_NO_SELF_MAIL; 25 26 $value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; 27 28 $errors = array(); 29 if ($request->isFormPost()) { 30 $preferences->setPreference( 31 $pref_no_mail, 32 $request->getStr($pref_no_mail)); 33 34 $preferences->setPreference( 35 $pref_no_self_mail, 36 $request->getStr($pref_no_self_mail)); 37 38 $new_tags = $request->getArr('mailtags'); 39 $mailtags = $preferences->getPreference('mailtags', array()); 40 $all_tags = $this->getAllTags($user); 41 42 foreach ($all_tags as $key => $label) { 43 $mailtags[$key] = (int)idx($new_tags, $key, $value_email); 44 } 45 $preferences->setPreference('mailtags', $mailtags); 46 47 $preferences->save(); 48 49 return id(new AphrontRedirectResponse()) 50 ->setURI($this->getPanelURI('?saved=true')); 51 } 52 53 $form = new AphrontFormView(); 54 $form 55 ->setUser($user) 56 ->appendRemarkupInstructions( 57 pht( 58 'These settings let you control how Phabricator notifies you about '. 59 'events. You can configure Phabricator to send you an email, '. 60 'just send a web notification, or not notify you at all.')) 61 ->appendRemarkupInstructions( 62 pht( 63 'If you disable **Email Notifications**, Phabricator will never '. 64 'send email to notify you about events. This preference overrides '. 65 'all your other settings.'. 66 "\n\n". 67 "//You may still receive some administrative email, like password ". 68 "reset email.//")) 69 ->appendChild( 70 id(new AphrontFormSelectControl()) 71 ->setLabel(pht('Email Notifications')) 72 ->setName($pref_no_mail) 73 ->setOptions( 74 array( 75 '0' => pht('Send me email notifications'), 76 '1' => pht('Never send email notifications'), 77 )) 78 ->setValue($preferences->getPreference($pref_no_mail, 0))) 79 ->appendRemarkupInstructions( 80 pht( 81 'If you disable **Self Actions**, Phabricator will not notify '. 82 'you about actions you take.')) 83 ->appendChild( 84 id(new AphrontFormSelectControl()) 85 ->setLabel(pht('Self Actions')) 86 ->setName($pref_no_self_mail) 87 ->setOptions( 88 array( 89 '0' => pht('Send me an email when I take an action'), 90 '1' => pht('Do not send me an email when I take an action'), 91 )) 92 ->setValue($preferences->getPreference($pref_no_self_mail, 0))); 93 94 $mailtags = $preferences->getPreference('mailtags', array()); 95 96 $form->appendChild( 97 id(new PHUIFormDividerControl())); 98 99 $form->appendRemarkupInstructions( 100 pht( 101 'You can adjust **Application Settings** here to customize when '. 102 'you are emailed and notified.'. 103 "\n\n". 104 "| Setting | Effect\n". 105 "| ------- | -------\n". 106 "| Email | You will receive an email and a notification, but the ". 107 "notification will be marked \"read\".\n". 108 "| Notify | You will receive an unread notification only.\n". 109 "| Ignore | You will receive nothing.\n". 110 "\n\n". 111 'If an update makes several changes (like adding CCs to a task, '. 112 'closing it, and adding a comment) you will receive the strongest '. 113 'notification any of the changes is configured to deliver.'. 114 "\n\n". 115 'These preferences **only** apply to objects you are connected to '. 116 '(for example, Revisions where you are a reviewer or tasks you are '. 117 'CC\'d on). To receive email alerts when other objects are created, '. 118 'configure [[ /herald/ | Herald Rules ]].')); 119 120 $editors = $this->getAllEditorsWithTags($user); 121 122 // Find all the tags shared by more than one application, and put them 123 // in a "common" group. 124 $all_tags = array(); 125 foreach ($editors as $editor) { 126 foreach ($editor->getMailTagsMap() as $tag => $name) { 127 if (empty($all_tags[$tag])) { 128 $all_tags[$tag] = array( 129 'count' => 0, 130 'name' => $name, 131 ); 132 } 133 $all_tags[$tag]['count']; 134 } 135 } 136 137 $common_tags = array(); 138 foreach ($all_tags as $tag => $info) { 139 if ($info['count'] > 1) { 140 $common_tags[$tag] = $info['name']; 141 } 142 } 143 144 // Build up the groups of application-specific options. 145 $tag_groups = array(); 146 foreach ($editors as $editor) { 147 $tag_groups[] = array( 148 $editor->getEditorObjectsDescription(), 149 array_diff_key($editor->getMailTagsMap(), $common_tags), 150 ); 151 } 152 153 // Sort them, then put "Common" at the top. 154 $tag_groups = isort($tag_groups, 0); 155 if ($common_tags) { 156 array_unshift($tag_groups, array(pht('Common'), $common_tags)); 157 } 158 159 // Finally, build the controls. 160 foreach ($tag_groups as $spec) { 161 list($label, $map) = $spec; 162 $control = $this->buildMailTagControl($label, $map, $mailtags); 163 $form->appendChild($control); 164 } 165 166 $form 167 ->appendChild( 168 id(new AphrontFormSubmitControl()) 169 ->setValue(pht('Save Preferences'))); 170 171 $form_box = id(new PHUIObjectBoxView()) 172 ->setHeaderText(pht('Email Preferences')) 173 ->setFormSaved($request->getStr('saved')) 174 ->setFormErrors($errors) 175 ->setForm($form); 176 177 return id(new AphrontNullView()) 178 ->appendChild( 179 array( 180 $form_box, 181 )); 182 } 183 184 private function getAllEditorsWithTags(PhabricatorUser $user) { 185 $editors = id(new PhutilSymbolLoader()) 186 ->setAncestorClass('PhabricatorApplicationTransactionEditor') 187 ->loadObjects(); 188 189 foreach ($editors as $key => $editor) { 190 // Remove editors which do not support mail tags. 191 if (!$editor->getMailTagsMap()) { 192 unset($editors[$key]); 193 } 194 195 // Remove editors for applications which are not installed. 196 $app = $editor->getEditorApplicationClass(); 197 if ($app !== null) { 198 if (!PhabricatorApplication::isClassInstalledForViewer($app, $user)) { 199 unset($editors[$key]); 200 } 201 } 202 } 203 204 return $editors; 205 } 206 207 private function getAllTags(PhabricatorUser $user) { 208 $tags = array(); 209 foreach ($this->getAllEditorsWithTags($user) as $editor) { 210 $tags += $editor->getMailTagsMap(); 211 } 212 return $tags; 213 } 214 215 private function buildMailTagControl( 216 $control_label, 217 array $tags, 218 array $prefs) { 219 220 $value_email = PhabricatorUserPreferences::MAILTAG_PREFERENCE_EMAIL; 221 $value_notify = PhabricatorUserPreferences::MAILTAG_PREFERENCE_NOTIFY; 222 $value_ignore = PhabricatorUserPreferences::MAILTAG_PREFERENCE_IGNORE; 223 224 $content = array(); 225 foreach ($tags as $key => $label) { 226 $select = AphrontFormSelectControl::renderSelectTag( 227 (int)idx($prefs, $key, $value_email), 228 array( 229 $value_email => pht("\xE2\x9A\xAB Email"), 230 $value_notify => pht("\xE2\x97\x90 Notify"), 231 $value_ignore => pht("\xE2\x9A\xAA Ignore"), 232 ), 233 array( 234 'name' => 'mailtags['.$key.']', 235 )); 236 237 $content[] = phutil_tag( 238 'div', 239 array( 240 'class' => 'psb', 241 ), 242 array( 243 $select, 244 ' ', 245 $label, 246 )); 247 } 248 249 $control = new AphrontFormStaticControl(); 250 $control->setLabel($control_label); 251 $control->setValue($content); 252 253 return $control; 254 } 255 256 }
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 |