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
97 * @return null|string Dispaly name of the contact if found
100 public 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
118 * array of Pcp if found
121 public 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
235 * Contains the pcp ID.
239 * @return total amount
241 public 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
257 * Contains the pcp ID.
263 public 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
;
287 * (reference) of action links
290 public static function &pcpLinks() {
291 if (!(self
::$_pcpLinks)) {
292 $deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
294 self
::$_pcpLinks['add'] = array(
295 CRM_Core_Action
::ADD
=> array(
296 'name' => ts('Create a Personal Campaign Page'),
297 'url' => 'civicrm/contribute/campaign',
298 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
299 'title' => ts('Configure'),
303 self
::$_pcpLinks['all'] = array(
304 CRM_Core_Action
::UPDATE
=> array(
305 'name' => ts('Edit Your Page'),
306 'url' => 'civicrm/pcp/info',
307 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
308 'title' => ts('Configure'),
310 CRM_Core_Action
::DETACH
=> array(
311 'name' => ts('Tell Friends'),
312 'url' => 'civicrm/friend',
313 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
314 'title' => ts('Tell Friends'),
316 CRM_Core_Action
::VIEW
=> array(
317 'name' => ts('URL for this Page'),
318 'url' => 'civicrm/pcp/info',
319 'qs' => 'reset=1&id=%%pcpId%%&component=%%pageComponent%%',
320 'title' => ts('URL for this Page'),
322 CRM_Core_Action
::BROWSE
=> array(
323 'name' => ts('Update Contact Information'),
324 'url' => 'civicrm/pcp/info',
325 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
326 'title' => ts('Update Contact Information'),
328 CRM_Core_Action
::ENABLE
=> array(
329 'name' => ts('Enable'),
330 'url' => 'civicrm/pcp',
331 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
332 'title' => ts('Enable'),
334 CRM_Core_Action
::DISABLE
=> array(
335 'name' => ts('Disable'),
336 'url' => 'civicrm/pcp',
337 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
338 'title' => ts('Disable'),
340 CRM_Core_Action
::DELETE
=> array(
341 'name' => ts('Delete'),
342 'url' => 'civicrm/pcp',
343 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
344 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
345 'title' => ts('Delete'),
349 return self
::$_pcpLinks;
353 * Delete the campaign page
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
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
434 * @param CRM_Core_Page $page
435 * @param null $elements
437 public 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
596 public 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).
635 * @param int $newStatus
637 * @param bool|int $isInitial is it the first time, campaign page has been created by the user
639 * @param string $component
645 public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
646 $pcpStatusName = CRM_Core_OptionGroup
::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
647 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
648 $config = CRM_Core_Config
::singleton();
650 if (!isset($pcpStatus[$newStatus])) {
654 require_once 'Mail/mime.php';
657 $loginURL = $config->userSystem
->getLoginURL();
659 // used in subject templates
660 $contribPageTitle = self
::getPcpPageTitle($pcpId, $component);
663 'loginUrl' => $loginURL,
664 'contribPageTitle' => $contribPageTitle,
668 //get the default domain email address.
669 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
671 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
672 $fixUrl = CRM_Utils_System
::url("civicrm/admin/domain", 'action=update&reset=1');
673 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)));
676 $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
678 // get recipient (supporter) name and email
679 $params = array('id' => $pcpId);
680 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
681 list($name, $address) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($pcpInfo['contact_id']);
683 // get pcp block info
684 list($blockId, $eid) = self
::getPcpBlockEntityId($pcpId, $component);
685 $params = array('id' => $blockId);
686 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
688 // assign urls required in email template
689 if ($pcpStatusName[$newStatus] == 'Approved') {
690 $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
691 if ($pcpBlockInfo['is_tellfriend_enabled']) {
692 $pcpTellFriendURL = CRM_Utils_System
::url('civicrm/friend',
693 "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
694 TRUE, NULL, FALSE, TRUE
696 $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
699 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
701 TRUE, NULL, FALSE, TRUE
703 $tplParams['pcpInfoURL'] = $pcpInfoURL;
704 $tplParams['contribPageTitle'] = $contribPageTitle;
705 if ($emails = CRM_Utils_Array
::value('notify_email', $pcpBlockInfo)) {
706 $emailArray = explode(',', $emails);
707 $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
709 // get appropriate message based on status
710 $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
712 $tplName = $isInitial ?
'pcp_supporter_notify' : 'pcp_status_change';
714 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
716 'groupName' => 'msg_tpl_workflow_contribution',
717 'valueName' => $tplName,
718 'contactId' => $pcpInfo['contact_id'],
719 'tplParams' => $tplParams,
720 'from' => $receiptFrom,
722 'toEmail' => $address,
729 * Enable / Disable the campaign page
738 public static function setDisable($id, $is_active) {
739 return CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
743 * Get pcp block is active
751 public 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
774 public static function getPcpBlockStatus($pageId, $component) {
776 SELECT pb.link_text as linkText
777 FROM civicrm_pcp_block pb
778 WHERE pb.is_active = 1 AND
779 pb.entity_id = %1 AND
780 pb.entity_table = %2";
782 $entity_table = self
::getPcpEntityTable($component);
784 $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
785 return CRM_Core_DAO
::singleValueQuery($query, $params);
789 * Find out if the PCP block is in use by one or more PCP page
797 public static function getPcpBlockInUse($id) {
801 WHERE pcp.pcp_block_id = %1";
803 $params = array(1 => array($id, 'Integer'));
804 $result = CRM_Core_DAO
::singleValueQuery($query, $params);
809 * Get email is enabled for supporter's profile
811 * @param int $profileId
812 * Supporter's profile id.
817 public static function checkEmailProfile($profileId) {
820 FROM civicrm_uf_field
821 WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
823 $params = array(1 => array($profileId, 'Integer'));
824 $dao = CRM_Core_DAO
::executeQuery($query, $params);
825 if (!$dao->fetch()) {
832 * Obtain the title of page associated with a pcp
840 public static function getPcpPageTitle($pcpId, $component) {
841 if ($component == 'contribute') {
845 LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
848 elseif ($component == 'event') {
852 LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
856 $params = array(1 => array($pcpId, 'Integer'));
857 return CRM_Core_DAO
::singleValueQuery($query, $params);
861 * Get pcp block & entity id given pcp id
869 public static function getPcpBlockEntityId($pcpId, $component) {
870 $entity_table = self
::getPcpEntityTable($component);
873 SELECT pb.id as pcpBlockId, pb.entity_id
875 LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
878 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
879 $dao = CRM_Core_DAO
::executeQuery($query, $params);
881 return array($dao->pcpBlockId
, $dao->entity_id
);
888 * Get pcp entity table given a component.
895 public static function getPcpEntityTable($component) {
896 $entity_table_map = array(
897 'event' => 'civicrm_event',
898 'civicrm_event' => 'civicrm_event',
899 'contribute' => 'civicrm_contribution_page',
900 'civicrm_contribution_page' => 'civicrm_contribution_page',
902 return isset($entity_table_map[$component]) ?
$entity_table_map[$component] : FALSE;
906 * Get supporter profile id
908 * @param int $component_id
909 * @param string $component
914 public static function getSupporterProfileId($component_id, $component = 'contribute') {
915 $entity_table = self
::getPcpEntityTable($component);
918 SELECT pcp.supporter_profile_id
919 FROM civicrm_pcp_block pcp
920 INNER JOIN civicrm_uf_group ufgroup
921 ON pcp.supporter_profile_id = ufgroup.id
922 WHERE pcp.entity_id = %1
923 AND pcp.entity_table = %2
924 AND ufgroup.is_active = 1";
926 $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
927 if (!$supporterProfileId = CRM_Core_DAO
::singleValueQuery($query, $params)) {
928 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.'));
931 return $supporterProfileId;