Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class provides the functionality for batch profile update for membership | |
22 | */ | |
23 | class CRM_Member_Form_Task_PickProfile extends CRM_Member_Form_Task { | |
24 | ||
25 | /** | |
100fef9d | 26 | * The title of the group |
6a488035 TO |
27 | * |
28 | * @var string | |
29 | */ | |
30 | protected $_title; | |
31 | ||
32 | /** | |
100fef9d | 33 | * Maximum members that should be allowed to update |
971e129b | 34 | * @var int |
6a488035 TO |
35 | */ |
36 | protected $_maxMembers = 100; | |
37 | ||
38 | /** | |
100fef9d | 39 | * Variable to store redirect path |
971e129b | 40 | * @var string |
6a488035 TO |
41 | */ |
42 | protected $_userContext; | |
43 | ||
44 | /** | |
fe482240 | 45 | * Build all the data structures needed to build the form. |
6a488035 TO |
46 | * |
47 | * @return void | |
6a488035 | 48 | */ |
00be9182 | 49 | public function preProcess() { |
c490a46a | 50 | // initialize the task and row fields |
6a488035 TO |
51 | parent::preProcess(); |
52 | $session = CRM_Core_Session::singleton(); | |
53 | $this->_userContext = $session->readUserContext(); | |
54 | ||
b581842f | 55 | CRM_Utils_System::setTitle(ts('Update multiple memberships')); |
6a488035 TO |
56 | |
57 | $validate = FALSE; | |
58 | //validations | |
59 | if (count($this->_memberIds) > $this->_maxMembers) { | |
be2fb01f | 60 | 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 |
61 | 1 => $this->_maxMembers, |
62 | 2 => count($this->_memberIds), | |
be2fb01f | 63 | ]), ts('Update multiple records error'), 'error'); |
6a488035 TO |
64 | $validate = TRUE; |
65 | } | |
66 | ||
67 | // than redirect | |
68 | if ($validate) { | |
69 | CRM_Utils_System::redirect($this->_userContext); | |
70 | } | |
71 | } | |
72 | ||
73 | /** | |
fe482240 | 74 | * Build the form object. |
6a488035 | 75 | * |
6a488035 TO |
76 | * |
77 | * @return void | |
78 | */ | |
00be9182 | 79 | public function buildQuickForm() { |
be2fb01f | 80 | $types = ['Membership']; |
6a488035 TO |
81 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); |
82 | ||
83 | if (empty($profiles)) { | |
be2fb01f | 84 | 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 |
85 | CRM_Utils_System::redirect($this->_userContext); |
86 | } | |
87 | ||
88 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
be2fb01f | 89 | [ |
87a890cc | 90 | '' => ts('- select profile -'), |
be2fb01f | 91 | ] + $profiles, TRUE |
6a488035 | 92 | ); |
f212d37d | 93 | $this->addDefaultButtons(ts('Continue')); |
6a488035 TO |
94 | } |
95 | ||
96 | /** | |
fe482240 | 97 | * Add local and global form rules. |
6a488035 | 98 | * |
6a488035 TO |
99 | * |
100 | * @return void | |
101 | */ | |
00be9182 | 102 | public function addRules() { |
be2fb01f | 103 | $this->addFormRule(['CRM_Member_Form_Task_PickProfile', 'formRule']); |
6a488035 TO |
104 | } |
105 | ||
106 | /** | |
fe482240 | 107 | * Global validation rules for the form. |
6a488035 | 108 | * |
b2363ea8 TO |
109 | * @param array $fields |
110 | * Posted values of the form. | |
6a488035 | 111 | * |
a6c01b45 CW |
112 | * @return array |
113 | * list of errors to be posted back to the form | |
6a488035 | 114 | */ |
00be9182 | 115 | public static function formRule($fields) { |
6a488035 TO |
116 | return TRUE; |
117 | } | |
118 | ||
119 | /** | |
fe482240 | 120 | * Process the form after the input has been submitted and validated. |
6a488035 | 121 | * |
6a488035 | 122 | * |
355ba699 | 123 | * @return void |
6a488035 TO |
124 | */ |
125 | public function postProcess() { | |
126 | $params = $this->exportValues(); | |
127 | ||
128 | $this->set('ufGroupId', $params['uf_group_id']); | |
129 | ||
130 | // also reset the batch page so it gets new values from the db | |
131 | $this->controller->resetPage('Batch'); | |
132 | } | |
96025800 | 133 | |
6a488035 | 134 | } |