Merge pull request #18440 from civicrm/5.30
[civicrm-core.git] / CRM / Event / Form / Task / Badge.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class helps to print the labels for contacts.
20 */
21 class CRM_Event_Form_Task_Badge extends CRM_Event_Form_Task {
22
23 /**
24 * Are we operating in "single mode", i.e. sending email to one
25 * specific contact?
26 *
27 * @var bool
28 */
29 public $_single = FALSE;
30
31 /**
32 * Component clause.
33 * @var string
34 */
35 public $_componentClause;
36
37 /**
38 * Build all the data structures needed to build the form.
39 *
40 * @param
41 *
42 * @return void
43 */
44 public function preProcess() {
45 $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
46 if ($this->_context == 'view') {
47 $this->_single = TRUE;
48
49 $participantID = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
50 $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
51 $this->_participantIds = [$participantID];
52 $this->_componentClause = " civicrm_participant.id = $participantID ";
53 $this->assign('totalSelectedParticipants', 1);
54
55 // also set the user context to send back to view page
56 $session = CRM_Core_Session::singleton();
57 $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/participant',
58 "reset=1&action=view&id={$participantID}&cid={$contactID}"
59 ));
60 }
61 else {
62 parent::preProcess();
63 }
64 }
65
66 /**
67 * Build the form object.
68 */
69 public function buildQuickForm() {
70 CRM_Utils_System::setTitle(ts('Make Name Badges'));
71
72 // Ajax submit would interfere with file download
73 $this->preventAjaxSubmit();
74
75 //add select for label
76 $label = CRM_Badge_BAO_Layout::getList();
77
78 $this->add('select',
79 'badge_id',
80 ts('Name Badge Format'),
81 [
82 '' => ts('- select -'),
83 ] + $label, TRUE
84 );
85
86 $next = 'next';
87 $back = $this->_single ? 'cancel' : 'back';
88 $this->addDefaultButtons(ts('Make Name Badges'), $next, $back);
89 }
90
91 /**
92 * Process the form after the input has been submitted and validated.
93 */
94 public function postProcess() {
95 $params = $this->controller->exportValues($this->_name);
96 CRM_Badge_BAO_Badge::buildBadges($params, $this);
97 }
98
99 }