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 * Form to process actions on Premiums.
21 class CRM_Contribute_Form_ContributionPage_Premium
extends CRM_Contribute_Form_ContributionPage
{
24 * Set variables up before form is built.
26 public function preProcess() {
28 $this->setSelectedChild('premium');
32 * Set default values for the form.
34 public function setDefaultValues() {
36 if (isset($this->_id
)) {
37 $dao = new CRM_Contribute_DAO_Premium();
38 $dao->entity_table
= 'civicrm_contribution_page';
39 $dao->entity_id
= $this->_id
;
41 CRM_Core_DAO
::storeValues($dao, $defaults);
47 * Build the form object.
49 public function buildQuickForm() {
50 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Premium');
51 $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL);
53 $this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']);
55 $this->add('textarea', 'premiums_intro_text', ts('Introductory Message'), 'rows=5, cols=50');
57 $this->add('text', 'premiums_contact_email', ts('Contact Email') . ' ', $attributes['premiums_contact_email']);
59 $this->addRule('premiums_contact_email', ts('Please enter a valid email address.') . ' ', 'email');
61 $this->add('text', 'premiums_contact_phone', ts('Contact Phone'), $attributes['premiums_contact_phone']);
63 $this->addRule('premiums_contact_phone', ts('Please enter a valid phone number.'), 'phone');
65 $this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?'));
67 // CRM-10999 Control label and position for No Thank-you radio button
68 $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label']);
69 $positions = [1 => ts('Before Premiums'), 2 => ts('After Premiums')];
70 $this->add('select', 'premiums_nothankyou_position', ts('No Thank-you Option'), $positions);
75 $daoPremium = new CRM_Contribute_DAO_Premium();
76 $daoPremium->entity_id
= $this->_id
;
77 $daoPremium->entity_table
= 'civicrm_contribution_page';
78 $daoPremium->premiums_active
= 1;
79 if ($daoPremium->find(TRUE)) {
84 $this->assign('showForm', $showForm);
86 parent
::buildQuickForm();
87 $this->addFormRule(['CRM_Contribute_Form_ContributionPage_Premium', 'formRule'], $this);
89 $premiumPage = new CRM_Contribute_Page_Premium();
90 $premiumPage->browse();
96 * @param array $params
97 * (ref.) an assoc array of name/value pairs.
100 * mixed true or array of errors
102 public static function formRule($params) {
104 if (!empty($params['premiums_active'])) {
105 if (empty($params['premiums_nothankyou_label'])) {
106 $errors['premiums_nothankyou_label'] = ts('No Thank-you Label is a required field.');
109 return empty($errors) ?
TRUE : $errors;
115 public function postProcess() {
116 // get the submitted form values.
117 $params = $this->controller
->exportValues($this->_name
);
119 // we do this in case the user has hit the forward/back button
121 $dao = new CRM_Contribute_DAO_Premium();
122 $dao->entity_table
= 'civicrm_contribution_page';
123 $dao->entity_id
= $this->_id
;
125 $premiumID = $dao->id
;
127 $params['id'] = $premiumID;
130 $params['premiums_active'] = CRM_Utils_Array
::value('premiums_active', $params, FALSE);
131 $params['premiums_display_min_contribution'] = CRM_Utils_Array
::value('premiums_display_min_contribution', $params, FALSE);
132 $params['entity_table'] = 'civicrm_contribution_page';
133 $params['entity_id'] = $this->_id
;
135 $dao = new CRM_Contribute_DAO_Premium();
136 $dao->copyValues($params);
138 parent
::endPostProcess();
142 * Return a descriptive name for the page, used in wizard header
146 public function getTitle() {
147 return ts('Premiums');