Commit | Line | Data |
---|---|---|
50998125 KJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | ||
42 | /** | |
43 | * Function to build the form | |
44 | * | |
45 | * @return None | |
46 | * @access public | |
47 | */ | |
48 | public function buildQuickForm() { | |
49 | ||
50 | parent::buildQuickForm(); | |
51 | ||
52 | if ($this->_action & CRM_Core_Action::DELETE) { | |
53 | return; | |
54 | } | |
55 | ||
56 | $this->applyFilter('__ALL__', 'trim'); | |
636f1cbe KJ |
57 | |
58 | $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'title'), true); | |
59 | ||
60 | $labelStyle = CRM_Core_PseudoConstant::get('CRM_Core_DAO_PrintLabel', 'label_format_id'); | |
61 | $this->add('select', 'label_format_id', ts('Label Style'), array('' => ts('- select -')) + $labelStyle, TRUE); | |
62 | ||
63 | $this->add('text', 'description', ts('Description'), | |
64 | CRM_Core_DAO::getAttribute('CRM_Core_DAO_PrintLabel', 'description')); | |
65 | ||
66 | // get the tokens | |
67 | $tokens = CRM_Core_SelectValues::contactTokens(); | |
68 | asort($tokens); | |
69 | ||
70 | $fontSizes = CRM_Core_BAO_LabelFormat::getFontSizes(); | |
71 | $fontNames = CRM_Core_BAO_LabelFormat::getFontNames('name_badge'); | |
72 | $textAlignment = CRM_Core_BAO_LabelFormat::getTextAlignments(); | |
73 | ||
74 | $rowCount = 3; | |
75 | for ( $i =1; $i <= $rowCount; $i++ ) { | |
76 | $this->add('select', "token[$i]", ts('Token'), array('' => ts('- none -')) + $tokens); | |
77 | $this->add('select', "font_name[$i]", ts('Font Name'), $fontNames); | |
78 | $this->add('select', "font_size[$i]", ts('Font Size'), $fontSizes); | |
79 | $this->add('select', "text_alignment[$i]", ts('Alignment'), $textAlignment); | |
80 | } | |
81 | $rowCount++; | |
82 | $this->assign('rowCount', $rowCount); | |
83 | ||
84 | $this->add('checkbox', 'add_barcode', ts('Barcode?')); | |
85 | unset($textAlignment['J']); | |
86 | $this->add('select', "barcode_alignment", ts('Alignment'), $textAlignment); | |
87 | ||
50998125 | 88 | $this->add('checkbox', 'is_default', ts('Default?')); |
636f1cbe KJ |
89 | $this->add('checkbox', 'is_active', ts('Enabled?')); |
90 | $this->add('checkbox', 'is_reserved', ts('Reserved?')); | |
50998125 KJ |
91 | |
92 | if ($this->_action == CRM_Core_Action::UPDATE && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PrintLabel', $this->_id, 'is_reserved')) { | |
636f1cbe KJ |
93 | $this->freeze(array('title', 'description', 'is_active')); |
94 | } | |
95 | } | |
96 | ||
97 | /** | |
98 | * This function sets the default values for the form. MobileProvider that in edit/view mode | |
99 | * the default values are retrieved from the database | |
100 | * | |
101 | * @access public | |
102 | * | |
103 | * @return None | |
104 | */ | |
105 | function setDefaultValues() { | |
106 | if (isset($this->_id) && empty($this->_values)) { | |
107 | $this->_values = array(); | |
108 | $params = array('id' => $this->_id); | |
109 | CRM_Badge_BAO_Layout::retrieve($params, $this->_values ); | |
110 | } | |
111 | ||
112 | $defaults = $this->_values; | |
113 | ||
114 | $data = get_object_vars(json_decode($this->_values['data'])); | |
115 | ||
116 | $specialFields = array('token', 'font_name', 'font_size', 'text_alignment'); | |
117 | foreach($specialFields as $field) { | |
118 | $defaults[$field] = get_object_vars($data[$field]); | |
50998125 | 119 | } |
636f1cbe KJ |
120 | |
121 | $defaults['add_barcode'] = $data['add_barcode']; | |
122 | $defaults['barcode_alignment'] = $data['barcode_alignment']; | |
123 | $defaults['label_format_id'] = $data['label_format_id']; | |
124 | ||
125 | if ($this->_action == CRM_Core_Action::DELETE && isset($defaults['title'])) { | |
126 | $this->assign('delName', $defaults['title']); | |
127 | } | |
128 | ||
129 | // its ok if there is no element called is_active | |
130 | $defaults['is_active'] = ($this->_id) ? CRM_Utils_Array::value('is_active', $defaults) : 1; | |
131 | ||
132 | return $defaults; | |
50998125 KJ |
133 | } |
134 | ||
135 | /** | |
136 | * Function to process the form | |
137 | * | |
138 | * @access public | |
139 | * | |
140 | * @return None | |
141 | */ | |
142 | public function postProcess() { | |
636f1cbe KJ |
143 | if ($this->_action & CRM_Core_Action::DELETE) { |
144 | CRM_Badge_BAO_Layout::del($this->_id); | |
145 | CRM_Core_Session::setStatus(ts('Selected badge layout has been deleted.'), ts('Record Deleted'), 'success'); | |
146 | return; | |
147 | } | |
148 | ||
149 | $params = $data = $this->controller->exportValues($this->_name); | |
150 | ||
151 | unset($data['qfKey']); | |
152 | $params['data'] = json_encode($data); | |
153 | ||
154 | if ($this->_id) { | |
155 | $params['id'] = $this->_id; | |
156 | } | |
157 | ||
158 | // store the submitted values in an array | |
159 | CRM_Badge_BAO_Layout::create($params); | |
160 | ||
161 | CRM_Core_Session::setStatus(ts("The badge layout '%1' has been saved.", | |
162 | array(1 => $params['title']) | |
163 | ), ts('Saved'), 'success'); | |
50998125 KJ |
164 | } |
165 | } |