Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | */ |
33 | class CRM_PCP_BAO_PCP extends CRM_PCP_DAO_PCP { | |
34 | ||
35 | /** | |
eceb18cc | 36 | * The action links that we need to display for the browse screen. |
6a488035 TO |
37 | * |
38 | * @var array | |
6a488035 TO |
39 | */ |
40 | static $_pcpLinks = NULL; | |
9d9922e7 | 41 | |
e0ef6999 | 42 | /** |
ad37ac8e | 43 | * Class constructor. |
e0ef6999 | 44 | */ |
00be9182 | 45 | public function __construct() { |
6a488035 TO |
46 | parent::__construct(); |
47 | } | |
48 | ||
49 | /** | |
eceb18cc | 50 | * Add or update either a Personal Campaign Page OR a PCP Block. |
6a488035 | 51 | * |
db95eff6 TO |
52 | * @param array $params |
53 | * Reference array contains the values submitted by the form. | |
54 | * @param bool $pcpBlock | |
55 | * If true, create or update PCPBlock, else PCP. | |
d75f2f47 | 56 | * |
6a488035 TO |
57 | * @return object |
58 | */ | |
00be9182 | 59 | public static function add(&$params, $pcpBlock = TRUE) { |
6a488035 TO |
60 | if ($pcpBlock) { |
61 | // action is taken depending upon the mode | |
62 | $dao = new CRM_PCP_DAO_PCPBlock(); | |
63 | $dao->copyValues($params); | |
64 | $dao->save(); | |
65 | return $dao; | |
66 | } | |
67 | ||
68 | $dao = new CRM_PCP_DAO_PCP(); | |
69 | $dao->copyValues($params); | |
70 | ||
71 | // ensure we set status_id since it is a not null field | |
72 | // we should change the schema and allow this to be null | |
73 | if (!$dao->id && !isset($dao->status_id)) { | |
74 | $dao->status_id = 0; | |
75 | } | |
76 | ||
77 | // set currency for CRM-1496 | |
78 | if (!isset($dao->currency)) { | |
353ffa53 | 79 | $config = &CRM_Core_Config::singleton(); |
9d9922e7 | 80 | $dao->currency = $config->defaultCurrency; |
6a488035 TO |
81 | } |
82 | ||
83 | $dao->save(); | |
84 | return $dao; | |
85 | } | |
86 | ||
87 | /** | |
eceb18cc | 88 | * Get the Display name of a contact for a PCP. |
6a488035 | 89 | * |
db95eff6 TO |
90 | * @param int $id |
91 | * Id for the PCP. | |
6a488035 | 92 | * |
72b3a70c CW |
93 | * @return null|string |
94 | * Dispaly name of the contact if found | |
6a488035 | 95 | */ |
00be9182 | 96 | public static function displayName($id) { |
6a488035 TO |
97 | $id = CRM_Utils_Type::escape($id, 'Integer'); |
98 | ||
99 | $query = " | |
100 | SELECT civicrm_contact.display_name | |
101 | FROM civicrm_pcp, civicrm_contact | |
102 | WHERE civicrm_pcp.contact_id = civicrm_contact.id | |
103 | AND civicrm_pcp.id = {$id} | |
104 | "; | |
9d2678f4 | 105 | return CRM_Core_DAO::singleValueQuery($query); |
6a488035 TO |
106 | } |
107 | ||
108 | /** | |
eceb18cc | 109 | * Return PCP Block info for dashboard. |
6a488035 | 110 | * |
100fef9d | 111 | * @param int $contactId |
dd244018 | 112 | * |
a6c01b45 CW |
113 | * @return array |
114 | * array of Pcp if found | |
6a488035 | 115 | */ |
00be9182 | 116 | public static function getPcpDashboardInfo($contactId) { |
6a488035 TO |
117 | $links = self::pcpLinks(); |
118 | ||
119 | $query = " | |
120 | SELECT * FROM civicrm_pcp pcp | |
6da0be4d | 121 | LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id |
6a488035 TO |
122 | WHERE pcp.is_active = 1 |
123 | AND pcp.contact_id = %1 | |
124 | ORDER BY page_type, page_id"; | |
125 | ||
126 | $params = array(1 => array($contactId, 'Integer')); | |
127 | ||
9d9922e7 | 128 | $pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params); |
129 | $pcpInfo = array(); | |
130 | $hide = $mask = array_sum(array_keys($links['all'])); | |
6a488035 TO |
131 | $contactPCPPages = array(); |
132 | ||
9d9922e7 | 133 | $event = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); |
6a488035 | 134 | $contribute = CRM_Contribute_PseudoConstant::contributionPage(); |
9d9922e7 | 135 | $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus(); |
136 | $approved = CRM_Utils_Array::key('Approved', $pcpStatus); | |
6a488035 TO |
137 | |
138 | while ($pcpInfoDao->fetch()) { | |
139 | $mask = $hide; | |
140 | if ($links) { | |
141 | $replace = array( | |
142 | 'pcpId' => $pcpInfoDao->id, | |
143 | 'pcpBlock' => $pcpInfoDao->pcp_block_id, | |
144 | 'pageComponent' => $pcpInfoDao->page_type, | |
145 | ); | |
146 | } | |
147 | ||
148 | $pcpLink = $links['all']; | |
149 | $class = ''; | |
150 | ||
151 | if ($pcpInfoDao->status_id != $approved || $pcpInfoDao->is_active != 1) { | |
152 | $class = 'disabled'; | |
6da0be4d | 153 | if (!$pcpInfoDao->is_tellfriend_enabled) { |
6a488035 TO |
154 | $mask -= CRM_Core_Action::DETACH; |
155 | } | |
156 | } | |
157 | ||
158 | if ($pcpInfoDao->is_active == 1) { | |
159 | $mask -= CRM_Core_Action::ENABLE; | |
160 | } | |
161 | else { | |
162 | $mask -= CRM_Core_Action::DISABLE; | |
163 | } | |
87dab4a4 AH |
164 | $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), |
165 | FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id); | |
6a488035 TO |
166 | $component = $pcpInfoDao->page_type; |
167 | $pageTitle = CRM_Utils_Array::value($pcpInfoDao->page_id, $$component); | |
168 | ||
169 | $pcpInfo[] = array( | |
170 | 'pageTitle' => $pageTitle, | |
171 | 'pcpId' => $pcpInfoDao->id, | |
172 | 'pcpTitle' => $pcpInfoDao->title, | |
173 | 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id], | |
174 | 'action' => $action, | |
175 | 'class' => $class, | |
176 | ); | |
177 | $contactPCPPages[$pcpInfoDao->page_type][] = $pcpInfoDao->page_id; | |
178 | } | |
179 | ||
180 | $excludePageClause = $clause = NULL; | |
181 | if (!empty($contactPCPPages)) { | |
182 | foreach ($contactPCPPages as $component => $entityIds) { | |
183 | $excludePageClause[] = " | |
184 | ( target_entity_type = '{$component}' | |
185 | AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )"; | |
186 | } | |
187 | ||
188 | $clause = ' AND ' . implode(' OR ', $excludePageClause); | |
189 | } | |
190 | ||
191 | $query = " | |
e5cceea5 | 192 | SELECT block.target_entity_type, block.target_entity_id |
6a488035 TO |
193 | FROM civicrm_pcp_block block |
194 | LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id | |
195 | WHERE block.is_active = 1 | |
196 | {$clause} | |
e5cceea5 | 197 | GROUP BY block.id, block.target_entity_type, block.target_entity_id |
6a488035 TO |
198 | ORDER BY target_entity_type, target_entity_id |
199 | "; | |
200 | $pcpBlockDao = CRM_Core_DAO::executeQuery($query); | |
9d9922e7 | 201 | $pcpBlock = array(); |
202 | $mask = 0; | |
6a488035 TO |
203 | |
204 | while ($pcpBlockDao->fetch()) { | |
205 | if ($links) { | |
206 | $replace = array( | |
207 | 'pageId' => $pcpBlockDao->target_entity_id, | |
208 | 'pageComponent' => $pcpBlockDao->target_entity_type, | |
209 | ); | |
210 | } | |
9d9922e7 | 211 | $pcpLink = $links['add']; |
87dab4a4 AH |
212 | $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'), |
213 | FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id); | |
9d9922e7 | 214 | $component = $pcpBlockDao->target_entity_type; |
6167c3d3 BS |
215 | if ($pageTitle = CRM_Utils_Array::value($pcpBlockDao->target_entity_id, $$component)) { |
216 | $pcpBlock[] = array( | |
217 | 'pageId' => $pcpBlockDao->target_entity_id, | |
218 | 'pageTitle' => $pageTitle, | |
219 | 'action' => $action, | |
220 | ); | |
221 | } | |
6a488035 TO |
222 | } |
223 | ||
224 | return array($pcpBlock, $pcpInfo); | |
225 | } | |
226 | ||
227 | /** | |
eceb18cc | 228 | * Show the total amount for Personal Campaign Page on thermometer. |
6a488035 | 229 | * |
db95eff6 TO |
230 | * @param array $pcpId |
231 | * Contains the pcp ID. | |
6a488035 | 232 | * |
ad37ac8e | 233 | * @return float |
234 | * Total amount | |
6a488035 | 235 | */ |
00be9182 | 236 | public static function thermoMeter($pcpId) { |
6a488035 TO |
237 | $query = " |
238 | SELECT SUM(cc.total_amount) as total | |
239 | FROM civicrm_pcp pcp | |
240 | LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id ) | |
241 | LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id) | |
242 | WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0"; | |
243 | ||
244 | $params = array(1 => array($pcpId, 'Integer')); | |
245 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
246 | } | |
247 | ||
248 | /** | |
ad37ac8e | 249 | * Show the amount, nickname on honor roll. |
6a488035 | 250 | * |
db95eff6 TO |
251 | * @param array $pcpId |
252 | * Contains the pcp ID. | |
6a488035 | 253 | * |
a6c01b45 | 254 | * @return array |
6a488035 | 255 | */ |
00be9182 | 256 | public static function honorRoll($pcpId) { |
6a488035 TO |
257 | $query = " |
258 | SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note, | |
259 | cc.total_amount, cc.currency | |
260 | FROM civicrm_contribution cc | |
261 | LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id | |
262 | WHERE cs.pcp_id = {$pcpId} | |
263 | AND cs.pcp_display_in_roll = 1 | |
264 | AND contribution_status_id = 1 | |
265 | AND is_test = 0"; | |
9d2678f4 | 266 | $dao = CRM_Core_DAO::executeQuery($query); |
6a488035 TO |
267 | $honor = array(); |
268 | while ($dao->fetch()) { | |
269 | $honor[$dao->id]['nickname'] = ucwords($dao->pcp_roll_nickname); | |
270 | $honor[$dao->id]['total_amount'] = CRM_Utils_Money::format($dao->total_amount, $dao->currency); | |
271 | $honor[$dao->id]['personal_note'] = $dao->pcp_personal_note; | |
272 | } | |
273 | return $honor; | |
274 | } | |
275 | ||
276 | /** | |
eceb18cc | 277 | * Get action links. |
6a488035 | 278 | * |
a6c01b45 CW |
279 | * @return array |
280 | * (reference) of action links | |
6a488035 | 281 | */ |
00be9182 | 282 | public static function &pcpLinks() { |
6a488035 TO |
283 | if (!(self::$_pcpLinks)) { |
284 | $deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.'); | |
285 | ||
286 | self::$_pcpLinks['add'] = array( | |
9d9922e7 | 287 | CRM_Core_Action::ADD => array( |
288 | 'name' => ts('Create a Personal Campaign Page'), | |
cbc1fad4 | 289 | 'class' => 'no-popup', |
6a488035 TO |
290 | 'url' => 'civicrm/contribute/campaign', |
291 | 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%', | |
292 | 'title' => ts('Configure'), | |
293 | ), | |
294 | ); | |
295 | ||
296 | self::$_pcpLinks['all'] = array( | |
9d9922e7 | 297 | CRM_Core_Action::UPDATE => array( |
298 | 'name' => ts('Edit Your Page'), | |
6a488035 TO |
299 | 'url' => 'civicrm/pcp/info', |
300 | 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
301 | 'title' => ts('Configure'), | |
302 | ), | |
9d9922e7 | 303 | CRM_Core_Action::DETACH => array( |
304 | 'name' => ts('Tell Friends'), | |
6a488035 TO |
305 | 'url' => 'civicrm/friend', |
306 | 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%', | |
307 | 'title' => ts('Tell Friends'), | |
308 | ), | |
ff06e012 DG |
309 | CRM_Core_Action::VIEW => array( |
310 | 'name' => ts('URL for this Page'), | |
311 | 'url' => 'civicrm/pcp/info', | |
312 | 'qs' => 'reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
313 | 'title' => ts('URL for this Page'), | |
314 | ), | |
9d9922e7 | 315 | CRM_Core_Action::BROWSE => array( |
316 | 'name' => ts('Update Contact Information'), | |
6a488035 TO |
317 | 'url' => 'civicrm/pcp/info', |
318 | 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
319 | 'title' => ts('Update Contact Information'), | |
320 | ), | |
9d9922e7 | 321 | CRM_Core_Action::ENABLE => array( |
322 | 'name' => ts('Enable'), | |
6a488035 TO |
323 | 'url' => 'civicrm/pcp', |
324 | 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
325 | 'title' => ts('Enable'), | |
326 | ), | |
9d9922e7 | 327 | CRM_Core_Action::DISABLE => array( |
328 | 'name' => ts('Disable'), | |
6a488035 TO |
329 | 'url' => 'civicrm/pcp', |
330 | 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
331 | 'title' => ts('Disable'), | |
332 | ), | |
9d9922e7 | 333 | CRM_Core_Action::DELETE => array( |
334 | 'name' => ts('Delete'), | |
6a488035 TO |
335 | 'url' => 'civicrm/pcp', |
336 | 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%', | |
337 | 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"', | |
338 | 'title' => ts('Delete'), | |
339 | ), | |
340 | ); | |
341 | } | |
342 | return self::$_pcpLinks; | |
343 | } | |
344 | ||
345 | /** | |
eceb18cc | 346 | * Delete the campaign page. |
6a488035 | 347 | * |
ad37ac8e | 348 | * @param int $id |
db95eff6 | 349 | * Campaign page id. |
6a488035 TO |
350 | */ |
351 | public static function deleteById($id) { | |
352 | CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray); | |
353 | ||
354 | $transaction = new CRM_Core_Transaction(); | |
355 | ||
356 | // delete from pcp table | |
357 | $pcp = new CRM_PCP_DAO_PCP(); | |
358 | $pcp->id = $id; | |
359 | $pcp->delete(); | |
360 | ||
361 | $transaction->commit(); | |
362 | ||
363 | CRM_Utils_Hook::post('delete', 'Campaign', $id, $pcp); | |
364 | } | |
365 | ||
366 | /** | |
eceb18cc | 367 | * Build the form object. |
6a488035 | 368 | * |
db95eff6 TO |
369 | * @param CRM_Core_Form $form |
370 | * Form object. | |
6a488035 | 371 | */ |
cad004cf | 372 | public static function buildPCPForm($form) { |
6a488035 TO |
373 | $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);")); |
374 | ||
375 | $form->addElement('checkbox', 'is_approval_needed', ts('Approval required')); | |
376 | ||
9d9922e7 | 377 | $profile = array(); |
6a488035 | 378 | $isUserRequired = NULL; |
9d9922e7 | 379 | $config = CRM_Core_Config::singleton(); |
6a488035 TO |
380 | if ($config->userFramework != 'Standalone') { |
381 | $isUserRequired = 2; | |
382 | } | |
9d9922e7 | 383 | CRM_Core_DAO::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array( |
384 | 'title', | |
21dfd5f5 | 385 | 'is_active', |
9d9922e7 | 386 | )); |
6a488035 TO |
387 | if (!empty($profiles)) { |
388 | foreach ($profiles as $key => $value) { | |
389 | if ($value['is_active']) { | |
390 | $profile[$key] = $value['title']; | |
391 | } | |
392 | } | |
393 | $form->assign('profile', $profile); | |
394 | } | |
395 | ||
a33733e6 | 396 | $form->add('select', 'supporter_profile_id', ts('Supporter Profile'), array('' => ts('- select -')) + $profile, TRUE); |
6a488035 | 397 | |
12f92dbd N |
398 | //CRM-15821 - To add new option for PCP "Owner" notification |
399 | $ownerNotifications = CRM_Core_OptionGroup::values('pcp_owner_notify'); | |
5798d2ec | 400 | $form->addRadio('owner_notify_id', ts('Owner Email Notification'), $ownerNotifications, NULL, '<br/>', TRUE); |
12f92dbd | 401 | |
6a488035 TO |
402 | $form->addElement('checkbox', 'is_tellfriend_enabled', ts("Allow 'Tell a friend' functionality"), NULL, array('onclick' => "return showHideByValue('is_tellfriend_enabled',true,'tflimit','table-row','radio',false);")); |
403 | ||
404 | $form->add('text', | |
405 | 'tellfriend_limit', | |
406 | ts("'Tell a friend' maximum recipients limit"), | |
407 | CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit') | |
408 | ); | |
409 | $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer'); | |
410 | ||
411 | $form->add('text', | |
412 | 'link_text', | |
413 | ts("'Create Personal Campaign Page' link text"), | |
414 | CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text') | |
415 | ); | |
416 | ||
417 | $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email')); | |
418 | } | |
419 | ||
420 | ||
e0ef6999 | 421 | /** |
eceb18cc | 422 | * Add PCP form elements to a form. |
d424ffde | 423 | * |
db95eff6 | 424 | * @param int $pcpId |
d75f2f47 | 425 | * @param CRM_Core_Page $page |
e0ef6999 EM |
426 | * @param null $elements |
427 | */ | |
5fe87df6 | 428 | public static function buildPcp($pcpId, &$page, &$elements = NULL) { |
6a488035 TO |
429 | |
430 | $prms = array('id' => $pcpId); | |
431 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); | |
6a488035 TO |
432 | if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($pcpId)) { |
433 | if ($pcpInfo['page_type'] == 'event') { | |
5fe87df6 | 434 | $pcp_supporter_text = ts('This event registration is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter)); |
eea141c0 | 435 | $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'event'); |
22e263ad | 436 | if (!empty($text)) { |
eea141c0 DG |
437 | $pcp_supporter_text .= "You can support it as well - once you complete the registration, you will be able to create your own Personal Campaign Page!"; |
438 | } | |
6a488035 TO |
439 | } |
440 | else { | |
5fe87df6 | 441 | $pcp_supporter_text = ts('This contribution is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter)); |
eea141c0 | 442 | $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'contribute'); |
22e263ad | 443 | if (!empty($text)) { |
eea141c0 DG |
444 | $pcp_supporter_text .= "You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!"; |
445 | } | |
6a488035 | 446 | } |
77b97be7 | 447 | |
eea141c0 | 448 | $page->assign('pcpSupporterText', $pcp_supporter_text); |
6a488035 TO |
449 | } |
450 | $page->assign('pcp', TRUE); | |
451 | ||
452 | // build honor roll fields for registration form if supporter has honor roll enabled for their PCP | |
453 | if ($pcpInfo['is_honor_roll']) { | |
454 | $page->assign('is_honor_roll', TRUE); | |
455 | $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL, | |
456 | array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );") | |
457 | ); | |
458 | $extraOption = array('onclick' => "return pcpAnonymous( );"); | |
9d9922e7 | 459 | $elements = array(); |
353ffa53 TO |
460 | $elements[] = &$page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption); |
461 | $elements[] = &$page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption); | |
6a488035 TO |
462 | $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' '); |
463 | $page->_defaults['pcp_is_anonymous'] = 0; | |
464 | ||
465 | $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); | |
466 | $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); | |
467 | } | |
468 | else { | |
469 | $page->assign('is_honor_roll', FALSE); | |
470 | } | |
471 | } | |
472 | ||
e0ef6999 | 473 | /** |
eceb18cc | 474 | * Process a PCP contribution. |
d424ffde | 475 | * |
100fef9d | 476 | * @param int $pcpId |
ad37ac8e | 477 | * @param string $component |
478 | * @param string $entity | |
e0ef6999 EM |
479 | * |
480 | * @return array | |
481 | */ | |
9d9922e7 | 482 | public static function handlePcp($pcpId, $component, $entity) { |
6a488035 | 483 | |
9d9922e7 | 484 | self::getPcpEntityTable($component); |
6a488035 TO |
485 | |
486 | if (!$pcpId) { | |
487 | return FALSE; | |
488 | } | |
489 | ||
490 | $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); | |
491 | ||
2158332a | 492 | $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); |
6a488035 TO |
493 | |
494 | $params = array('id' => $pcpId); | |
495 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); | |
496 | ||
497 | $params = array('id' => $pcpInfo['pcp_block_id']); | |
498 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock); | |
499 | ||
500 | $params = array('id' => $pcpInfo['page_id']); | |
9d9922e7 | 501 | $now = time(); |
6a488035 TO |
502 | |
503 | if ($component == 'event') { | |
504 | // figure out where to redirect if an exception occurs below based on target entity | |
505 | $urlBase = 'civicrm/event/register'; | |
506 | ||
507 | // ignore startDate for events - PCP's can be active long before event start date | |
508 | $startDate = 0; | |
9d9922e7 | 509 | $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity)); |
6a488035 | 510 | } |
6a488035 TO |
511 | elseif ($component == 'contribute') { |
512 | $urlBase = 'civicrm/contribute/transact'; | |
513 | //start and end date of the contribution page | |
514 | $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $entity)); | |
9d9922e7 | 515 | $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity)); |
6a488035 TO |
516 | } |
517 | ||
518 | // define redirect url back to contrib page or event if needed | |
481a74f4 | 519 | $url = CRM_Utils_System::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE); |
6a488035 TO |
520 | |
521 | if ($pcpBlock['target_entity_id'] != $entity['id']) { | |
522 | $statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.'); | |
523 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
524 | } | |
525 | elseif ($pcpInfo['status_id'] != $approvedId) { | |
526 | $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign here.', array(1 => $pcpStatus[$pcpInfo['status_id']])); | |
527 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
528 | } | |
a7488080 | 529 | elseif (empty($pcpBlock['is_active'])) { |
6a488035 TO |
530 | $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.'); |
531 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
532 | } | |
a7488080 | 533 | elseif (empty($pcpInfo['is_active'])) { |
6a488035 TO |
534 | $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.'); |
535 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
536 | } | |
537 | // Check if we're in range for contribution page start and end dates. for events, check if after event end date | |
538 | elseif (($startDate && $startDate > $now) || ($endDate && $endDate < $now)) { | |
539 | $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $entity)); | |
540 | $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $entity)); | |
541 | if ($startDate && $endDate) { | |
542 | $statusMessage = ts('The Personal Campaign Page you have just visited is only active from %1 to %2. However you can still support the campaign here.', | |
543 | array(1 => $customStartDate, 2 => $customEndDate) | |
544 | ); | |
545 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
546 | } | |
547 | elseif ($startDate) { | |
548 | $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign here.', array(1 => $customStartDate)); | |
549 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
550 | } | |
551 | elseif ($endDate) { | |
552 | if ($component == 'event') { | |
553 | // Target_entity is an event and the event is over, redirect to event info instead of event registration page. | |
554 | $url = CRM_Utils_System::url('civicrm/event/info', | |
555 | "reset=1&id={$pcpBlock['entity_id']}", | |
556 | FALSE, NULL, FALSE, TRUE | |
557 | ); | |
558 | $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate)); | |
559 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
9d9922e7 | 560 | } |
561 | else { | |
6a488035 TO |
562 | $statusMessage = ts('The Personal Campaign Page you have just visited is no longer active (as of %1). However you can still support the campaign here.', array(1 => $customEndDate)); |
563 | CRM_Core_Error::statusBounce($statusMessage, $url); | |
564 | } | |
565 | } | |
566 | } | |
567 | ||
568 | return array( | |
569 | 'pcpId' => $pcpId, | |
570 | 'pcpBlock' => $pcpBlock, | |
571 | 'pcpInfo' => $pcpInfo, | |
572 | ); | |
573 | } | |
574 | ||
575 | /** | |
54957108 | 576 | * Approve / Reject the campaign page. |
6a488035 | 577 | * |
db95eff6 TO |
578 | * @param int $id |
579 | * Campaign page id. | |
6a488035 | 580 | * |
ad37ac8e | 581 | * @param bool $is_active |
6a488035 | 582 | */ |
00be9182 | 583 | public static function setIsActive($id, $is_active) { |
6a488035 TO |
584 | switch ($is_active) { |
585 | case 0: | |
586 | $is_active = 3; | |
587 | break; | |
588 | ||
589 | case 1: | |
590 | $is_active = 2; | |
591 | break; | |
592 | } | |
593 | ||
594 | CRM_Core_DAO::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active); | |
595 | ||
9d9922e7 | 596 | $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title'); |
597 | $pcpPageType = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type'); | |
6a488035 | 598 | |
2158332a | 599 | $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); |
6a488035 TO |
600 | $pcpStatus = $pcpStatus[$is_active]; |
601 | ||
9d9922e7 | 602 | CRM_Core_Session::setStatus(ts("%1 status has been updated to %2.", array( |
603 | 1 => $pcpTitle, | |
21dfd5f5 | 604 | 2 => $pcpStatus, |
9d9922e7 | 605 | )), 'Status Updated', 'success'); |
6a488035 TO |
606 | |
607 | // send status change mail | |
608 | $result = self::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType); | |
609 | ||
610 | if ($result) { | |
611 | CRM_Core_Session::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success'); | |
612 | } | |
613 | } | |
614 | ||
615 | /** | |
ad37ac8e | 616 | * Send notification email to supporter. |
617 | * | |
6a488035 TO |
618 | * 1. when their PCP status is changed by site admin. |
619 | * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true). | |
620 | * | |
db95eff6 TO |
621 | * @param int $pcpId |
622 | * Campaign page id. | |
623 | * @param int $newStatus | |
624 | * Pcp status id. | |
2a6da8d7 | 625 | * @param bool|int $isInitial is it the first time, campaign page has been created by the user |
6a488035 | 626 | * |
2a6da8d7 EM |
627 | * @param string $component |
628 | * | |
629 | * @throws Exception | |
6a488035 | 630 | * @return null |
6a488035 | 631 | */ |
00be9182 | 632 | public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') { |
aef123f6 C |
633 | $pcpStatusName = CRM_Core_OptionGroup::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name'); |
634 | $pcpStatus = CRM_Core_OptionGroup::values("pcp_status"); | |
6a488035 TO |
635 | $config = CRM_Core_Config::singleton(); |
636 | ||
637 | if (!isset($pcpStatus[$newStatus])) { | |
638 | return FALSE; | |
639 | } | |
640 | ||
641 | require_once 'Mail/mime.php'; | |
642 | ||
643 | //set loginUrl | |
644 | $loginURL = $config->userSystem->getLoginURL(); | |
645 | ||
646 | // used in subject templates | |
647 | $contribPageTitle = self::getPcpPageTitle($pcpId, $component); | |
648 | ||
649 | $tplParams = array( | |
650 | 'loginUrl' => $loginURL, | |
651 | 'contribPageTitle' => $contribPageTitle, | |
652 | 'pcpId' => $pcpId, | |
653 | ); | |
654 | ||
655 | //get the default domain email address. | |
656 | list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); | |
657 | ||
658 | if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') { | |
659 | $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1'); | |
660 | CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM » Communications » FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl))); | |
661 | } | |
662 | ||
663 | $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>'; | |
664 | ||
665 | // get recipient (supporter) name and email | |
666 | $params = array('id' => $pcpId); | |
667 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); | |
668 | list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']); | |
669 | ||
670 | // get pcp block info | |
671 | list($blockId, $eid) = self::getPcpBlockEntityId($pcpId, $component); | |
672 | $params = array('id' => $blockId); | |
673 | CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo); | |
674 | ||
675 | // assign urls required in email template | |
aef123f6 | 676 | if ($pcpStatusName[$newStatus] == 'Approved') { |
6a488035 TO |
677 | $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled']; |
678 | if ($pcpBlockInfo['is_tellfriend_enabled']) { | |
679 | $pcpTellFriendURL = CRM_Utils_System::url('civicrm/friend', | |
680 | "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp", | |
681 | TRUE, NULL, FALSE, TRUE | |
682 | ); | |
683 | $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL; | |
684 | } | |
685 | } | |
686 | $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info', | |
687 | "reset=1&id=$pcpId", | |
688 | TRUE, NULL, FALSE, TRUE | |
689 | ); | |
690 | $tplParams['pcpInfoURL'] = $pcpInfoURL; | |
691 | $tplParams['contribPageTitle'] = $contribPageTitle; | |
692 | if ($emails = CRM_Utils_Array::value('notify_email', $pcpBlockInfo)) { | |
693 | $emailArray = explode(',', $emails); | |
694 | $tplParams['pcpNotifyEmailAddress'] = $emailArray[0]; | |
695 | } | |
696 | // get appropriate message based on status | |
697 | $tplParams['pcpStatus'] = $pcpStatus[$newStatus]; | |
698 | ||
699 | $tplName = $isInitial ? 'pcp_supporter_notify' : 'pcp_status_change'; | |
700 | ||
c6327d7d | 701 | list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate( |
6a488035 TO |
702 | array( |
703 | 'groupName' => 'msg_tpl_workflow_contribution', | |
704 | 'valueName' => $tplName, | |
705 | 'contactId' => $pcpInfo['contact_id'], | |
706 | 'tplParams' => $tplParams, | |
707 | 'from' => $receiptFrom, | |
708 | 'toName' => $name, | |
709 | 'toEmail' => $address, | |
710 | ) | |
711 | ); | |
712 | return $sent; | |
713 | } | |
714 | ||
715 | /** | |
ad37ac8e | 716 | * Enable / Disable the campaign page. |
6a488035 | 717 | * |
db95eff6 TO |
718 | * @param int $id |
719 | * Campaign page id. | |
6a488035 | 720 | * |
ad37ac8e | 721 | * @param bool $is_active |
6a488035 | 722 | * @return null |
6a488035 | 723 | */ |
00be9182 | 724 | public static function setDisable($id, $is_active) { |
6a488035 TO |
725 | return CRM_Core_DAO::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active); |
726 | } | |
727 | ||
728 | /** | |
eceb18cc | 729 | * Get pcp block is active. |
6a488035 | 730 | * |
c490a46a | 731 | * @param int $pcpId |
2a6da8d7 | 732 | * @param $component |
6a488035 TO |
733 | * |
734 | * @return int | |
6a488035 | 735 | */ |
00be9182 | 736 | public static function getStatus($pcpId, $component) { |
6a488035 TO |
737 | $query = " |
738 | SELECT pb.is_active | |
739 | FROM civicrm_pcp pcp | |
740 | LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id ) | |
741 | WHERE pcp.id = %1 | |
742 | AND pb.entity_table = %2"; | |
743 | ||
744 | $entity_table = self::getPcpEntityTable($component); | |
745 | ||
746 | $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String')); | |
747 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
748 | } | |
749 | ||
750 | /** | |
eceb18cc | 751 | * Get pcp block is enabled for component page. |
6a488035 | 752 | * |
c490a46a | 753 | * @param int $pageId |
2a6da8d7 | 754 | * @param $component |
6a488035 | 755 | * |
c490a46a | 756 | * @return string |
6a488035 | 757 | */ |
00be9182 | 758 | public static function getPcpBlockStatus($pageId, $component) { |
6a488035 TO |
759 | $query = " |
760 | SELECT pb.link_text as linkText | |
eea141c0 DG |
761 | FROM civicrm_pcp_block pb |
762 | WHERE pb.is_active = 1 AND | |
763 | pb.entity_id = %1 AND | |
764 | pb.entity_table = %2"; | |
6a488035 TO |
765 | |
766 | $entity_table = self::getPcpEntityTable($component); | |
767 | ||
768 | $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String')); | |
769 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
770 | } | |
771 | ||
772 | /** | |
eceb18cc | 773 | * Find out if the PCP block is in use by one or more PCP page. |
6a488035 | 774 | * |
db95eff6 TO |
775 | * @param int $id |
776 | * Pcp block id. | |
6a488035 | 777 | * |
d5cc0fc2 | 778 | * @return Bool |
6a488035 | 779 | */ |
00be9182 | 780 | public static function getPcpBlockInUse($id) { |
6a488035 TO |
781 | $query = " |
782 | SELECT count(*) | |
783 | FROM civicrm_pcp pcp | |
784 | WHERE pcp.pcp_block_id = %1"; | |
785 | ||
786 | $params = array(1 => array($id, 'Integer')); | |
787 | $result = CRM_Core_DAO::singleValueQuery($query, $params); | |
788 | return $result > 0; | |
789 | } | |
790 | ||
791 | /** | |
100fef9d | 792 | * Get email is enabled for supporter's profile |
6a488035 | 793 | * |
db95eff6 TO |
794 | * @param int $profileId |
795 | * Supporter's profile id. | |
6a488035 | 796 | * |
d5cc0fc2 | 797 | * @return bool |
6a488035 | 798 | */ |
00be9182 | 799 | public static function checkEmailProfile($profileId) { |
6a488035 TO |
800 | $query = " |
801 | SELECT field_name | |
802 | FROM civicrm_uf_field | |
803 | WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1"; | |
804 | ||
805 | $params = array(1 => array($profileId, 'Integer')); | |
806 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
807 | if (!$dao->fetch()) { | |
808 | return TRUE; | |
809 | } | |
810 | return FALSE; | |
811 | } | |
812 | ||
813 | /** | |
eceb18cc | 814 | * Obtain the title of page associated with a pcp. |
6a488035 | 815 | * |
c490a46a | 816 | * @param int $pcpId |
dd244018 EM |
817 | * @param $component |
818 | * | |
6a488035 | 819 | * @return int |
6a488035 | 820 | */ |
00be9182 | 821 | public static function getPcpPageTitle($pcpId, $component) { |
6a488035 TO |
822 | if ($component == 'contribute') { |
823 | $query = " | |
824 | SELECT cp.title | |
825 | FROM civicrm_pcp pcp | |
826 | LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id ) | |
827 | WHERE pcp.id = %1"; | |
828 | } | |
829 | elseif ($component == 'event') { | |
830 | $query = " | |
831 | SELECT ce.title | |
832 | FROM civicrm_pcp pcp | |
833 | LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id ) | |
834 | WHERE pcp.id = %1"; | |
835 | } | |
836 | ||
837 | $params = array(1 => array($pcpId, 'Integer')); | |
838 | return CRM_Core_DAO::singleValueQuery($query, $params); | |
839 | } | |
840 | ||
841 | /** | |
100fef9d | 842 | * Get pcp block & entity id given pcp id |
6a488035 | 843 | * |
c490a46a | 844 | * @param int $pcpId |
dd244018 EM |
845 | * @param $component |
846 | * | |
d5cc0fc2 | 847 | * @return string |
6a488035 | 848 | */ |
00be9182 | 849 | public static function getPcpBlockEntityId($pcpId, $component) { |
6a488035 TO |
850 | $entity_table = self::getPcpEntityTable($component); |
851 | ||
852 | $query = " | |
853 | SELECT pb.id as pcpBlockId, pb.entity_id | |
854 | FROM civicrm_pcp pcp | |
855 | LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 ) | |
856 | WHERE pcp.id = %1"; | |
857 | ||
858 | $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String')); | |
859 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
860 | if ($dao->fetch()) { | |
861 | return array($dao->pcpBlockId, $dao->entity_id); | |
862 | } | |
863 | ||
864 | return array(); | |
865 | } | |
866 | ||
867 | /** | |
100fef9d | 868 | * Get pcp entity table given a component. |
6a488035 | 869 | * |
2a6da8d7 EM |
870 | * @param $component |
871 | * | |
d5cc0fc2 | 872 | * @return string |
6a488035 | 873 | */ |
00be9182 | 874 | public static function getPcpEntityTable($component) { |
6a488035 TO |
875 | $entity_table_map = array( |
876 | 'event' => 'civicrm_event', | |
877 | 'civicrm_event' => 'civicrm_event', | |
878 | 'contribute' => 'civicrm_contribution_page', | |
879 | 'civicrm_contribution_page' => 'civicrm_contribution_page', | |
880 | ); | |
881 | return isset($entity_table_map[$component]) ? $entity_table_map[$component] : FALSE; | |
882 | } | |
883 | ||
884 | /** | |
eceb18cc | 885 | * Get supporter profile id. |
6a488035 | 886 | * |
c490a46a | 887 | * @param int $component_id |
fd31fa4c EM |
888 | * @param string $component |
889 | * | |
6a488035 | 890 | * @return int |
6a488035 | 891 | */ |
c1204160 | 892 | public static function getSupporterProfileId($component_id, $component = 'contribute') { |
6a488035 TO |
893 | $entity_table = self::getPcpEntityTable($component); |
894 | ||
895 | $query = " | |
896 | SELECT pcp.supporter_profile_id | |
897 | FROM civicrm_pcp_block pcp | |
898 | INNER JOIN civicrm_uf_group ufgroup | |
899 | ON pcp.supporter_profile_id = ufgroup.id | |
900 | WHERE pcp.entity_id = %1 | |
901 | AND pcp.entity_table = %2 | |
902 | AND ufgroup.is_active = 1"; | |
903 | ||
904 | $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String')); | |
905 | if (!$supporterProfileId = CRM_Core_DAO::singleValueQuery($query, $params)) { | |
906 | CRM_Core_Error::fatal(ts('Supporter profile is not set for this Personal Campaign Page or the profile is disabled. Please contact the site administrator if you need assistance.')); | |
907 | } | |
908 | else { | |
909 | return $supporterProfileId; | |
910 | } | |
911 | } | |
96025800 | 912 | |
12f92dbd | 913 | /** |
eceb18cc | 914 | * Get owner notification id. |
12f92dbd | 915 | * |
5fe87df6 | 916 | * @param int $component_id |
12f92dbd N |
917 | * @param $component |
918 | * | |
12f92dbd N |
919 | * @return int |
920 | */ | |
5fe87df6 N |
921 | public static function getOwnerNotificationId($component_id, $component = 'contribute') { |
922 | $entity_table = self::getPcpEntityTable($component); | |
12f92dbd N |
923 | $query = " |
924 | SELECT pb.owner_notify_id | |
925 | FROM civicrm_pcp_block pb | |
5fe87df6 N |
926 | WHERE pb.entity_id = %1 AND pb.entity_table = %2"; |
927 | $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String')); | |
928 | if (!$ownerNotificationId = CRM_Core_DAO::singleValueQuery($query, $params)) { | |
929 | CRM_Core_Error::fatal(ts('Owner Notification is not set for this Personal Campaign Page. Please contact the site administrator if you need assistance.')); | |
930 | } | |
931 | else { | |
932 | return $ownerNotificationId; | |
933 | } | |
12f92dbd | 934 | } |
eceb18cc | 935 | |
6a488035 | 936 | } |