Merge pull request #11629 from JMAConsulting/CRM-21675
[civicrm-core.git] / CRM / Event / Form / Task / Badge.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
32 */
33
34 /**
35 * This class helps to print the labels for contacts.
36 */
37 class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
38
39 /**
40 * Are we operating in "single mode", i.e. sending email to one
41 * specific contact?
42 *
43 * @var boolean
44 */
45 public $_single = FALSE;
46
47 /**
48 * Component clause.
49 */
50 public $_componentClause;
51
52 /**
53 * Build all the data structures needed to build the form.
54 *
55 * @param
56 *
57 * @return void
58 */
59 public function preProcess() {
60 $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
61 if ($this->_context == 'view') {
62 $this->_single = TRUE;
63
64 $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
65 $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
66 $this->_participantIds = array($participantID);
67 $this->_componentClause = " civicrm_participant.id = $participantID ";
68 $this->assign('totalSelectedParticipants', 1);
69
70 // also set the user context to send back to view page
71 $session = CRM_Core_Session::singleton();
72 $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/participant',
73 "reset=1&action=view&id={$participantID}&cid={$contactID}"
74 ));
75 }
76 else {
77 parent::preProcess();
78 }
79 }
80
81 /**
82 * Build the form object.
83 */
84 public function buildQuickForm() {
85 CRM_Utils_System::setTitle(ts('Make Name Badges'));
86
87 // Ajax submit would interfere with file download
88 $this->preventAjaxSubmit();
89
90 //add select for label
91 $label = CRM_Badge_BAO_Layout::getList();
92
93 $this->add('select',
94 'badge_id',
95 ts('Name Badge Format'),
96 array(
97 '' => ts('- select -'),
98 ) + $label, TRUE
99 );
100
101 $next = 'next';
102 $back = $this->_single ? 'cancel' : 'back';
103 $this->addDefaultButtons(ts('Make Name Badges'), $next, $back);
104 }
105
106 /**
107 * Process the form after the input has been submitted and validated.
108 */
109 public function postProcess() {
110 $params = $this->controller->exportValues($this->_name);
111 CRM_Badge_BAO_Badge::buildBadges($params, $this);
112 }
113
114 }