Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
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 | /** | |
42 | * the title of the group | |
43 | * | |
44 | * @var string | |
45 | */ | |
46 | protected $_title; | |
47 | ||
48 | /** | |
49 | * maximum members that should be allowed to update | |
50 | * | |
51 | */ | |
52 | protected $_maxMembers = 100; | |
53 | ||
54 | /** | |
55 | * variable to store redirect path | |
56 | * | |
57 | */ | |
58 | protected $_userContext; | |
59 | ||
60 | /** | |
61 | * build all the data structures needed to build the form | |
62 | * | |
63 | * @return void | |
64 | * @access public | |
65 | */ | |
66 | function preProcess() { | |
67 | /* | |
68 | * initialize the task and row fields | |
69 | */ | |
70 | parent::preProcess(); | |
71 | $session = CRM_Core_Session::singleton(); | |
72 | $this->_userContext = $session->readUserContext(); | |
73 | ||
74 | CRM_Utils_System::setTitle(ts('Batch Profile Update for Membership')); | |
75 | ||
76 | $validate = FALSE; | |
77 | //validations | |
78 | if (count($this->_memberIds) > $this->_maxMembers) { | |
10a5be27 | 79 | 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 |
80 | $validate = TRUE; |
81 | } | |
82 | ||
83 | // than redirect | |
84 | if ($validate) { | |
85 | CRM_Utils_System::redirect($this->_userContext); | |
86 | } | |
87 | } | |
88 | ||
89 | /** | |
90 | * Build the form | |
91 | * | |
92 | * @access public | |
93 | * | |
94 | * @return void | |
95 | */ | |
96 | function buildQuickForm() { | |
97 | $types = array('Membership'); | |
98 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); | |
99 | ||
100 | if (empty($profiles)) { | |
10a5be27 | 101 | 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 |
102 | CRM_Utils_System::redirect($this->_userContext); |
103 | } | |
104 | ||
105 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
106 | array( | |
107 | '' => ts('- select profile -')) + $profiles, TRUE | |
108 | ); | |
109 | $this->addDefaultButtons(ts('Continue >>')); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Add local and global form rules | |
114 | * | |
115 | * @access protected | |
116 | * | |
117 | * @return void | |
118 | */ | |
119 | function addRules() { | |
120 | $this->addFormRule(array('CRM_Member_Form_Task_PickProfile', 'formRule')); | |
121 | } | |
122 | ||
123 | /** | |
124 | * global validation rules for the form | |
125 | * | |
126 | * @param array $fields posted values of the form | |
127 | * | |
128 | * @return array list of errors to be posted back to the form | |
129 | * @static | |
130 | * @access public | |
131 | */ | |
132 | static function formRule($fields) { | |
133 | return TRUE; | |
134 | } | |
135 | ||
136 | /** | |
137 | * process the form after the input has been submitted and validated | |
138 | * | |
139 | * @access public | |
140 | * | |
355ba699 | 141 | * @return void |
6a488035 TO |
142 | */ |
143 | public function postProcess() { | |
144 | $params = $this->exportValues(); | |
145 | ||
146 | $this->set('ufGroupId', $params['uf_group_id']); | |
147 | ||
148 | // also reset the batch page so it gets new values from the db | |
149 | $this->controller->resetPage('Batch'); | |
150 | } | |
151 | //end of function | |
152 | } | |
153 |