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 * Administer Personal Campaign Pages - Search form
23 class CRM_PCP_Form_PCP
extends CRM_Core_Form
{
28 * Set variables up before form is built.
30 * @throws \CRM_Core_Exception
32 public function preProcess() {
33 if ($this->_action
& CRM_Core_Action
::DELETE
) {
34 //check permission for action.
35 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', $this->_action
)) {
36 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
39 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
40 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
41 $this->assign('title', $this->_title
);
45 if (!$this->_action
) {
46 $this->_action
= $_GET['action'] ??
NULL;
47 $this->_id
= $_GET['id'] ??
NULL;
50 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
54 if (!isset($this->_context
)) {
55 $this->_context
= CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
58 $this->assign('context', $this->_context
);
60 $session = CRM_Core_Session
::singleton();
61 $context = $session->popUserContext();
62 $userID = $session->get('userID');
64 //do not allow destructive actions without permissions
66 if (CRM_Core_Permission
::check('administer CiviCRM') ||
67 ($userID && (CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP',
74 if ($permission && $this->_id
) {
76 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_PCP_DAO_PCP', $this->_id
, 'title');
77 switch ($this->_action
) {
78 case CRM_Core_Action
::DELETE
:
80 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
81 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", [1 => $this->_title
]), ts('Page Deleted'), 'success');
84 case CRM_Core_Action
::DISABLE
:
86 CRM_PCP_BAO_PCP
::setDisable($this->_id
, '0');
87 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been disabled.", [1 => $this->_title
]), ts('Page Disabled'), 'success');
90 case CRM_Core_Action
::ENABLE
:
92 CRM_PCP_BAO_PCP
::setDisable($this->_id
, '1');
93 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been enabled.", [1 => $this->_title
]), ts('Page Enabled'), 'success');
98 CRM_Utils_System
::redirect($context);
104 * Set default values for the form. Note that in edit/view mode
105 * the default values are retrieved from the database
108 * array of default values
110 public function setDefaultValues() {
113 $pageType = CRM_Utils_Request
::retrieve('page_type', 'String', $this);
114 $defaults['page_type'] = !empty($pageType) ?
$pageType : '';
120 * Build the form object.
122 public function buildQuickForm() {
123 if ($this->_action
& CRM_Core_Action
::DELETE
) {
127 'name' => ts('Delete Campaign'),
132 'name' => ts('Cancel'),
138 $status = ['' => ts('- select -')] + CRM_Core_OptionGroup
::values("pcp_status");
140 '' => ts('- select -'),
141 'contribute' => ts('Contribution'),
142 'event' => ts('Event'),
144 $contribPages = ['' => ts('- select -')] + CRM_Contribute_PseudoConstant
::contributionPage();
145 $eventPages = ['' => ts('- select -')] + CRM_Event_PseudoConstant
::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
147 $this->addElement('select', 'status_id', ts('Status'), $status);
148 $this->addElement('select', 'page_type', ts('Source Type'), $types);
149 $this->addElement('select', 'page_id', ts('Contribution Page'), $contribPages);
150 $this->addElement('select', 'event_id', ts('Event Page'), $eventPages);
154 'name' => ts('Search'),
155 'spacing' => ' ',
159 parent
::buildQuickForm();
164 * Global validation rules for the form.
166 * @param array $fields
167 * Posted values of the form.
168 * @param array $files
169 * @param CRM_Core_Form $form
172 * list of errors to be posted back to the form
174 public static function formRule($fields, $files, $form) {
181 public function postProcess() {
182 if ($this->_action
& CRM_Core_Action
::DELETE
) {
183 CRM_PCP_BAO_PCP
::deleteById($this->_id
);
184 CRM_Core_Session
::setStatus(ts("The Campaign Page '%1' has been deleted.", [1 => $this->_title
]), ts('Page Deleted'), 'success');
187 $params = $this->controller
->exportValues($this->_name
);
188 $parent = $this->controller
->getParent();
190 if (!empty($params)) {
191 $fields = ['status_id', 'page_id'];
192 foreach ($fields as $field) {
193 if (isset($params[$field]) &&
194 !CRM_Utils_System
::isNull($params[$field])
196 $parent->set($field, $params[$field]);
199 $parent->set($field, NULL);