Index: trunk/extensions/Contest/api/ApiMailContestants.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | parent::__construct( $main, $action ); |
20 | 20 | } |
21 | 21 | |
| 22 | + // TODO |
22 | 23 | public function execute() { |
23 | 24 | global $wgUser; |
24 | 25 | |
— | — | @@ -29,19 +30,35 @@ |
30 | 31 | |
31 | 32 | $everythingOk = true; |
32 | 33 | |
33 | | - $contestIds = array(); |
34 | | - $challengeIds = array(); |
| 34 | + $contestIds = is_null( $params['contestids'] ) ? array() : $params['contestids']; |
| 35 | + $challengeIds = is_null( $params['challengeids'] ) ? array() : $params['challengeids']; |
35 | 36 | |
36 | | - if ( !is_null( 'challengetitles' ) ) { |
| 37 | + if ( !is_null( $params['challengetitles'] ) ) { |
| 38 | + $challenges = ContestChallenge::s()->select( 'id', array( 'title' => $params['challengetitles'] ) ); |
37 | 39 | |
| 40 | + if ( $challenges === false ) { |
| 41 | + // TODO: error |
| 42 | + } |
| 43 | + |
| 44 | + foreach ( $challenges as /* ContestChallenge */ $challenge ) { |
| 45 | + $challengeIds[] = $challenge->getId(); |
| 46 | + } |
38 | 47 | } |
39 | 48 | |
40 | | - if ( !is_null( 'contestnames' ) ) { |
| 49 | + if ( !is_null( $params['contestnames'] ) ) { |
| 50 | + $contests = Contest::s()->select( 'id', array( 'name' => $params['contestnames'] ) ); |
41 | 51 | |
| 52 | + if ( $contests === false ) { |
| 53 | + // TODO: error |
| 54 | + } |
| 55 | + |
| 56 | + foreach ( $contests as /* Contest */ $contest ) { |
| 57 | + $contestIds[] = $contest->getId(); |
| 58 | + } |
42 | 59 | } |
43 | 60 | |
44 | 61 | $conditions = array(); |
45 | | - // TODO |
| 62 | + |
46 | 63 | if ( count( $contestIds ) > 0 ) { |
47 | 64 | $conditions[] = array( 'contest_id' => $contestIds ); |
48 | 65 | } |
— | — | @@ -60,11 +77,18 @@ |
61 | 78 | $recipients = array(); |
62 | 79 | |
63 | 80 | foreach ( $contestants as /* ContestContestant */ $contestant ) { |
64 | | - $recipients[] = $contestant->getField( 'email' ); |
| 81 | + $recipients[] = new MailAddress( $contestant->getField( 'email' ) ); |
65 | 82 | } |
66 | 83 | |
67 | | - $everythingOk = $this->sendReminderEmail( $recipients ); |
| 84 | + $everythingOk = $this->sendReminderEmail( |
| 85 | + ContestUtils::getParsedArticleContent( $params['page'] ), // TODO: have some magic here for params such as daysleft |
| 86 | + $recipients, |
| 87 | + array( 'daysleft' => $this->getContest()->getDaysLeft() ) |
| 88 | + ); |
68 | 89 | } |
| 90 | + else { |
| 91 | + // TODO: error |
| 92 | + } |
69 | 93 | |
70 | 94 | $this->getResult()->addValue( |
71 | 95 | null, |
— | — | @@ -80,21 +104,22 @@ |
81 | 105 | * |
82 | 106 | * @since 0.1 |
83 | 107 | * |
| 108 | + * @param string $emailText |
| 109 | + * @param array $recipients |
| 110 | + * |
84 | 111 | * @return Status |
85 | 112 | */ |
86 | | - public function sendReminderEmail( array $recipients ) { |
| 113 | + public function sendReminderEmail( $emailText, array /* of MailAddress */ $recipients, array $params ) { |
87 | 114 | global $wgPasswordSender, $wgPasswordSenderName; |
88 | 115 | |
89 | | - $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $this->getContest()->getDaysLeft() ); |
90 | | - $emailText = ContestUtils::getParsedArticleContent( $this->getContest()->getField( 'reminder_email' ) ); |
91 | | - $user = $this->getUser(); |
| 116 | + $title = wfMsgExt( 'contest-email-reminder-title', 'parsemag', $params['daysleft'] ); |
92 | 117 | $sender = $wgPasswordSender; |
93 | 118 | $senderName = $wgPasswordSenderName; |
94 | 119 | |
95 | | - wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$user, &$sender, &$senderName ) ); |
| 120 | + wfRunHooks( 'ContestBeforeReminderEmail', array( &$this, &$title, &$emailText, &$recipients, &$sender, &$senderName ) ); |
96 | 121 | |
97 | 122 | return UserMailer::send( |
98 | | - new MailAddress( $user ), |
| 123 | + $recipients, |
99 | 124 | new MailAddress( $sender, $senderName ), |
100 | 125 | $title, |
101 | 126 | $emailText, |
— | — | @@ -118,6 +143,11 @@ |
119 | 144 | */ |
120 | 145 | public function getAllowedParams() { |
121 | 146 | return array( |
| 147 | + 'page' => array( |
| 148 | + ApiBase::PARAM_TYPE => 'string', |
| 149 | + ApiBase::PARAM_REQUIRED => true, |
| 150 | + ApiBase::PARAM_ISMULTI => false, |
| 151 | + ), |
122 | 152 | 'ids' => array( |
123 | 153 | ApiBase::PARAM_TYPE => 'integer', |
124 | 154 | ApiBase::PARAM_REQUIRED => false, |
— | — | @@ -149,14 +179,20 @@ |
150 | 180 | |
151 | 181 | public function getParamDescription() { |
152 | 182 | return array( |
| 183 | + 'page' => 'Name of the page from which to pull content for the email body', |
153 | 184 | 'ids' => 'The IDs of the contestants to mail', |
| 185 | + 'contestids' => 'The IDs of the contests where of the contestants should be mailed', |
| 186 | + 'contestnames' => 'The names of the contests where of the contestants should be mailed', |
| 187 | + 'challengeids' => 'The IDs of the challenges where of the contestants should be mailed', |
| 188 | + 'challengetitles' => 'The titles of the challenges where of the contestants should be mailed', |
154 | 189 | 'token' => 'Edit token', |
155 | 190 | ); |
156 | 191 | } |
157 | 192 | |
158 | 193 | public function getDescription() { |
159 | 194 | return array( |
160 | | - 'API module for mailing contestants. The provided conditions such as contest ids and challenge titles will be joined with AND.' |
| 195 | + 'API module for mailing contestants. Selection criteria will be joined with AND, |
| 196 | + except for the challange ids/titles and contest ids/names pairs, which will be joined wit OR.' |
161 | 197 | ); |
162 | 198 | } |
163 | 199 | |