Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class provides the functionality for batch profile update for membership | |
38 | */ | |
39 | class CRM_Member_Form_Task_PickProfile extends CRM_Member_Form_Task { | |
40 | ||
41 | /** | |
100fef9d | 42 | * The title of the group |
6a488035 TO |
43 | * |
44 | * @var string | |
45 | */ | |
46 | protected $_title; | |
47 | ||
48 | /** | |
100fef9d | 49 | * Maximum members that should be allowed to update |
971e129b | 50 | * @var int |
6a488035 TO |
51 | */ |
52 | protected $_maxMembers = 100; | |
53 | ||
54 | /** | |
100fef9d | 55 | * Variable to store redirect path |
971e129b | 56 | * @var string |
6a488035 TO |
57 | */ |
58 | protected $_userContext; | |
59 | ||
60 | /** | |
fe482240 | 61 | * Build all the data structures needed to build the form. |
6a488035 TO |
62 | * |
63 | * @return void | |
6a488035 | 64 | */ |
00be9182 | 65 | public function preProcess() { |
c490a46a | 66 | // initialize the task and row fields |
6a488035 TO |
67 | parent::preProcess(); |
68 | $session = CRM_Core_Session::singleton(); | |
69 | $this->_userContext = $session->readUserContext(); | |
70 | ||
b581842f | 71 | CRM_Utils_System::setTitle(ts('Update multiple memberships')); |
6a488035 TO |
72 | |
73 | $validate = FALSE; | |
74 | //validations | |
75 | if (count($this->_memberIds) > $this->_maxMembers) { | |
be2fb01f | 76 | CRM_Core_Session::setStatus(ts("The maximum number of members you can select for Update multiple memberships is %1. You have selected %2. Please select fewer members from your search results and try again.", [ |
c5c263ca AH |
77 | 1 => $this->_maxMembers, |
78 | 2 => count($this->_memberIds), | |
be2fb01f | 79 | ]), ts('Update multiple records error'), 'error'); |
6a488035 TO |
80 | $validate = TRUE; |
81 | } | |
82 | ||
83 | // than redirect | |
84 | if ($validate) { | |
85 | CRM_Utils_System::redirect($this->_userContext); | |
86 | } | |
87 | } | |
88 | ||
89 | /** | |
fe482240 | 90 | * Build the form object. |
6a488035 | 91 | * |
6a488035 TO |
92 | * |
93 | * @return void | |
94 | */ | |
00be9182 | 95 | public function buildQuickForm() { |
be2fb01f | 96 | $types = ['Membership']; |
6a488035 TO |
97 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); |
98 | ||
99 | if (empty($profiles)) { | |
be2fb01f | 100 | CRM_Core_Session::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Update multiple memberships. Navigate to Administer CiviCRM >> CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", [1 => $types[0]]), ts('Update multiple records error'), 'error'); |
6a488035 TO |
101 | CRM_Utils_System::redirect($this->_userContext); |
102 | } | |
103 | ||
104 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
be2fb01f | 105 | [ |
87a890cc | 106 | '' => ts('- select profile -'), |
be2fb01f | 107 | ] + $profiles, TRUE |
6a488035 | 108 | ); |
f212d37d | 109 | $this->addDefaultButtons(ts('Continue')); |
6a488035 TO |
110 | } |
111 | ||
112 | /** | |
fe482240 | 113 | * Add local and global form rules. |
6a488035 | 114 | * |
6a488035 TO |
115 | * |
116 | * @return void | |
117 | */ | |
00be9182 | 118 | public function addRules() { |
be2fb01f | 119 | $this->addFormRule(['CRM_Member_Form_Task_PickProfile', 'formRule']); |
6a488035 TO |
120 | } |
121 | ||
122 | /** | |
fe482240 | 123 | * Global validation rules for the form. |
6a488035 | 124 | * |
b2363ea8 TO |
125 | * @param array $fields |
126 | * Posted values of the form. | |
6a488035 | 127 | * |
a6c01b45 CW |
128 | * @return array |
129 | * list of errors to be posted back to the form | |
6a488035 | 130 | */ |
00be9182 | 131 | public static function formRule($fields) { |
6a488035 TO |
132 | return TRUE; |
133 | } | |
134 | ||
135 | /** | |
fe482240 | 136 | * Process the form after the input has been submitted and validated. |
6a488035 | 137 | * |
6a488035 | 138 | * |
355ba699 | 139 | * @return void |
6a488035 TO |
140 | */ |
141 | public function postProcess() { | |
142 | $params = $this->exportValues(); | |
143 | ||
144 | $this->set('ufGroupId', $params['uf_group_id']); | |
145 | ||
146 | // also reset the batch page so it gets new values from the db | |
147 | $this->controller->resetPage('Batch'); | |
148 | } | |
96025800 | 149 | |
6a488035 | 150 | } |