Merge pull request #4493 from eileenmcnaughton/CRM-15555
[civicrm-core.git] / CRM / Activity / Form / Task / PickProfile.php
CommitLineData
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 Activity
38 */
39class CRM_Activity_Form_Task_PickProfile extends CRM_Activity_Form_Task {
40
41 /**
42 * the title of the group
43 *
44 * @var string
45 */
46 protected $_title;
47
48 /**
49 * maximum Activities that should be allowed to update
50 *
51 */
52 protected $_maxActivities = 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 */
f813f78e 70
6a488035
TO
71 parent::preProcess();
72 $session = CRM_Core_Session::singleton();
73 $this->_userContext = $session->readUserContext();
74
75 CRM_Utils_System::setTitle(ts('Batch Profile Update for Activities'));
76
77 $validate = FALSE;
78 //validations
79 if (count($this->_activityHolderIds) > $this->_maxActivities) {
80 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');
81 $validate = TRUE;
82 }
83
84 // than redirect
85 if ($validate) {
86 CRM_Utils_System::redirect($this->_userContext);
87 }
88 }
89
90 /**
91 * Build the form
92 *
93 * @access public
94 *
95 * @return void
96 */
97 function buildQuickForm() {
98 $types = array('Activity');
99 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
100
101 $activityTypeIds = array_flip(CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'));
102 $nonEditableActivityTypeIds = array(
103 $activityTypeIds['Email'],
104 $activityTypeIds['Bulk Email'],
105 $activityTypeIds['Contribution'],
106 $activityTypeIds['Inbound Email'],
107 $activityTypeIds['Pledge Reminder'],
108 $activityTypeIds['Membership Signup'],
109 $activityTypeIds['Membership Renewal'],
110 $activityTypeIds['Event Registration'],
111 $activityTypeIds['Pledge Acknowledgment'],
112 );
113 $notEditable = FALSE;
114 foreach ($this->_activityHolderIds as $activityId) {
115 $typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
116 if (in_array($typeId, $nonEditableActivityTypeIds)) {
117 $notEditable = TRUE;
118 break;
119 }
120 }
121
122 if (empty($profiles)) {
a08aa8e8 123 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
124 CRM_Utils_System::redirect($this->_userContext);
125 }
126 elseif ($notEditable) {
127 CRM_Core_Session::setStatus("", ts("Some of the selected activities are not editable."), "alert");
128 CRM_Utils_System::redirect($this->_userContext);
129 }
130
131 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
132 array(
133 '' => ts('- select profile -')) + $profiles, TRUE
134 );
135 $this->addDefaultButtons(ts('Continue >>'));
136 }
137
138 /**
139 * Add local and global form rules
140 *
141 * @access protected
142 *
143 * @return void
144 */
145 function addRules() {
146 $this->addFormRule(array('CRM_Activity_Form_Task_PickProfile', 'formRule'));
147 }
148
149 /**
150 * global validation rules for the form
151 *
152 * @param array $fields posted values of the form
153 *
154 * @return array list of errors to be posted back to the form
155 * @static
156 * @access public
157 */
158 static function formRule($fields) {
159 return TRUE;
160 }
161
162 /**
163 * process the form after the input has been submitted and validated
164 *
165 * @access public
166 *
355ba699 167 * @return void
6a488035
TO
168 */
169 public function postProcess() {
170 $params = $this->exportValues();
171
172 $this->set('ufGroupId', $params['uf_group_id']);
173
174 // also reset the batch page so it gets new values from the db
175 $this->controller->resetPage('Batch');
176 }
177 //end of function
178}
179