3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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);
163 $component = $pcpInfoDao->page_type
;
164 $pageTitle = CRM_Utils_Array
::value($pcpInfoDao->page_id
, $
$component);
167 'pageTitle' => $pageTitle,
168 'pcpId' => $pcpInfoDao->id
,
169 'pcpTitle' => $pcpInfoDao->title
,
170 'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id
],
174 $contactPCPPages[$pcpInfoDao->page_type
][] = $pcpInfoDao->page_id
;
177 $excludePageClause = $clause = NULL;
178 if (!empty($contactPCPPages)) {
179 foreach ($contactPCPPages as $component => $entityIds) {
180 $excludePageClause[] = "
181 ( target_entity_type = '{$component}'
182 AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
185 $clause = ' AND ' . implode(' OR ', $excludePageClause);
190 FROM civicrm_pcp_block block
191 LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id
192 WHERE block.is_active = 1
195 ORDER BY target_entity_type, target_entity_id
197 $pcpBlockDao = CRM_Core_DAO
::executeQuery($query);
201 while ($pcpBlockDao->fetch()) {
204 'pageId' => $pcpBlockDao->target_entity_id
,
205 'pageComponent' => $pcpBlockDao->target_entity_type
,
208 $pcpLink = $links['add'];
209 $action = CRM_Core_Action
::formLink($pcpLink, $mask, $replace);
210 $component = $pcpBlockDao->target_entity_type
;
211 $pageTitle = CRM_Utils_Array
::value($pcpBlockDao->target_entity_id
, $
$component);
213 'pageId' => $pcpBlockDao->target_entity_id
,
214 'pageTitle' => $pageTitle,
219 return array($pcpBlock, $pcpInfo);
223 * function to show the total amount for Personal Campaign Page on thermometer
225 * @param array $pcpId contains the pcp ID
230 * @return total amount
232 static function thermoMeter($pcpId) {
234 SELECT SUM(cc.total_amount) as total
236 LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )
237 LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)
238 WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0";
240 $params = array(1 => array($pcpId, 'Integer'));
241 return CRM_Core_DAO
::singleValueQuery($query, $params);
245 * function to show the amount, nickname on honor roll
247 * @param array $pcpId contains the pcp ID
252 * @return array $honor
254 static function honorRoll($pcpId) {
256 SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note,
257 cc.total_amount, cc.currency
258 FROM civicrm_contribution cc
259 LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id
260 WHERE cs.pcp_id = {$pcpId}
261 AND cs.pcp_display_in_roll = 1
262 AND contribution_status_id = 1
264 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
266 while ($dao->fetch()) {
267 $honor[$dao->id
]['nickname'] = ucwords($dao->pcp_roll_nickname
);
268 $honor[$dao->id
]['total_amount'] = CRM_Utils_Money
::format($dao->total_amount
, $dao->currency
);
269 $honor[$dao->id
]['personal_note'] = $dao->pcp_personal_note
;
277 * @return array (reference) of action links
280 static function &pcpLinks() {
281 if (!(self
::$_pcpLinks)) {
282 $deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
284 self
::$_pcpLinks['add'] = array(
285 CRM_Core_Action
::ADD
=> array(
286 'name' => ts('Create a Personal Campaign Page'),
287 'url' => 'civicrm/contribute/campaign',
288 'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
289 'title' => ts('Configure'),
293 self
::$_pcpLinks['all'] = array(
294 CRM_Core_Action
::UPDATE
=> array(
295 'name' => ts('Edit Your Page'),
296 'url' => 'civicrm/pcp/info',
297 'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
298 'title' => ts('Configure'),
300 CRM_Core_Action
::DETACH
=> array(
301 'name' => ts('Tell Friends'),
302 'url' => 'civicrm/friend',
303 'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
304 'title' => ts('Tell Friends'),
306 CRM_Core_Action
::BROWSE
=> array(
307 'name' => ts('Update Contact Information'),
308 'url' => 'civicrm/pcp/info',
309 'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
310 'title' => ts('Update Contact Information'),
312 CRM_Core_Action
::ENABLE
=> array(
313 'name' => ts('Enable'),
314 'url' => 'civicrm/pcp',
315 'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
316 'title' => ts('Enable'),
318 CRM_Core_Action
::DISABLE
=> array(
319 'name' => ts('Disable'),
320 'url' => 'civicrm/pcp',
321 'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
322 'title' => ts('Disable'),
324 CRM_Core_Action
::DELETE
=> array(
325 'name' => ts('Delete'),
326 'url' => 'civicrm/pcp',
327 'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
328 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
329 'title' => ts('Delete'),
333 return self
::$_pcpLinks;
337 * Function to Delete the campaign page
339 * @param int $id campaign page id
346 public static function deleteById($id) {
347 CRM_Utils_Hook
::pre('delete', 'Campaign', $id, CRM_Core_DAO
::$_nullArray);
349 $transaction = new CRM_Core_Transaction();
351 // delete from pcp table
352 $pcp = new CRM_PCP_DAO_PCP();
356 $transaction->commit();
358 CRM_Utils_Hook
::post('delete', 'Campaign', $id, $pcp);
362 * Function to build the form
364 * @param object $form form object
369 public static function buildPCPForm($form) {
370 $form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
372 $form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
375 $isUserRequired = NULL;
376 $config = CRM_Core_Config
::singleton();
377 if ($config->userFramework
!= 'Standalone') {
380 CRM_Core_DAO
::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array(
384 if (!empty($profiles)) {
385 foreach ($profiles as $key => $value) {
386 if ($value['is_active']) {
387 $profile[$key] = $value['title'];
390 $form->assign('profile', $profile);
393 $form->add('select', 'supporter_profile_id', ts('Supporter profile'), array('' => ts('- select -')) +
$profile, TRUE);
395 $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);"));
399 ts("'Tell a friend' maximum recipients limit"),
400 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit')
402 $form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
406 ts("'Create Personal Campaign Page' link text"),
407 CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text')
410 $form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO
::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
415 * Add PCP form elements to a form
417 function buildPcp($pcpId, &$page, &$elements = NULL) {
419 $prms = array('id' => $pcpId);
420 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
421 if ($pcpSupporter = CRM_PCP_BAO_PCP
::displayName($pcpId)) {
422 if ($pcpInfo['page_type'] == 'event') {
423 $pcp_supporter_text = ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
424 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'event');
426 $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!";
430 $pcp_supporter_text = ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
431 $text = CRM_PCP_BAO_PCP
::getPcpBlockStatus($pcpInfo['page_id'], 'contribute');
433 $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!";
437 $page->assign('pcpSupporterText', $pcp_supporter_text);
439 $page->assign('pcp', TRUE);
441 // build honor roll fields for registration form if supporter has honor roll enabled for their PCP
442 if ($pcpInfo['is_honor_roll']) {
443 $page->assign('is_honor_roll', TRUE);
444 $page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL,
445 array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
447 $extraOption = array('onclick' => "return pcpAnonymous( );");
449 $elements[] = & $page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
450 $elements[] = & $page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption);
451 $page->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
452 $page->_defaults
['pcp_is_anonymous'] = 0;
454 $page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
455 $page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
458 $page->assign('is_honor_roll', FALSE);
463 * Process a PCP contribution/
465 public static function handlePcp($pcpId, $component, $entity) {
467 self
::getPcpEntityTable($component);
473 $approvedId = CRM_Core_OptionGroup
::getValue('pcp_status', 'Approved', 'name');
475 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
477 $params = array('id' => $pcpId);
478 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
480 $params = array('id' => $pcpInfo['pcp_block_id']);
481 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock);
483 $params = array('id' => $pcpInfo['page_id']);
486 if ($component == 'event') {
487 // figure out where to redirect if an exception occurs below based on target entity
488 $urlBase = 'civicrm/event/register';
490 // ignore startDate for events - PCP's can be active long before event start date
492 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
494 elseif ($component == 'contribute') {
495 $urlBase = 'civicrm/contribute/transact';
496 //start and end date of the contribution page
497 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $entity));
498 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $entity));
501 // define redirect url back to contrib page or event if needed
502 $url = CRM_Utils_System
::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE );
504 if ($pcpBlock['target_entity_id'] != $entity['id']) {
505 $statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
506 CRM_Core_Error
::statusBounce($statusMessage, $url);
508 elseif ($pcpInfo['status_id'] != $approvedId) {
509 $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']]));
510 CRM_Core_Error
::statusBounce($statusMessage, $url);
512 elseif (!CRM_Utils_Array
::value('is_active', $pcpBlock)) {
513 $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.');
514 CRM_Core_Error
::statusBounce($statusMessage, $url);
516 elseif (!CRM_Utils_Array
::value('is_active', $pcpInfo)) {
517 $statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.');
518 CRM_Core_Error
::statusBounce($statusMessage, $url);
520 // Check if we're in range for contribution page start and end dates. for events, check if after event end date
521 elseif (($startDate && $startDate > $now) ||
($endDate && $endDate < $now)) {
522 $customStartDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('start_date', $entity));
523 $customEndDate = CRM_Utils_Date
::customFormat(CRM_Utils_Array
::value('end_date', $entity));
524 if ($startDate && $endDate) {
525 $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.',
526 array(1 => $customStartDate, 2 => $customEndDate)
528 CRM_Core_Error
::statusBounce($statusMessage, $url);
530 elseif ($startDate) {
531 $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));
532 CRM_Core_Error
::statusBounce($statusMessage, $url);
535 if ($component == 'event') {
536 // Target_entity is an event and the event is over, redirect to event info instead of event registration page.
537 $url = CRM_Utils_System
::url('civicrm/event/info',
538 "reset=1&id={$pcpBlock['entity_id']}",
539 FALSE, NULL, FALSE, TRUE
541 $statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate));
542 CRM_Core_Error
::statusBounce($statusMessage, $url);
545 $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));
546 CRM_Core_Error
::statusBounce($statusMessage, $url);
553 'pcpBlock' => $pcpBlock,
554 'pcpInfo' => $pcpInfo,
559 * Function to Approve / Reject the campaign page
561 * @param int $id campaign page id
568 static function setIsActive($id, $is_active) {
569 switch ($is_active) {
579 CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active);
581 $pcpTitle = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title');
582 $pcpPageType = CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type');
584 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
585 $pcpStatus = $pcpStatus[$is_active];
587 CRM_Core_Session
::setStatus(ts("%1 status has been updated to %2.", array(
590 )), 'Status Updated', 'success');
592 // send status change mail
593 $result = self
::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType);
596 CRM_Core_Session
::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success');
601 * Function to send notfication email to supporter
602 * 1. when their PCP status is changed by site admin.
603 * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
605 * @param int $pcpId campaign page id
606 * @param int $newStatus pcp status id
607 * @param int $isInitial is it the first time, campaign page has been created by the user
614 static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
615 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
616 $config = CRM_Core_Config
::singleton();
618 if (!isset($pcpStatus[$newStatus])) {
622 require_once 'Mail/mime.php';
625 $loginURL = $config->userSystem
->getLoginURL();
627 // used in subject templates
628 $contribPageTitle = self
::getPcpPageTitle($pcpId, $component);
631 'loginUrl' => $loginURL,
632 'contribPageTitle' => $contribPageTitle,
636 //get the default domain email address.
637 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain
::getNameAndEmail();
639 if (!$domainEmailAddress ||
$domainEmailAddress == 'info@EXAMPLE.ORG') {
640 $fixUrl = CRM_Utils_System
::url("civicrm/admin/domain", 'action=update&reset=1');
641 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)));
644 $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
646 // get recipient (supporter) name and email
647 $params = array('id' => $pcpId);
648 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
649 list($name, $address) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($pcpInfo['contact_id']);
651 // get pcp block info
652 list($blockId, $eid) = self
::getPcpBlockEntityId($pcpId, $component);
653 $params = array('id' => $blockId);
654 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
656 // assign urls required in email template
657 if ($pcpStatus[$newStatus] == 'Approved') {
658 $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
659 if ($pcpBlockInfo['is_tellfriend_enabled']) {
660 $pcpTellFriendURL = CRM_Utils_System
::url('civicrm/friend',
661 "reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
662 TRUE, NULL, FALSE, TRUE
664 $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
667 $pcpInfoURL = CRM_Utils_System
::url('civicrm/pcp/info',
669 TRUE, NULL, FALSE, TRUE
671 $tplParams['pcpInfoURL'] = $pcpInfoURL;
672 $tplParams['contribPageTitle'] = $contribPageTitle;
673 if ($emails = CRM_Utils_Array
::value('notify_email', $pcpBlockInfo)) {
674 $emailArray = explode(',', $emails);
675 $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
677 // get appropriate message based on status
678 $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
680 $tplName = $isInitial ?
'pcp_supporter_notify' : 'pcp_status_change';
682 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
684 'groupName' => 'msg_tpl_workflow_contribution',
685 'valueName' => $tplName,
686 'contactId' => $pcpInfo['contact_id'],
687 'tplParams' => $tplParams,
688 'from' => $receiptFrom,
690 'toEmail' => $address,
697 * Function to Enable / Disable the campaign page
699 * @param int $id campaign page id
706 static function setDisable($id, $is_active) {
707 return CRM_Core_DAO
::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
711 * Function to get pcp block is active
713 * @param int $id campaign page id
720 static function getStatus($pcpId, $component) {
724 LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id )
726 AND pb.entity_table = %2";
728 $entity_table = self
::getPcpEntityTable($component);
730 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
731 return CRM_Core_DAO
::singleValueQuery($query, $params);
735 * Function to get pcp block is enabled for component page
737 * @param int $id contribution page id
744 static function getPcpBlockStatus($pageId, $component) {
746 SELECT pb.link_text as linkText
747 FROM civicrm_pcp_block pb
748 WHERE pb.is_active = 1 AND
749 pb.entity_id = %1 AND
750 pb.entity_table = %2";
752 $entity_table = self
::getPcpEntityTable($component);
754 $params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
755 return CRM_Core_DAO
::singleValueQuery($query, $params);
759 * Function to find out if the PCP block is in use by one or more PCP page
761 * @param int $id pcp block id
768 static function getPcpBlockInUse($id) {
772 WHERE pcp.pcp_block_id = %1";
774 $params = array(1 => array($id, 'Integer'));
775 $result = CRM_Core_DAO
::singleValueQuery($query, $params);
780 * Function to get email is enabled for supporter's profile
782 * @param int $id supporter's profile id
789 static function checkEmailProfile($profileId) {
792 FROM civicrm_uf_field
793 WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
795 $params = array(1 => array($profileId, 'Integer'));
796 $dao = CRM_Core_DAO
::executeQuery($query, $params);
797 if (!$dao->fetch()) {
804 * Function to obtain the title of page associated with a pcp
806 * @param int $id campaign page id
813 static function getPcpPageTitle($pcpId, $component) {
814 if ($component == 'contribute') {
818 LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
821 elseif ($component == 'event') {
825 LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
829 $params = array(1 => array($pcpId, 'Integer'));
830 return CRM_Core_DAO
::singleValueQuery($query, $params);
834 * Function to get pcp block & entity id given pcp id
836 * @param int $id campaign page id
843 static function getPcpBlockEntityId($pcpId, $component) {
844 $entity_table = self
::getPcpEntityTable($component);
847 SELECT pb.id as pcpBlockId, pb.entity_id
849 LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
852 $params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
853 $dao = CRM_Core_DAO
::executeQuery($query, $params);
855 return array($dao->pcpBlockId
, $dao->entity_id
);
862 * Function to get pcp entity table given a component.
864 * @param int $id campaign page id
871 static function getPcpEntityTable($component) {
872 $entity_table_map = array(
873 'event' => 'civicrm_event',
874 'civicrm_event' => 'civicrm_event',
875 'contribute' => 'civicrm_contribution_page',
876 'civicrm_contribution_page' => 'civicrm_contribution_page',
878 return isset($entity_table_map[$component]) ?
$entity_table_map[$component] : FALSE;
882 * Function to get supporter profile id
884 * @param int $contributionPageId contribution page id
890 public function getSupporterProfileId($component_id, $component = 'contribute') {
891 $entity_table = self
::getPcpEntityTable($component);
894 SELECT pcp.supporter_profile_id
895 FROM civicrm_pcp_block pcp
896 INNER JOIN civicrm_uf_group ufgroup
897 ON pcp.supporter_profile_id = ufgroup.id
898 WHERE pcp.entity_id = %1
899 AND pcp.entity_table = %2
900 AND ufgroup.is_active = 1";
902 $params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
903 if (!$supporterProfileId = CRM_Core_DAO
::singleValueQuery($query, $params)) {
904 CRM_Core_Error
::fatal(ts('Supporter profile is not set for this Personal Campaign Page or the profile is disabled. Please contact the site administrator if you need assistance.'));
907 return $supporterProfileId;