First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
926
sites/all/modules/civicrm/CRM/PCP/BAO/PCP.php
Normal file
926
sites/all/modules/civicrm/CRM/PCP/BAO/PCP.php
Normal file
|
@ -0,0 +1,926 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_PCP_BAO_PCP extends CRM_PCP_DAO_PCP {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_pcpLinks = NULL;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update either a Personal Campaign Page OR a PCP Block.
|
||||
*
|
||||
* @param array $params
|
||||
* Values to create the pcp.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function create($params) {
|
||||
|
||||
$dao = new CRM_PCP_DAO_PCP();
|
||||
$dao->copyValues($params);
|
||||
|
||||
// ensure we set status_id since it is a not null field
|
||||
// we should change the schema and allow this to be null
|
||||
if (!$dao->id && !isset($dao->status_id)) {
|
||||
$dao->status_id = 0;
|
||||
}
|
||||
|
||||
// set currency for CRM-1496
|
||||
if (!isset($dao->currency)) {
|
||||
$dao->currency = CRM_Core_Config::singleton()->defaultCurrency;
|
||||
}
|
||||
|
||||
$dao->save();
|
||||
return $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Display name of a contact for a PCP.
|
||||
*
|
||||
* @param int $id
|
||||
* Id for the PCP.
|
||||
*
|
||||
* @return null|string
|
||||
* Dispaly name of the contact if found
|
||||
*/
|
||||
public static function displayName($id) {
|
||||
$id = CRM_Utils_Type::escape($id, 'Integer');
|
||||
|
||||
$query = "
|
||||
SELECT civicrm_contact.display_name
|
||||
FROM civicrm_pcp, civicrm_contact
|
||||
WHERE civicrm_pcp.contact_id = civicrm_contact.id
|
||||
AND civicrm_pcp.id = {$id}
|
||||
";
|
||||
return CRM_Core_DAO::singleValueQuery($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PCP Block info for dashboard.
|
||||
*
|
||||
* @param int $contactId
|
||||
*
|
||||
* @return array
|
||||
* array of Pcp if found
|
||||
*/
|
||||
public static function getPcpDashboardInfo($contactId) {
|
||||
$links = self::pcpLinks();
|
||||
|
||||
$query = "
|
||||
SELECT pcp.*, block.is_tellfriend_enabled FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_pcp_block block ON block.id = pcp.pcp_block_id
|
||||
WHERE pcp.is_active = 1
|
||||
AND pcp.contact_id = %1
|
||||
ORDER BY page_type, page_id";
|
||||
|
||||
$params = array(1 => array($contactId, 'Integer'));
|
||||
|
||||
$pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
$pcpInfo = array();
|
||||
$hide = $mask = array_sum(array_keys($links['all']));
|
||||
$contactPCPPages = array();
|
||||
|
||||
$event = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
|
||||
$contribute = CRM_Contribute_PseudoConstant::contributionPage();
|
||||
$pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus();
|
||||
$approved = CRM_Utils_Array::key('Approved', $pcpStatus);
|
||||
|
||||
while ($pcpInfoDao->fetch()) {
|
||||
$mask = $hide;
|
||||
if ($links) {
|
||||
$replace = array(
|
||||
'pcpId' => $pcpInfoDao->id,
|
||||
'pcpBlock' => $pcpInfoDao->pcp_block_id,
|
||||
'pageComponent' => $pcpInfoDao->page_type,
|
||||
);
|
||||
}
|
||||
|
||||
$pcpLink = $links['all'];
|
||||
$class = '';
|
||||
|
||||
if ($pcpInfoDao->status_id != $approved || $pcpInfoDao->is_active != 1) {
|
||||
$class = 'disabled';
|
||||
if (!$pcpInfoDao->is_tellfriend_enabled) {
|
||||
$mask -= CRM_Core_Action::DETACH;
|
||||
}
|
||||
}
|
||||
|
||||
if ($pcpInfoDao->is_active == 1) {
|
||||
$mask -= CRM_Core_Action::ENABLE;
|
||||
}
|
||||
else {
|
||||
$mask -= CRM_Core_Action::DISABLE;
|
||||
}
|
||||
$action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'),
|
||||
FALSE, 'pcp.dashboard.active', 'PCP', $pcpInfoDao->id);
|
||||
$component = $pcpInfoDao->page_type;
|
||||
$pageTitle = CRM_Utils_Array::value($pcpInfoDao->page_id, $$component);
|
||||
|
||||
$pcpInfo[] = array(
|
||||
'pageTitle' => $pageTitle,
|
||||
'pcpId' => $pcpInfoDao->id,
|
||||
'pcpTitle' => $pcpInfoDao->title,
|
||||
'pcpStatus' => $pcpStatus[$pcpInfoDao->status_id],
|
||||
'action' => $action,
|
||||
'class' => $class,
|
||||
);
|
||||
$contactPCPPages[$pcpInfoDao->page_type][] = $pcpInfoDao->page_id;
|
||||
}
|
||||
|
||||
$excludePageClause = $clause = NULL;
|
||||
if (!empty($contactPCPPages)) {
|
||||
foreach ($contactPCPPages as $component => $entityIds) {
|
||||
$excludePageClause[] = "
|
||||
( target_entity_type = '{$component}'
|
||||
AND target_entity_id NOT IN ( " . implode(',', $entityIds) . ") )";
|
||||
}
|
||||
|
||||
$clause = ' AND ' . implode(' OR ', $excludePageClause);
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM civicrm_pcp_block block
|
||||
LEFT JOIN civicrm_pcp pcp ON pcp.pcp_block_id = block.id
|
||||
WHERE block.is_active = 1
|
||||
{$clause}
|
||||
GROUP BY block.id, pcp.id
|
||||
ORDER BY target_entity_type, target_entity_id
|
||||
";
|
||||
$pcpBlockDao = CRM_Core_DAO::executeQuery($query);
|
||||
$pcpBlock = array();
|
||||
$mask = 0;
|
||||
|
||||
while ($pcpBlockDao->fetch()) {
|
||||
if ($links) {
|
||||
$replace = array(
|
||||
'pageId' => $pcpBlockDao->target_entity_id,
|
||||
'pageComponent' => $pcpBlockDao->target_entity_type,
|
||||
);
|
||||
}
|
||||
$pcpLink = $links['add'];
|
||||
$action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'),
|
||||
FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id);
|
||||
$component = $pcpBlockDao->target_entity_type;
|
||||
if ($pageTitle = CRM_Utils_Array::value($pcpBlockDao->target_entity_id, $$component)) {
|
||||
$pcpBlock[] = array(
|
||||
'pageId' => $pcpBlockDao->target_entity_id,
|
||||
'pageTitle' => $pageTitle,
|
||||
'action' => $action,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array($pcpBlock, $pcpInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the total amount for Personal Campaign Page on thermometer.
|
||||
*
|
||||
* @param array $pcpId
|
||||
* Contains the pcp ID.
|
||||
*
|
||||
* @return float
|
||||
* Total amount
|
||||
*/
|
||||
public static function thermoMeter($pcpId) {
|
||||
$query = "
|
||||
SELECT SUM(cc.total_amount) as total
|
||||
FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )
|
||||
LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)
|
||||
WHERE pcp.id = %1 AND cc.contribution_status_id =1 AND cc.is_test = 0";
|
||||
|
||||
$params = array(1 => array($pcpId, 'Integer'));
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the amount, nickname on honor roll.
|
||||
*
|
||||
* @param array $pcpId
|
||||
* Contains the pcp ID.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function honorRoll($pcpId) {
|
||||
$query = "
|
||||
SELECT cc.id, cs.pcp_roll_nickname, cs.pcp_personal_note,
|
||||
cc.total_amount, cc.currency
|
||||
FROM civicrm_contribution cc
|
||||
LEFT JOIN civicrm_contribution_soft cs ON cc.id = cs.contribution_id
|
||||
WHERE cs.pcp_id = {$pcpId}
|
||||
AND cs.pcp_display_in_roll = 1
|
||||
AND contribution_status_id = 1
|
||||
AND is_test = 0";
|
||||
$dao = CRM_Core_DAO::executeQuery($query);
|
||||
$honor = array();
|
||||
while ($dao->fetch()) {
|
||||
$honor[$dao->id]['nickname'] = ucwords($dao->pcp_roll_nickname);
|
||||
$honor[$dao->id]['total_amount'] = CRM_Utils_Money::format($dao->total_amount, $dao->currency);
|
||||
$honor[$dao->id]['personal_note'] = $dao->pcp_personal_note;
|
||||
}
|
||||
return $honor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public static function &pcpLinks() {
|
||||
if (!(self::$_pcpLinks)) {
|
||||
$deleteExtra = ts('Are you sure you want to delete this Personal Campaign Page?') . '\n' . ts('This action cannot be undone.');
|
||||
|
||||
self::$_pcpLinks['add'] = array(
|
||||
CRM_Core_Action::ADD => array(
|
||||
'name' => ts('Create a Personal Campaign Page'),
|
||||
'class' => 'no-popup',
|
||||
'url' => 'civicrm/contribute/campaign',
|
||||
'qs' => 'action=add&reset=1&pageId=%%pageId%%&component=%%pageComponent%%',
|
||||
'title' => ts('Configure'),
|
||||
),
|
||||
);
|
||||
|
||||
self::$_pcpLinks['all'] = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit Your Page'),
|
||||
'url' => 'civicrm/pcp/info',
|
||||
'qs' => 'action=update&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'title' => ts('Configure'),
|
||||
),
|
||||
CRM_Core_Action::DETACH => array(
|
||||
'name' => ts('Tell Friends'),
|
||||
'url' => 'civicrm/friend',
|
||||
'qs' => 'eid=%%pcpId%%&blockId=%%pcpBlock%%&reset=1&pcomponent=pcp&component=%%pageComponent%%',
|
||||
'title' => ts('Tell Friends'),
|
||||
),
|
||||
CRM_Core_Action::VIEW => array(
|
||||
'name' => ts('URL for this Page'),
|
||||
'url' => 'civicrm/pcp/info',
|
||||
'qs' => 'reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'title' => ts('URL for this Page'),
|
||||
),
|
||||
CRM_Core_Action::BROWSE => array(
|
||||
'name' => ts('Update Contact Information'),
|
||||
'url' => 'civicrm/pcp/info',
|
||||
'qs' => 'action=browse&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'title' => ts('Update Contact Information'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'url' => 'civicrm/pcp',
|
||||
'qs' => 'action=enable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'title' => ts('Enable'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'url' => 'civicrm/pcp',
|
||||
'qs' => 'action=disable&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'title' => ts('Disable'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/pcp',
|
||||
'qs' => 'action=delete&reset=1&id=%%pcpId%%&component=%%pageComponent%%',
|
||||
'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
|
||||
'title' => ts('Delete'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_pcpLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the campaign page.
|
||||
*
|
||||
* @param int $id
|
||||
* Campaign page id.
|
||||
*/
|
||||
public static function deleteById($id) {
|
||||
CRM_Utils_Hook::pre('delete', 'Campaign', $id, CRM_Core_DAO::$_nullArray);
|
||||
|
||||
$transaction = new CRM_Core_Transaction();
|
||||
|
||||
// delete from pcp table
|
||||
$pcp = new CRM_PCP_DAO_PCP();
|
||||
$pcp->id = $id;
|
||||
$pcp->delete();
|
||||
|
||||
$transaction->commit();
|
||||
|
||||
CRM_Utils_Hook::post('delete', 'Campaign', $id, $pcp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @param CRM_Core_Form $form
|
||||
* Form object.
|
||||
*/
|
||||
public static function buildPCPForm($form) {
|
||||
$form->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages?'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','block','radio',false);"));
|
||||
|
||||
$form->addElement('checkbox', 'is_approval_needed', ts('Approval required'));
|
||||
|
||||
$profile = array();
|
||||
$isUserRequired = NULL;
|
||||
$config = CRM_Core_Config::singleton();
|
||||
if ($config->userFramework != 'Standalone') {
|
||||
$isUserRequired = 2;
|
||||
}
|
||||
CRM_Core_DAO::commonRetrieveAll('CRM_Core_DAO_UFGroup', 'is_cms_user', $isUserRequired, $profiles, array(
|
||||
'title',
|
||||
'is_active',
|
||||
));
|
||||
if (!empty($profiles)) {
|
||||
foreach ($profiles as $key => $value) {
|
||||
if ($value['is_active']) {
|
||||
$profile[$key] = $value['title'];
|
||||
}
|
||||
}
|
||||
$form->assign('profile', $profile);
|
||||
}
|
||||
|
||||
$form->add('select', 'supporter_profile_id', ts('Supporter Profile'), array('' => ts('- select -')) + $profile, TRUE);
|
||||
|
||||
//CRM-15821 - To add new option for PCP "Owner" notification
|
||||
$ownerNotifications = CRM_Core_OptionGroup::values('pcp_owner_notify');
|
||||
$form->addRadio('owner_notify_id', ts('Owner Email Notification'), $ownerNotifications, NULL, '<br/>', TRUE);
|
||||
|
||||
$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);"));
|
||||
|
||||
$form->add('text',
|
||||
'tellfriend_limit',
|
||||
ts("'Tell a friend' maximum recipients limit"),
|
||||
CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'tellfriend_limit')
|
||||
);
|
||||
$form->addRule('tellfriend_limit', ts('Please enter a valid limit.'), 'integer');
|
||||
|
||||
$form->add('text',
|
||||
'link_text',
|
||||
ts("'Create Personal Campaign Page' link text"),
|
||||
CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'link_text')
|
||||
);
|
||||
|
||||
$form->add('text', 'notify_email', ts('Notify Email'), CRM_Core_DAO::getAttribute('CRM_PCP_DAO_PCPBlock', 'notify_email'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add PCP form elements to a form.
|
||||
*
|
||||
* @param int $pcpId
|
||||
* @param CRM_Core_Page $page
|
||||
* @param null $elements
|
||||
*/
|
||||
public static function buildPcp($pcpId, &$page, &$elements = NULL) {
|
||||
|
||||
$prms = array('id' => $pcpId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
|
||||
if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($pcpId)) {
|
||||
if ($pcpInfo['page_type'] == 'event') {
|
||||
$pcp_supporter_text = ts('This event registration is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
|
||||
$text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'event');
|
||||
if (!empty($text)) {
|
||||
$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!";
|
||||
}
|
||||
}
|
||||
else {
|
||||
$pcp_supporter_text = ts('This contribution is being made thanks to the efforts of <strong>%1</strong>, who supports our campaign. ', array(1 => $pcpSupporter));
|
||||
$text = CRM_PCP_BAO_PCP::getPcpBlockStatus($pcpInfo['page_id'], 'contribute');
|
||||
if (!empty($text)) {
|
||||
$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!";
|
||||
}
|
||||
}
|
||||
|
||||
$page->assign('pcpSupporterText', $pcp_supporter_text);
|
||||
}
|
||||
$page->assign('pcp', TRUE);
|
||||
|
||||
// build honor roll fields for registration form if supporter has honor roll enabled for their PCP
|
||||
if ($pcpInfo['is_honor_roll']) {
|
||||
$page->assign('is_honor_roll', TRUE);
|
||||
$page->add('checkbox', 'pcp_display_in_roll', ts('Show my support in the public honor roll'), NULL, NULL,
|
||||
array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
|
||||
);
|
||||
$extraOption = array('onclick' => "return pcpAnonymous( );");
|
||||
$elements = array();
|
||||
$elements[] = &$page->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
|
||||
$elements[] = &$page->createElement('radio', NULL, '', ts('List my support anonymously'), 1, $extraOption);
|
||||
$page->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
|
||||
$page->_defaults['pcp_is_anonymous'] = 0;
|
||||
|
||||
$page->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30));
|
||||
$page->add('textarea', "pcp_personal_note", ts('Personal Note'), array('style' => 'height: 3em; width: 40em;'));
|
||||
}
|
||||
else {
|
||||
$page->assign('is_honor_roll', FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a PCP contribution.
|
||||
*
|
||||
* @param int $pcpId
|
||||
* @param string $component
|
||||
* @param string $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function handlePcp($pcpId, $component, $entity) {
|
||||
|
||||
self::getPcpEntityTable($component);
|
||||
|
||||
if (!$pcpId) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
|
||||
|
||||
$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
|
||||
|
||||
$params = array('id' => $pcpId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
|
||||
|
||||
$params = array('id' => $pcpInfo['pcp_block_id']);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlock);
|
||||
|
||||
$params = array('id' => $pcpInfo['page_id']);
|
||||
$now = time();
|
||||
|
||||
if ($component == 'event') {
|
||||
// figure out where to redirect if an exception occurs below based on target entity
|
||||
$urlBase = 'civicrm/event/register';
|
||||
|
||||
// ignore startDate for events - PCP's can be active long before event start date
|
||||
$startDate = 0;
|
||||
$endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity));
|
||||
}
|
||||
elseif ($component == 'contribute') {
|
||||
$urlBase = 'civicrm/contribute/transact';
|
||||
//start and end date of the contribution page
|
||||
$startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $entity));
|
||||
$endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $entity));
|
||||
}
|
||||
|
||||
// define redirect url back to contrib page or event if needed
|
||||
$url = CRM_Utils_System::url($urlBase, "reset=1&id={$pcpBlock['entity_id']}", FALSE, NULL, FALSE, TRUE);
|
||||
|
||||
if ($pcpBlock['target_entity_id'] != $entity['id']) {
|
||||
$statusMessage = ts('This page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.');
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
elseif ($pcpInfo['status_id'] != $approvedId) {
|
||||
$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']]));
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
elseif (empty($pcpBlock['is_active'])) {
|
||||
$statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign here.');
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
elseif (empty($pcpInfo['is_active'])) {
|
||||
$statusMessage = ts('The Personal Campaign Page you have just visited is currently inactive. However you can still support the campaign here.');
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
// Check if we're in range for contribution page start and end dates. for events, check if after event end date
|
||||
elseif (($startDate && $startDate > $now) || ($endDate && $endDate < $now)) {
|
||||
$customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $entity));
|
||||
$customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $entity));
|
||||
if ($startDate && $endDate) {
|
||||
$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.',
|
||||
array(1 => $customStartDate, 2 => $customEndDate)
|
||||
);
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
elseif ($startDate) {
|
||||
$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));
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
elseif ($endDate) {
|
||||
if ($component == 'event') {
|
||||
// Target_entity is an event and the event is over, redirect to event info instead of event registration page.
|
||||
$url = CRM_Utils_System::url('civicrm/event/info',
|
||||
"reset=1&id={$pcpBlock['entity_id']}",
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
);
|
||||
$statusMessage = ts('The event linked to the Personal Campaign Page you have just visited is over (as of %1).', array(1 => $customEndDate));
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
else {
|
||||
$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));
|
||||
CRM_Core_Error::statusBounce($statusMessage, $url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'pcpId' => $pcpId,
|
||||
'pcpBlock' => $pcpBlock,
|
||||
'pcpInfo' => $pcpInfo,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve / Reject the campaign page.
|
||||
*
|
||||
* @param int $id
|
||||
* Campaign page id.
|
||||
*
|
||||
* @param bool $is_active
|
||||
*/
|
||||
public static function setIsActive($id, $is_active) {
|
||||
switch ($is_active) {
|
||||
case 0:
|
||||
$is_active = 3;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
$is_active = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
CRM_Core_DAO::setFieldValue('CRM_PCP_DAO_PCP', $id, 'status_id', $is_active);
|
||||
|
||||
$pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $id, 'title');
|
||||
$pcpPageType = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $id, 'page_type');
|
||||
|
||||
$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
|
||||
$pcpStatus = $pcpStatus[$is_active];
|
||||
|
||||
CRM_Core_Session::setStatus(ts("%1 status has been updated to %2.", array(
|
||||
1 => $pcpTitle,
|
||||
2 => $pcpStatus,
|
||||
)), 'Status Updated', 'success');
|
||||
|
||||
// send status change mail
|
||||
$result = self::sendStatusUpdate($id, $is_active, FALSE, $pcpPageType);
|
||||
|
||||
if ($result) {
|
||||
CRM_Core_Session::setStatus(ts("A notification email has been sent to the supporter."), ts('Email Sent'), 'success');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification email to supporter.
|
||||
*
|
||||
* 1. when their PCP status is changed by site admin.
|
||||
* 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
|
||||
*
|
||||
* @param int $pcpId
|
||||
* Campaign page id.
|
||||
* @param int $newStatus
|
||||
* Pcp status id.
|
||||
* @param bool|int $isInitial is it the first time, campaign page has been created by the user
|
||||
*
|
||||
* @param string $component
|
||||
*
|
||||
* @throws Exception
|
||||
* @return null
|
||||
*/
|
||||
public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') {
|
||||
$pcpStatusName = CRM_Core_OptionGroup::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
|
||||
$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
|
||||
$config = CRM_Core_Config::singleton();
|
||||
|
||||
if (!isset($pcpStatus[$newStatus])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
require_once 'Mail/mime.php';
|
||||
|
||||
//set loginUrl
|
||||
$loginURL = $config->userSystem->getLoginURL();
|
||||
|
||||
// used in subject templates
|
||||
$contribPageTitle = self::getPcpPageTitle($pcpId, $component);
|
||||
|
||||
$tplParams = array(
|
||||
'loginUrl' => $loginURL,
|
||||
'contribPageTitle' => $contribPageTitle,
|
||||
'pcpId' => $pcpId,
|
||||
);
|
||||
|
||||
//get the default domain email address.
|
||||
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
|
||||
|
||||
if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
|
||||
$fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
|
||||
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)));
|
||||
}
|
||||
|
||||
$receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
|
||||
|
||||
// get recipient (supporter) name and email
|
||||
$params = array('id' => $pcpId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
|
||||
list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']);
|
||||
|
||||
// get pcp block info
|
||||
list($blockId, $eid) = self::getPcpBlockEntityId($pcpId, $component);
|
||||
$params = array('id' => $blockId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
|
||||
|
||||
// assign urls required in email template
|
||||
if ($pcpStatusName[$newStatus] == 'Approved') {
|
||||
$tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
|
||||
if ($pcpBlockInfo['is_tellfriend_enabled']) {
|
||||
$pcpTellFriendURL = CRM_Utils_System::url('civicrm/friend',
|
||||
"reset=1&eid=$pcpId&blockId=$blockId&pcomponent=pcp",
|
||||
TRUE, NULL, FALSE, TRUE
|
||||
);
|
||||
$tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
|
||||
}
|
||||
}
|
||||
$pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info',
|
||||
"reset=1&id=$pcpId",
|
||||
TRUE, NULL, FALSE, TRUE
|
||||
);
|
||||
$tplParams['pcpInfoURL'] = $pcpInfoURL;
|
||||
$tplParams['contribPageTitle'] = $contribPageTitle;
|
||||
if ($emails = CRM_Utils_Array::value('notify_email', $pcpBlockInfo)) {
|
||||
$emailArray = explode(',', $emails);
|
||||
$tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
|
||||
}
|
||||
// get appropriate message based on status
|
||||
$tplParams['pcpStatus'] = $pcpStatus[$newStatus];
|
||||
|
||||
$tplName = $isInitial ? 'pcp_supporter_notify' : 'pcp_status_change';
|
||||
|
||||
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_contribution',
|
||||
'valueName' => $tplName,
|
||||
'contactId' => $pcpInfo['contact_id'],
|
||||
'tplParams' => $tplParams,
|
||||
'from' => $receiptFrom,
|
||||
'toName' => $name,
|
||||
'toEmail' => $address,
|
||||
)
|
||||
);
|
||||
return $sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable / Disable the campaign page.
|
||||
*
|
||||
* @param int $id
|
||||
* Campaign page id.
|
||||
*
|
||||
* @param bool $is_active
|
||||
* @return null
|
||||
*/
|
||||
public static function setDisable($id, $is_active) {
|
||||
return CRM_Core_DAO::setFieldValue('CRM_PCP_DAO_PCP', $id, 'is_active', $is_active);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pcp block is active.
|
||||
*
|
||||
* @param int $pcpId
|
||||
* @param $component
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getStatus($pcpId, $component) {
|
||||
$query = "
|
||||
SELECT pb.is_active
|
||||
FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_pcp_block pb ON ( pcp.page_id = pb.entity_id )
|
||||
WHERE pcp.id = %1
|
||||
AND pb.entity_table = %2";
|
||||
|
||||
$entity_table = self::getPcpEntityTable($component);
|
||||
|
||||
$params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pcp block is enabled for component page.
|
||||
*
|
||||
* @param int $pageId
|
||||
* @param $component
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPcpBlockStatus($pageId, $component) {
|
||||
$query = "
|
||||
SELECT pb.link_text as linkText
|
||||
FROM civicrm_pcp_block pb
|
||||
WHERE pb.is_active = 1 AND
|
||||
pb.entity_id = %1 AND
|
||||
pb.entity_table = %2";
|
||||
|
||||
$entity_table = self::getPcpEntityTable($component);
|
||||
|
||||
$params = array(1 => array($pageId, 'Integer'), 2 => array($entity_table, 'String'));
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out if the PCP block is in use by one or more PCP page.
|
||||
*
|
||||
* @param int $id
|
||||
* Pcp block id.
|
||||
*
|
||||
* @return Bool
|
||||
*/
|
||||
public static function getPcpBlockInUse($id) {
|
||||
$query = "
|
||||
SELECT count(*)
|
||||
FROM civicrm_pcp pcp
|
||||
WHERE pcp.pcp_block_id = %1";
|
||||
|
||||
$params = array(1 => array($id, 'Integer'));
|
||||
$result = CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
return $result > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email is enabled for supporter's profile
|
||||
*
|
||||
* @param int $profileId
|
||||
* Supporter's profile id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function checkEmailProfile($profileId) {
|
||||
$query = "
|
||||
SELECT field_name
|
||||
FROM civicrm_uf_field
|
||||
WHERE field_name like 'email%' And is_active = 1 And uf_group_id = %1";
|
||||
|
||||
$params = array(1 => array($profileId, 'Integer'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
if (!$dao->fetch()) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the title of page associated with a pcp.
|
||||
*
|
||||
* @param int $pcpId
|
||||
* @param $component
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getPcpPageTitle($pcpId, $component) {
|
||||
if ($component == 'contribute') {
|
||||
$query = "
|
||||
SELECT cp.title
|
||||
FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_contribution_page as cp ON ( cp.id = pcp.page_id )
|
||||
WHERE pcp.id = %1";
|
||||
}
|
||||
elseif ($component == 'event') {
|
||||
$query = "
|
||||
SELECT ce.title
|
||||
FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_event as ce ON ( ce.id = pcp.page_id )
|
||||
WHERE pcp.id = %1";
|
||||
}
|
||||
|
||||
$params = array(1 => array($pcpId, 'Integer'));
|
||||
return CRM_Core_DAO::singleValueQuery($query, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pcp block & entity id given pcp id
|
||||
*
|
||||
* @param int $pcpId
|
||||
* @param $component
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPcpBlockEntityId($pcpId, $component) {
|
||||
$entity_table = self::getPcpEntityTable($component);
|
||||
|
||||
$query = "
|
||||
SELECT pb.id as pcpBlockId, pb.entity_id
|
||||
FROM civicrm_pcp pcp
|
||||
LEFT JOIN civicrm_pcp_block pb ON ( pb.entity_id = pcp.page_id AND pb.entity_table = %2 )
|
||||
WHERE pcp.id = %1";
|
||||
|
||||
$params = array(1 => array($pcpId, 'Integer'), 2 => array($entity_table, 'String'));
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $params);
|
||||
if ($dao->fetch()) {
|
||||
return array($dao->pcpBlockId, $dao->entity_id);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pcp entity table given a component.
|
||||
*
|
||||
* @param $component
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getPcpEntityTable($component) {
|
||||
$entity_table_map = array(
|
||||
'event' => 'civicrm_event',
|
||||
'civicrm_event' => 'civicrm_event',
|
||||
'contribute' => 'civicrm_contribution_page',
|
||||
'civicrm_contribution_page' => 'civicrm_contribution_page',
|
||||
);
|
||||
return isset($entity_table_map[$component]) ? $entity_table_map[$component] : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supporter profile id.
|
||||
*
|
||||
* @param int $component_id
|
||||
* @param string $component
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSupporterProfileId($component_id, $component = 'contribute') {
|
||||
$entity_table = self::getPcpEntityTable($component);
|
||||
|
||||
$query = "
|
||||
SELECT pcp.supporter_profile_id
|
||||
FROM civicrm_pcp_block pcp
|
||||
INNER JOIN civicrm_uf_group ufgroup
|
||||
ON pcp.supporter_profile_id = ufgroup.id
|
||||
WHERE pcp.entity_id = %1
|
||||
AND pcp.entity_table = %2
|
||||
AND ufgroup.is_active = 1";
|
||||
|
||||
$params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
|
||||
if (!$supporterProfileId = CRM_Core_DAO::singleValueQuery($query, $params)) {
|
||||
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.'));
|
||||
}
|
||||
else {
|
||||
return $supporterProfileId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get owner notification id.
|
||||
*
|
||||
* @param int $component_id
|
||||
* @param $component
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getOwnerNotificationId($component_id, $component = 'contribute') {
|
||||
$entity_table = self::getPcpEntityTable($component);
|
||||
$query = "
|
||||
SELECT pb.owner_notify_id
|
||||
FROM civicrm_pcp_block pb
|
||||
WHERE pb.entity_id = %1 AND pb.entity_table = %2";
|
||||
$params = array(1 => array($component_id, 'Integer'), 2 => array($entity_table, 'String'));
|
||||
if (!$ownerNotificationId = CRM_Core_DAO::singleValueQuery($query, $params)) {
|
||||
CRM_Core_Error::fatal(ts('Owner Notification is not set for this Personal Campaign Page. Please contact the site administrator if you need assistance.'));
|
||||
}
|
||||
else {
|
||||
return $ownerNotificationId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
49
sites/all/modules/civicrm/CRM/PCP/BAO/PCPBlock.php
Normal file
49
sites/all/modules/civicrm/CRM/PCP/BAO/PCPBlock.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
class CRM_PCP_BAO_PCPBlock extends CRM_PCP_DAO_PCPBlock {
|
||||
|
||||
/**
|
||||
* Create or update either a Personal Campaign Page OR a PCP Block.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return CRM_PCP_DAO_PCPBlock
|
||||
*/
|
||||
public static function create($params) {
|
||||
$dao = new CRM_PCP_DAO_PCPBlock();
|
||||
$dao->copyValues($params);
|
||||
$dao->save();
|
||||
return $dao;
|
||||
}
|
||||
|
||||
}
|
76
sites/all/modules/civicrm/CRM/PCP/Controller/PCP.php
Normal file
76
sites/all/modules/civicrm/CRM/PCP/Controller/PCP.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is used by the Search functionality.
|
||||
*
|
||||
* - the search controller is used for building/processing multiform
|
||||
* searches.
|
||||
*
|
||||
* Typically the first form will display the search criteria and its results
|
||||
*
|
||||
* The second form is used to process search results with the associated actions
|
||||
*
|
||||
*/
|
||||
class CRM_PCP_Controller_PCP extends CRM_Core_Controller {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param string $title
|
||||
* @param bool|int $action
|
||||
* @param bool $modal
|
||||
*/
|
||||
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
|
||||
|
||||
parent::__construct($title, $modal);
|
||||
|
||||
$this->_stateMachine = new CRM_PCP_StateMachine_PCP($this, $action);
|
||||
|
||||
// create and instantiate the pages
|
||||
$this->addPages($this->_stateMachine, $action);
|
||||
|
||||
// add all the actions
|
||||
$uploadNames = $this->get('uploadNames');
|
||||
if (!empty($uploadNames)) {
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->addActions($config->customFileUploadDir, $uploadNames);
|
||||
}
|
||||
else {
|
||||
$this->addActions();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
459
sites/all/modules/civicrm/CRM/PCP/DAO/PCP.php
Normal file
459
sites/all/modules/civicrm/CRM/PCP/DAO/PCP.php
Normal file
|
@ -0,0 +1,459 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/PCP/PCP.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:6913feaec692244b1d39e330ba00188c)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_PCP_DAO_PCP constructor.
|
||||
*/
|
||||
class CRM_PCP_DAO_PCP extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_pcp';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* Personal Campaign Page ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* FK to Contact ID
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $contact_id;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $status_id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $intro_text;
|
||||
/**
|
||||
*
|
||||
* @var text
|
||||
*/
|
||||
public $page_text;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $donate_link_text;
|
||||
/**
|
||||
* The Contribution or Event Page which triggered this pcp
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $page_id;
|
||||
/**
|
||||
* The type of PCP this is: contribute or event
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $page_type;
|
||||
/**
|
||||
* The pcp block that this pcp page was created from
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $pcp_block_id;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $is_thermometer;
|
||||
/**
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $is_honor_roll;
|
||||
/**
|
||||
* Goal amount of this Personal Campaign Page.
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $goal_amount;
|
||||
/**
|
||||
* 3 character string, value from config setting or input via user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $currency;
|
||||
/**
|
||||
* Is Personal Campaign Page enabled/active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* Notify owner via email when someone donates to page?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_notify;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_pcp';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contact_id', 'civicrm_contact', 'id');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'pcp_id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Personal Campaign Page ID') ,
|
||||
'description' => 'Personal Campaign Page ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'pcp_contact_id' => array(
|
||||
'name' => 'contact_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contact ID') ,
|
||||
'description' => 'FK to Contact ID',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Contact_DAO_Contact',
|
||||
'html' => array(
|
||||
'type' => 'EntityRef',
|
||||
) ,
|
||||
) ,
|
||||
'status_id' => array(
|
||||
'name' => 'status_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Personal Campaign Page Status') ,
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'pcp_status',
|
||||
'optionEditPath' => 'civicrm/admin/options/pcp_status',
|
||||
)
|
||||
) ,
|
||||
'title' => array(
|
||||
'name' => 'title',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Personal Campaign Page Title') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'intro_text' => array(
|
||||
'name' => 'intro_text',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Intro Text') ,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'page_text' => array(
|
||||
'name' => 'page_text',
|
||||
'type' => CRM_Utils_Type::T_TEXT,
|
||||
'title' => ts('Page Text') ,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'TextArea',
|
||||
) ,
|
||||
) ,
|
||||
'donate_link_text' => array(
|
||||
'name' => 'donate_link_text',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Donate Link Text') ,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'page_id' => array(
|
||||
'name' => 'page_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Contribution Page') ,
|
||||
'description' => 'The Contribution or Event Page which triggered this pcp',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'page_type' => array(
|
||||
'name' => 'page_type',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('PCP Page Type') ,
|
||||
'description' => 'The type of PCP this is: contribute or event',
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'default' => 'contribute',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
) ,
|
||||
'pcp_block_id' => array(
|
||||
'name' => 'pcp_block_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('PCP Block') ,
|
||||
'description' => 'The pcp block that this pcp page was created from',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_thermometer' => array(
|
||||
'name' => 'is_thermometer',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Use Thermometer?') ,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'is_honor_roll' => array(
|
||||
'name' => 'is_honor_roll',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Show Honor Roll?') ,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'goal_amount' => array(
|
||||
'name' => 'goal_amount',
|
||||
'type' => CRM_Utils_Type::T_MONEY,
|
||||
'title' => ts('Goal Amount') ,
|
||||
'description' => 'Goal amount of this Personal Campaign Page.',
|
||||
'precision' => array(
|
||||
20,
|
||||
2
|
||||
) ,
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Text',
|
||||
) ,
|
||||
) ,
|
||||
'currency' => array(
|
||||
'name' => 'currency',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Currency') ,
|
||||
'description' => '3 character string, value from config setting or input via user.',
|
||||
'maxlength' => 3,
|
||||
'size' => CRM_Utils_Type::FOUR,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Select',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'table' => 'civicrm_currency',
|
||||
'keyColumn' => 'name',
|
||||
'labelColumn' => 'full_name',
|
||||
'nameColumn' => 'name',
|
||||
)
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Enabled?') ,
|
||||
'description' => 'Is Personal Campaign Page enabled/active?',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
'is_notify' => array(
|
||||
'name' => 'is_notify',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Notify Owner?') ,
|
||||
'description' => 'Notify owner via email when someone donates to page?',
|
||||
'table_name' => 'civicrm_pcp',
|
||||
'entity' => 'PCP',
|
||||
'bao' => 'CRM_PCP_BAO_PCP',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'CheckBox',
|
||||
) ,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return self::$_tableName;
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'pcp', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'pcp', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
380
sites/all/modules/civicrm/CRM/PCP/DAO/PCPBlock.php
Normal file
380
sites/all/modules/civicrm/CRM/PCP/DAO/PCPBlock.php
Normal file
|
@ -0,0 +1,380 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
/**
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*
|
||||
* Generated from xml/schema/CRM/PCP/PCPBlock.xml
|
||||
* DO NOT EDIT. Generated by CRM_Core_CodeGen
|
||||
* (GenCodeChecksum:5e7c52122eb7d5b428bb717c7c634327)
|
||||
*/
|
||||
require_once 'CRM/Core/DAO.php';
|
||||
require_once 'CRM/Utils/Type.php';
|
||||
/**
|
||||
* CRM_PCP_DAO_PCPBlock constructor.
|
||||
*/
|
||||
class CRM_PCP_DAO_PCPBlock extends CRM_Core_DAO {
|
||||
/**
|
||||
* Static instance to hold the table name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
static $_tableName = 'civicrm_pcp_block';
|
||||
/**
|
||||
* Should CiviCRM log any modifications to this table in the civicrm_log table.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
static $_log = true;
|
||||
/**
|
||||
* PCP block Id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $entity_table;
|
||||
/**
|
||||
* FK to civicrm_contribution_page.id OR civicrm_event.id
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $entity_id;
|
||||
/**
|
||||
* The type of entity that this pcp targets
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $target_entity_type;
|
||||
/**
|
||||
* The entity that this pcp targets
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $target_entity_id;
|
||||
/**
|
||||
* FK to civicrm_uf_group.id. Does Personal Campaign Page require manual activation by administrator? (is inactive by default after setup)?
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $supporter_profile_id;
|
||||
/**
|
||||
* FK to civicrm_option_group with name = PCP owner notifications
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $owner_notify_id;
|
||||
/**
|
||||
* Does Personal Campaign Page require manual activation by administrator? (is inactive by default after setup)?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_approval_needed;
|
||||
/**
|
||||
* Does Personal Campaign Page allow using tell a friend?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_tellfriend_enabled;
|
||||
/**
|
||||
* Maximum recipient fields allowed in tell a friend
|
||||
*
|
||||
* @var int unsigned
|
||||
*/
|
||||
public $tellfriend_limit;
|
||||
/**
|
||||
* Link text for PCP.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $link_text;
|
||||
/**
|
||||
* Is Personal Campaign Page Block enabled/active?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_active;
|
||||
/**
|
||||
* If set, notification is automatically emailed to this email-address on create/update Personal Campaign Page
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $notify_email;
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->__table = 'civicrm_pcp_block';
|
||||
parent::__construct();
|
||||
}
|
||||
/**
|
||||
* Returns foreign keys and entity references.
|
||||
*
|
||||
* @return array
|
||||
* [CRM_Core_Reference_Interface]
|
||||
*/
|
||||
static function getReferenceColumns() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['links'])) {
|
||||
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'supporter_profile_id', 'civicrm_uf_group', 'id');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
|
||||
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'target_entity_id', NULL, 'id', 'target_entity_type');
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['links'];
|
||||
}
|
||||
/**
|
||||
* Returns all the column names of this table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &fields() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
|
||||
Civi::$statics[__CLASS__]['fields'] = array(
|
||||
'id' => array(
|
||||
'name' => 'id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('PCP Block ID') ,
|
||||
'description' => 'PCP block Id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_table' => array(
|
||||
'name' => 'entity_table',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Entity Table') ,
|
||||
'maxlength' => 64,
|
||||
'size' => CRM_Utils_Type::BIG,
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'entity_id' => array(
|
||||
'name' => 'entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Entity') ,
|
||||
'description' => 'FK to civicrm_contribution_page.id OR civicrm_event.id',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'target_entity_type' => array(
|
||||
'name' => 'target_entity_type',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Target Entity') ,
|
||||
'description' => 'The type of entity that this pcp targets',
|
||||
'required' => true,
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'default' => 'contribute',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'target_entity_id' => array(
|
||||
'name' => 'target_entity_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Target Entity ID') ,
|
||||
'description' => 'The entity that this pcp targets',
|
||||
'required' => true,
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'supporter_profile_id' => array(
|
||||
'name' => 'supporter_profile_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Supporter Profile') ,
|
||||
'description' => 'FK to civicrm_uf_group.id. Does Personal Campaign Page require manual activation by administrator? (is inactive by default after setup)?',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
'FKClassName' => 'CRM_Core_DAO_UFGroup',
|
||||
) ,
|
||||
'owner_notify_id' => array(
|
||||
'name' => 'owner_notify_id',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Owner Notification') ,
|
||||
'description' => 'FK to civicrm_option_group with name = PCP owner notifications',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
'html' => array(
|
||||
'type' => 'Radio',
|
||||
) ,
|
||||
'pseudoconstant' => array(
|
||||
'optionGroupName' => 'pcp_owner_notify',
|
||||
'optionEditPath' => 'civicrm/admin/options/pcp_owner_notify',
|
||||
)
|
||||
) ,
|
||||
'is_approval_needed' => array(
|
||||
'name' => 'is_approval_needed',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Approval Required?') ,
|
||||
'description' => 'Does Personal Campaign Page require manual activation by administrator? (is inactive by default after setup)?',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'is_tellfriend_enabled' => array(
|
||||
'name' => 'is_tellfriend_enabled',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Tell a Friend Enabled?') ,
|
||||
'description' => 'Does Personal Campaign Page allow using tell a friend?',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'tellfriend_limit' => array(
|
||||
'name' => 'tellfriend_limit',
|
||||
'type' => CRM_Utils_Type::T_INT,
|
||||
'title' => ts('Tell A Friend Limit') ,
|
||||
'description' => 'Maximum recipient fields allowed in tell a friend',
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'link_text' => array(
|
||||
'name' => 'link_text',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Link Text') ,
|
||||
'description' => 'Link text for PCP.',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 1,
|
||||
) ,
|
||||
'is_active' => array(
|
||||
'name' => 'is_active',
|
||||
'type' => CRM_Utils_Type::T_BOOLEAN,
|
||||
'title' => ts('Enabled?') ,
|
||||
'description' => 'Is Personal Campaign Page Block enabled/active?',
|
||||
'default' => '1',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
'notify_email' => array(
|
||||
'name' => 'notify_email',
|
||||
'type' => CRM_Utils_Type::T_STRING,
|
||||
'title' => ts('Notification Email') ,
|
||||
'description' => 'If set, notification is automatically emailed to this email-address on create/update Personal Campaign Page',
|
||||
'maxlength' => 255,
|
||||
'size' => CRM_Utils_Type::HUGE,
|
||||
'default' => 'NULL',
|
||||
'table_name' => 'civicrm_pcp_block',
|
||||
'entity' => 'PCPBlock',
|
||||
'bao' => 'CRM_PCP_BAO_PCPBlock',
|
||||
'localizable' => 0,
|
||||
) ,
|
||||
);
|
||||
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fields'];
|
||||
}
|
||||
/**
|
||||
* Return a mapping from field-name to the corresponding key (as used in fields()).
|
||||
*
|
||||
* @return array
|
||||
* Array(string $name => string $uniqueName).
|
||||
*/
|
||||
static function &fieldKeys() {
|
||||
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
|
||||
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
|
||||
}
|
||||
return Civi::$statics[__CLASS__]['fieldKeys'];
|
||||
}
|
||||
/**
|
||||
* Returns the names of this table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
static function getTableName() {
|
||||
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
|
||||
}
|
||||
/**
|
||||
* Returns if this table needs to be logged
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function getLog() {
|
||||
return self::$_log;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be imported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &import($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'pcp_block', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of fields that can be exported
|
||||
*
|
||||
* @param bool $prefix
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
static function &export($prefix = false) {
|
||||
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'pcp_block', $prefix, array());
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Returns the list of indices
|
||||
*/
|
||||
public static function indices($localize = TRUE) {
|
||||
$indices = array();
|
||||
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
|
||||
}
|
||||
}
|
374
sites/all/modules/civicrm/CRM/PCP/Form/Campaign.php
Normal file
374
sites/all/modules/civicrm/CRM/PCP/Form/Campaign.php
Normal file
|
@ -0,0 +1,374 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a pcp page.
|
||||
*/
|
||||
class CRM_PCP_Form_Campaign extends CRM_Core_Form {
|
||||
public $_context;
|
||||
public $_component;
|
||||
|
||||
/**
|
||||
* Pre-process form.
|
||||
*/
|
||||
public function preProcess() {
|
||||
// we do not want to display recently viewed items, so turn off
|
||||
$this->assign('displayRecent', FALSE);
|
||||
|
||||
// component null in controller object - fix? dgg
|
||||
// $this->_component = $this->controller->get('component');
|
||||
$this->_component = CRM_Utils_Request::retrieve('component', 'String', $this);
|
||||
$this->assign('component', $this->_component);
|
||||
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$this->_pageId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
|
||||
$title = ts('Setup a Personal Campaign Page - Step 2');
|
||||
|
||||
if ($this->_pageId) {
|
||||
$title = ts('Edit Your Personal Campaign Page');
|
||||
}
|
||||
|
||||
CRM_Utils_System::setTitle($title);
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default form values.
|
||||
*
|
||||
* @return array
|
||||
* Default values for the form.
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
$dao = new CRM_PCP_DAO_PCP();
|
||||
|
||||
if ($this->_pageId) {
|
||||
$dao->id = $this->_pageId;
|
||||
if ($dao->find(TRUE)) {
|
||||
CRM_Core_DAO::storeValues($dao, $defaults);
|
||||
}
|
||||
// fix the display of the monetary value, CRM-4038
|
||||
if (isset($defaults['goal_amount'])) {
|
||||
$defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a');
|
||||
}
|
||||
|
||||
$defaults['pcp_title'] = CRM_Utils_Array::value('title', $defaults);
|
||||
$defaults['pcp_intro_text'] = CRM_Utils_Array::value('intro_text', $defaults);
|
||||
}
|
||||
|
||||
if ($this->get('action') & CRM_Core_Action::ADD) {
|
||||
$defaults['is_active'] = 1;
|
||||
$defaults['is_honor_roll'] = 1;
|
||||
$defaults['is_thermometer'] = 1;
|
||||
$defaults['is_notify'] = 1;
|
||||
}
|
||||
|
||||
$this->_contactID = CRM_Utils_Array::value('contact_id', $defaults);
|
||||
$this->_contriPageId = CRM_Utils_Array::value('page_id', $defaults);
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->add('text', 'pcp_title', ts('Title'), NULL, TRUE);
|
||||
$this->add('textarea', 'pcp_intro_text', ts('Welcome'), NULL, TRUE);
|
||||
$this->add('text', 'goal_amount', ts('Your Goal'), NULL, TRUE);
|
||||
$this->addRule('goal_amount', ts('Goal Amount should be a numeric value'), 'money');
|
||||
|
||||
$attributes = array();
|
||||
if ($this->_component == 'event') {
|
||||
if ($this->get('action') & CRM_Core_Action::ADD) {
|
||||
$attributes = array('value' => ts('Join Us'), 'onClick' => 'select();');
|
||||
}
|
||||
$this->add('text', 'donate_link_text', ts('Sign up Button'), $attributes);
|
||||
}
|
||||
else {
|
||||
if ($this->get('action') & CRM_Core_Action::ADD) {
|
||||
$attributes = array('value' => ts('Donate Now'), 'onClick' => 'select();');
|
||||
}
|
||||
$this->add('text', 'donate_link_text', ts('Donation Button'), $attributes);
|
||||
}
|
||||
|
||||
$attrib = array('rows' => 8, 'cols' => 60);
|
||||
$this->add('textarea', 'page_text', ts('Your Message'), NULL, FALSE);
|
||||
|
||||
$maxAttachments = 1;
|
||||
CRM_Core_BAO_File::buildAttachment($this, 'civicrm_pcp', $this->_pageId, $maxAttachments);
|
||||
|
||||
$this->addElement('checkbox', 'is_thermometer', ts('Progress Bar'));
|
||||
$this->addElement('checkbox', 'is_honor_roll', ts('Honor Roll'), NULL);
|
||||
if ($this->_pageId) {
|
||||
$params = array('id' => $this->_pageId);
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
|
||||
$owner_notification_option = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
|
||||
}
|
||||
else {
|
||||
$owner_notification_option = CRM_PCP_BAO_PCP::getOwnerNotificationId($this->controller->get('component_page_id'), $this->_component ? $this->_component : 'contribute');
|
||||
}
|
||||
if ($owner_notification_option == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name')) {
|
||||
$this->assign('owner_notification_option', TRUE);
|
||||
$this->addElement('checkbox', 'is_notify', ts('Notify me via email when someone donates to my page'), NULL);
|
||||
}
|
||||
|
||||
$this->addElement('checkbox', 'is_active', ts('Active'));
|
||||
if ($this->_context == 'dashboard') {
|
||||
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
|
||||
}
|
||||
|
||||
$this->addButtons(
|
||||
array(
|
||||
array(
|
||||
'type' => 'upload',
|
||||
'name' => ts('Save'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
$this->addFormRule(array('CRM_PCP_Form_Campaign', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
if ($fields['goal_amount'] <= 0) {
|
||||
$errors['goal_amount'] = ts('Goal Amount should be a numeric value greater than zero.');
|
||||
}
|
||||
if (strlen($fields['donate_link_text']) >= 64) {
|
||||
$errors['donate_link_text'] = ts('Button Text must be less than 64 characters.');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active', 'is_notify');
|
||||
|
||||
foreach ($checkBoxes as $key) {
|
||||
if (!isset($params[$key])) {
|
||||
$params[$key] = 0;
|
||||
}
|
||||
}
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID');
|
||||
if (!$contactID) {
|
||||
$contactID = $this->get('contactID');
|
||||
}
|
||||
$params['title'] = $params['pcp_title'];
|
||||
$params['intro_text'] = $params['pcp_intro_text'];
|
||||
$params['contact_id'] = $contactID;
|
||||
$params['page_id'] = $this->get('component_page_id') ? $this->get('component_page_id') : $this->_contriPageId;
|
||||
$params['page_type'] = $this->_component;
|
||||
|
||||
// since we are allowing html input from the user
|
||||
// we also need to purify it, so lets clean it up
|
||||
$htmlFields = array('intro_text', 'page_text', 'title');
|
||||
foreach ($htmlFields as $field) {
|
||||
if (!empty($params[$field])) {
|
||||
$params[$field] = CRM_Utils_String::purifyHTML($params[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
$entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($params['page_type']);
|
||||
|
||||
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
|
||||
$pcpBlock->entity_table = $entity_table;
|
||||
$pcpBlock->entity_id = $params['page_id'];
|
||||
$pcpBlock->find(TRUE);
|
||||
|
||||
$params['pcp_block_id'] = $pcpBlock->id;
|
||||
|
||||
$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);
|
||||
|
||||
$approval_needed = $pcpBlock->is_approval_needed;
|
||||
$approvalMessage = NULL;
|
||||
|
||||
if ($this->get('action') & CRM_Core_Action::ADD) {
|
||||
$params['status_id'] = $approval_needed ? 1 : 2;
|
||||
$approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin promoting your campaign. You will receive an email confirmation shortly which includes a link to return to this page.') : ts('and is ready to use.');
|
||||
}
|
||||
|
||||
$params['id'] = $this->_pageId;
|
||||
|
||||
$pcp = CRM_PCP_BAO_PCP::create($params);
|
||||
|
||||
// add attachments as needed
|
||||
CRM_Core_BAO_File::formatAttachment($params,
|
||||
$params,
|
||||
'civicrm_pcp',
|
||||
$pcp->id
|
||||
);
|
||||
|
||||
$pageStatus = isset($this->_pageId) ? ts('updated') : ts('created');
|
||||
$statusId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcp->id, 'status_id');
|
||||
|
||||
//send notification of PCP create/update.
|
||||
$pcpParams = array('entity_table' => $entity_table, 'entity_id' => $pcp->page_id);
|
||||
$notifyParams = array();
|
||||
$notifyStatus = "";
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email'));
|
||||
|
||||
if ($emails = $pcpBlock->notify_email) {
|
||||
$this->assign('pcpTitle', $pcp->title);
|
||||
|
||||
if ($this->_pageId) {
|
||||
$this->assign('mode', 'Update');
|
||||
}
|
||||
else {
|
||||
$this->assign('mode', 'Add');
|
||||
}
|
||||
$pcpStatus = CRM_Core_PseudoConstant::getLabel('CRM_PCP_DAO_PCP', 'status_id', $statusId);
|
||||
$this->assign('pcpStatus', $pcpStatus);
|
||||
|
||||
$this->assign('pcpId', $pcp->id);
|
||||
|
||||
$supporterUrl = CRM_Utils_System::url('civicrm/contact/view',
|
||||
"reset=1&cid={$pcp->contact_id}",
|
||||
TRUE, NULL, FALSE,
|
||||
FALSE
|
||||
);
|
||||
$this->assign('supporterUrl', $supporterUrl);
|
||||
$supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name');
|
||||
$this->assign('supporterName', $supporterName);
|
||||
|
||||
if ($this->_component == 'contribute') {
|
||||
$pageUrl = CRM_Utils_System::url('civicrm/contribute/transact',
|
||||
"reset=1&id={$pcpBlock->entity_id}",
|
||||
TRUE, NULL, FALSE,
|
||||
TRUE
|
||||
);
|
||||
$contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcpBlock->entity_id, 'title');
|
||||
}
|
||||
elseif ($this->_component == 'event') {
|
||||
$pageUrl = CRM_Utils_System::url('civicrm/event',
|
||||
"reset=1&id={$pcpBlock->entity_id}",
|
||||
TRUE, NULL, FALSE,
|
||||
TRUE
|
||||
);
|
||||
$contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $pcpBlock->entity_id, 'title');
|
||||
}
|
||||
|
||||
$this->assign('contribPageUrl', $pageUrl);
|
||||
$this->assign('contribPageTitle', $contribPageTitle);
|
||||
|
||||
$managePCPUrl = CRM_Utils_System::url('civicrm/admin/pcp',
|
||||
"reset=1",
|
||||
TRUE, NULL, FALSE,
|
||||
FALSE
|
||||
);
|
||||
$this->assign('managePCPUrl', $managePCPUrl);
|
||||
|
||||
//get the default domain email address.
|
||||
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
|
||||
|
||||
if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
|
||||
$fixUrl = CRM_Utils_System::url('civicrm/admin/domain', 'action=update&reset=1');
|
||||
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)));
|
||||
}
|
||||
|
||||
//if more than one email present for PCP notification ,
|
||||
//first email take it as To and other as CC and First email
|
||||
//address should be sent in users email receipt for
|
||||
//support purpose.
|
||||
$emailArray = explode(',', $emails);
|
||||
$to = $emailArray[0];
|
||||
unset($emailArray[0]);
|
||||
$cc = implode(',', $emailArray);
|
||||
|
||||
list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
|
||||
array(
|
||||
'groupName' => 'msg_tpl_workflow_contribution',
|
||||
'valueName' => 'pcp_notify',
|
||||
'contactId' => $contactID,
|
||||
'from' => "$domainEmailName <$domainEmailAddress>",
|
||||
'toEmail' => $to,
|
||||
'cc' => $cc,
|
||||
)
|
||||
);
|
||||
|
||||
if ($sent) {
|
||||
$notifyStatus = ts('A notification email has been sent to the site administrator.');
|
||||
}
|
||||
}
|
||||
|
||||
CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id);
|
||||
|
||||
// send email notification to supporter, if initial setup / add mode.
|
||||
if (!$this->_pageId) {
|
||||
CRM_PCP_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, TRUE, $this->_component);
|
||||
if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) {
|
||||
$notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.');
|
||||
}
|
||||
}
|
||||
|
||||
//check if pcp created by anonymous user
|
||||
$anonymousPCP = 0;
|
||||
if (!$session->get('userID')) {
|
||||
$anonymousPCP = 1;
|
||||
}
|
||||
|
||||
CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3",
|
||||
array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus)
|
||||
), '', 'info');
|
||||
if (!$this->_pageId) {
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}"));
|
||||
}
|
||||
elseif ($this->_context == 'dashboard') {
|
||||
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/pcp', 'reset=1'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
184
sites/all/modules/civicrm/CRM/PCP/Form/Contribute.php
Normal file
184
sites/all/modules/civicrm/CRM/PCP/Form/Contribute.php
Normal file
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for Tell A Friend
|
||||
*
|
||||
*/
|
||||
class CRM_PCP_Form_Contribute extends CRM_Contribute_Form_ContributionPage {
|
||||
|
||||
/**
|
||||
* The type of pcp component.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_component = 'contribute';
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
if (isset($this->_id)) {
|
||||
$params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_contribution_page');
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
|
||||
$defaults['pcp_active'] = CRM_Utils_Array::value('is_active', $defaults);
|
||||
// Assign contribution page ID to pageId for referencing in PCP.hlp - since $id is overwritten there. dgg
|
||||
$this->assign('pageId', $this->_id);
|
||||
}
|
||||
|
||||
if (empty($defaults['id'])) {
|
||||
$defaults['target_entity_type'] = 'contribute';
|
||||
$defaults['is_approval_needed'] = 1;
|
||||
$defaults['is_tellfriend_enabled'] = 1;
|
||||
$defaults['tellfriend_limit'] = 5;
|
||||
$defaults['link_text'] = ts('Create your own fundraising page');
|
||||
$defaults['owner_notify_id'] = CRM_Core_OptionGroup::getDefaultValue('pcp_owner_notify');
|
||||
|
||||
if ($ccReceipt = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'cc_receipt')) {
|
||||
$defaults['notify_email'] = $ccReceipt;
|
||||
}
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$this->_last = TRUE;
|
||||
CRM_PCP_BAO_PCP::buildPCPForm($this);
|
||||
|
||||
$this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this contribution page)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);"));
|
||||
|
||||
parent::buildQuickForm();
|
||||
$this->addFormRule(array('CRM_PCP_Form_Contribute', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
if (!empty($params['is_active'])) {
|
||||
|
||||
if (!empty($params['is_tellfriend_enabled']) &&
|
||||
(CRM_Utils_Array::value('tellfriend_limit', $params) <= 0)
|
||||
) {
|
||||
$errors['tellfriend_limit'] = ts('if Tell Friend is enabled, Maximum recipients limit should be greater than zero.');
|
||||
}
|
||||
if (empty($params['supporter_profile_id'])) {
|
||||
$errors['supporter_profile_id'] = ts('Supporter profile is a required field.');
|
||||
}
|
||||
else {
|
||||
if (CRM_PCP_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) {
|
||||
$errors['supporter_profile_id'] = ts('Profile is not configured with Email address.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($emails = CRM_Utils_Array::value('notify_email', $params)) {
|
||||
$emailArray = explode(',', $emails);
|
||||
foreach ($emailArray as $email) {
|
||||
if ($email && !CRM_Utils_Rule::email(trim($email))) {
|
||||
$errors['notify_email'] = ts('A valid Notify Email address must be specified');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
// Source
|
||||
$params['entity_table'] = 'civicrm_contribution_page';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
// Target
|
||||
$params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'contribute');
|
||||
$params['target_entity_id'] = $this->_id;
|
||||
|
||||
$dao = new CRM_PCP_DAO_PCPBlock();
|
||||
$dao->entity_table = $params['entity_table'];
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$params['id'] = $dao->id;
|
||||
$params['is_active'] = CRM_Utils_Array::value('pcp_active', $params, FALSE);
|
||||
$params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE);
|
||||
$params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE);
|
||||
|
||||
CRM_PCP_BAO_PCPBlock::create($params);
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Enable Personal Campaign Pages');
|
||||
}
|
||||
|
||||
}
|
226
sites/all/modules/civicrm/CRM/PCP/Form/Event.php
Normal file
226
sites/all/modules/civicrm/CRM/PCP/Form/Event.php
Normal file
|
@ -0,0 +1,226 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for PCP
|
||||
*
|
||||
*/
|
||||
class CRM_PCP_Form_Event extends CRM_Event_Form_ManageEvent {
|
||||
|
||||
/**
|
||||
* The type of pcp component.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $_component = 'event';
|
||||
|
||||
|
||||
public function preProcess() {
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$defaults = array();
|
||||
if (isset($this->_id)) {
|
||||
$title = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_id, 'title');
|
||||
CRM_Utils_System::setTitle(ts('Personal Campaign Page Settings (%1)', array(1 => $title)));
|
||||
|
||||
$params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $defaults);
|
||||
$defaults['pcp_active'] = CRM_Utils_Array::value('is_active', $defaults);
|
||||
// Assign contribution page ID to pageId for referencing in PCP.hlp - since $id is overwritten there. dgg
|
||||
$this->assign('pageId', $this->_id);
|
||||
}
|
||||
|
||||
if (empty($defaults['id'])) {
|
||||
$defaults['target_entity_type'] = 'event';
|
||||
$defaults['is_approval_needed'] = 1;
|
||||
$defaults['is_tellfriend_enabled'] = 1;
|
||||
$defaults['tellfriend_limit'] = 5;
|
||||
$defaults['link_text'] = ts('Promote this event with a personal campaign page');
|
||||
$defaults['owner_notify_id'] = CRM_Core_OptionGroup::getDefaultValue('pcp_owner_notify');
|
||||
|
||||
if ($this->_id &&
|
||||
$ccReceipt = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'cc_receipt')
|
||||
) {
|
||||
$defaults['notify_email'] = $ccReceipt;
|
||||
}
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
CRM_PCP_BAO_PCP::buildPCPForm($this);
|
||||
|
||||
$this->addElement('checkbox', 'pcp_active', ts('Enable Personal Campaign Pages? (for this event)'), NULL, array('onclick' => "return showHideByValue('pcp_active',true,'pcpFields','table-row','radio',false);"));
|
||||
|
||||
$this->add('select', 'target_entity_type', ts('Campaign Type'),
|
||||
array('' => ts('- select -'), 'event' => ts('Event'), 'contribute' => ts('Contribution')),
|
||||
NULL, array('onchange' => "return showHideByValue('target_entity_type','contribute','pcpDetailFields','block','select',false);")
|
||||
);
|
||||
|
||||
$this->add('select', 'target_entity_id',
|
||||
ts('Online Contribution Page'),
|
||||
array(
|
||||
'' => ts('- select -'),
|
||||
) +
|
||||
CRM_Contribute_PseudoConstant::contributionPage()
|
||||
);
|
||||
|
||||
parent::buildQuickForm();
|
||||
|
||||
// If at least one PCP has been created, don't allow changing the target
|
||||
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
|
||||
$pcpBlock->entity_table = 'civicrm_event';
|
||||
$pcpBlock->entity_id = $this->_id;
|
||||
$pcpBlock->find(TRUE);
|
||||
|
||||
if (!empty($pcpBlock->id) && CRM_PCP_BAO_PCP::getPcpBlockInUse($pcpBlock->id)) {
|
||||
foreach (array(
|
||||
'target_entity_type',
|
||||
'target_entity_id',
|
||||
) as $element_name) {
|
||||
$element = $this->getElement($element_name);
|
||||
$element->freeze();
|
||||
}
|
||||
}
|
||||
$this->addFormRule(array('CRM_PCP_Form_Event', 'formRule'), $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation.
|
||||
*
|
||||
* @param array $params
|
||||
* (ref.) an assoc array of name/value pairs.
|
||||
*
|
||||
* @param $files
|
||||
* @param $self
|
||||
*
|
||||
* @return bool|array
|
||||
* mixed true or array of errors
|
||||
*/
|
||||
public static function formRule($params, $files, $self) {
|
||||
$errors = array();
|
||||
if (!empty($params['is_active'])) {
|
||||
|
||||
if (!empty($params['is_tellfriend_enabled']) &&
|
||||
(CRM_Utils_Array::value('tellfriend_limit', $params) <= 0)
|
||||
) {
|
||||
$errors['tellfriend_limit'] = ts('if Tell Friend is enable, Maximum recipients limit should be greater than zero.');
|
||||
}
|
||||
if (empty($params['supporter_profile_id'])) {
|
||||
$errors['supporter_profile_id'] = ts('Supporter profile is a required field.');
|
||||
}
|
||||
else {
|
||||
if (CRM_PCP_BAO_PCP::checkEmailProfile($params['supporter_profile_id'])) {
|
||||
$errors['supporter_profile_id'] = ts('Profile is not configured with Email address.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($emails = CRM_Utils_Array::value('notify_email', $params)) {
|
||||
$emailArray = explode(',', $emails);
|
||||
foreach ($emailArray as $email) {
|
||||
if ($email && !CRM_Utils_Rule::email(trim($email))) {
|
||||
$errors['notify_email'] = ts('A valid Notify Email address must be specified');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
// get the submitted form values.
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
|
||||
// Source
|
||||
$params['entity_table'] = 'civicrm_event';
|
||||
$params['entity_id'] = $this->_id;
|
||||
|
||||
// Target
|
||||
$params['target_entity_type'] = CRM_Utils_Array::value('target_entity_type', $params, 'event');
|
||||
if ($params['target_entity_type'] == 'event') {
|
||||
$params['target_entity_id'] = $this->_id;
|
||||
}
|
||||
else {
|
||||
$params['target_entity_id'] = CRM_Utils_Array::value('target_entity_id', $params, $this->_id);
|
||||
}
|
||||
|
||||
$dao = new CRM_PCP_DAO_PCPBlock();
|
||||
$dao->entity_table = $params['entity_table'];
|
||||
$dao->entity_id = $this->_id;
|
||||
$dao->find(TRUE);
|
||||
$params['id'] = $dao->id;
|
||||
$params['is_active'] = CRM_Utils_Array::value('pcp_active', $params, FALSE);
|
||||
$params['is_approval_needed'] = CRM_Utils_Array::value('is_approval_needed', $params, FALSE);
|
||||
$params['is_tellfriend_enabled'] = CRM_Utils_Array::value('is_tellfriend_enabled', $params, FALSE);
|
||||
|
||||
CRM_PCP_BAO_PCPBlock::create($params);
|
||||
|
||||
// Update tab "disabled" css class
|
||||
$this->ajaxResponse['tabValid'] = !empty($params['is_active']);
|
||||
|
||||
parent::endPostProcess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a descriptive name for the page, used in wizard header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle() {
|
||||
return ts('Enable Personal Campaign Pages');
|
||||
}
|
||||
|
||||
}
|
222
sites/all/modules/civicrm/CRM/PCP/Form/PCP.php
Normal file
222
sites/all/modules/civicrm/CRM/PCP/Form/PCP.php
Normal file
|
@ -0,0 +1,222 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Administer Personal Campaign Pages - Search form
|
||||
*/
|
||||
class CRM_PCP_Form_PCP extends CRM_Core_Form {
|
||||
|
||||
public $_context;
|
||||
|
||||
/**
|
||||
* Set variables up before form is built.
|
||||
*/
|
||||
public function preProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
//check permission for action.
|
||||
if (!CRM_Core_Permission::checkActionPermission('CiviEvent', $this->_action)) {
|
||||
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
|
||||
}
|
||||
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title');
|
||||
$this->assign('title', $this->_title);
|
||||
parent::preProcess();
|
||||
}
|
||||
|
||||
if (!$this->_action) {
|
||||
$this->_action = CRM_Utils_Array::value('action', $_GET);
|
||||
$this->_id = CRM_Utils_Array::value('id', $_GET);
|
||||
}
|
||||
else {
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
}
|
||||
|
||||
//give the context.
|
||||
if (!isset($this->_context)) {
|
||||
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
|
||||
}
|
||||
|
||||
$this->assign('context', $this->_context);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$context = $session->popUserContext();
|
||||
$userID = $session->get('userID');
|
||||
|
||||
//do not allow destructive actions without permissions
|
||||
$permission = FALSE;
|
||||
if (CRM_Core_Permission::check('administer CiviCRM') ||
|
||||
($userID && (CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
|
||||
$this->_id,
|
||||
'contact_id'
|
||||
) == $userID))
|
||||
) {
|
||||
$permission = TRUE;
|
||||
}
|
||||
if ($permission && $this->_id) {
|
||||
|
||||
$this->_title = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'title');
|
||||
switch ($this->_action) {
|
||||
case CRM_Core_Action::DELETE:
|
||||
case 'delete':
|
||||
CRM_PCP_BAO_PCP::deleteById($this->_id);
|
||||
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::DISABLE:
|
||||
case 'disable':
|
||||
CRM_PCP_BAO_PCP::setDisable($this->_id, '0');
|
||||
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been disabled.", array(1 => $this->_title)), ts('Page Disabled'), 'success');
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::ENABLE:
|
||||
case 'enable':
|
||||
CRM_PCP_BAO_PCP::setDisable($this->_id, '1');
|
||||
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been enabled.", array(1 => $this->_title)), ts('Page Enabled'), 'success');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($context) {
|
||||
CRM_Utils_System::redirect($context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default values for the form. Note that in edit/view mode
|
||||
* the default values are retrieved from the database
|
||||
*
|
||||
* @return array
|
||||
* array of default values
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$defaults = array();
|
||||
|
||||
$pageType = CRM_Utils_Request::retrieve('page_type', 'String', $this);
|
||||
$defaults['page_type'] = !empty($pageType) ? $pageType : '';
|
||||
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Delete Campaign'),
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
||||
$status = array('' => ts('- select -')) + CRM_Core_OptionGroup::values("pcp_status");
|
||||
$types = array(
|
||||
'' => ts('- select -'),
|
||||
'contribute' => ts('Contribution'),
|
||||
'event' => ts('Event'),
|
||||
);
|
||||
$contribPages = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage();
|
||||
$eventPages = array('' => ts('- select -')) + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
|
||||
|
||||
$this->addElement('select', 'status_id', ts('Status'), $status);
|
||||
$this->addElement('select', 'page_type', ts('Source Type'), $types);
|
||||
$this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages);
|
||||
$this->addElement('select', 'event_id', ts('Event Page'), $eventPages);
|
||||
$this->addButtons(array(
|
||||
array(
|
||||
'type' => 'refresh',
|
||||
'name' => ts('Search'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
)
|
||||
);
|
||||
parent::buildQuickForm();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global validation rules for the form.
|
||||
*
|
||||
* @param array $fields
|
||||
* Posted values of the form.
|
||||
* @param array $files
|
||||
* @param CRM_Core_Form $form
|
||||
*
|
||||
* @return array|NULL
|
||||
* list of errors to be posted back to the form
|
||||
*/
|
||||
public static function formRule($fields, $files, $form) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form.
|
||||
*/
|
||||
public function postProcess() {
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
CRM_PCP_BAO_PCP::deleteById($this->_id);
|
||||
CRM_Core_Session::setStatus(ts("The Campaign Page '%1' has been deleted.", array(1 => $this->_title)), ts('Page Deleted'), 'success');
|
||||
}
|
||||
else {
|
||||
$params = $this->controller->exportValues($this->_name);
|
||||
$parent = $this->controller->getParent();
|
||||
|
||||
if (!empty($params)) {
|
||||
$fields = array('status_id', 'page_id');
|
||||
foreach ($fields as $field) {
|
||||
if (isset($params[$field]) &&
|
||||
!CRM_Utils_System::isNull($params[$field])
|
||||
) {
|
||||
$parent->set($field, $params[$field]);
|
||||
}
|
||||
else {
|
||||
$parent->set($field, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
280
sites/all/modules/civicrm/CRM/PCP/Form/PCPAccount.php
Normal file
280
sites/all/modules/civicrm/CRM/PCP/Form/PCPAccount.php
Normal file
|
@ -0,0 +1,280 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class generates form components for processing a contribution.
|
||||
*/
|
||||
class CRM_PCP_Form_PCPAccount extends CRM_Core_Form {
|
||||
|
||||
/**
|
||||
* Variable defined for Contribution Page Id.
|
||||
*/
|
||||
public $_pageId = NULL;
|
||||
public $_id = NULL;
|
||||
public $_component = NULL;
|
||||
|
||||
/**
|
||||
* Are we in single form mode or wizard mode?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $_single;
|
||||
|
||||
public function preProcess() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
|
||||
$this->_pageId = CRM_Utils_Request::retrieve('pageId', 'Positive', $this);
|
||||
$this->_component = CRM_Utils_Request::retrieve('component', 'String', $this);
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
|
||||
|
||||
if (!$this->_pageId && $config->userFramework == 'Joomla' && $config->userFrameworkFrontend) {
|
||||
$this->_pageId = $this->_id;
|
||||
}
|
||||
|
||||
if ($this->_id) {
|
||||
$contactID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id');
|
||||
}
|
||||
|
||||
$this->_contactID = isset($contactID) ? $contactID : $session->get('userID');
|
||||
if (!$this->_pageId) {
|
||||
if (!$this->_id) {
|
||||
$msg = ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.');
|
||||
CRM_Core_Error::fatal($msg);
|
||||
}
|
||||
else {
|
||||
$this->_pageId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'page_id');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->_pageId) {
|
||||
CRM_Core_Error::fatal(ts('Could not find source page id.'));
|
||||
}
|
||||
|
||||
$this->_single = $this->get('single');
|
||||
|
||||
if (!$this->_single) {
|
||||
$this->_single = $session->get('singleForm');
|
||||
}
|
||||
|
||||
$this->set('action', $this->_action);
|
||||
$this->set('page_id', $this->_id);
|
||||
$this->set('component_page_id', $this->_pageId);
|
||||
|
||||
// we do not want to display recently viewed items, so turn off
|
||||
$this->assign('displayRecent', FALSE);
|
||||
|
||||
$this->assign('pcpComponent', $this->_component);
|
||||
|
||||
if ($this->_single) {
|
||||
CRM_Utils_System::setTitle(ts('Update Contact Information'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function setDefaultValues() {
|
||||
$this->_defaults = array();
|
||||
if ($this->_contactID) {
|
||||
foreach ($this->_fields as $name => $dontcare) {
|
||||
$fields[$name] = 1;
|
||||
}
|
||||
|
||||
CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $this->_defaults);
|
||||
}
|
||||
//set custom field defaults
|
||||
foreach ($this->_fields as $name => $field) {
|
||||
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
|
||||
if (!isset($this->_defaults[$name])) {
|
||||
CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults,
|
||||
NULL, CRM_Profile_Form::MODE_REGISTER
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the form object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildQuickForm() {
|
||||
$id = CRM_PCP_BAO_PCP::getSupporterProfileId($this->_pageId, $this->_component);
|
||||
if (CRM_PCP_BAO_PCP::checkEmailProfile($id)) {
|
||||
$this->assign('profileDisplay', TRUE);
|
||||
}
|
||||
$fields = NULL;
|
||||
if ($this->_contactID) {
|
||||
if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $this->_contactID)) {
|
||||
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
$this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
|
||||
}
|
||||
else {
|
||||
CRM_Core_BAO_CMSUser::buildForm($this, $id, TRUE);
|
||||
|
||||
$fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD);
|
||||
}
|
||||
|
||||
if ($fields) {
|
||||
$this->assign('fields', $fields);
|
||||
$addCaptcha = FALSE;
|
||||
foreach ($fields as $key => $field) {
|
||||
if (isset($field['data_type']) && $field['data_type'] == 'File') {
|
||||
// ignore file upload fields
|
||||
continue;
|
||||
}
|
||||
CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE);
|
||||
$this->_fields[$key] = $field;
|
||||
|
||||
// CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
|
||||
if ($field['add_captcha'] && !$this->_contactID) {
|
||||
$addCaptcha = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($addCaptcha) {
|
||||
$captcha = &CRM_Utils_ReCAPTCHA::singleton();
|
||||
$captcha->add($this);
|
||||
$this->assign('isCaptcha', TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_component == 'contribute') {
|
||||
$this->assign('campaignName', CRM_Contribute_PseudoConstant::contributionPage($this->_pageId));
|
||||
}
|
||||
elseif ($this->_component == 'event') {
|
||||
$this->assign('campaignName', CRM_Event_PseudoConstant::event($this->_pageId));
|
||||
}
|
||||
|
||||
if ($this->_single) {
|
||||
$button = array(
|
||||
array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Save'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
),
|
||||
array(
|
||||
'type' => 'cancel',
|
||||
'name' => ts('Cancel'),
|
||||
),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$button[] = array(
|
||||
'type' => 'next',
|
||||
'name' => ts('Continue'),
|
||||
'spacing' => ' ',
|
||||
'isDefault' => TRUE,
|
||||
);
|
||||
}
|
||||
$this->addFormRule(array('CRM_PCP_Form_PCPAccount', 'formRule'), $this);
|
||||
$this->addButtons($button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global form rule.
|
||||
*
|
||||
* @param array $fields
|
||||
* The input form values.
|
||||
* @param array $files
|
||||
* The uploaded files if any.
|
||||
* @param $self
|
||||
*
|
||||
*
|
||||
* @return bool|array
|
||||
* true if no errors, else array of errors
|
||||
*/
|
||||
public static function formRule($fields, $files, $self) {
|
||||
$errors = array();
|
||||
foreach ($fields as $key => $value) {
|
||||
if (strpos($key, 'email-') !== FALSE && !empty($value)) {
|
||||
$ufContactId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
|
||||
if ($ufContactId && $ufContactId != $self->_contactID) {
|
||||
$errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
|
||||
}
|
||||
}
|
||||
}
|
||||
return empty($errors) ? TRUE : $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the form submission.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postProcess() {
|
||||
$params = $this->controller->exportValues($this->getName());
|
||||
|
||||
if (!$this->_contactID && isset($params['cms_create_account'])) {
|
||||
foreach ($params as $key => $value) {
|
||||
if (substr($key, 0, 5) == 'email' && !empty($value)) {
|
||||
list($fieldName, $locTypeId) = CRM_Utils_System::explode('-', $key, 2);
|
||||
$isPrimary = 0;
|
||||
if ($locTypeId == 'Primary') {
|
||||
$locTypeDefault = CRM_Core_BAO_LocationType::getDefault();
|
||||
$locTypeId = NULL;
|
||||
if ($locTypeDefault) {
|
||||
$locTypeId = $locTypeDefault->id;
|
||||
}
|
||||
$isPrimary = 1;
|
||||
}
|
||||
|
||||
$params['email'] = array();
|
||||
$params['email'][1]['email'] = $value;
|
||||
$params['email'][1]['location_type_id'] = $locTypeId;
|
||||
$params['email'][1]['is_primary'] = $isPrimary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($params, 'Individual', 'Unsupervised', array(), FALSE);
|
||||
|
||||
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_contactID);
|
||||
$this->set('contactID', $contactID);
|
||||
|
||||
if (!empty($params['email'])) {
|
||||
$params['email'] = $params['email'][1]['email'];
|
||||
}
|
||||
|
||||
CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params, $contactID, 'email');
|
||||
}
|
||||
|
||||
}
|
413
sites/all/modules/civicrm/CRM/PCP/Page/PCP.php
Normal file
413
sites/all/modules/civicrm/CRM/PCP/Page/PCP.php
Normal file
|
@ -0,0 +1,413 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Page for displaying list of financial types
|
||||
*/
|
||||
class CRM_PCP_Page_PCP extends CRM_Core_Page_Basic {
|
||||
|
||||
/**
|
||||
* The action links that we need to display for the browse screen.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
static $_links = NULL;
|
||||
|
||||
/**
|
||||
* Get BAO Name.
|
||||
*
|
||||
* @return string
|
||||
* Classname of BAO.
|
||||
*/
|
||||
public function getBAOName() {
|
||||
return 'CRM_PCP_BAO_PCP';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get action Links.
|
||||
*
|
||||
* @return array
|
||||
* (reference) of action links
|
||||
*/
|
||||
public function &links() {
|
||||
if (!(self::$_links)) {
|
||||
// helper variable for nicer formatting
|
||||
$deleteExtra = ts('Are you sure you want to delete this Campaign Page ?');
|
||||
|
||||
self::$_links = array(
|
||||
CRM_Core_Action::UPDATE => array(
|
||||
'name' => ts('Edit'),
|
||||
'url' => 'civicrm/pcp/info',
|
||||
'qs' => 'action=update&reset=1&id=%%id%%&context=dashboard',
|
||||
'title' => ts('Edit Personal Campaign Page'),
|
||||
),
|
||||
CRM_Core_Action::RENEW => array(
|
||||
'name' => ts('Approve'),
|
||||
'url' => 'civicrm/admin/pcp',
|
||||
'qs' => 'action=renew&id=%%id%%',
|
||||
'title' => ts('Approve Personal Campaign Page'),
|
||||
),
|
||||
CRM_Core_Action::REVERT => array(
|
||||
'name' => ts('Reject'),
|
||||
'url' => 'civicrm/admin/pcp',
|
||||
'qs' => 'action=revert&id=%%id%%',
|
||||
'title' => ts('Reject Personal Campaign Page'),
|
||||
),
|
||||
CRM_Core_Action::DELETE => array(
|
||||
'name' => ts('Delete'),
|
||||
'url' => 'civicrm/admin/pcp',
|
||||
'qs' => 'action=delete&id=%%id%%',
|
||||
'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
|
||||
'title' => ts('Delete Personal Campaign Page'),
|
||||
),
|
||||
CRM_Core_Action::ENABLE => array(
|
||||
'name' => ts('Enable'),
|
||||
'url' => 'civicrm/admin/pcp',
|
||||
'qs' => 'action=enable&id=%%id%%',
|
||||
'title' => ts('Enable'),
|
||||
),
|
||||
CRM_Core_Action::DISABLE => array(
|
||||
'name' => ts('Disable'),
|
||||
'url' => 'civicrm/admin/pcp',
|
||||
'qs' => 'action=disable&id=%%id%%',
|
||||
'title' => ts('Disable'),
|
||||
),
|
||||
);
|
||||
}
|
||||
return self::$_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the page.
|
||||
*
|
||||
* This method is called after the page is created. It checks for the
|
||||
* type of action and executes that action.
|
||||
* Finally it calls the parent's run method.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
$id = $this->getIdAndAction();
|
||||
|
||||
if ($this->_action & CRM_Core_Action::REVERT) {
|
||||
CRM_PCP_BAO_PCP::setIsActive($id, 0);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::RENEW) {
|
||||
CRM_PCP_BAO_PCP::setIsActive($id, 1);
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
|
||||
}
|
||||
elseif ($this->_action & CRM_Core_Action::DELETE) {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse'));
|
||||
$controller = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP',
|
||||
'Personal Campaign Page',
|
||||
CRM_Core_Action::DELETE
|
||||
);
|
||||
//$this->setContext( $id, $action );
|
||||
$controller->set('id', $id);
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
|
||||
// finally browse
|
||||
$this->browse();
|
||||
|
||||
// parent run
|
||||
CRM_Core_Page::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Browse all custom data groups.
|
||||
*
|
||||
*
|
||||
* @param null $action
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function browse($action = NULL) {
|
||||
CRM_Core_Resources::singleton()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
|
||||
|
||||
$this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter',
|
||||
'String',
|
||||
$this
|
||||
);
|
||||
if ($this->_sortByCharacter == 1 ||
|
||||
!empty($_POST)
|
||||
) {
|
||||
$this->_sortByCharacter = '';
|
||||
}
|
||||
|
||||
$status = CRM_PCP_BAO_PCP::buildOptions('status_id', 'create');
|
||||
|
||||
$pcpSummary = $params = array();
|
||||
$whereClause = NULL;
|
||||
|
||||
if (!empty($_POST) || !empty($_GET['page_type'])) {
|
||||
if (!empty($_POST['status_id'])) {
|
||||
$whereClause = ' AND cp.status_id = %1';
|
||||
$params['1'] = array($_POST['status_id'], 'Integer');
|
||||
}
|
||||
|
||||
if (!empty($_POST['page_type'])) {
|
||||
$whereClause .= ' AND cp.page_type = %2';
|
||||
$params['2'] = array($_POST['page_type'], 'String');
|
||||
}
|
||||
elseif (!empty($_GET['page_type'])) {
|
||||
$whereClause .= ' AND cp.page_type = %2';
|
||||
$params['2'] = array($_GET['page_type'], 'String');
|
||||
}
|
||||
|
||||
if (!empty($_POST['page_id'])) {
|
||||
$whereClause .= ' AND cp.page_id = %4 AND cp.page_type = "contribute"';
|
||||
$params['4'] = array($_POST['page_id'], 'Integer');
|
||||
}
|
||||
|
||||
if (!empty($_POST['event_id'])) {
|
||||
$whereClause .= ' AND cp.page_id = %5 AND cp.page_type = "event"';
|
||||
$params['5'] = array($_POST['event_id'], 'Integer');
|
||||
}
|
||||
|
||||
if ($whereClause) {
|
||||
$this->set('whereClause', $whereClause);
|
||||
$this->set('params', $params);
|
||||
}
|
||||
else {
|
||||
$this->set('whereClause', NULL);
|
||||
$this->set('params', NULL);
|
||||
}
|
||||
}
|
||||
|
||||
$approvedId = CRM_Core_PseudoConstant::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
|
||||
|
||||
//check for delete CRM-4418
|
||||
$allowToDelete = CRM_Core_Permission::check('delete in CiviContribute');
|
||||
|
||||
// get all contribution pages
|
||||
$query = "SELECT id, title, start_date, end_date FROM civicrm_contribution_page WHERE (1)";
|
||||
$cpages = CRM_Core_DAO::executeQuery($query);
|
||||
while ($cpages->fetch()) {
|
||||
$pages['contribute'][$cpages->id]['id'] = $cpages->id;
|
||||
$pages['contribute'][$cpages->id]['title'] = $cpages->title;
|
||||
$pages['contribute'][$cpages->id]['start_date'] = $cpages->start_date;
|
||||
$pages['contribute'][$cpages->id]['end_date'] = $cpages->end_date;
|
||||
}
|
||||
|
||||
// get all event pages. pcp campaign start and end dates for event related pcp's use the online registration start and end dates,
|
||||
// although if target is contribution page this might not be correct. fixme? dgg
|
||||
$query = "SELECT id, title, start_date, end_date, registration_start_date, registration_end_date
|
||||
FROM civicrm_event
|
||||
WHERE is_template IS NULL OR is_template != 1";
|
||||
$epages = CRM_Core_DAO::executeQuery($query);
|
||||
while ($epages->fetch()) {
|
||||
$pages['event'][$epages->id]['id'] = $epages->id;
|
||||
$pages['event'][$epages->id]['title'] = $epages->title;
|
||||
$pages['event'][$epages->id]['start_date'] = $epages->registration_start_date;
|
||||
$pages['event'][$epages->id]['end_date'] = $epages->registration_end_date;
|
||||
}
|
||||
|
||||
$params = $this->get('params') ? $this->get('params') : array();
|
||||
|
||||
$title = '1';
|
||||
if ($this->_sortByCharacter !== NULL) {
|
||||
$clauses[] = "cp.title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT cp.id, cp.contact_id , cp.status_id, cp.title, cp.is_active, cp.page_type, cp.page_id
|
||||
FROM civicrm_pcp cp
|
||||
WHERE $title" . $this->get('whereClause') . " ORDER BY cp.status_id";
|
||||
|
||||
$pcp = CRM_Core_DAO::executeQuery($query, $params);
|
||||
while ($pcp->fetch()) {
|
||||
$action = array_sum(array_keys($this->links()));
|
||||
$contact = CRM_Contact_BAO_Contact::getDisplayAndImage($pcp->contact_id);
|
||||
|
||||
$class = '';
|
||||
|
||||
if ($pcp->status_id != $approvedId || $pcp->is_active != 1) {
|
||||
$class = 'disabled';
|
||||
}
|
||||
|
||||
switch ($pcp->status_id) {
|
||||
case 2:
|
||||
$action -= CRM_Core_Action::RENEW;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$action -= CRM_Core_Action::REVERT;
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($pcp->is_active) {
|
||||
case 1:
|
||||
$action -= CRM_Core_Action::ENABLE;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
$action -= CRM_Core_Action::DISABLE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$allowToDelete) {
|
||||
$action -= CRM_Core_Action::DELETE;
|
||||
}
|
||||
|
||||
$page_type = $pcp->page_type;
|
||||
$page_id = (int) $pcp->page_id;
|
||||
if ($pages[$page_type][$page_id]['title'] == '' || $pages[$page_type][$page_id]['title'] == NULL) {
|
||||
$title = '(no title found for ' . $page_type . ' id ' . $page_id . ')';
|
||||
}
|
||||
else {
|
||||
$title = $pages[$page_type][$page_id]['title'];
|
||||
}
|
||||
|
||||
if ($pcp->page_type == 'contribute') {
|
||||
$pageUrl = CRM_Utils_System::url('civicrm/' . $page_type . '/transact', 'reset=1&id=' . $pcp->page_id);
|
||||
}
|
||||
else {
|
||||
$pageUrl = CRM_Utils_System::url('civicrm/' . $page_type . '/register', 'reset=1&id=' . $pcp->page_id);
|
||||
}
|
||||
|
||||
$pcpSummary[$pcp->id] = array(
|
||||
'id' => $pcp->id,
|
||||
'start_date' => $pages[$page_type][$page_id]['start_date'],
|
||||
'end_date' => $pages[$page_type][$page_id]['end_date'],
|
||||
'supporter' => $contact['0'],
|
||||
'supporter_id' => $pcp->contact_id,
|
||||
'status_id' => $status[$pcp->status_id],
|
||||
'page_id' => $page_id,
|
||||
'page_title' => $title,
|
||||
'page_url' => $pageUrl,
|
||||
'page_type' => $page_type,
|
||||
'action' => CRM_Core_Action::formLink(self::links(), $action,
|
||||
array('id' => $pcp->id), ts('more'), FALSE, 'contributionpage.pcp.list', 'PCP', $pcp->id
|
||||
),
|
||||
'title' => $pcp->title,
|
||||
'class' => $class,
|
||||
);
|
||||
}
|
||||
|
||||
$this->search();
|
||||
$this->pagerAToZ($this->get('whereClause'), $params);
|
||||
|
||||
$this->assign('rows', $pcpSummary);
|
||||
|
||||
// Let template know if user has run a search or not
|
||||
if ($this->get('whereClause')) {
|
||||
$this->assign('isSearch', 1);
|
||||
}
|
||||
else {
|
||||
$this->assign('isSearch', 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function search() {
|
||||
|
||||
if ($this->_action & CRM_Core_Action::DELETE) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new CRM_Core_Controller_Simple('CRM_PCP_Form_PCP', ts('Search Campaign Pages'), CRM_Core_Action::ADD);
|
||||
$form->setEmbedded(TRUE);
|
||||
$form->setParent($this);
|
||||
$form->process();
|
||||
$form->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of edit form.
|
||||
*
|
||||
* @return string
|
||||
* Classname of edit form.
|
||||
*/
|
||||
public function editForm() {
|
||||
return 'CRM_PCP_Form_PCP';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit form name.
|
||||
*
|
||||
* @return string
|
||||
* name of this page.
|
||||
*/
|
||||
public function editName() {
|
||||
return ts('Personal Campaign Page');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user context.
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
* user context.
|
||||
*/
|
||||
public function userContext($mode = NULL) {
|
||||
return 'civicrm/admin/pcp';
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO this function changed, debug this at runtime
|
||||
* @param $whereClause
|
||||
* @param array $whereParams
|
||||
*/
|
||||
public function pagerAtoZ($whereClause, $whereParams) {
|
||||
$where = '';
|
||||
if ($whereClause) {
|
||||
if (strpos($whereClause, ' AND') == 0) {
|
||||
$whereClause = substr($whereClause, 4);
|
||||
}
|
||||
$where = 'WHERE ' . $whereClause;
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT UPPER(LEFT(cp.title, 1)) as sort_name
|
||||
FROM civicrm_pcp cp
|
||||
" . $where . "
|
||||
ORDER BY LEFT(cp.title, 1);
|
||||
";
|
||||
|
||||
$dao = CRM_Core_DAO::executeQuery($query, $whereParams);
|
||||
|
||||
$aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE);
|
||||
$this->assign('aToZ', $aToZBar);
|
||||
}
|
||||
|
||||
}
|
348
sites/all/modules/civicrm/CRM/PCP/Page/PCPInfo.php
Normal file
348
sites/all/modules/civicrm/CRM/PCP/Page/PCPInfo.php
Normal file
|
@ -0,0 +1,348 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* PCP Info Page - Summary about the PCP
|
||||
*/
|
||||
class CRM_PCP_Page_PCPInfo extends CRM_Core_Page {
|
||||
public $_component;
|
||||
|
||||
/**
|
||||
* Run the page.
|
||||
*
|
||||
* This method is called after the page is created. It checks for the
|
||||
* type of action and executes that action.
|
||||
* Finally it calls the parent's run method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$config = CRM_Core_Config::singleton();
|
||||
$permissionCheck = FALSE;
|
||||
$statusMessage = '';
|
||||
if ($config->userFramework != 'Joomla') {
|
||||
$permissionCheck = CRM_Core_Permission::check('administer CiviCRM');
|
||||
}
|
||||
//get the pcp id.
|
||||
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
|
||||
|
||||
$action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
|
||||
|
||||
$prms = array('id' => $this->_id);
|
||||
|
||||
CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
|
||||
$this->_component = $pcpInfo['page_type'];
|
||||
|
||||
if (empty($pcpInfo)) {
|
||||
$statusMessage = ts('The personal campaign page you requested is currently unavailable.');
|
||||
CRM_Core_Error::statusBounce($statusMessage,
|
||||
$config->userFrameworkBaseURL
|
||||
);
|
||||
}
|
||||
|
||||
CRM_Utils_System::setTitle($pcpInfo['title']);
|
||||
$this->assign('pcp', $pcpInfo);
|
||||
|
||||
$pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
|
||||
$approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name');
|
||||
|
||||
// check if PCP is created by anonymous user
|
||||
$anonymousPCP = CRM_Utils_Request::retrieve('ap', 'Boolean', $this);
|
||||
if ($anonymousPCP) {
|
||||
$loginURL = $config->userSystem->getLoginURL();
|
||||
$anonMessage = ts('Once you\'ve received your new account welcome email, you can <a href=%1>click here</a> to login and promote your campaign page.', array(1 => $loginURL));
|
||||
CRM_Core_Session::setStatus($anonMessage, ts('Success'), 'success');
|
||||
}
|
||||
else {
|
||||
$statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
|
||||
}
|
||||
|
||||
$pcpBlock = new CRM_PCP_DAO_PCPBlock();
|
||||
$pcpBlock->entity_table = CRM_PCP_BAO_PCP::getPcpEntityTable($pcpInfo['page_type']);
|
||||
$pcpBlock->entity_id = $pcpInfo['page_id'];
|
||||
$pcpBlock->find(TRUE);
|
||||
|
||||
// Redirect back to source page in case of error.
|
||||
if ($pcpInfo['page_type'] == 'contribute') {
|
||||
$urlBase = 'civicrm/contribute/transact';
|
||||
}
|
||||
elseif ($pcpInfo['page_type'] == 'event') {
|
||||
$urlBase = 'civicrm/event/register';
|
||||
}
|
||||
|
||||
if ($pcpInfo['status_id'] != $approvedId || !$pcpInfo['is_active']) {
|
||||
if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) {
|
||||
CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase,
|
||||
"reset=1&id=" . $pcpInfo['page_id'],
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
$getStatus = CRM_PCP_BAO_PCP::getStatus($this->_id, $this->_component);
|
||||
if (!$getStatus) {
|
||||
// PCP not enabled for this contribution page. Forward everyone to source page
|
||||
CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url($urlBase,
|
||||
"reset=1&id=" . $pcpInfo['page_id'],
|
||||
FALSE, NULL, FALSE, TRUE
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$default = array();
|
||||
|
||||
if ($pcpBlock->target_entity_type == 'contribute') {
|
||||
$urlBase = 'civicrm/contribute/transact';
|
||||
}
|
||||
elseif ($pcpBlock->target_entity_type == 'event') {
|
||||
$urlBase = 'civicrm/event/register';
|
||||
}
|
||||
|
||||
if ($pcpBlock->entity_table == 'civicrm_event') {
|
||||
$page_class = 'CRM_Event_DAO_Event';
|
||||
$this->assign('pageName', CRM_Event_PseudoConstant::event($pcpInfo['page_id']));
|
||||
CRM_Core_DAO::commonRetrieveAll($page_class, 'id',
|
||||
$pcpInfo['page_id'], $default, array(
|
||||
'start_date',
|
||||
'end_date',
|
||||
'registration_start_date',
|
||||
'registration_end_date',
|
||||
)
|
||||
);
|
||||
}
|
||||
elseif ($pcpBlock->entity_table == 'civicrm_contribution_page') {
|
||||
$page_class = 'CRM_Contribute_DAO_ContributionPage';
|
||||
$this->assign('pageName', CRM_Contribute_PseudoConstant::contributionPage($pcpInfo['page_id'], TRUE));
|
||||
CRM_Core_DAO::commonRetrieveAll($page_class, 'id',
|
||||
$pcpInfo['page_id'], $default, array('start_date', 'end_date')
|
||||
);
|
||||
}
|
||||
|
||||
$pageInfo = $default[$pcpInfo['page_id']];
|
||||
|
||||
if ($pcpInfo['contact_id'] == $session->get('userID')) {
|
||||
$owner = $pageInfo;
|
||||
$owner['status'] = CRM_Utils_Array::value($pcpInfo['status_id'], $pcpStatus);
|
||||
|
||||
$this->assign('owner', $owner);
|
||||
|
||||
$link = CRM_PCP_BAO_PCP::pcpLinks();
|
||||
|
||||
$hints = array(
|
||||
CRM_Core_Action::UPDATE => ts('Change the content and appearance of your page'),
|
||||
CRM_Core_Action::DETACH => ts('Send emails inviting your friends to support your campaign!'),
|
||||
CRM_Core_Action::VIEW => ts('Copy this link to share directly with your network!'),
|
||||
CRM_Core_Action::BROWSE => ts('Update your personal contact information'),
|
||||
CRM_Core_Action::DISABLE => ts('De-activate the page (you can re-activate it later)'),
|
||||
CRM_Core_Action::ENABLE => ts('Activate the page (you can de-activate it later)'),
|
||||
CRM_Core_Action::DELETE => ts('Remove the page (this cannot be undone!)'),
|
||||
);
|
||||
|
||||
$replace = array(
|
||||
'id' => $this->_id,
|
||||
'block' => $pcpBlock->id,
|
||||
'pageComponent' => $this->_component,
|
||||
);
|
||||
|
||||
if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array::value('status_id', $pcpInfo) != $approvedId) {
|
||||
unset($link['all'][CRM_Core_Action::DETACH]);
|
||||
}
|
||||
|
||||
switch ($pcpInfo['is_active']) {
|
||||
case 1:
|
||||
unset($link['all'][CRM_Core_Action::ENABLE]);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
unset($link['all'][CRM_Core_Action::DISABLE]);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assign('links', $link['all']);
|
||||
$this->assign('hints', $hints);
|
||||
$this->assign('replace', $replace);
|
||||
}
|
||||
|
||||
$honor = CRM_PCP_BAO_PCP::honorRoll($this->_id);
|
||||
|
||||
$entityFile = CRM_Core_BAO_File::getEntityFile('civicrm_pcp', $this->_id);
|
||||
if (!empty($entityFile)) {
|
||||
$fileInfo = reset($entityFile);
|
||||
$fileId = $fileInfo['fileID'];
|
||||
$image = '<img src="' . CRM_Utils_System::url('civicrm/file',
|
||||
"reset=1&id=$fileId&eid={$this->_id}"
|
||||
) . '" />';
|
||||
$this->assign('image', $image);
|
||||
}
|
||||
|
||||
$totalAmount = CRM_PCP_BAO_PCP::thermoMeter($this->_id);
|
||||
$achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
|
||||
|
||||
if ($pcpBlock->is_active == 1) {
|
||||
$linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign',
|
||||
"action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}",
|
||||
TRUE, NULL, TRUE,
|
||||
TRUE
|
||||
);
|
||||
$this->assign('linkTextUrl', $linkTextUrl);
|
||||
$this->assign('linkText', $pcpBlock->link_text);
|
||||
}
|
||||
|
||||
$this->assign('honor', $honor);
|
||||
$this->assign('total', $totalAmount ? $totalAmount : '0.0');
|
||||
$this->assign('achieved', $achieved <= 100 ? $achieved : 100);
|
||||
|
||||
if ($achieved <= 100) {
|
||||
$this->assign('remaining', 100 - $achieved);
|
||||
}
|
||||
// make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set
|
||||
if ($pcpBlock->entity_table == 'civicrm_event') {
|
||||
$startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_start_date', $pageInfo));
|
||||
$endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('registration_end_date', $pageInfo));
|
||||
}
|
||||
else {
|
||||
$startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $pageInfo));
|
||||
$endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $pageInfo));
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$validDate = TRUE;
|
||||
if ($startDate && $startDate >= $now) {
|
||||
$validDate = FALSE;
|
||||
}
|
||||
if ($endDate && $endDate < $now) {
|
||||
$validDate = FALSE;
|
||||
}
|
||||
|
||||
$this->assign('validDate', $validDate);
|
||||
|
||||
// form parent page url
|
||||
if ($action == CRM_Core_Action::PREVIEW) {
|
||||
$parentUrl = CRM_Utils_System::url($urlBase,
|
||||
"id={$pcpInfo['page_id']}&reset=1&action=preview",
|
||||
TRUE, NULL, TRUE,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
else {
|
||||
$parentUrl = CRM_Utils_System::url($urlBase,
|
||||
"id={$pcpInfo['page_id']}&reset=1",
|
||||
TRUE, NULL, TRUE,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
|
||||
$this->assign('parentURL', $parentUrl);
|
||||
|
||||
if ($validDate) {
|
||||
|
||||
$contributionText = ts('Contribute Now');
|
||||
if (!empty($pcpInfo['donate_link_text'])) {
|
||||
$contributionText = $pcpInfo['donate_link_text'];
|
||||
}
|
||||
|
||||
$this->assign('contributionText', $contributionText);
|
||||
|
||||
// we always generate urls for the front end in joomla
|
||||
if ($action == CRM_Core_Action::PREVIEW) {
|
||||
$url = CRM_Utils_System::url($urlBase,
|
||||
"id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1&action=preview",
|
||||
TRUE, NULL, TRUE,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
else {
|
||||
$url = CRM_Utils_System::url($urlBase,
|
||||
"id=" . $pcpBlock->target_entity_id . "&pcpId={$this->_id}&reset=1",
|
||||
TRUE, NULL, TRUE,
|
||||
TRUE
|
||||
);
|
||||
}
|
||||
$this->assign('contributeURL', $url);
|
||||
}
|
||||
|
||||
// we do not want to display recently viewed items, so turn off
|
||||
$this->assign('displayRecent', FALSE);
|
||||
|
||||
$single = $permission = FALSE;
|
||||
switch ($action) {
|
||||
case CRM_Core_Action::BROWSE:
|
||||
$subForm = 'PCPAccount';
|
||||
$form = "CRM_PCP_Form_$subForm";
|
||||
$single = TRUE;
|
||||
break;
|
||||
|
||||
case CRM_Core_Action::UPDATE:
|
||||
$subForm = 'Campaign';
|
||||
$form = "CRM_PCP_Form_$subForm";
|
||||
$single = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
$userID = $session->get('userID');
|
||||
//make sure the user has "administer CiviCRM" permission
|
||||
//OR has created the PCP
|
||||
if (CRM_Core_Permission::check('administer CiviCRM') ||
|
||||
($userID && (CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $this->_id, 'contact_id') == $userID))
|
||||
) {
|
||||
$permission = TRUE;
|
||||
}
|
||||
if ($single && $permission) {
|
||||
$controller = new CRM_Core_Controller_Simple($form, $subForm, $action);
|
||||
$controller->set('id', $this->_id);
|
||||
$controller->set('single', TRUE);
|
||||
$controller->process();
|
||||
return $controller->run();
|
||||
}
|
||||
$session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&id=' . $this->_id));
|
||||
parent::run();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplateFileName() {
|
||||
if ($this->_id) {
|
||||
$templateFile = "CRM/PCP/Page/{$this->_id}/PCPInfo.tpl";
|
||||
$template = &CRM_Core_Page::getTemplate();
|
||||
if ($template->template_exists($templateFile)) {
|
||||
return $templateFile;
|
||||
}
|
||||
}
|
||||
return parent::getTemplateFileName();
|
||||
}
|
||||
|
||||
}
|
65
sites/all/modules/civicrm/CRM/PCP/StateMachine/PCP.php
Normal file
65
sites/all/modules/civicrm/CRM/PCP/StateMachine/PCP.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/*
|
||||
+--------------------------------------------------------------------+
|
||||
| CiviCRM version 4.7 |
|
||||
+--------------------------------------------------------------------+
|
||||
| Copyright CiviCRM LLC (c) 2004-2017 |
|
||||
+--------------------------------------------------------------------+
|
||||
| This file is a part of CiviCRM. |
|
||||
| |
|
||||
| CiviCRM is free software; you can copy, modify, and distribute it |
|
||||
| under the terms of the GNU Affero General Public License |
|
||||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
|
||||
| |
|
||||
| CiviCRM is distributed in the hope that it will be useful, but |
|
||||
| WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| See the GNU Affero General Public License for more details. |
|
||||
| |
|
||||
| You should have received a copy of the GNU Affero General Public |
|
||||
| License and the CiviCRM Licensing Exception along |
|
||||
| with this program; if not, contact CiviCRM LLC |
|
||||
| at info[AT]civicrm[DOT]org. If you have questions about the |
|
||||
| GNU Affero General Public License or the licensing of CiviCRM, |
|
||||
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
|
||||
+--------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package CRM
|
||||
* @copyright CiviCRM LLC (c) 2004-2017
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* State machine for managing different states of the Import process.
|
||||
*
|
||||
*/
|
||||
class CRM_PCP_StateMachine_PCP extends CRM_Core_StateMachine {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param object $controller
|
||||
* @param \const|int $action
|
||||
*
|
||||
* @internal param \CRM_Contact_Import_Controller $object
|
||||
* @return \CRM_PCP_StateMachine_PCP CRM_Contact_Import_StateMachine
|
||||
*/
|
||||
public function __construct($controller, $action = CRM_Core_Action::NONE) {
|
||||
parent::__construct($controller, $action);
|
||||
|
||||
$session = CRM_Core_Session::singleton();
|
||||
$session->set('singleForm', FALSE);
|
||||
|
||||
$this->_pages = array(
|
||||
'CRM_PCP_Form_PCPAccount' => NULL,
|
||||
'CRM_PCP_Form_Campaign' => NULL,
|
||||
);
|
||||
|
||||
$this->addSequentialPages($this->_pages, $action);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue