add status preference dao to ignore list
[civicrm-core.git] / CRM / Contact / Form / Task / PickProfile.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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 * $Id$
33 *
34 */
35
36/**
37 * This class provides the functionality for batch profile update
38 */
39class CRM_Contact_Form_Task_PickProfile extends CRM_Contact_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 contacts that should be allowed to update
6a488035
TO
50 */
51 protected $_maxContacts = 100;
52
53 /**
100fef9d 54 * Maximum profile fields that will be displayed
6a488035
TO
55 */
56 protected $_maxFields = 9;
57
58 /**
100fef9d 59 * Variable to store redirect path
6a488035
TO
60 */
61 protected $_userContext;
62
63 /**
fe482240 64 * Build all the data structures needed to build the form.
6a488035
TO
65 *
66 * @return void
6a488035 67 */
00be9182 68 public function preProcess() {
d424ffde 69 // initialize the task and row fields
6a488035
TO
70 parent::preProcess();
71
72 $session = CRM_Core_Session::singleton();
73 $this->_userContext = $session->readUserContext();
74
75 $validate = FALSE;
76 //validations
77 if (count($this->_contactIds) > $this->_maxContacts) {
353ffa53
TO
78 CRM_Core_Session::setStatus(ts("The maximum number of contacts you can select for Batch Update is %1. You have selected %2. Please select fewer contacts from your search results and try again.", array(
79 1 => $this->_maxContacts,
3bdca100 80 2 => count($this->_contactIds),
353ffa53 81 )), ts('Maximum Exceeded'), 'error');
6a488035
TO
82 $validate = TRUE;
83 }
84
85 if (CRM_Contact_BAO_Contact_Utils::checkContactType($this->_contactIds)) {
86 CRM_Core_Session::setStatus(ts("Batch update requires that all selected contacts be the same basic type (e.g. all Individuals OR all Organizations...). Please modify your selection and try again."), ts('Contact Type Mismatch'), 'error');
87 $validate = TRUE;
88 }
89
90 // than redirect
91 if ($validate) {
92 CRM_Utils_System::redirect($this->_userContext);
93 }
94 }
95
96 /**
fe482240 97 * Build the form object.
6a488035 98 *
6a488035
TO
99 *
100 * @return void
101 */
00be9182 102 public function buildQuickForm() {
6a488035
TO
103 CRM_Utils_System::setTitle(ts('Batch Profile Update for Contact'));
104
105 foreach ($this->_contactIds as $id) {
106 $this->_contactTypes = CRM_Contact_BAO_Contact::getContactTypes($id);
107 }
108
109 //add Contact type profiles
110 $this->_contactTypes[] = 'Contact';
111
112 $profiles = CRM_Core_BAO_UFGroup::getProfiles($this->_contactTypes);
113
114 if (empty($profiles)) {
115 $types = implode(' ' . ts('or') . ' ', $this->_contactTypes);
116 CRM_Core_Session::setStatus(ts("The contact type selected for Batch Update does not have a corresponding profile. Please set up a profile for %1s and try again.", array(1 => $types)), ts('No Profile Available'), 'error');
117 CRM_Utils_System::redirect($this->_userContext);
118 }
24431f7b 119 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), array('' => ts('- select profile -')) + $profiles, TRUE, array('class' => 'crm-select2 huge'));
6a488035 120
f212d37d 121 $this->addDefaultButtons(ts('Continue'));
6a488035
TO
122 }
123
124 /**
fe482240 125 * Add local and global form rules.
6a488035 126 *
6a488035
TO
127 *
128 * @return void
129 */
00be9182 130 public function addRules() {
6a488035
TO
131 $this->addFormRule(array('CRM_Contact_Form_Task_PickProfile', 'formRule'));
132 }
133
134 /**
fe482240 135 * Global validation rules for the form.
6a488035 136 *
77c5b619
TO
137 * @param array $fields
138 * Posted values of the form.
6a488035 139 *
a6c01b45
CW
140 * @return array
141 * list of errors to be posted back to the form
6a488035 142 */
00be9182 143 public static function formRule($fields) {
6a488035
TO
144 if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) {
145 $errorMsg['uf_group_id'] = "You cannot select mix profile for batch update.";
146 }
147
148 if (!empty($errorMsg)) {
149 return $errorMsg;
150 }
151
152 return TRUE;
153 }
154
155 /**
fe482240 156 * Process the form after the input has been submitted and validated.
6a488035 157 *
6a488035 158 *
355ba699 159 * @return void
6a488035
TO
160 */
161 public function postProcess() {
162 $params = $this->exportValues();
163
164 $this->set('ufGroupId', $params['uf_group_id']);
165
166 // also reset the batch page so it gets new values from the db
167 $this->controller->resetPage('Batch');
168 }
96025800 169
6a488035 170}