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 Activity | |
38 | */ | |
39 | class CRM_Activity_Form_Task_PickProfile extends CRM_Activity_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 Activities that should be allowed to update |
6a488035 TO |
50 | * |
51 | */ | |
52 | protected $_maxActivities = 100; | |
53 | ||
54 | /** | |
100fef9d | 55 | * Variable to store redirect path |
6a488035 TO |
56 | * |
57 | */ | |
58 | protected $_userContext; | |
59 | ||
60 | /** | |
100fef9d | 61 | * Build all the data structures needed to build the form |
6a488035 TO |
62 | * |
63 | * @return void | |
6a488035 | 64 | */ |
00be9182 | 65 | public function preProcess() { |
6a488035 TO |
66 | /* |
67 | * initialize the task and row fields | |
68 | */ | |
f813f78e | 69 | |
6a488035 TO |
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 Activities')); | |
75 | ||
76 | $validate = FALSE; | |
77 | //validations | |
78 | if (count($this->_activityHolderIds) > $this->_maxActivities) { | |
79 | CRM_Core_Session::setStatus(ts("The maximum number of Activities you can select for Batch Update is %1. You have selected %2. Please select fewer Activities from your search results and try again.", array(1 => $this->_maxActivities, 2 => count($this->_activityHolderIds))), ts('Maximum Exceeded'), 'error'); | |
80 | $validate = TRUE; | |
81 | } | |
82 | ||
83 | // than redirect | |
84 | if ($validate) { | |
85 | CRM_Utils_System::redirect($this->_userContext); | |
86 | } | |
87 | } | |
88 | ||
89 | /** | |
c490a46a | 90 | * Build the form object |
6a488035 | 91 | * |
6a488035 TO |
92 | * |
93 | * @return void | |
94 | */ | |
00be9182 | 95 | public function buildQuickForm() { |
6a488035 TO |
96 | $types = array('Activity'); |
97 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); | |
98 | ||
99 | $activityTypeIds = array_flip(CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name')); | |
100 | $nonEditableActivityTypeIds = array( | |
101 | $activityTypeIds['Email'], | |
102 | $activityTypeIds['Bulk Email'], | |
103 | $activityTypeIds['Contribution'], | |
104 | $activityTypeIds['Inbound Email'], | |
105 | $activityTypeIds['Pledge Reminder'], | |
106 | $activityTypeIds['Membership Signup'], | |
107 | $activityTypeIds['Membership Renewal'], | |
108 | $activityTypeIds['Event Registration'], | |
109 | $activityTypeIds['Pledge Acknowledgment'], | |
110 | ); | |
111 | $notEditable = FALSE; | |
112 | foreach ($this->_activityHolderIds as $activityId) { | |
113 | $typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id'); | |
114 | if (in_array($typeId, $nonEditableActivityTypeIds)) { | |
115 | $notEditable = TRUE; | |
116 | break; | |
117 | } | |
118 | } | |
119 | ||
120 | if (empty($profiles)) { | |
a08aa8e8 | 121 | 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 > Customize Data and Screens > Profiles to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts("No Profile Configured"), "alert"); |
6a488035 TO |
122 | CRM_Utils_System::redirect($this->_userContext); |
123 | } | |
124 | elseif ($notEditable) { | |
125 | CRM_Core_Session::setStatus("", ts("Some of the selected activities are not editable."), "alert"); | |
126 | CRM_Utils_System::redirect($this->_userContext); | |
127 | } | |
128 | ||
129 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
130 | array( | |
131 | '' => ts('- select profile -')) + $profiles, TRUE | |
132 | ); | |
133 | $this->addDefaultButtons(ts('Continue >>')); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Add local and global form rules | |
138 | * | |
6a488035 TO |
139 | * |
140 | * @return void | |
141 | */ | |
00be9182 | 142 | public function addRules() { |
6a488035 TO |
143 | $this->addFormRule(array('CRM_Activity_Form_Task_PickProfile', 'formRule')); |
144 | } | |
145 | ||
146 | /** | |
100fef9d | 147 | * Global validation rules for the form |
6a488035 TO |
148 | * |
149 | * @param array $fields posted values of the form | |
150 | * | |
151 | * @return array list of errors to be posted back to the form | |
152 | * @static | |
6a488035 | 153 | */ |
00be9182 | 154 | public static function formRule($fields) { |
6a488035 TO |
155 | return TRUE; |
156 | } | |
157 | ||
158 | /** | |
100fef9d | 159 | * Process the form after the input has been submitted and validated |
6a488035 | 160 | * |
6a488035 | 161 | * |
355ba699 | 162 | * @return void |
6a488035 TO |
163 | */ |
164 | public function postProcess() { | |
165 | $params = $this->exportValues(); | |
166 | ||
167 | $this->set('ufGroupId', $params['uf_group_id']); | |
168 | ||
169 | // also reset the batch page so it gets new values from the db | |
170 | $this->controller->resetPage('Batch'); | |
171 | } | |
6a488035 | 172 | } |