3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_PCP_BAO_PCP
extends CRM_PCP_DAO_PCP
{
38 * The action links that we need to display for the browse screen
43 static $_pcpLinks = NULL;
47 public function __construct() {
48 parent
::__construct();
52 * Add or update either a Personal Campaign Page OR a PCP Block
54 * @param array $params
55 * Reference array contains the values submitted by the form.
56 * @param bool $pcpBlock
57 * If true, create or update PCPBlock, else PCP.
63 public static function add(&$params, $pcpBlock = TRUE) {
65 // action is taken depending upon the mode
66 $dao = new CRM_PCP_DAO_PCPBlock();
67 $dao->copyValues($params);
72 $dao = new CRM_PCP_DAO_PCP();
73 $dao->copyValues($params);
75 // ensure we set status_id since it is a not null field
76 // we should change the schema and allow this to be null
77 if (!$dao->id
&& !isset($dao->status_id
)) {
81 // set currency for CRM-1496
82 if (!isset($dao->currency
)) {
83 $config = &CRM_Core_Config
::singleton();
84 $dao->currency
= $config->defaultCurrency
;
92 * Get the Display name of a contact for a PCP
98 * Dispaly name of the contact if found
101 public static function displayName($id) {
102 $id = CRM_Utils_Type
::escape($id, 'Integer');
105 SELECT civicrm_contact.display_name
106 FROM civicrm_pcp, civicrm_contact
107 WHERE civicrm_pcp.contact_id = civicrm_contact.id
108 AND civicrm_pcp.id = {$id}
110 return CRM_Core_DAO
::singleValueQuery($query, CRM_Core_DAO
::$_nullArray);
114 * Return PCP Block info for dashboard
116 * @param int $contactId
119 * array of Pcp if found
122 public static function getPcpDashboardInfo($contactId) {
123 $links = self
::pcpLinks();
126 SELECT * FROM civicrm_pcp pcp
127 WHERE pcp.is_active = 1
128 AND pcp.contact_id = %1
129 ORDER BY page_type, page_id";
131 $params = array(1 => array($contactId, 'Integer'));
133 $pcpInfoDao = CRM_Core_DAO
::executeQuery($query, $params);
135 $hide = $mask = array_sum(array_keys($links['all']));
136 $contactPCPPages = array();
138 $event = CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
139 $contribute = CRM_Contribute_PseudoConstant
::contributionPage();
140 $pcpStatus = CRM_Contribute_PseudoConstant
::pcpStatus();
141 $approved = CRM_Utils_Array
::key('Approved', $pcpStatus);
143 while ($pcpInfoDao->fetch()) {
147 'pcpId' => $pcpInfoDao->id
,
148 'pcpBlock' => $pcpInfoDao->pcp_block_id
,
149 'pageComponent' => $pcpInfoDao->page_type
,
153 $pcpLink = $links['all'];
156 if ($pcpInfoDao->status_id
!= $approved ||
$pcpInfoDao->is_active
!= 1) {
158 if (!$pcpInfoDao->tellfriend
) {
159 $mask -= CRM_Core_Action
::DETACH
;
163 if ($pcpInfoDao->is_active
== 1) {
164 $mask -= CRM_Core_Action
::ENABLE
;
167 $mask -= CRM_Core_Action
::DISABLE
;
169 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
170 FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id
);
171 $component = $pcpInfoDao->page_type
;
172 $pageTitle = CRM_Utils_Array
::value($pcpInfoDao->page_id
, $
$component);
175 'pageTitle' => $pageTitle,
176 'pcpId' => $pcpInfoDao->id
,
177 'pcpTitle' => $pcpInfoDao->title
,
178 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id
],
182 $contactPCPPages[$pcpInfoDao->page_type
][] = $pcpInfoDao->page_id
;
185 $excludePageClause = $clause = NULL;
186 if (!empty($contactPCPPages)) {
187 foreach ($contactPCPPages as $component => $entityIds) {
188 $excludePageClause[] = "
189 ( target_entity_type = '{$component}'
190 AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
193 $clause = ' AND ' . implode(' OR ', $excludePageClause);
198 FROM civicrm_pcp_block block
199 LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id
200 WHERE block.is_active = 1
203 ORDER BY target_entity_type, target_entity_id
205 $pcpBlockDao = CRM_Core_DAO
::executeQuery($query);
209 while ($pcpBlockDao->fetch()) {
212 'pageId' => $pcpBlockDao->target_entity_id
,
213 'pageComponent' => $pcpBlockDao->target_entity_type
,
216 $pcpLink = $links['add'];
217 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
218 FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id
);
219 $component = $pcpBlockDao->target_entity_type
;
220 $pageTitle = CRM_Utils_Array
::value($pcpBlockDao->target_entity_id
, $
$component);
222 'pageId' => $pcpBlockDao->target_entity_id
,
223 'pageTitle' => $pageTitle,
224 'component' => $pcpBlockDao->target_entity_type
,
229 return array($pcpBlock, $pcpInfo);
233 * Show the total amount for Personal Campaign Page on thermometer
235 * @param array $pcpId
236 * Contains the pcp ID.
243 public static function thermoMeter($pcpId) {
245 SELECT SUM(cc.total_amount) as total
247 LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )
248 LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)
249 WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0";
251 $params = array(1 => array($pcpId, 'Integer'));
252 return CRM_Core_DAO
::singleValueQuery($query, $params);
256 * Show the amount, nickname on honor roll
258 * @param array $pcpId
259 * Contains the pcp ID.
265 public static function honorRoll($pcpId) {
267 SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note,
268 cc.total_amount, cc.currency
269 FROM civicrm_contribution cc
270 LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id
271 WHERE cs.pcp_id = {$pcpId}
272 AND cs.pcp_display_in_roll = 1
273 AND contribution_status_id = 1
275 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
277 while ($dao->fetch()) {
278 $honor[$dao->id
]['nickname'] = ucwords($dao->pcp_roll_nickname
);
279 $honor[$dao->id
]['total_amount'] = CRM_Utils_Money
::format($dao->total_amount
, $dao->currency
);
280 $honor[$dao->id
]['personal_note'] = $dao->pcp_personal_note
;
289 * (reference) of action links
292 public static function &pcpLinks() {
293 if (!(self
::$_pcpLinks)) {
294 $deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
296 self
::$_pcpLinks['add'] = array(
297 CRM_Core_Action
::ADD
=> array(
298 'name' => ts('Create a Personal Campaign Page'),
299 'url' => 'civicrm/contribute/campaign',
300 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
301 'title' => ts('Configure'),
305 self
::$_pcpLinks['all'] = array(
306 CRM_Core_Action
::UPDATE
=> array(
307 'name' => ts('Edit Your Page'),
308 'url' => 'civicrm/pcp/info',
309 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
310 'title' => ts('Configure'),
312 CRM_Core_Action
::DETACH
=> array(
313 'name' => ts('Tell Friends'),
314 'url' => 'civicrm/friend',
315 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
316 'title' => ts('Tell Friends'),
318 CRM_Core_Action
::VIEW
=> array(
319 'name' => ts('URL for this Page'),
320 'url' => 'civicrm/pcp/info',
321 'qs' => 'reset=1&id=%%pcpId%%&component=%%pageComponent%%',
322 'title' => ts('URL for this Page'),
324 CRM_Core_Action
::BROWSE
=> array(
325 'name' => ts('Update Contact Information'),
326 'url' => 'civicrm/pcp/info',
327 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
328 'title' => ts('Update Contact Information'),
330 CRM_Core_Action
::ENABLE
=> array(
331 'name' => ts('Enable'),
332 'url' => 'civicrm/pcp',
333 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
334 'title' => ts('Enable'),
336 CRM_Core_Action
::DISABLE
=> array(
337 'name' => ts('Disable'),
338 'url' => 'civicrm/pcp',
339 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
340 'title' => ts('Disable'),
342 CRM_Core_Action
::DELETE
=> array(
343 'name' => ts('Delete'),
344 'url' => 'civicrm/pcp',
345 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
346 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
347 'title' => ts('Delete'),
351 return self
::$_pcpLinks;
355 * Delete the campaign page
363 public static function deleteById($id) {
364 CRM_Utils_Hook
::pre('delete', 'Campaign', $id, CRM_Core_DAO
::$_nullArray);
366 $transaction = new CRM_Core_Transaction();
368 // delete from pcp table
369 $pcp = new CRM_PCP_DAO_PCP();
373 $transaction->commit();
375 CRM_Utils_Hook
::post('delete', 'Campaign', $id, $pcp);
379 * Build the form object
381 * @param CRM_Core_Form $form
386 public static function buildPCPForm($form) {
387 $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
389 $form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
392 $isUserRequired = NULL;
393 $config = CRM_Core_Config
::singleton();
394 if ($config->userFramework
!= 'Standalone') {
397 CRM_Core_DAO
::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array(
401 if (!empty($profiles)) {
402 foreach ($profiles as $key => $value) {
403 if ($value['is_active']) {
404 $profile[$key] = $value['title'];
407 $form->assign('profile', $profile);
410 $form->add('select', 'supporter_profile_id', ts('Supporter Profile'), array('' => ts('- select -')) +
$profile, TRUE);
412 $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);"));
416 ts("'Tell a friend' maximum recipients limit"),
417 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit')
419 $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
423 ts("'Create Personal Campaign Page' link text"),
424 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text')
427 $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
432 * Add PCP form elements to a form
436 * @param CRM_Core_Page $page
437 * @param null $elements
439 public function buildPcp($pcpId, &$page, &$elements = NULL) {
441 $prms = array('id' => $pcpId);
442 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
443 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($pcpId)) {
444 if ($pcpInfo['page_type'] == 'event') {
445 $pcp_supporter_text = ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
446 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'event');
448 $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!";
452 $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
453 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'contribute');
455 $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!";
459 $page->assign('pcpSupporterText', $pcp_supporter_text);
461 $page->assign('pcp', TRUE);
463 // build honor roll fields for registration form if supporter has honor roll enabled for their PCP
464 if ($pcpInfo['is_honor_roll']) {
465 $page->assign('is_honor_roll', TRUE);
466 $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL,
467 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
469 $extraOption = array('onclick' => "return pcpAnonymous( );");
471 $elements[] = &$page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
472 $elements[] = &$page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption);
473 $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
474 $page->_defaults
['pcp_is_anonymous'] = 0;
476 $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
477 $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
480 $page->assign('is_honor_roll', FALSE);
485 * Process a PCP contribution/
494 public static function handlePcp($pcpId, $component, $entity) {
496 self
::getPcpEntityTable($component);
502 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
504 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
506 $params = array('id' => $pcpId);
507 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
509 $params = array('id' => $pcpInfo['pcp_block_id']);
510 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock);
512 $params = array('id' => $pcpInfo['page_id']);
515 if ($component == 'event') {
516 // figure out where to redirect if an exception occurs below based on target entity
517 $urlBase = 'civicrm/event/register';
519 // ignore startDate for events - PCP's can be active long before event start date
521 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
523 elseif ($component == 'contribute') {
524 $urlBase = 'civicrm/contribute/transact';
525 //start and end date of the contribution page
526 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $entity));
527 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
530 // define redirect url back to contrib page or event if needed
531 $url = CRM_Utils_System
::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE);
533 if ($pcpBlock['target_entity_id'] != $entity['id']) {
534 $statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
535 CRM_Core_Error
::statusBounce($statusMessage, $url);
537 elseif ($pcpInfo['status_id'] != $approvedId) {
538 $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']]));
539 CRM_Core_Error
::statusBounce($statusMessage, $url);
541 elseif (empty($pcpBlock['is_active'])) {
542 $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.');
543 CRM_Core_Error
::statusBounce($statusMessage, $url);
545 elseif (empty($pcpInfo['is_active'])) {
546 $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.');
547 CRM_Core_Error
::statusBounce($statusMessage, $url);
549 // Check if we're in range for contribution page start and end dates. for events, check if after event end date
550 elseif (($startDate && $startDate > $now) ||
($endDate && $endDate < $now)) {
551 $customStartDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('start_date', $entity));
552 $customEndDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('end_date', $entity));
553 if ($startDate && $endDate) {
554 $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.',
555 array(1 => $customStartDate, 2 => $customEndDate)
557 CRM_Core_Error
::statusBounce($statusMessage, $url);
559 elseif ($startDate) {
560 $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));
561 CRM_Core_Error
::statusBounce($statusMessage, $url);
564 if ($component == 'event') {
565 // Target_entity is an event and the event is over, redirect to event info instead of event registration page.
566 $url = CRM_Utils_System
::url('civicrm/event/info',
567 "reset=1&id={$pcpBlock['entity_id']}",
568 FALSE, NULL, FALSE, TRUE
570 $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate));
571 CRM_Core_Error
::statusBounce($statusMessage, $url);
574 $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));
575 CRM_Core_Error
::statusBounce($statusMessage, $url);
582 'pcpBlock' => $pcpBlock,
583 'pcpInfo' => $pcpInfo,
588 * Approve / Reject the campaign page
598 public static function setIsActive($id, $is_active) {
599 switch ($is_active) {
609 CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active);
611 $pcpTitle = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title');
612 $pcpPageType = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type');
614 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
615 $pcpStatus = $pcpStatus[$is_active];
617 CRM_Core_Session
::setStatus(ts("%1 status has been updated to %2.", array(
620 )), 'Status Updated', 'success');
622 // send status change mail
623 $result = self
::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType);
626 CRM_Core_Session
::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success');
631 * Send notfication email to supporter
632 * 1. when their PCP status is changed by site admin.
633 * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
637 * @param int $newStatus
639 * @param bool|int $isInitial is it the first time, campaign page has been created by the user
641 * @param string $component
647 public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
648 $pcpStatusName = CRM_Core_OptionGroup
::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
649 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
650 $config = CRM_Core_Config
::singleton();
652 if (!isset($pcpStatus[$newStatus])) {
656 require_once 'Mail/mime.php';
659 $loginURL = $config->userSystem
->getLoginURL();
661 // used in subject templates
662 $contribPageTitle = self
::getPcpPageTitle($pcpId, $component);
665 'loginUrl' => $loginURL,
666 'contribPageTitle' => $contribPageTitle,
670 //get the default domain email address.
671 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
673 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
674 $fixUrl = CRM_Utils_System
::url("civicrm/admin/domain", 'action=update&reset=1');
675 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)));
678 $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
680 // get recipient (supporter) name and email
681 $params = array('id' => $pcpId);
682 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
683 list($name, $address) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($pcpInfo['contact_id']);
685 // get pcp block info
686 list($blockId, $eid) = self
::getPcpBlockEntityId($pcpId, $component);
687 $params = array('id' => $blockId);
688 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
690 // assign urls required in email template
691 if ($pcpStatusName[$newStatus] == 'Approved') {
692 $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
693 if ($pcpBlockInfo['is_tellfriend_enabled']) {
694 $pcpTellFriendURL = CRM_Utils_System
::url('civicrm/friend',
695 "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
696 TRUE, NULL, FALSE, TRUE
698 $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
701 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
703 TRUE, NULL, FALSE, TRUE
705 $tplParams['pcpInfoURL'] = $pcpInfoURL;
706 $tplParams['contribPageTitle'] = $contribPageTitle;
707 if ($emails = CRM_Utils_Array
::value('notify_email', $pcpBlockInfo)) {
708 $emailArray = explode(',', $emails);
709 $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
711 // get appropriate message based on status
712 $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
714 $tplName = $isInitial ?
'pcp_supporter_notify' : 'pcp_status_change';
716 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
718 'groupName' => 'msg_tpl_workflow_contribution',
719 'valueName' => $tplName,
720 'contactId' => $pcpInfo['contact_id'],
721 'tplParams' => $tplParams,
722 'from' => $receiptFrom,
724 'toEmail' => $address,
731 * Enable / Disable the campaign page
740 public static function setDisable($id, $is_active) {
741 return CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
745 * Get pcp block is active
753 public static function getStatus($pcpId, $component) {
757 LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id )
759 AND pb.entity_table = %2";
761 $entity_table = self
::getPcpEntityTable($component);
763 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
764 return CRM_Core_DAO
::singleValueQuery($query, $params);
768 * Get pcp block is enabled for component page
776 public static function getPcpBlockStatus($pageId, $component) {
778 SELECT pb.link_text as linkText
779 FROM civicrm_pcp_block pb
780 WHERE pb.is_active = 1 AND
781 pb.entity_id = %1 AND
782 pb.entity_table = %2";
784 $entity_table = self
::getPcpEntityTable($component);
786 $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
787 return CRM_Core_DAO
::singleValueQuery($query, $params);
791 * Find out if the PCP block is in use by one or more PCP page
799 public static function getPcpBlockInUse($id) {
803 WHERE pcp.pcp_block_id = %1";
805 $params = array(1 => array($id, 'Integer'));
806 $result = CRM_Core_DAO
::singleValueQuery($query, $params);
811 * Get email is enabled for supporter's profile
813 * @param int $profileId
814 * Supporter's profile id.
819 public static function checkEmailProfile($profileId) {
822 FROM civicrm_uf_field
823 WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
825 $params = array(1 => array($profileId, 'Integer'));
826 $dao = CRM_Core_DAO
::executeQuery($query, $params);
827 if (!$dao->fetch()) {
834 * Obtain the title of page associated with a pcp
842 public static function getPcpPageTitle($pcpId, $component) {
843 if ($component == 'contribute') {
847 LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
850 elseif ($component == 'event') {
854 LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
858 $params = array(1 => array($pcpId, 'Integer'));
859 return CRM_Core_DAO
::singleValueQuery($query, $params);
863 * Get pcp block & entity id given pcp id
871 public static function getPcpBlockEntityId($pcpId, $component) {
872 $entity_table = self
::getPcpEntityTable($component);
875 SELECT pb.id as pcpBlockId, pb.entity_id
877 LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
880 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
881 $dao = CRM_Core_DAO
::executeQuery($query, $params);
883 return array($dao->pcpBlockId
, $dao->entity_id
);
890 * Get pcp entity table given a component.
897 public static function getPcpEntityTable($component) {
898 $entity_table_map = array(
899 'event' => 'civicrm_event',
900 'civicrm_event' => 'civicrm_event',
901 'contribute' => 'civicrm_contribution_page',
902 'civicrm_contribution_page' => 'civicrm_contribution_page',
904 return isset($entity_table_map[$component]) ?
$entity_table_map[$component] : FALSE;
908 * Get supporter profile id
910 * @param int $component_id
911 * @param string $component
916 public static function getSupporterProfileId($component_id, $component = 'contribute') {
917 $entity_table = self
::getPcpEntityTable($component);
920 SELECT pcp.supporter_profile_id
921 FROM civicrm_pcp_block pcp
922 INNER JOIN civicrm_uf_group ufgroup
923 ON pcp.supporter_profile_id = ufgroup.id
924 WHERE pcp.entity_id = %1
925 AND pcp.entity_table = %2
926 AND ufgroup.is_active = 1";
928 $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
929 if (!$supporterProfileId = CRM_Core_DAO
::singleValueQuery($query, $params)) {
930 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.'));
933 return $supporterProfileId;