3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * PCP Info Page - Summary about the PCP
21 class CRM_PCP_Page_PCPInfo
extends CRM_Core_Page
{
27 * This method is called after the page is created. It checks for the
28 * type of action and executes that action.
29 * Finally it calls the parent's run method.
33 public function run() {
34 $session = CRM_Core_Session
::singleton();
35 $config = CRM_Core_Config
::singleton();
36 $permissionCheck = FALSE;
38 if ($config->userFramework
!= 'Joomla') {
39 $permissionCheck = CRM_Core_Permission
::check('administer CiviCRM');
42 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
44 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
46 $prms = ['id' => $this->_id
];
48 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
49 $this->_component
= $pcpInfo['page_type'];
51 if (empty($pcpInfo)) {
52 $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
53 CRM_Core_Error
::statusBounce($statusMessage,
54 $config->userFrameworkBaseURL
58 CRM_Utils_System
::setTitle($pcpInfo['title']);
59 $this->assign('pcp', $pcpInfo);
61 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
62 $approvedId = CRM_Core_PseudoConstant
::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
64 // check if PCP is created by anonymous user
65 $anonymousPCP = CRM_Utils_Request
::retrieve('ap', 'Boolean', $this);
67 $loginURL = $config->userSystem
->getLoginURL();
68 $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.', [1 => $loginURL]);
69 CRM_Core_Session
::setStatus($anonMessage, ts('Success'), 'success');
72 $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
75 $pcpBlock = new CRM_PCP_DAO_PCPBlock();
76 $pcpBlock->entity_table
= CRM_PCP_BAO_PCP
::getPcpEntityTable($pcpInfo['page_type']);
77 $pcpBlock->entity_id
= $pcpInfo['page_id'];
78 $pcpBlock->find(TRUE);
80 // Redirect back to source page in case of error.
81 if ($pcpInfo['page_type'] == 'contribute') {
82 $urlBase = 'civicrm/contribute/transact';
84 elseif ($pcpInfo['page_type'] == 'event') {
85 $urlBase = 'civicrm/event/register';
88 if ($pcpInfo['status_id'] != $approvedId ||
!$pcpInfo['is_active']) {
89 if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) {
90 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
91 "reset=1&id=" . $pcpInfo['page_id'],
92 FALSE, NULL, FALSE, TRUE
97 $getStatus = CRM_PCP_BAO_PCP
::getStatus($this->_id
, $this->_component
);
99 // PCP not enabled for this contribution page. Forward everyone to source page
100 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
101 "reset=1&id=" . $pcpInfo['page_id'],
102 FALSE, NULL, FALSE, TRUE
109 if ($pcpBlock->target_entity_type
== 'contribute') {
110 $urlBase = 'civicrm/contribute/transact';
112 elseif ($pcpBlock->target_entity_type
== 'event') {
113 $urlBase = 'civicrm/event/register';
116 if ($pcpBlock->entity_table
== 'civicrm_event') {
117 $page_class = 'CRM_Event_DAO_Event';
118 $this->assign('pageName', CRM_Event_PseudoConstant
::event($pcpInfo['page_id']));
119 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
120 $pcpInfo['page_id'], $default, [
123 'registration_start_date',
124 'registration_end_date',
128 elseif ($pcpBlock->entity_table
== 'civicrm_contribution_page') {
129 $page_class = 'CRM_Contribute_DAO_ContributionPage';
130 $this->assign('pageName', CRM_Contribute_PseudoConstant
::contributionPage($pcpInfo['page_id'], TRUE));
131 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
132 $pcpInfo['page_id'], $default, ['start_date', 'end_date']
136 $pageInfo = $default[$pcpInfo['page_id']];
138 if ($pcpInfo['contact_id'] == $session->get('userID')) {
140 $owner['status'] = $pcpStatus[$pcpInfo['status_id']] ??
NULL;
142 $this->assign('owner', $owner);
144 $link = CRM_PCP_BAO_PCP
::pcpLinks($pcpInfo['id']);
147 CRM_Core_Action
::UPDATE
=> ts('Change the content and appearance of your page'),
148 CRM_Core_Action
::DETACH
=> ts('Send emails inviting your friends to support your campaign!'),
149 CRM_Core_Action
::VIEW
=> ts('Copy this link to share directly with your network!'),
150 CRM_Core_Action
::BROWSE
=> ts('Update your personal contact information'),
151 CRM_Core_Action
::DISABLE
=> ts('De-activate the page (you can re-activate it later)'),
152 CRM_Core_Action
::ENABLE
=> ts('Activate the page (you can de-activate it later)'),
153 CRM_Core_Action
::DELETE
=> ts('Remove the page (this cannot be undone!)'),
158 'block' => $pcpBlock->id
,
159 'pageComponent' => $this->_component
,
162 if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array
::value('status_id', $pcpInfo) != $approvedId) {
163 unset($link['all'][CRM_Core_Action
::DETACH
]);
166 switch ($pcpInfo['is_active']) {
168 unset($link['all'][CRM_Core_Action
::ENABLE
]);
172 unset($link['all'][CRM_Core_Action
::DISABLE
]);
176 $this->assign('links', $link['all']);
177 $this->assign('hints', $hints);
178 $this->assign('replace', $replace);
181 $honor = CRM_PCP_BAO_PCP
::honorRoll($this->_id
);
183 $entityFile = CRM_Core_BAO_File
::getEntityFile('civicrm_pcp', $this->_id
);
184 if (!empty($entityFile)) {
185 $fileInfo = reset($entityFile);
186 $fileId = $fileInfo['fileID'];
187 $fileHash = CRM_Core_BAO_File
::generateFileHash($this->_id
, $fileId);
188 $image = '<img src="' . CRM_Utils_System
::url('civicrm/file',
189 "reset=1&id=$fileId&eid={$this->_id}&fcs={$fileHash}"
191 $this->assign('image', $image);
194 $totalAmount = CRM_PCP_BAO_PCP
::thermoMeter($this->_id
);
195 $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
197 if ($pcpBlock->is_active
== 1) {
198 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
199 "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}",
203 $this->assign('linkTextUrl', $linkTextUrl);
204 $this->assign('linkText', $pcpBlock->link_text
);
207 $this->assign('honor', $honor);
208 $this->assign('total', $totalAmount ?
$totalAmount : '0.0');
209 $this->assign('achieved', $achieved <= 100 ?
$achieved : 100);
211 if ($achieved <= 100) {
212 $this->assign('remaining', 100 - $achieved);
214 // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set
215 if ($pcpBlock->entity_table
== 'civicrm_event') {
216 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $pageInfo));
217 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $pageInfo));
220 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $pageInfo));
221 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $pageInfo));
226 if ($startDate && $startDate >= $now) {
229 if ($endDate && $endDate < $now) {
233 $this->assign('validDate', $validDate);
235 // form parent page url
236 if ($action == CRM_Core_Action
::PREVIEW
) {
237 $parentUrl = CRM_Utils_System
::url($urlBase,
238 "id={$pcpInfo['page_id']}&reset=1&action=preview",
244 $parentUrl = CRM_Utils_System
::url($urlBase,
245 "id={$pcpInfo['page_id']}&reset=1",
251 $this->assign('parentURL', $parentUrl);
255 $contributionText = ts('Contribute Now');
256 if (!empty($pcpInfo['donate_link_text'])) {
257 $contributionText = $pcpInfo['donate_link_text'];
260 $this->assign('contributionText', $contributionText);
262 // we always generate urls for the front end in joomla
263 if ($action == CRM_Core_Action
::PREVIEW
) {
264 $url = CRM_Utils_System
::url($urlBase,
265 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1&action=preview",
271 $url = CRM_Utils_System
::url($urlBase,
272 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1",
277 $this->assign('contributeURL', $url);
280 // we do not want to display recently viewed items, so turn off
281 $this->assign('displayRecent', FALSE);
283 $single = $permission = FALSE;
285 case CRM_Core_Action
::BROWSE
:
286 $subForm = 'PCPAccount';
287 $form = "CRM_PCP_Form_$subForm";
291 case CRM_Core_Action
::UPDATE
:
292 $subForm = 'Campaign';
293 $form = "CRM_PCP_Form_$subForm";
298 $userID = $session->get('userID');
299 //make sure the user has "administer CiviCRM" permission
300 //OR has created the PCP
301 if (CRM_Core_Permission
::check('administer CiviCRM') ||
302 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'contact_id') == $userID))
306 if ($single && $permission) {
307 $controller = new CRM_Core_Controller_Simple($form, $subForm, $action);
308 $controller->set('id', $this->_id
);
309 $controller->set('single', TRUE);
310 $controller->process();
311 return $controller->run();
313 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&id=' . $this->_id
));
320 public function getTemplateFileName() {
322 $templateFile = "CRM/PCP/Page/{$this->_id}/PCPInfo.tpl";
323 $template = &CRM_Core_Page
::getTemplate();
324 if ($template->template_exists($templateFile)) {
325 return $templateFile;
328 return parent
::getTemplateFileName();