Index: trunk/extensions/SemanticTasks/SemanticTasks.classes.php |
— | — | @@ -4,23 +4,33 @@ |
5 | 5 | define("NEWTASK", 0); |
6 | 6 | define("UPDATE", 1); |
7 | 7 | define("ASSIGNED", 2); |
| 8 | +define("CLOSED", 3); |
8 | 9 | |
9 | 10 | /** |
10 | 11 | * This class handles the creation and sending of notification emails. |
11 | 12 | */ |
12 | 13 | class SemanticTasksMailer { |
13 | | - private static $class_assignees; |
| 14 | + private static $task_assignees; |
| 15 | + private static $task_status; |
14 | 16 | |
15 | 17 | function findOldValues( &$article, &$user, &$text, &$summary, $minor, $watch, $sectionanchor, &$flags ) { |
16 | 18 | $title = $article->getTitle(); |
17 | 19 | $title_text = $title->getText(); |
18 | 20 | |
19 | 21 | $assignees = self::getAssignees( 'Assigned to', $title_text, $user ); |
| 22 | + $status = self::getStatus( 'Status', $title_text, $user ); |
20 | 23 | |
21 | 24 | self::printDebug( "Old assignees: ", $assignees ); |
| 25 | + self::printDebug( "Old status: " , $status ); |
22 | 26 | |
23 | | - self::$class_assignees = $assignees; |
| 27 | + self::$task_assignees = $assignees; |
24 | 28 | |
| 29 | + if ( count( $status ) > 0 ) { |
| 30 | + self::$task_status = $status[0]; |
| 31 | + } else { |
| 32 | + self::$task_status = ""; |
| 33 | + } |
| 34 | + |
25 | 35 | return true; |
26 | 36 | } |
27 | 37 | |
— | — | @@ -46,7 +56,8 @@ |
47 | 57 | } |
48 | 58 | |
49 | 59 | function mailAssignees( $article, $text, $user, $status ) { |
50 | | - self::printDebug( "Saved assignees:", self::$class_assignees ); |
| 60 | + self::printDebug( "Saved assignees:", self::$task_assignees ); |
| 61 | + self::printDebug( "Saved task status: " . self::$task_status ); |
51 | 62 | |
52 | 63 | $title = $article->getTitle(); |
53 | 64 | $title_text = $title->getText(); |
— | — | @@ -54,11 +65,11 @@ |
55 | 66 | $assignees_to_task = array(); |
56 | 67 | $current_assignees = self::getAssignees( 'Assigned to', $title_text, $user ); |
57 | 68 | |
58 | | - self::printDebug( "Previous assignees: ", self::$class_assignees ); |
| 69 | + self::printDebug( "Previous assignees: ", self::$task_assignees ); |
59 | 70 | self::printDebug( "New assignees: ", $current_assignees ); |
60 | 71 | |
61 | 72 | foreach ( $current_assignees as $assignee ) { |
62 | | - if ( !in_array( $assignee, self::$class_assignees ) ) { |
| 73 | + if ( !in_array( $assignee, self::$task_assignees ) ) { |
63 | 74 | array_push( $assignees_to_task, $assignee ); |
64 | 75 | } |
65 | 76 | } |
— | — | @@ -79,6 +90,16 @@ |
80 | 91 | |
81 | 92 | $copies = self::getAssignees( 'Carbon copy', $title_text, $user ); |
82 | 93 | |
| 94 | + $current_task_status = self::getStatus( 'Status', $title_text, $user ); |
| 95 | + self::printDebug( "New status: ", $current_task_status ); |
| 96 | + if ( count( $current_task_status ) > 0 ) { |
| 97 | + $current_task_status = $current_task_status[0]; |
| 98 | + if ( $current_task_status == "Closed" && self::$task_status != "Closed" ) { |
| 99 | + $close_mailto = self::getAssigneeAddresses( $copies ); |
| 100 | + self::mailNotification( $close_mailto, $text, $title, $user, CLOSED ); |
| 101 | + } |
| 102 | + } |
| 103 | + |
83 | 104 | $mailto = array_merge( $current_assignees, $copies, $groups ); |
84 | 105 | $mailto = array_unique( $mailto ); |
85 | 106 | $mailto = self::getAssigneeAddresses( $mailto ); |
— | — | @@ -90,9 +111,9 @@ |
91 | 112 | } |
92 | 113 | |
93 | 114 | /** |
94 | | - * Returns an array of assignees based on $query_word |
95 | | - * @param $query_word String: the property that designate the users to notify. |
96 | | - */ |
| 115 | + * Returns an array of properties based on $query_word |
| 116 | + * @param $query_word String: the property that designate the users to notify. |
| 117 | + */ |
97 | 118 | function getAssignees( $query_word, $title_text, $user ) { |
98 | 119 | // Array of assignees to return |
99 | 120 | $assignee_arr = array(); |
— | — | @@ -123,9 +144,41 @@ |
124 | 145 | } |
125 | 146 | |
126 | 147 | /** |
127 | | - * Returns an array of assignees based on $query_word |
128 | | - * @param $query_word String: the property that designate the users to notify. |
129 | | - */ |
| 148 | + * Returns an array of properties based on $query_word |
| 149 | + * @param $query_word String: the property that designate the users to notify. |
| 150 | + */ |
| 151 | + function getStatus( $query_word, $title_text, $user ) { |
| 152 | + // Array of assignees to return |
| 153 | + $assignee_arr = array(); |
| 154 | + |
| 155 | + // get the result of the query "[[$title]][[$query_word::+]]" |
| 156 | + $properties_to_display = array(); |
| 157 | + $properties_to_display[0] = $query_word; |
| 158 | + $results = self::getQueryResults( "[[$title_text]][[$query_word::+]]", $properties_to_display, false ); |
| 159 | + |
| 160 | + // In theory, there is only one row |
| 161 | + while ( $row = $results->getNext() ) { |
| 162 | + $task_assignees = $row[0]; |
| 163 | + } |
| 164 | + |
| 165 | + // If not any row, do nothing |
| 166 | + if ( !empty( $task_assignees ) ) { |
| 167 | + while ( $task_assignee = $task_assignees->getNextObject() ) { |
| 168 | + $assignee_name = $task_assignee->getWikiValue(); |
| 169 | + $assignee_name = $assignee_name; |
| 170 | + |
| 171 | + array_push( $assignee_arr, $assignee_name ); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + return $assignee_arr; |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + /** |
| 180 | + * Returns an array of assignees based on $query_word |
| 181 | + * @param $query_word String: the property that designate the users to notify. |
| 182 | + */ |
130 | 183 | function getGroupAssignees( $query_word, $title_text, $user ) { |
131 | 184 | // Array of assignees to return |
132 | 185 | $assignee_arr = array(); |
— | — | @@ -177,17 +230,20 @@ |
178 | 231 | $assignee_arr = array(); |
179 | 232 | foreach ( $assignees as $assignee_name ) { |
180 | 233 | $assignee = User::newFromName( $assignee_name ); |
181 | | - $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name ); |
182 | | - array_push( $assignee_arr, $assignee_mail ); |
183 | | - self::printDebug( $assignee_name ); |
| 234 | + // if assignee is the current user, do nothing |
| 235 | + #if ( $assignee->getID() != $user->getID() ) { |
| 236 | + $assignee_mail = new MailAddress( $assignee->getEmail(), $assignee_name ); |
| 237 | + array_push( $assignee_arr, $assignee_mail ); |
| 238 | + self::printDebug( $assignee_name ); |
| 239 | + #} |
184 | 240 | } |
185 | 241 | |
186 | 242 | return $assignee_arr; |
187 | 243 | } |
188 | 244 | |
189 | 245 | /** |
190 | | - * Sends mail notifications |
191 | | - */ |
| 246 | + * Sends mail notifications |
| 247 | + */ |
192 | 248 | function mailNotification( $assignees, $text, $title, $user, $status ) { |
193 | 249 | global $wgSitename; |
194 | 250 | |
— | — | @@ -209,6 +265,11 @@ |
210 | 266 | $message = 'semantictasks-updatedtoyou-msg2'; |
211 | 267 | $body = wfMsg( $message , $title_text ) . " " . $link; |
212 | 268 | $body .= "\n \n" . wfMsg( 'semantictasks-diff-message' ) . "\n" . self::generateDiffBodyTxt( $title ); |
| 269 | + } else if ( $status == CLOSED ) { |
| 270 | + $subject = '[' . $wgSitename . '] ' . wfMsg( 'semantictasks-taskclosed' ) . ' ' . $title_text; |
| 271 | + $message = 'semantictasks-taskclosed-msg'; |
| 272 | + $body = wfMsg( $message , $title_text ) . " " . $link; |
| 273 | + $body .= "\n \n" . wfMsg( 'semantictasks-text-message' ) . "\n" . $text; |
213 | 274 | } else { |
214 | 275 | //status == ASSIGNED |
215 | 276 | $subject = '[' . $wgSitename . '] ' . wfMsg( 'semantictasks-taskassigned' ) . ' ' . $title_text; |
— | — | @@ -224,10 +285,10 @@ |
225 | 286 | } |
226 | 287 | |
227 | 288 | /** |
228 | | - * Generates a diff txt |
229 | | - * @param Title $title |
230 | | - * @return string |
231 | | - */ |
| 289 | + * Generates a diff txt |
| 290 | + * @param Title $title |
| 291 | + * @return string |
| 292 | + */ |
232 | 293 | function generateDiffBodyTxt( $title ) { |
233 | 294 | $revision = Revision::newFromTitle( $title, 0 ); |
234 | 295 | $diff = new DifferenceEngine( $title, $revision->getId(), 'prev' ); |
— | — | @@ -247,13 +308,13 @@ |
248 | 309 | } |
249 | 310 | |
250 | 311 | /** |
251 | | - * This function returns to results of a certain query |
252 | | - * Thank you Yaron Koren for advices concerning this code |
253 | | - * @param $query_string String : the query |
254 | | - * @param $properties_to_display array(String): array of property names to display |
255 | | - * @param $display_title Boolean : add the page title in the result |
256 | | - * @return TODO |
257 | | -*/ |
| 312 | + * This function returns to results of a certain query |
| 313 | + * Thank you Yaron Koren for advices concerning this code |
| 314 | + * @param $query_string String : the query |
| 315 | + * @param $properties_to_display array(String): array of property names to display |
| 316 | + * @param $display_title Boolean : add the page title in the result |
| 317 | + * @return TODO |
| 318 | + */ |
258 | 319 | function getQueryResults( $query_string, $properties_to_display, $display_title ) { |
259 | 320 | // i18n |
260 | 321 | wfLoadExtensionMessages( 'SemanticTasks' ); |
— | — | @@ -352,8 +413,8 @@ |
353 | 414 | */ |
354 | 415 | function printDebug( $debugText, $debugArr = null ) { |
355 | 416 | global $wgSemanticTasksDebug; |
356 | | - |
357 | | - if ( $wgSemanticTasksDebug ) { |
| 417 | + |
| 418 | + if ( $wgSemanticTasksDebug ) { |
358 | 419 | if ( isset( $debugArr ) ) { |
359 | 420 | $text = $debugText . " " . implode( "::", $debugArr ); |
360 | 421 | wfDebugLog( 'semantic-tasks', $text, false ); |
Index: trunk/extensions/SemanticTasks/SemanticTasks.i18n.php |
— | — | @@ -14,7 +14,9 @@ |
15 | 15 | 'semantictasks-newtask' => 'New task:', |
16 | 16 | 'semantictasks-taskassigned' => 'Task assigned:', |
17 | 17 | 'semantictasks-taskupdated' => 'Task updated:', |
| 18 | + 'semantictasks-taskclosed' => 'Task closed:', |
18 | 19 | 'semantictasks-newtask-msg' => 'The task "$1" has just been created.', |
| 20 | + 'semantictasks-taskclosed-msg' => 'The task "$1" has just been closed.', |
19 | 21 | 'semantictasks-assignedtoyou-msg2' => 'The task "$1" has just been assigned to you.', |
20 | 22 | 'semantictasks-updatedtoyou-msg2' => 'The task "$1" has just been updated.', |
21 | 23 | 'semantictasks-reminder' => 'Reminder:', |