Merge pull request #7844 from eileenmcnaughton/report-sql
[civicrm-core.git] / CRM / Activity / Form / Task / PickProfile.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 */
33
34/**
b6c94f42 35 * This class provides the functionality for batch profile update for Activity.
6a488035
TO
36 */
37class CRM_Activity_Form_Task_PickProfile extends CRM_Activity_Form_Task {
38
39 /**
fe482240 40 * The title of the group.
6a488035
TO
41 *
42 * @var string
43 */
44 protected $_title;
45
46 /**
fe482240 47 * Maximum Activities that should be allowed to update.
6a488035
TO
48 */
49 protected $_maxActivities = 100;
50
51 /**
fe482240 52 * Variable to store redirect path.
6a488035
TO
53 */
54 protected $_userContext;
55
56 /**
fe482240 57 * Build all the data structures needed to build the form.
6a488035 58 */
00be9182 59 public function preProcess() {
f813f78e 60
7808aae6 61 // Initialize the task and row fields.
6a488035
TO
62 parent::preProcess();
63 $session = CRM_Core_Session::singleton();
64 $this->_userContext = $session->readUserContext();
65
b581842f 66 CRM_Utils_System::setTitle(ts('Update multiple activities'));
6a488035
TO
67
68 $validate = FALSE;
7808aae6 69 // Validations.
6a488035 70 if (count($this->_activityHolderIds) > $this->_maxActivities) {
b581842f 71 CRM_Core_Session::setStatus(ts("The maximum number of activities you can select for Update multiple activities is %1. You have selected %2. Please select fewer Activities from your search results and try again.", array(
353ffa53 72 1 => $this->_maxActivities,
389bcebf 73 2 => count($this->_activityHolderIds),
353ffa53 74 )), ts('Maximum Exceeded'), 'error');
6a488035
TO
75 $validate = TRUE;
76 }
77
7808aae6 78 // Then redirect.
6a488035
TO
79 if ($validate) {
80 CRM_Utils_System::redirect($this->_userContext);
81 }
82 }
83
84 /**
fe482240 85 * Build the form object.
6a488035 86 */
00be9182 87 public function buildQuickForm() {
6a488035
TO
88 $types = array('Activity');
89 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
90
91 $activityTypeIds = array_flip(CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name'));
92 $nonEditableActivityTypeIds = array(
93 $activityTypeIds['Email'],
94 $activityTypeIds['Bulk Email'],
95 $activityTypeIds['Contribution'],
96 $activityTypeIds['Inbound Email'],
97 $activityTypeIds['Pledge Reminder'],
98 $activityTypeIds['Membership Signup'],
99 $activityTypeIds['Membership Renewal'],
100 $activityTypeIds['Event Registration'],
101 $activityTypeIds['Pledge Acknowledgment'],
102 );
103 $notEditable = FALSE;
104 foreach ($this->_activityHolderIds as $activityId) {
105 $typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
106 if (in_array($typeId, $nonEditableActivityTypeIds)) {
107 $notEditable = TRUE;
108 break;
109 }
110 }
111
112 if (empty($profiles)) {
b581842f 113 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 activities. 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
114 CRM_Utils_System::redirect($this->_userContext);
115 }
116 elseif ($notEditable) {
117 CRM_Core_Session::setStatus("", ts("Some of the selected activities are not editable."), "alert");
118 CRM_Utils_System::redirect($this->_userContext);
119 }
120
121 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
122 array(
389bcebf 123 '' => ts('- select profile -'),
353ffa53 124 ) + $profiles, TRUE
6a488035 125 );
f212d37d 126 $this->addDefaultButtons(ts('Continue'));
6a488035
TO
127 }
128
129 /**
fe482240 130 * Add local and global form rules.
6a488035 131 */
00be9182 132 public function addRules() {
6a488035
TO
133 $this->addFormRule(array('CRM_Activity_Form_Task_PickProfile', 'formRule'));
134 }
135
136 /**
fe482240 137 * Global validation rules for the form.
6a488035 138 *
041ab3d1
TO
139 * @param array $fields
140 * Posted values of the form.
6a488035 141 *
a6c01b45
CW
142 * @return array
143 * list of errors to be posted back to the form
6a488035 144 */
00be9182 145 public static function formRule($fields) {
6a488035
TO
146 return TRUE;
147 }
148
149 /**
fe482240 150 * Process the form after the input has been submitted and validated.
6a488035
TO
151 */
152 public function postProcess() {
153 $params = $this->exportValues();
154
155 $this->set('ufGroupId', $params['uf_group_id']);
156
157 // also reset the batch page so it gets new values from the db
158 $this->controller->resetPage('Batch');
159 }
96025800 160
6a488035 161}