Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
07f8d162 | 35 | * Form to process actions on Premiums. |
6a488035 TO |
36 | */ |
37 | class CRM_Contribute_Form_ContributionPage_Premium extends CRM_Contribute_Form_ContributionPage { | |
38 | ||
39 | /** | |
95cdcc0f | 40 | * Set default values for the form. |
6a488035 | 41 | */ |
00be9182 | 42 | public function setDefaultValues() { |
6a488035 TO |
43 | $defaults = array(); |
44 | if (isset($this->_id)) { | |
353ffa53 | 45 | $dao = new CRM_Contribute_DAO_Premium(); |
6a488035 | 46 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 47 | $dao->entity_id = $this->_id; |
6a488035 TO |
48 | $dao->find(TRUE); |
49 | CRM_Core_DAO::storeValues($dao, $defaults); | |
50 | } | |
51 | return $defaults; | |
52 | } | |
53 | ||
54 | /** | |
fe482240 | 55 | * Build the form object. |
6a488035 TO |
56 | */ |
57 | public function buildQuickForm() { | |
58 | $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Premium'); | |
2560550d | 59 | $this->addElement('checkbox', 'premiums_active', ts('Premiums Section Enabled?'), NULL); |
6a488035 TO |
60 | |
61 | $this->addElement('text', 'premiums_intro_title', ts('Title'), $attributes['premiums_intro_title']); | |
62 | ||
63 | $this->add('textarea', 'premiums_intro_text', ts('Introductory Message'), 'rows=5, cols=50'); | |
64 | ||
65 | $this->add('text', 'premiums_contact_email', ts('Contact Email') . ' ', $attributes['premiums_contact_email']); | |
66 | ||
f289559e | 67 | $this->addRule('premiums_contact_email', ts('Please enter a valid email address.') . ' ', 'email'); |
6a488035 TO |
68 | |
69 | $this->add('text', 'premiums_contact_phone', ts('Contact Phone'), $attributes['premiums_contact_phone']); | |
70 | ||
71 | $this->addRule('premiums_contact_phone', ts('Please enter a valid phone number.'), 'phone'); | |
72 | ||
73 | $this->addElement('checkbox', 'premiums_display_min_contribution', ts('Display Minimum Contribution Amount?')); | |
74 | ||
75 | // CRM-10999 Control label and position for No Thank-you radio button | |
2560550d | 76 | $this->add('text', 'premiums_nothankyou_label', ts('No Thank-you Label'), $attributes['premiums_nothankyou_label']); |
6a488035 | 77 | $positions = array(1 => ts('Before Premiums'), 2 => ts('After Premiums')); |
874c9be7 | 78 | $this->add('select', 'premiums_nothankyou_position', ts('No Thank-you Option'), $positions); |
6a488035 TO |
79 | $showForm = TRUE; |
80 | ||
81 | if ($this->_single) { | |
82 | if ($this->_id) { | |
83 | $daoPremium = new CRM_Contribute_DAO_Premium(); | |
84 | $daoPremium->entity_id = $this->_id; | |
85 | $daoPremium->entity_table = 'civicrm_contribution_page'; | |
86 | $daoPremium->premiums_active = 1; | |
87 | if ($daoPremium->find(TRUE)) { | |
88 | $showForm = FALSE; | |
89 | } | |
90 | } | |
91 | } | |
92 | $this->assign('showForm', $showForm); | |
93 | ||
94 | parent::buildQuickForm(); | |
2560550d | 95 | $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Premium', 'formRule'), $this); |
6a488035 TO |
96 | |
97 | $premiumPage = new CRM_Contribute_Page_Premium(); | |
98 | $premiumPage->browse(); | |
99 | } | |
100 | ||
2560550d | 101 | /** |
fe482240 | 102 | * Validation. |
2560550d | 103 | * |
014c4014 TO |
104 | * @param array $params |
105 | * (ref.) an assoc array of name/value pairs. | |
2560550d | 106 | * |
72b3a70c CW |
107 | * @return bool|array |
108 | * mixed true or array of errors | |
2560550d AW |
109 | */ |
110 | public static function formRule($params) { | |
111 | $errors = array(); | |
a7488080 CW |
112 | if (!empty($params['premiums_active'])) { |
113 | if (empty($params['premiums_nothankyou_label'])) { | |
2560550d AW |
114 | $errors['premiums_nothankyou_label'] = ts('No Thank-you Label is a required field.'); |
115 | } | |
116 | } | |
117 | return empty($errors) ? TRUE : $errors; | |
118 | } | |
119 | ||
6a488035 | 120 | /** |
fe482240 | 121 | * Process the form. |
6a488035 TO |
122 | */ |
123 | public function postProcess() { | |
124 | // get the submitted form values. | |
125 | $params = $this->controller->exportValues($this->_name); | |
126 | ||
127 | // we do this in case the user has hit the forward/back button | |
128 | ||
353ffa53 | 129 | $dao = new CRM_Contribute_DAO_Premium(); |
6a488035 | 130 | $dao->entity_table = 'civicrm_contribution_page'; |
353ffa53 | 131 | $dao->entity_id = $this->_id; |
6a488035 TO |
132 | $dao->find(TRUE); |
133 | $premiumID = $dao->id; | |
134 | if ($premiumID) { | |
135 | $params['id'] = $premiumID; | |
136 | } | |
137 | ||
138 | $params['premiums_active'] = CRM_Utils_Array::value('premiums_active', $params, FALSE); | |
139 | $params['premiums_display_min_contribution'] = CRM_Utils_Array::value('premiums_display_min_contribution', $params, FALSE); | |
140 | $params['entity_table'] = 'civicrm_contribution_page'; | |
141 | $params['entity_id'] = $this->_id; | |
142 | ||
143 | $dao = new CRM_Contribute_DAO_Premium(); | |
144 | $dao->copyValues($params); | |
145 | $dao->save(); | |
146 | parent::endPostProcess(); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Return a descriptive name for the page, used in wizard header | |
151 | * | |
152 | * @return string | |
6a488035 TO |
153 | */ |
154 | public function getTitle() { | |
155 | return ts('Premiums'); | |
156 | } | |
96025800 | 157 | |
6a488035 | 158 | } |