Commit | Line | Data |
---|---|---|
50998125 KJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
50998125 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
50998125 KJ |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
50998125 KJ |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for name badge layout | |
38 | * | |
39 | */ | |
40 | class CRM_Badge_Form_Layout extends CRM_Admin_Form { | |
41 | ||
ea343109 | 42 | const FIELD_ROWCOUNT = 6; |
50998125 KJ |
43 | /** |
44 | * Function to build the form | |
45 | * | |
355ba699 | 46 | * @return void |
50998125 KJ |
47 | * @access public |
48 | */ | |
49 | public function buildQuickForm() { | |
50998125 | 50 | if ($this->_action & CRM_Core_Action::DELETE) { |
a1f552a9 | 51 | return parent::buildQuickForm(); |
50998125 KJ |
52 | } |
53 | ||
d87c3006 KJ |
54 | $config = CRM_Core_Config::singleton(); |
55 | $resources = CRM_Core_Resources::singleton(); | |
56 | $resources->addSetting( | |
57 | array( | |
58 | 'kcfinderPath' => $config->userFrameworkResourceURL .'packages' .DIRECTORY_SEPARATOR | |
59 | ) | |
60 | ); | |
61 | $resources->addScriptFile('civicrm', 'templates/CRM/Badge/Form/Layout.js'); | |
62 | ||
50998125 | 63 | $this->applyFilter('__ALL__', 'trim'); |
636f1cbe KJ |
64 | |
65 | $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true); | |
66 | ||
d34dbf05 | 67 | $labelStyle = CRM_Core_BAO_LabelFormat::getList(TRUE, 'name_badge'); |
15cb4bd7 | 68 | $this->add('select', 'label_format_name', ts('Label Format'), array('' => ts('- select -')) + $labelStyle, TRUE); |
636f1cbe KJ |
69 | |
70 | $this->add('text', 'description', ts('Description'), | |
2df183e7 | 71 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); |
636f1cbe KJ |
72 | |
73 | // get the tokens | |
012ee9a8 | 74 | $contactTokens = CRM_Core_SelectValues::contactTokens(); |
f5ea9580 | 75 | $eventTokens = array( |
76 | '{event.event_id}' => ts('Event ID'), | |
77 | '{event.title}' => ts('Event Title'), | |
78 | '{event.start_date}' => ts('Event Start Date'), | |
79 | '{event.end_date}' => ts('Event End Date') | |
80 | ); | |
ea921622 KJ |
81 | $participantTokens = CRM_Core_SelectValues::participantTokens(); |
82 | ||
83 | $tokens = array_merge($contactTokens, $eventTokens, $participantTokens); | |
636f1cbe KJ |
84 | asort($tokens); |
85 | ||
50f52554 | 86 | $tokens = array_merge(array('spacer' => ts('- spacer -')) + $tokens); |
87 | ||
636f1cbe | 88 | $fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes(); |
0bc1ba89 | 89 | $fontStyles = CRM_Core_BAO_LabelFormat::getFontStyles(); |
636f1cbe KJ |
90 | $fontNames = CRM_Core_BAO_LabelFormat::getFontNames('name_badge'); |
91 | $textAlignment = CRM_Core_BAO_LabelFormat::getTextAlignments(); | |
609df1ed M |
92 | $imageAlignment = $textAlignment; |
93 | unset($imageAlignment['C']); | |
636f1cbe | 94 | |
ea343109 | 95 | $rowCount = self::FIELD_ROWCOUNT; |
636f1cbe | 96 | for ( $i =1; $i <= $rowCount; $i++ ) { |
50f52554 | 97 | $this->add('select', "token[$i]", ts('Token'), array('' => ts('- skip -')) + $tokens); |
636f1cbe KJ |
98 | $this->add('select', "font_name[$i]", ts('Font Name'), $fontNames); |
99 | $this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes); | |
0bc1ba89 | 100 | $this->add('select', "font_style[$i]", ts('Font Style'), $fontStyles); |
636f1cbe KJ |
101 | $this->add('select', "text_alignment[$i]", ts('Alignment'), $textAlignment); |
102 | } | |
103 | $rowCount++; | |
104 | $this->assign('rowCount', $rowCount); | |
105 | ||
f38395f7 | 106 | $barcodeTypes = CRM_Core_SelectValues::getBarcodeTypes(); |
636f1cbe | 107 | $this->add('checkbox', 'add_barcode', ts('Barcode?')); |
f38395f7 | 108 | $this->add('select', "barcode_type", ts('Type'), $barcodeTypes); |
636f1cbe KJ |
109 | $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment); |
110 | ||
f38395f7 | 111 | |
8367d0c5 | 112 | $attributes = array('readonly'=> true); |
b82c9857 | 113 | $this->add('text', 'image_1', ts('Image (top left)'), |
8367d0c5 | 114 | $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); |
efdb8203 | 115 | $this->add('text', 'width_image_1', ts('Width (mm)'), array('size' => 6)); |
116 | $this->add('text', 'height_image_1', ts('Height (mm)'), array('size' => 6)); | |
07d113b7 | 117 | |
b82c9857 | 118 | $this->add('text', 'image_2', ts('Image (top right)'), |
8367d0c5 | 119 | $attributes + CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title')); |
efdb8203 | 120 | $this->add('text', 'width_image_2', ts('Width (mm)'), array('size' => 6)); |
121 | $this->add('text', 'height_image_2', ts('Height (mm)'), array('size' => 6)); | |
d87c3006 | 122 | |
cf723d2e | 123 | |
609df1ed | 124 | $this->add('checkbox', 'show_participant_image', ts('Use Participant Image?')); |
cf723d2e M |
125 | $this->add('text', 'width_participant_image', ts('Width (mm)'), array('size' => 6)); |
126 | $this->add('text', 'height_participant_image', ts('Height (mm)'), array('size' => 6)); | |
609df1ed | 127 | $this->add('select', "alignment_participant_image", ts('Image Alignment'), $imageAlignment); |
cf723d2e | 128 | |
50998125 | 129 | $this->add('checkbox', 'is_default', ts('Default?')); |
636f1cbe KJ |
130 | $this->add('checkbox', 'is_active', ts('Enabled?')); |
131 | $this->add('checkbox', 'is_reserved', ts('Reserved?')); | |
890a1fbb | 132 | |
50f52554 | 133 | $this->addRule('width_image_1', ts('Enter valid width'), 'positiveInteger'); |
134 | $this->addRule('width_image_2', ts('Enter valid width'), 'positiveInteger'); | |
135 | $this->addRule('height_image_1', ts('Enter valid height'), 'positiveInteger'); | |
136 | $this->addRule('height_image_2', ts('Enter valid height'), 'positiveInteger'); | |
cf723d2e M |
137 | $this->addRule('height_participant_image', ts('Enter valid height'), 'positiveInteger'); |
138 | $this->addRule('width_participant_image', ts('Enter valid height'), 'positiveInteger'); | |
6d4a64c8 KJ |
139 | |
140 | $this->addButtons(array( | |
141 | array( | |
142 | 'type' => 'next', | |
143 | 'name' => ts('Save'), | |
144 | 'isDefault' => TRUE, | |
145 | ), | |
146 | array( | |
147 | 'type' => 'refresh', | |
148 | 'name' => ts('Save and Preview'), | |
149 | ), | |
150 | array( | |
151 | 'type' => 'cancel', | |
152 | 'name' => ts('Cancel'), | |
153 | ), | |
154 | ) | |
155 | ); | |
890a1fbb KJ |
156 | } |
157 | ||
636f1cbe KJ |
158 | /** |
159 | * This function sets the default values for the form. MobileProvider that in edit/view mode | |
160 | * the default values are retrieved from the database | |
161 | * | |
162 | * @access public | |
163 | * | |
355ba699 | 164 | * @return void |
636f1cbe KJ |
165 | */ |
166 | function setDefaultValues() { | |
ea921622 | 167 | if (isset($this->_id)) { |
2df183e7 KJ |
168 | $defaults = array_merge($this->_values, |
169 | CRM_Badge_BAO_Layout::getDecodedData($this->_values['data'])); | |
170 | } | |
3c7ab739 | 171 | else { |
ea343109 | 172 | for ($i = 1; $i <= self::FIELD_ROWCOUNT; $i++) { |
3c7ab739 KJ |
173 | $defaults['text_alignment'][$i] = "C"; |
174 | } | |
175 | } | |
d87c3006 | 176 | |
636f1cbe KJ |
177 | if ($this->_action == CRM_Core_Action::DELETE && isset($defaults['title'])) { |
178 | $this->assign('delName', $defaults['title']); | |
179 | } | |
180 | ||
181 | // its ok if there is no element called is_active | |
182 | $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1; | |
183 | ||
184 | return $defaults; | |
50998125 KJ |
185 | } |
186 | ||
187 | /** | |
188 | * Function to process the form | |
189 | * | |
190 | * @access public | |
191 | * | |
355ba699 | 192 | * @return void |
50998125 KJ |
193 | */ |
194 | public function postProcess() { | |
636f1cbe KJ |
195 | if ($this->_action & CRM_Core_Action::DELETE) { |
196 | CRM_Badge_BAO_Layout::del($this->_id); | |
197 | CRM_Core_Session::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success'); | |
198 | return; | |
199 | } | |
200 | ||
6d4a64c8 | 201 | $params = $data = $this->exportValues(); |
636f1cbe KJ |
202 | |
203 | unset($data['qfKey']); | |
204 | $params['data'] = json_encode($data); | |
205 | ||
206 | if ($this->_id) { | |
207 | $params['id'] = $this->_id; | |
208 | } | |
209 | ||
210 | // store the submitted values in an array | |
6d4a64c8 KJ |
211 | $badgeInfo = CRM_Badge_BAO_Layout::create($params); |
212 | ||
213 | if (isset($params['_qf_Layout_refresh'])) { | |
1a502055 | 214 | $this->set('id', $badgeInfo->id); |
6d4a64c8 KJ |
215 | $params['badge_id'] = $badgeInfo->id; |
216 | self::buildPreview($params); | |
217 | } | |
218 | else { | |
219 | CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.", | |
220 | array(1 => $params['title']) | |
221 | ), ts('Saved'), 'success'); | |
222 | } | |
223 | } | |
224 | ||
225 | public function buildPreview(&$params) { | |
226 | // get a max participant id | |
227 | $participantID = CRM_Core_DAO::singleValueQuery('select max(id) from civicrm_participant'); | |
228 | ||
1a502055 KJ |
229 | if (!$participantID) { |
230 | CRM_Core_Session::setStatus(ts('Preview requires at least one event and one participant record. | |
231 | If you are just getting started, you can add a test participant record.'), ts('Preview Requirements'), 'alert'); | |
232 | return; | |
233 | } | |
234 | ||
6d4a64c8 KJ |
235 | $this->_single = TRUE; |
236 | $this->_participantIds = array($participantID); | |
237 | $this->_componentClause = " civicrm_participant.id = $participantID "; | |
636f1cbe | 238 | |
6d4a64c8 | 239 | CRM_Badge_BAO_Badge::buildBadges($params, $this); |
50998125 KJ |
240 | } |
241 | } |