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