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;
48 function __construct() {
49 parent
::__construct();
53 * Add or update either a Personal Campaign Page OR a PCP Block
55 * @param array $params reference array contains the values submitted by the form
56 * @param bool $pcpBlock if true, create or update PCPBlock, else PCP
63 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
94 * @param int $id id for the PCP
96 * @return null|string Dispaly name of the contact if found
100 static function displayName($id) {
101 $id = CRM_Utils_Type
::escape($id, 'Integer');
104 SELECT civicrm_contact.display_name
105 FROM civicrm_pcp, civicrm_contact
106 WHERE civicrm_pcp.contact_id = civicrm_contact.id
107 AND civicrm_pcp.id = {$id}
109 return CRM_Core_DAO
::singleValueQuery($query, CRM_Core_DAO
::$_nullArray);
113 * Return PCP Block info for dashboard
115 * @param int $contactId
117 * @return array array of Pcp if found
121 static function getPcpDashboardInfo($contactId) {
122 $links = self
::pcpLinks();
125 SELECT * FROM civicrm_pcp pcp
126 WHERE pcp.is_active = 1
127 AND pcp.contact_id = %1
128 ORDER BY page_type, page_id";
130 $params = array(1 => array($contactId, 'Integer'));
132 $pcpInfoDao = CRM_Core_DAO
::executeQuery($query, $params);
134 $hide = $mask = array_sum(array_keys($links['all']));
135 $contactPCPPages = array();
137 $event = CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
138 $contribute = CRM_Contribute_PseudoConstant
::contributionPage();
139 $pcpStatus = CRM_Contribute_PseudoConstant
::pcpStatus();
140 $approved = CRM_Utils_Array
::key('Approved', $pcpStatus);
142 while ($pcpInfoDao->fetch()) {
146 'pcpId' => $pcpInfoDao->id
,
147 'pcpBlock' => $pcpInfoDao->pcp_block_id
,
148 'pageComponent' => $pcpInfoDao->page_type
,
152 $pcpLink = $links['all'];
155 if ($pcpInfoDao->status_id
!= $approved ||
$pcpInfoDao->is_active
!= 1) {
157 if (!$pcpInfoDao->tellfriend
) {
158 $mask -= CRM_Core_Action
::DETACH
;
162 if ($pcpInfoDao->is_active
== 1) {
163 $mask -= CRM_Core_Action
::ENABLE
;
166 $mask -= CRM_Core_Action
::DISABLE
;
168 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
169 FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id
);
170 $component = $pcpInfoDao->page_type
;
171 $pageTitle = CRM_Utils_Array
::value($pcpInfoDao->page_id
, $
$component);
174 'pageTitle' => $pageTitle,
175 'pcpId' => $pcpInfoDao->id
,
176 'pcpTitle' => $pcpInfoDao->title
,
177 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id
],
181 $contactPCPPages[$pcpInfoDao->page_type
][] = $pcpInfoDao->page_id
;
184 $excludePageClause = $clause = NULL;
185 if (!empty($contactPCPPages)) {
186 foreach ($contactPCPPages as $component => $entityIds) {
187 $excludePageClause[] = "
188 ( target_entity_type = '{$component}'
189 AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
192 $clause = ' AND ' . implode(' OR ', $excludePageClause);
197 FROM civicrm_pcp_block block
198 LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id
199 WHERE block.is_active = 1
202 ORDER BY target_entity_type, target_entity_id
204 $pcpBlockDao = CRM_Core_DAO
::executeQuery($query);
208 while ($pcpBlockDao->fetch()) {
211 'pageId' => $pcpBlockDao->target_entity_id
,
212 'pageComponent' => $pcpBlockDao->target_entity_type
,
215 $pcpLink = $links['add'];
216 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
217 FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id
);
218 $component = $pcpBlockDao->target_entity_type
;
219 $pageTitle = CRM_Utils_Array
::value($pcpBlockDao->target_entity_id
, $
$component);
221 'pageId' => $pcpBlockDao->target_entity_id
,
222 'pageTitle' => $pageTitle,
223 'component' => $pcpBlockDao->target_entity_type
,
228 return array($pcpBlock, $pcpInfo);
232 * Show the total amount for Personal Campaign Page on thermometer
234 * @param array $pcpId contains the pcp ID
239 * @return total amount
241 static function thermoMeter($pcpId) {
243 SELECT SUM(cc.total_amount) as total
245 LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )
246 LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)
247 WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0";
249 $params = array(1 => array($pcpId, 'Integer'));
250 return CRM_Core_DAO
::singleValueQuery($query, $params);
254 * Show the amount, nickname on honor roll
256 * @param array $pcpId contains the pcp ID
261 * @return array $honor
263 static function honorRoll($pcpId) {
265 SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note,
266 cc.total_amount, cc.currency
267 FROM civicrm_contribution cc
268 LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id
269 WHERE cs.pcp_id = {$pcpId}
270 AND cs.pcp_display_in_roll = 1
271 AND contribution_status_id = 1
273 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
275 while ($dao->fetch()) {
276 $honor[$dao->id
]['nickname'] = ucwords($dao->pcp_roll_nickname
);
277 $honor[$dao->id
]['total_amount'] = CRM_Utils_Money
::format($dao->total_amount
, $dao->currency
);
278 $honor[$dao->id
]['personal_note'] = $dao->pcp_personal_note
;
286 * @return array (reference) of action links
289 static function &pcpLinks() {
290 if (!(self
::$_pcpLinks)) {
291 $deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
293 self
::$_pcpLinks['add'] = array(
294 CRM_Core_Action
::ADD
=> array(
295 'name' => ts('Create a Personal Campaign Page'),
296 'url' => 'civicrm/contribute/campaign',
297 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
298 'title' => ts('Configure'),
302 self
::$_pcpLinks['all'] = array(
303 CRM_Core_Action
::UPDATE
=> array(
304 'name' => ts('Edit Your Page'),
305 'url' => 'civicrm/pcp/info',
306 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
307 'title' => ts('Configure'),
309 CRM_Core_Action
::DETACH
=> array(
310 'name' => ts('Tell Friends'),
311 'url' => 'civicrm/friend',
312 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
313 'title' => ts('Tell Friends'),
315 CRM_Core_Action
::VIEW
=> array(
316 'name' => ts('URL for this Page'),
317 'url' => 'civicrm/pcp/info',
318 'qs' => 'reset=1&id=%%pcpId%%&component=%%pageComponent%%',
319 'title' => ts('URL for this Page'),
321 CRM_Core_Action
::BROWSE
=> array(
322 'name' => ts('Update Contact Information'),
323 'url' => 'civicrm/pcp/info',
324 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
325 'title' => ts('Update Contact Information'),
327 CRM_Core_Action
::ENABLE
=> array(
328 'name' => ts('Enable'),
329 'url' => 'civicrm/pcp',
330 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
331 'title' => ts('Enable'),
333 CRM_Core_Action
::DISABLE
=> array(
334 'name' => ts('Disable'),
335 'url' => 'civicrm/pcp',
336 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
337 'title' => ts('Disable'),
339 CRM_Core_Action
::DELETE
=> array(
340 'name' => ts('Delete'),
341 'url' => 'civicrm/pcp',
342 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
343 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
344 'title' => ts('Delete'),
348 return self
::$_pcpLinks;
352 * Delete the campaign page
354 * @param int $id campaign page id
361 public static function deleteById($id) {
362 CRM_Utils_Hook
::pre('delete', 'Campaign', $id, CRM_Core_DAO
::$_nullArray);
364 $transaction = new CRM_Core_Transaction();
366 // delete from pcp table
367 $pcp = new CRM_PCP_DAO_PCP();
371 $transaction->commit();
373 CRM_Utils_Hook
::post('delete', 'Campaign', $id, $pcp);
377 * Build the form object
379 * @param CRM_Core_Form $form form object
384 public static function buildPCPForm($form) {
385 $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
387 $form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
390 $isUserRequired = NULL;
391 $config = CRM_Core_Config
::singleton();
392 if ($config->userFramework
!= 'Standalone') {
395 CRM_Core_DAO
::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array(
399 if (!empty($profiles)) {
400 foreach ($profiles as $key => $value) {
401 if ($value['is_active']) {
402 $profile[$key] = $value['title'];
405 $form->assign('profile', $profile);
408 $form->add('select', 'supporter_profile_id', ts('Supporter Profile'), array('' => ts('- select -')) +
$profile, TRUE);
410 $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);"));
414 ts("'Tell a friend' maximum recipients limit"),
415 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit')
417 $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
421 ts("'Create Personal Campaign Page' link text"),
422 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text')
425 $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
430 * Add PCP form elements to a form
433 * @param integer $pcpId
434 * @param CRM_Core_Page $page
435 * @param null $elements
437 function buildPcp($pcpId, &$page, &$elements = NULL) {
439 $prms = array('id' => $pcpId);
440 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
441 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($pcpId)) {
442 if ($pcpInfo['page_type'] == 'event') {
443 $pcp_supporter_text = ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
444 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'event');
446 $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!";
450 $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
451 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'contribute');
453 $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!";
457 $page->assign('pcpSupporterText', $pcp_supporter_text);
459 $page->assign('pcp', TRUE);
461 // build honor roll fields for registration form if supporter has honor roll enabled for their PCP
462 if ($pcpInfo['is_honor_roll']) {
463 $page->assign('is_honor_roll', TRUE);
464 $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL,
465 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
467 $extraOption = array('onclick' => "return pcpAnonymous( );");
469 $elements[] = & $page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
470 $elements[] = & $page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption);
471 $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
472 $page->_defaults
['pcp_is_anonymous'] = 0;
474 $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
475 $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
478 $page->assign('is_honor_roll', FALSE);
483 * Process a PCP contribution/
492 public static function handlePcp($pcpId, $component, $entity) {
494 self
::getPcpEntityTable($component);
500 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
502 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
504 $params = array('id' => $pcpId);
505 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
507 $params = array('id' => $pcpInfo['pcp_block_id']);
508 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock);
510 $params = array('id' => $pcpInfo['page_id']);
513 if ($component == 'event') {
514 // figure out where to redirect if an exception occurs below based on target entity
515 $urlBase = 'civicrm/event/register';
517 // ignore startDate for events - PCP's can be active long before event start date
519 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
521 elseif ($component == 'contribute') {
522 $urlBase = 'civicrm/contribute/transact';
523 //start and end date of the contribution page
524 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $entity));
525 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
528 // define redirect url back to contrib page or event if needed
529 $url = CRM_Utils_System
::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE );
531 if ($pcpBlock['target_entity_id'] != $entity['id']) {
532 $statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
533 CRM_Core_Error
::statusBounce($statusMessage, $url);
535 elseif ($pcpInfo['status_id'] != $approvedId) {
536 $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']]));
537 CRM_Core_Error
::statusBounce($statusMessage, $url);
539 elseif (empty($pcpBlock['is_active'])) {
540 $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.');
541 CRM_Core_Error
::statusBounce($statusMessage, $url);
543 elseif (empty($pcpInfo['is_active'])) {
544 $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.');
545 CRM_Core_Error
::statusBounce($statusMessage, $url);
547 // Check if we're in range for contribution page start and end dates. for events, check if after event end date
548 elseif (($startDate && $startDate > $now) ||
($endDate && $endDate < $now)) {
549 $customStartDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('start_date', $entity));
550 $customEndDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('end_date', $entity));
551 if ($startDate && $endDate) {
552 $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.',
553 array(1 => $customStartDate, 2 => $customEndDate)
555 CRM_Core_Error
::statusBounce($statusMessage, $url);
557 elseif ($startDate) {
558 $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));
559 CRM_Core_Error
::statusBounce($statusMessage, $url);
562 if ($component == 'event') {
563 // Target_entity is an event and the event is over, redirect to event info instead of event registration page.
564 $url = CRM_Utils_System
::url('civicrm/event/info',
565 "reset=1&id={$pcpBlock['entity_id']}",
566 FALSE, NULL, FALSE, TRUE
568 $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate));
569 CRM_Core_Error
::statusBounce($statusMessage, $url);
572 $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));
573 CRM_Core_Error
::statusBounce($statusMessage, $url);
580 'pcpBlock' => $pcpBlock,
581 'pcpInfo' => $pcpInfo,
586 * Approve / Reject the campaign page
588 * @param int $id campaign page id
596 static function setIsActive($id, $is_active) {
597 switch ($is_active) {
607 CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active);
609 $pcpTitle = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title');
610 $pcpPageType = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type');
612 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
613 $pcpStatus = $pcpStatus[$is_active];
615 CRM_Core_Session
::setStatus(ts("%1 status has been updated to %2.", array(
618 )), 'Status Updated', 'success');
620 // send status change mail
621 $result = self
::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType);
624 CRM_Core_Session
::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success');
629 * Send notfication email to supporter
630 * 1. when their PCP status is changed by site admin.
631 * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
633 * @param int $pcpId campaign page id
634 * @param int $newStatus pcp status id
635 * @param bool|int $isInitial is it the first time, campaign page has been created by the user
637 * @param string $component
644 static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
645 $pcpStatusName = CRM_Core_OptionGroup
::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
646 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
647 $config = CRM_Core_Config
::singleton();
649 if (!isset($pcpStatus[$newStatus])) {
653 require_once 'Mail/mime.php';
656 $loginURL = $config->userSystem
->getLoginURL();
658 // used in subject templates
659 $contribPageTitle = self
::getPcpPageTitle($pcpId, $component);
662 'loginUrl' => $loginURL,
663 'contribPageTitle' => $contribPageTitle,
667 //get the default domain email address.
668 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
670 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
671 $fixUrl = CRM_Utils_System
::url("civicrm/admin/domain", 'action=update&reset=1');
672 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)));
675 $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
677 // get recipient (supporter) name and email
678 $params = array('id' => $pcpId);
679 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
680 list($name, $address) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($pcpInfo['contact_id']);
682 // get pcp block info
683 list($blockId, $eid) = self
::getPcpBlockEntityId($pcpId, $component);
684 $params = array('id' => $blockId);
685 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
687 // assign urls required in email template
688 if ($pcpStatusName[$newStatus] == 'Approved') {
689 $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
690 if ($pcpBlockInfo['is_tellfriend_enabled']) {
691 $pcpTellFriendURL = CRM_Utils_System
::url('civicrm/friend',
692 "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
693 TRUE, NULL, FALSE, TRUE
695 $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
698 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
700 TRUE, NULL, FALSE, TRUE
702 $tplParams['pcpInfoURL'] = $pcpInfoURL;
703 $tplParams['contribPageTitle'] = $contribPageTitle;
704 if ($emails = CRM_Utils_Array
::value('notify_email', $pcpBlockInfo)) {
705 $emailArray = explode(',', $emails);
706 $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
708 // get appropriate message based on status
709 $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
711 $tplName = $isInitial ?
'pcp_supporter_notify' : 'pcp_status_change';
713 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
715 'groupName' => 'msg_tpl_workflow_contribution',
716 'valueName' => $tplName,
717 'contactId' => $pcpInfo['contact_id'],
718 'tplParams' => $tplParams,
719 'from' => $receiptFrom,
721 'toEmail' => $address,
728 * Enable / Disable the campaign page
730 * @param int $id campaign page id
737 static function setDisable($id, $is_active) {
738 return CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
742 * Get pcp block is active
751 static function getStatus($pcpId, $component) {
755 LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id )
757 AND pb.entity_table = %2";
759 $entity_table = self
::getPcpEntityTable($component);
761 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
762 return CRM_Core_DAO
::singleValueQuery($query, $params);
766 * Get pcp block is enabled for component page
775 static function getPcpBlockStatus($pageId, $component) {
777 SELECT pb.link_text as linkText
778 FROM civicrm_pcp_block pb
779 WHERE pb.is_active = 1 AND
780 pb.entity_id = %1 AND
781 pb.entity_table = %2";
783 $entity_table = self
::getPcpEntityTable($component);
785 $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
786 return CRM_Core_DAO
::singleValueQuery($query, $params);
790 * Find out if the PCP block is in use by one or more PCP page
792 * @param int $id pcp block id
799 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 supporter's profile id
819 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
843 static function getPcpPageTitle($pcpId, $component) {
844 if ($component == 'contribute') {
848 LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
851 elseif ($component == 'event') {
855 LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
859 $params = array(1 => array($pcpId, 'Integer'));
860 return CRM_Core_DAO
::singleValueQuery($query, $params);
864 * Get pcp block & entity id given pcp id
873 static function getPcpBlockEntityId($pcpId, $component) {
874 $entity_table = self
::getPcpEntityTable($component);
877 SELECT pb.id as pcpBlockId, pb.entity_id
879 LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
882 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
883 $dao = CRM_Core_DAO
::executeQuery($query, $params);
885 return array($dao->pcpBlockId
, $dao->entity_id
);
892 * Get pcp entity table given a component.
900 static function getPcpEntityTable($component) {
901 $entity_table_map = array(
902 'event' => 'civicrm_event',
903 'civicrm_event' => 'civicrm_event',
904 'contribute' => 'civicrm_contribution_page',
905 'civicrm_contribution_page' => 'civicrm_contribution_page',
907 return isset($entity_table_map[$component]) ?
$entity_table_map[$component] : FALSE;
911 * Get supporter profile id
913 * @param int $component_id
914 * @param string $component
920 public static function getSupporterProfileId($component_id, $component = 'contribute') {
921 $entity_table = self
::getPcpEntityTable($component);
924 SELECT pcp.supporter_profile_id
925 FROM civicrm_pcp_block pcp
926 INNER JOIN civicrm_uf_group ufgroup
927 ON pcp.supporter_profile_id = ufgroup.id
928 WHERE pcp.entity_id = %1
929 AND pcp.entity_table = %2
930 AND ufgroup.is_active = 1";
932 $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
933 if (!$supporterProfileId = CRM_Core_DAO
::singleValueQuery($query, $params)) {
934 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.'));
937 return $supporterProfileId;