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
21 * PCP Info Page - Summary about the PCP
23 class CRM_PCP_Page_PCPInfo
extends CRM_Core_Page
{
29 * This method is called after the page is created. It checks for the
30 * type of action and executes that action.
31 * Finally it calls the parent's run method.
35 public function run() {
36 $session = CRM_Core_Session
::singleton();
37 $config = CRM_Core_Config
::singleton();
38 $permissionCheck = FALSE;
40 if ($config->userFramework
!= 'Joomla') {
41 $permissionCheck = CRM_Core_Permission
::check('administer CiviCRM');
44 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
46 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
48 $prms = ['id' => $this->_id
];
50 CRM_Core_DAO
::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo);
51 $this->_component
= $pcpInfo['page_type'];
53 if (empty($pcpInfo)) {
54 $statusMessage = ts('The personal campaign page you requested is currently unavailable.');
55 CRM_Core_Error
::statusBounce($statusMessage,
56 $config->userFrameworkBaseURL
60 CRM_Utils_System
::setTitle($pcpInfo['title']);
61 $this->assign('pcp', $pcpInfo);
63 $pcpStatus = CRM_Core_OptionGroup
::values("pcp_status");
64 $approvedId = CRM_Core_PseudoConstant
::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
66 // check if PCP is created by anonymous user
67 $anonymousPCP = CRM_Utils_Request
::retrieve('ap', 'Boolean', $this);
69 $loginURL = $config->userSystem
->getLoginURL();
70 $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]);
71 CRM_Core_Session
::setStatus($anonMessage, ts('Success'), 'success');
74 $statusMessage = ts('The personal campaign page you requested is currently unavailable. However you can still support the campaign by making a contribution here.');
77 $pcpBlock = new CRM_PCP_DAO_PCPBlock();
78 $pcpBlock->entity_table
= CRM_PCP_BAO_PCP
::getPcpEntityTable($pcpInfo['page_type']);
79 $pcpBlock->entity_id
= $pcpInfo['page_id'];
80 $pcpBlock->find(TRUE);
82 // Redirect back to source page in case of error.
83 if ($pcpInfo['page_type'] == 'contribute') {
84 $urlBase = 'civicrm/contribute/transact';
86 elseif ($pcpInfo['page_type'] == 'event') {
87 $urlBase = 'civicrm/event/register';
90 if ($pcpInfo['status_id'] != $approvedId ||
!$pcpInfo['is_active']) {
91 if ($pcpInfo['contact_id'] != $session->get('userID') && !$permissionCheck) {
92 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
93 "reset=1&id=" . $pcpInfo['page_id'],
94 FALSE, NULL, FALSE, TRUE
99 $getStatus = CRM_PCP_BAO_PCP
::getStatus($this->_id
, $this->_component
);
101 // PCP not enabled for this contribution page. Forward everyone to source page
102 CRM_Core_Error
::statusBounce($statusMessage, CRM_Utils_System
::url($urlBase,
103 "reset=1&id=" . $pcpInfo['page_id'],
104 FALSE, NULL, FALSE, TRUE
111 if ($pcpBlock->target_entity_type
== 'contribute') {
112 $urlBase = 'civicrm/contribute/transact';
114 elseif ($pcpBlock->target_entity_type
== 'event') {
115 $urlBase = 'civicrm/event/register';
118 if ($pcpBlock->entity_table
== 'civicrm_event') {
119 $page_class = 'CRM_Event_DAO_Event';
120 $this->assign('pageName', CRM_Event_PseudoConstant
::event($pcpInfo['page_id']));
121 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
122 $pcpInfo['page_id'], $default, [
125 'registration_start_date',
126 'registration_end_date',
130 elseif ($pcpBlock->entity_table
== 'civicrm_contribution_page') {
131 $page_class = 'CRM_Contribute_DAO_ContributionPage';
132 $this->assign('pageName', CRM_Contribute_PseudoConstant
::contributionPage($pcpInfo['page_id'], TRUE));
133 CRM_Core_DAO
::commonRetrieveAll($page_class, 'id',
134 $pcpInfo['page_id'], $default, ['start_date', 'end_date']
138 $pageInfo = $default[$pcpInfo['page_id']];
140 if ($pcpInfo['contact_id'] == $session->get('userID')) {
142 $owner['status'] = CRM_Utils_Array
::value($pcpInfo['status_id'], $pcpStatus);
144 $this->assign('owner', $owner);
146 $link = CRM_PCP_BAO_PCP
::pcpLinks();
149 CRM_Core_Action
::UPDATE
=> ts('Change the content and appearance of your page'),
150 CRM_Core_Action
::DETACH
=> ts('Send emails inviting your friends to support your campaign!'),
151 CRM_Core_Action
::VIEW
=> ts('Copy this link to share directly with your network!'),
152 CRM_Core_Action
::BROWSE
=> ts('Update your personal contact information'),
153 CRM_Core_Action
::DISABLE
=> ts('De-activate the page (you can re-activate it later)'),
154 CRM_Core_Action
::ENABLE
=> ts('Activate the page (you can de-activate it later)'),
155 CRM_Core_Action
::DELETE
=> ts('Remove the page (this cannot be undone!)'),
160 'block' => $pcpBlock->id
,
161 'pageComponent' => $this->_component
,
164 if (!$pcpBlock->is_tellfriend_enabled || CRM_Utils_Array
::value('status_id', $pcpInfo) != $approvedId) {
165 unset($link['all'][CRM_Core_Action
::DETACH
]);
168 switch ($pcpInfo['is_active']) {
170 unset($link['all'][CRM_Core_Action
::ENABLE
]);
174 unset($link['all'][CRM_Core_Action
::DISABLE
]);
178 $this->assign('links', $link['all']);
179 $this->assign('hints', $hints);
180 $this->assign('replace', $replace);
183 $honor = CRM_PCP_BAO_PCP
::honorRoll($this->_id
);
185 $entityFile = CRM_Core_BAO_File
::getEntityFile('civicrm_pcp', $this->_id
);
186 if (!empty($entityFile)) {
187 $fileInfo = reset($entityFile);
188 $fileId = $fileInfo['fileID'];
189 $fileHash = CRM_Core_BAO_File
::generateFileHash($this->_id
, $fileId);
190 $image = '<img src="' . CRM_Utils_System
::url('civicrm/file',
191 "reset=1&id=$fileId&eid={$this->_id}&fcs={$fileHash}"
193 $this->assign('image', $image);
196 $totalAmount = CRM_PCP_BAO_PCP
::thermoMeter($this->_id
);
197 $achieved = round($totalAmount / $pcpInfo['goal_amount'] * 100, 2);
199 if ($pcpBlock->is_active
== 1) {
200 $linkTextUrl = CRM_Utils_System
::url('civicrm/contribute/campaign',
201 "action=add&reset=1&pageId={$pcpInfo['page_id']}&component={$pcpInfo['page_type']}",
205 $this->assign('linkTextUrl', $linkTextUrl);
206 $this->assign('linkText', $pcpBlock->link_text
);
209 $this->assign('honor', $honor);
210 $this->assign('total', $totalAmount ?
$totalAmount : '0.0');
211 $this->assign('achieved', $achieved <= 100 ?
$achieved : 100);
213 if ($achieved <= 100) {
214 $this->assign('remaining', 100 - $achieved);
216 // make sure that we are between contribution page start and end dates OR registration start date and end dates if they are set
217 if ($pcpBlock->entity_table
== 'civicrm_event') {
218 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $pageInfo));
219 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $pageInfo));
222 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('start_date', $pageInfo));
223 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $pageInfo));
228 if ($startDate && $startDate >= $now) {
231 if ($endDate && $endDate < $now) {
235 $this->assign('validDate', $validDate);
237 // form parent page url
238 if ($action == CRM_Core_Action
::PREVIEW
) {
239 $parentUrl = CRM_Utils_System
::url($urlBase,
240 "id={$pcpInfo['page_id']}&reset=1&action=preview",
246 $parentUrl = CRM_Utils_System
::url($urlBase,
247 "id={$pcpInfo['page_id']}&reset=1",
253 $this->assign('parentURL', $parentUrl);
257 $contributionText = ts('Contribute Now');
258 if (!empty($pcpInfo['donate_link_text'])) {
259 $contributionText = $pcpInfo['donate_link_text'];
262 $this->assign('contributionText', $contributionText);
264 // we always generate urls for the front end in joomla
265 if ($action == CRM_Core_Action
::PREVIEW
) {
266 $url = CRM_Utils_System
::url($urlBase,
267 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1&action=preview",
273 $url = CRM_Utils_System
::url($urlBase,
274 "id=" . $pcpBlock->target_entity_id
. "&pcpId={$this->_id}&reset=1",
279 $this->assign('contributeURL', $url);
282 // we do not want to display recently viewed items, so turn off
283 $this->assign('displayRecent', FALSE);
285 $single = $permission = FALSE;
287 case CRM_Core_Action
::BROWSE
:
288 $subForm = 'PCPAccount';
289 $form = "CRM_PCP_Form_$subForm";
293 case CRM_Core_Action
::UPDATE
:
294 $subForm = 'Campaign';
295 $form = "CRM_PCP_Form_$subForm";
300 $userID = $session->get('userID');
301 //make sure the user has "administer CiviCRM" permission
302 //OR has created the PCP
303 if (CRM_Core_Permission
::check('administer CiviCRM') ||
304 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'contact_id') == $userID))
308 if ($single && $permission) {
309 $controller = new CRM_Core_Controller_Simple($form, $subForm, $action);
310 $controller->set('id', $this->_id
);
311 $controller->set('single', TRUE);
312 $controller->process();
313 return $controller->run();
315 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&id=' . $this->_id
));
322 public function getTemplateFileName() {
324 $templateFile = "CRM/PCP/Page/{$this->_id}/PCPInfo.tpl";
325 $template = &CRM_Core_Page
::getTemplate();
326 if ($template->template_exists($templateFile)) {
327 return $templateFile;
330 return parent
::getTemplateFileName();