3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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;
45 function __construct() {
46 parent
::__construct();
50 * function to add or update either a Personal Campaign Page OR a PCP Block
52 * @param array $params reference array contains the values submitted by the form
53 * @param bool $pcpBlock if true, create or update PCPBlock, else PCP
59 static function add(&$params, $pcpBlock = TRUE) {
61 // action is taken depending upon the mode
62 $dao = new CRM_PCP_DAO_PCPBlock();
63 $dao->copyValues($params);
68 $dao = new CRM_PCP_DAO_PCP();
69 $dao->copyValues($params);
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
)) {
77 // set currency for CRM-1496
78 if (!isset($dao->currency
)) {
79 $config = & CRM_Core_Config
::singleton();
80 $dao->currency
= $config->defaultCurrency
;
88 * function to get the Display name of a contact for a PCP
90 * @param int $id id for the PCP
92 * @return null|string Dispaly name of the contact if found
96 static function displayName($id) {
97 $id = CRM_Utils_Type
::escape($id, 'Integer');
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}
105 return CRM_Core_DAO
::singleValueQuery($query, CRM_Core_DAO
::$_nullArray);
109 * Function to return PCP Block info for dashboard
111 * @return array array of Pcp if found
115 static function getPcpDashboardInfo($contactId) {
116 $links = self
::pcpLinks();
119 SELECT * FROM civicrm_pcp pcp
120 WHERE pcp.is_active = 1
121 AND pcp.contact_id = %1
122 ORDER BY page_type, page_id";
124 $params = array(1 => array($contactId, 'Integer'));
126 $pcpInfoDao = CRM_Core_DAO
::executeQuery($query, $params);
128 $hide = $mask = array_sum(array_keys($links['all']));
129 $contactPCPPages = array();
131 $event = CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
132 $contribute = CRM_Contribute_PseudoConstant
::contributionPage();
133 $pcpStatus = CRM_Contribute_PseudoConstant
::pcpStatus();
134 $approved = CRM_Utils_Array
::key('Approved', $pcpStatus);
136 while ($pcpInfoDao->fetch()) {
140 'pcpId' => $pcpInfoDao->id
,
141 'pcpBlock' => $pcpInfoDao->pcp_block_id
,
142 'pageComponent' => $pcpInfoDao->page_type
,
146 $pcpLink = $links['all'];
149 if ($pcpInfoDao->status_id
!= $approved ||
$pcpInfoDao->is_active
!= 1) {
151 if (!$pcpInfoDao->tellfriend
) {
152 $mask -= CRM_Core_Action
::DETACH
;
156 if ($pcpInfoDao->is_active
== 1) {
157 $mask -= CRM_Core_Action
::ENABLE
;
160 $mask -= CRM_Core_Action
::DISABLE
;
162 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
163 FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id
);
164 $component = $pcpInfoDao->page_type
;
165 $pageTitle = CRM_Utils_Array
::value($pcpInfoDao->page_id
, $
$component);
168 'pageTitle' => $pageTitle,
169 'pcpId' => $pcpInfoDao->id
,
170 'pcpTitle' => $pcpInfoDao->title
,
171 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id
],
175 $contactPCPPages[$pcpInfoDao->page_type
][] = $pcpInfoDao->page_id
;
178 $excludePageClause = $clause = NULL;
179 if (!empty($contactPCPPages)) {
180 foreach ($contactPCPPages as $component => $entityIds) {
181 $excludePageClause[] = "
182 ( target_entity_type = '{$component}'
183 AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
186 $clause = ' AND ' . implode(' OR ', $excludePageClause);
191 FROM civicrm_pcp_block block
192 LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id
193 WHERE block.is_active = 1
196 ORDER BY target_entity_type, target_entity_id
198 $pcpBlockDao = CRM_Core_DAO
::executeQuery($query);
202 while ($pcpBlockDao->fetch()) {
205 'pageId' => $pcpBlockDao->target_entity_id
,
206 'pageComponent' => $pcpBlockDao->target_entity_type
,
209 $pcpLink = $links['add'];
210 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace, ts('more'),
211 FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id
);
212 $component = $pcpBlockDao->target_entity_type
;
213 $pageTitle = CRM_Utils_Array
::value($pcpBlockDao->target_entity_id
, $
$component);
215 'pageId' => $pcpBlockDao->target_entity_id
,
216 'pageTitle' => $pageTitle,
221 return array($pcpBlock, $pcpInfo);
225 * function to show the total amount for Personal Campaign Page on thermometer
227 * @param array $pcpId contains the pcp ID
232 * @return total amount
234 static function thermoMeter($pcpId) {
236 SELECT SUM(cc.total_amount) as total
238 LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )
239 LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)
240 WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0";
242 $params = array(1 => array($pcpId, 'Integer'));
243 return CRM_Core_DAO
::singleValueQuery($query, $params);
247 * function to show the amount, nickname on honor roll
249 * @param array $pcpId contains the pcp ID
254 * @return array $honor
256 static function honorRoll($pcpId) {
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
266 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
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
;
279 * @return array (reference) of action links
282 static function &pcpLinks() {
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.');
286 self
::$_pcpLinks['add'] = array(
287 CRM_Core_Action
::ADD
=> array(
288 'name' => ts('Create a Personal Campaign Page'),
289 'url' => 'civicrm/contribute/campaign',
290 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
291 'title' => ts('Configure'),
295 self
::$_pcpLinks['all'] = array(
296 CRM_Core_Action
::UPDATE
=> array(
297 'name' => ts('Edit Your Page'),
298 'url' => 'civicrm/pcp/info',
299 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
300 'title' => ts('Configure'),
302 CRM_Core_Action
::DETACH
=> array(
303 'name' => ts('Tell Friends'),
304 'url' => 'civicrm/friend',
305 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
306 'title' => ts('Tell Friends'),
308 CRM_Core_Action
::BROWSE
=> array(
309 'name' => ts('Update Contact Information'),
310 'url' => 'civicrm/pcp/info',
311 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
312 'title' => ts('Update Contact Information'),
314 CRM_Core_Action
::ENABLE
=> array(
315 'name' => ts('Enable'),
316 'url' => 'civicrm/pcp',
317 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
318 'title' => ts('Enable'),
320 CRM_Core_Action
::DISABLE
=> array(
321 'name' => ts('Disable'),
322 'url' => 'civicrm/pcp',
323 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
324 'title' => ts('Disable'),
326 CRM_Core_Action
::DELETE
=> array(
327 'name' => ts('Delete'),
328 'url' => 'civicrm/pcp',
329 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
330 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
331 'title' => ts('Delete'),
335 return self
::$_pcpLinks;
339 * Function to Delete the campaign page
341 * @param int $id campaign page id
348 public static function deleteById($id) {
349 CRM_Utils_Hook
::pre('delete', 'Campaign', $id, CRM_Core_DAO
::$_nullArray);
351 $transaction = new CRM_Core_Transaction();
353 // delete from pcp table
354 $pcp = new CRM_PCP_DAO_PCP();
358 $transaction->commit();
360 CRM_Utils_Hook
::post('delete', 'Campaign', $id, $pcp);
364 * Function to build the form
366 * @param object $form form object
371 public static function buildPCPForm($form) {
372 $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
374 $form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
377 $isUserRequired = NULL;
378 $config = CRM_Core_Config
::singleton();
379 if ($config->userFramework
!= 'Standalone') {
382 CRM_Core_DAO
::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array(
386 if (!empty($profiles)) {
387 foreach ($profiles as $key => $value) {
388 if ($value['is_active']) {
389 $profile[$key] = $value['title'];
392 $form->assign('profile', $profile);
395 $form->add('select', 'supporter_profile_id', ts('Supporter profile'), array('' => ts('- select -')) +
$profile, TRUE);
397 $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);"));
401 ts("'Tell a friend' maximum recipients limit"),
402 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit')
404 $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
408 ts("'Create Personal Campaign Page' link text"),
409 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text')
412 $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
417 * Add PCP form elements to a form
419 function buildPcp($pcpId, &$page, &$elements = NULL) {
421 $prms = array('id' => $pcpId);
422 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
423 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($pcpId)) {
424 if ($pcpInfo['page_type'] == 'event') {
425 $pcp_supporter_text = ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
426 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'event');
428 $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!";
432 $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
433 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'contribute');
435 $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!";
439 $page->assign('pcpSupporterText', $pcp_supporter_text);
441 $page->assign('pcp', TRUE);
443 // build honor roll fields for registration form if supporter has honor roll enabled for their PCP
444 if ($pcpInfo['is_honor_roll']) {
445 $page->assign('is_honor_roll', TRUE);
446 $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL,
447 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
449 $extraOption = array('onclick' => "return pcpAnonymous( );");
451 $elements[] = & $page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
452 $elements[] = & $page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption);
453 $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
454 $page->_defaults
['pcp_is_anonymous'] = 0;
456 $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
457 $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
460 $page->assign('is_honor_roll', FALSE);
465 * Process a PCP contribution/
467 public static function handlePcp($pcpId, $component, $entity) {
469 self
::getPcpEntityTable($component);
475 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
477 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
479 $params = array('id' => $pcpId);
480 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
482 $params = array('id' => $pcpInfo['pcp_block_id']);
483 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock);
485 $params = array('id' => $pcpInfo['page_id']);
488 if ($component == 'event') {
489 // figure out where to redirect if an exception occurs below based on target entity
490 $urlBase = 'civicrm/event/register';
492 // ignore startDate for events - PCP's can be active long before event start date
494 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
496 elseif ($component == 'contribute') {
497 $urlBase = 'civicrm/contribute/transact';
498 //start and end date of the contribution page
499 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $entity));
500 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
503 // define redirect url back to contrib page or event if needed
504 $url = CRM_Utils_System
::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE );
506 if ($pcpBlock['target_entity_id'] != $entity['id']) {
507 $statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
508 CRM_Core_Error
::statusBounce($statusMessage, $url);
510 elseif ($pcpInfo['status_id'] != $approvedId) {
511 $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']]));
512 CRM_Core_Error
::statusBounce($statusMessage, $url);
514 elseif (empty($pcpBlock['is_active'])) {
515 $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.');
516 CRM_Core_Error
::statusBounce($statusMessage, $url);
518 elseif (empty($pcpInfo['is_active'])) {
519 $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.');
520 CRM_Core_Error
::statusBounce($statusMessage, $url);
522 // Check if we're in range for contribution page start and end dates. for events, check if after event end date
523 elseif (($startDate && $startDate > $now) ||
($endDate && $endDate < $now)) {
524 $customStartDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('start_date', $entity));
525 $customEndDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('end_date', $entity));
526 if ($startDate && $endDate) {
527 $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.',
528 array(1 => $customStartDate, 2 => $customEndDate)
530 CRM_Core_Error
::statusBounce($statusMessage, $url);
532 elseif ($startDate) {
533 $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));
534 CRM_Core_Error
::statusBounce($statusMessage, $url);
537 if ($component == 'event') {
538 // Target_entity is an event and the event is over, redirect to event info instead of event registration page.
539 $url = CRM_Utils_System
::url('civicrm/event/info',
540 "reset=1&id={$pcpBlock['entity_id']}",
541 FALSE, NULL, FALSE, TRUE
543 $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate));
544 CRM_Core_Error
::statusBounce($statusMessage, $url);
547 $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));
548 CRM_Core_Error
::statusBounce($statusMessage, $url);
555 'pcpBlock' => $pcpBlock,
556 'pcpInfo' => $pcpInfo,
561 * Function to Approve / Reject the campaign page
563 * @param int $id campaign page id
570 static function setIsActive($id, $is_active) {
571 switch ($is_active) {
581 CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active);
583 $pcpTitle = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title');
584 $pcpPageType = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type');
586 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
587 $pcpStatus = $pcpStatus[$is_active];
589 CRM_Core_Session
::setStatus(ts("%1 status has been updated to %2.", array(
592 )), 'Status Updated', 'success');
594 // send status change mail
595 $result = self
::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType);
598 CRM_Core_Session
::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success');
603 * Function to send notfication email to supporter
604 * 1. when their PCP status is changed by site admin.
605 * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
607 * @param int $pcpId campaign page id
608 * @param int $newStatus pcp status id
609 * @param int $isInitial is it the first time, campaign page has been created by the user
616 static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
617 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
618 $config = CRM_Core_Config
::singleton();
620 if (!isset($pcpStatus[$newStatus])) {
624 require_once 'Mail/mime.php';
627 $loginURL = $config->userSystem
->getLoginURL();
629 // used in subject templates
630 $contribPageTitle = self
::getPcpPageTitle($pcpId, $component);
633 'loginUrl' => $loginURL,
634 'contribPageTitle' => $contribPageTitle,
638 //get the default domain email address.
639 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
641 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
642 $fixUrl = CRM_Utils_System
::url("civicrm/admin/domain", 'action=update&reset=1');
643 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)));
646 $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
648 // get recipient (supporter) name and email
649 $params = array('id' => $pcpId);
650 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
651 list($name, $address) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($pcpInfo['contact_id']);
653 // get pcp block info
654 list($blockId, $eid) = self
::getPcpBlockEntityId($pcpId, $component);
655 $params = array('id' => $blockId);
656 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
658 // assign urls required in email template
659 if ($pcpStatus[$newStatus] == 'Approved') {
660 $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
661 if ($pcpBlockInfo['is_tellfriend_enabled']) {
662 $pcpTellFriendURL = CRM_Utils_System
::url('civicrm/friend',
663 "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
664 TRUE, NULL, FALSE, TRUE
666 $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
669 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
671 TRUE, NULL, FALSE, TRUE
673 $tplParams['pcpInfoURL'] = $pcpInfoURL;
674 $tplParams['contribPageTitle'] = $contribPageTitle;
675 if ($emails = CRM_Utils_Array
::value('notify_email', $pcpBlockInfo)) {
676 $emailArray = explode(',', $emails);
677 $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
679 // get appropriate message based on status
680 $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
682 $tplName = $isInitial ?
'pcp_supporter_notify' : 'pcp_status_change';
684 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
686 'groupName' => 'msg_tpl_workflow_contribution',
687 'valueName' => $tplName,
688 'contactId' => $pcpInfo['contact_id'],
689 'tplParams' => $tplParams,
690 'from' => $receiptFrom,
692 'toEmail' => $address,
699 * Function to Enable / Disable the campaign page
701 * @param int $id campaign page id
708 static function setDisable($id, $is_active) {
709 return CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
713 * Function to get pcp block is active
715 * @param int $id campaign page id
722 static function getStatus($pcpId, $component) {
726 LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id )
728 AND pb.entity_table = %2";
730 $entity_table = self
::getPcpEntityTable($component);
732 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
733 return CRM_Core_DAO
::singleValueQuery($query, $params);
737 * Function to get pcp block is enabled for component page
739 * @param int $id contribution page id
746 static function getPcpBlockStatus($pageId, $component) {
748 SELECT pb.link_text as linkText
749 FROM civicrm_pcp_block pb
750 WHERE pb.is_active = 1 AND
751 pb.entity_id = %1 AND
752 pb.entity_table = %2";
754 $entity_table = self
::getPcpEntityTable($component);
756 $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
757 return CRM_Core_DAO
::singleValueQuery($query, $params);
761 * Function to find out if the PCP block is in use by one or more PCP page
763 * @param int $id pcp block id
770 static function getPcpBlockInUse($id) {
774 WHERE pcp.pcp_block_id = %1";
776 $params = array(1 => array($id, 'Integer'));
777 $result = CRM_Core_DAO
::singleValueQuery($query, $params);
782 * Function to get email is enabled for supporter's profile
784 * @param int $id supporter's profile id
791 static function checkEmailProfile($profileId) {
794 FROM civicrm_uf_field
795 WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
797 $params = array(1 => array($profileId, 'Integer'));
798 $dao = CRM_Core_DAO
::executeQuery($query, $params);
799 if (!$dao->fetch()) {
806 * Function to obtain the title of page associated with a pcp
808 * @param int $id campaign page id
815 static function getPcpPageTitle($pcpId, $component) {
816 if ($component == 'contribute') {
820 LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
823 elseif ($component == 'event') {
827 LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
831 $params = array(1 => array($pcpId, 'Integer'));
832 return CRM_Core_DAO
::singleValueQuery($query, $params);
836 * Function to get pcp block & entity id given pcp id
838 * @param int $id campaign page id
845 static function getPcpBlockEntityId($pcpId, $component) {
846 $entity_table = self
::getPcpEntityTable($component);
849 SELECT pb.id as pcpBlockId, pb.entity_id
851 LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
854 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
855 $dao = CRM_Core_DAO
::executeQuery($query, $params);
857 return array($dao->pcpBlockId
, $dao->entity_id
);
864 * Function to get pcp entity table given a component.
866 * @param int $id campaign page id
873 static function getPcpEntityTable($component) {
874 $entity_table_map = array(
875 'event' => 'civicrm_event',
876 'civicrm_event' => 'civicrm_event',
877 'contribute' => 'civicrm_contribution_page',
878 'civicrm_contribution_page' => 'civicrm_contribution_page',
880 return isset($entity_table_map[$component]) ?
$entity_table_map[$component] : FALSE;
884 * Function to get supporter profile id
886 * @param int $contributionPageId contribution page id
892 public function getSupporterProfileId($component_id, $component = 'contribute') {
893 $entity_table = self
::getPcpEntityTable($component);
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";
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.'));
909 return $supporterProfileId;