Commit | Line | Data |
---|---|---|
6a488035 TO |
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 helps to print the labels for contacts | |
38 | * | |
39 | */ | |
40 | class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task { | |
41 | ||
42 | /** | |
43 | * Are we operating in "single mode", i.e. sending email to one | |
44 | * specific contact? | |
45 | * | |
46 | * @var boolean | |
47 | */ | |
48 | public $_single = FALSE; | |
49 | ||
50 | /** | |
51 | * build all the data structures needed to build the form | |
52 | * | |
53 | * @param | |
54 | * | |
55 | * @return void | |
56 | * @access public | |
57 | */ function preProcess() { | |
58 | $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
59 | if ($this->_context == 'view') { | |
60 | $this->_single = TRUE; | |
61 | ||
62 | $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); | |
63 | $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
64 | $this->_participantIds = array($participantID); | |
65 | $this->_componentClause = " civicrm_participant.id = $participantID "; | |
66 | $this->assign('totalSelectedParticipants', 1); | |
67 | ||
68 | // also set the user context to send back to view page | |
69 | $session = CRM_Core_Session::singleton(); | |
70 | $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', | |
71 | "reset=1&action=view&id={$participantID}&cid={$contactID}" | |
72 | )); | |
73 | } | |
74 | else { | |
75 | parent::preProcess(); | |
76 | } | |
77 | } | |
78 | ||
79 | /** | |
80 | * Build the form | |
81 | * | |
82 | * @access public | |
83 | * | |
84 | * @return void | |
85 | */ | |
86 | function buildQuickForm() { | |
87 | CRM_Utils_System::setTitle(ts('Make Name Badges')); | |
88 | ||
89 | //add select for label | |
90 | $label = CRM_Core_OptionGroup::values('event_badge'); | |
91 | ||
92 | $this->add('select', | |
93 | 'badge_id', | |
94 | ts('Name Badge Format'), | |
95 | array( | |
96 | '' => ts('- select -')) + $label, TRUE | |
97 | ); | |
98 | ||
99 | $next = 'next'; | |
100 | $back = $this->_single ? 'cancel' : 'back'; | |
101 | $this->addDefaultButtons(ts('Make Name Badges'), $next, $back); | |
102 | } | |
103 | ||
104 | /** | |
105 | * process the form after the input has been submitted and validated | |
106 | * | |
107 | * @access public | |
108 | * | |
109 | * @return void | |
110 | */ | |
111 | public function postProcess() { | |
112 | $params = $this->controller->exportValues($this->_name); | |
113 | $config = CRM_Core_Config::singleton(); | |
114 | ||
115 | ||
116 | $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT); | |
117 | $additionalFields = array('first_name', 'last_name', 'middle_name', 'current_employer'); | |
118 | foreach ($additionalFields as $field) { | |
119 | $returnProperties[$field] = 1; | |
120 | } | |
121 | ||
122 | if ($this->_single) { | |
123 | $queryParams = NULL; | |
124 | } | |
125 | else { | |
126 | $queryParams = $this->get('queryParams'); | |
127 | } | |
128 | ||
129 | $query = new CRM_Contact_BAO_Query($queryParams, $returnProperties, NULL, FALSE, FALSE, | |
130 | CRM_Contact_BAO_Query::MODE_EVENT | |
131 | ); | |
132 | ||
133 | list($select, $from, $where, $having) = $query->query(); | |
134 | if (empty($where)) { | |
135 | $where = "WHERE {$this->_componentClause}"; | |
136 | } | |
137 | else { | |
138 | $where .= " AND {$this->_componentClause}"; | |
139 | } | |
140 | ||
141 | $sortOrder = NULL; | |
142 | if ($this->get(CRM_Utils_Sort::SORT_ORDER)) { | |
143 | $sortOrder = $this->get(CRM_Utils_Sort::SORT_ORDER); | |
144 | if (!empty($sortOrder)) { | |
145 | $sortOrder = " ORDER BY $sortOrder"; | |
146 | } | |
147 | } | |
148 | $queryString = "$select $from $where $having $sortOrder"; | |
149 | ||
150 | $dao = CRM_Core_DAO::executeQuery($queryString); | |
151 | $rows = array(); | |
152 | while ($dao->fetch()) { | |
153 | $rows[$dao->participant_id] = array(); | |
154 | foreach ($returnProperties as $key => $dontCare) { | |
155 | $rows[$dao->participant_id][$key] = isset($dao->$key) ? $dao->$key : NULL; | |
156 | } | |
157 | } | |
158 | ||
159 | // get the class name from the participantListingID | |
160 | $className = CRM_Core_OptionGroup::getValue('event_badge', | |
161 | $params['badge_id'], | |
162 | 'value', | |
163 | 'Integer', | |
164 | 'name' | |
165 | ); | |
166 | ||
167 | $classFile = str_replace('_', | |
168 | DIRECTORY_SEPARATOR, | |
169 | $className | |
170 | ) . '.php'; | |
171 | $error = include_once ($classFile); | |
172 | if ($error == FALSE) { | |
173 | CRM_Core_Error::fatal('Event Badge code file: ' . $classFile . ' does not exist. Please verify your custom event badge settings in CiviCRM administrative panel.'); | |
174 | } | |
175 | ||
176 | eval("\$eventBadgeClass = new $className( );"); | |
177 | ||
178 | ||
179 | $eventBadgeClass->run($rows); | |
180 | } | |
181 | } | |
182 |