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 * Administer Personal Campaign Pages - Search form
21 class CRM_PCP_Form_PCP
extends CRM_Core_Form
{
26 * Set variables up before form is built.
28 * @throws \CRM_Core_Exception
30 public function preProcess() {
31 if ($this->_action
& CRM_Core_Action
::DELETE
) {
32 //check permission for action.
33 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
34 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
37 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
38 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
39 $this->assign('title', $this->_title
);
43 if (!$this->_action
) {
44 $this->_action
= $_GET['action'] ??
NULL;
45 $this->_id
= $_GET['id'] ??
NULL;
48 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
52 if (!isset($this->_context
)) {
53 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
56 $this->assign('context', $this->_context
);
58 $session = CRM_Core_Session
::singleton();
59 $context = $session->popUserContext();
60 $userID = $session->get('userID');
62 //do not allow destructive actions without permissions
64 if (CRM_Core_Permission
::check('administer CiviCRM') ||
65 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
72 if ($permission && $this->_id
) {
74 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
75 switch ($this->_action
) {
76 case CRM_Core_Action
::DELETE
:
78 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
79 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", [1 => $this->_title
]), ts('Page Deleted'), 'success');
82 case CRM_Core_Action
::DISABLE
:
84 CRM_PCP_BAO_PCP
::setDisable($this->_id
, '0');
85 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been disabled.", [1 => $this->_title
]), ts('Page Disabled'), 'success');
88 case CRM_Core_Action
::ENABLE
:
90 CRM_PCP_BAO_PCP
::setDisable($this->_id
, '1');
91 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been enabled.", [1 => $this->_title
]), ts('Page Enabled'), 'success');
96 CRM_Utils_System
::redirect($context);
102 * Set default values for the form. Note that in edit/view mode
103 * the default values are retrieved from the database
106 * array of default values
108 public function setDefaultValues() {
111 $pageType = CRM_Utils_Request
::retrieve('page_type', 'String', $this);
112 $defaults['page_type'] = !empty($pageType) ?
$pageType : '';
118 * Build the form object.
120 public function buildQuickForm() {
121 if ($this->_action
& CRM_Core_Action
::DELETE
) {
125 'name' => ts('Delete Campaign'),
130 'name' => ts('Cancel'),
136 $status = ['' => ts('- select -')] + CRM_Core_OptionGroup
::values("pcp_status");
138 '' => ts('- select -'),
139 'contribute' => ts('Contribution'),
140 'event' => ts('Event'),
142 $contribPages = ['' => ts('- select -')] + CRM_Contribute_PseudoConstant
::contributionPage();
143 $eventPages = ['' => ts('- select -')] + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
145 $this->addElement('select', 'status_id', ts('Status'), $status);
146 $this->addElement('select', 'page_type', ts('Source Type'), $types);
147 $this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages);
148 $this->addElement('select', 'event_id', ts('Event Page'), $eventPages);
152 'name' => ts('Search'),
153 'spacing' => ' ',
157 parent
::buildQuickForm();
162 * Global validation rules for the form.
164 * @param array $fields
165 * Posted values of the form.
166 * @param array $files
167 * @param CRM_Core_Form $form
170 * list of errors to be posted back to the form
172 public static function formRule($fields, $files, $form) {
179 public function postProcess() {
180 if ($this->_action
& CRM_Core_Action
::DELETE
) {
181 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
182 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", [1 => $this->_title
]), ts('Page Deleted'), 'success');
185 $params = $this->controller
->exportValues($this->_name
);
186 $parent = $this->controller
->getParent();
188 if (!empty($params)) {
189 $fields = ['status_id', 'page_id'];
190 foreach ($fields as $field) {
191 if (isset($params[$field]) &&
192 !CRM_Utils_System
::isNull($params[$field])
194 $parent->set($field, $params[$field]);
197 $parent->set($field, NULL);