3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * This class provides the functionality for batch profile update
39 class CRM_Contact_Form_Task_PickProfile
extends CRM_Contact_Form_Task
{
42 * the title of the group
49 * maximum contacts that should be allowed to update
52 protected $_maxContacts = 100;
55 * maximum profile fields that will be displayed
58 protected $_maxFields = 9;
61 * variable to store redirect path
64 protected $_userContext;
67 * build all the data structures needed to build the form
72 function preProcess() {
74 * initialize the task and row fields
78 $session = CRM_Core_Session
::singleton();
79 $this->_userContext
= $session->readUserContext();
83 if (count($this->_contactIds
) > $this->_maxContacts
) {
84 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(1 => $this->_maxContacts
, 2 => count($this->_contactIds
))), ts('Maximum Exceeded'), 'error');
88 if (CRM_Contact_BAO_Contact_Utils
::checkContactType($this->_contactIds
)) {
89 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');
95 CRM_Utils_System
::redirect($this->_userContext
);
106 function buildQuickForm() {
107 CRM_Utils_System
::setTitle(ts('Batch Profile Update for Contact'));
109 foreach ($this->_contactIds
as $id) {
110 $this->_contactTypes
= CRM_Contact_BAO_Contact
::getContactTypes($id);
113 //add Contact type profiles
114 $this->_contactTypes
[] = 'Contact';
116 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($this->_contactTypes
);
118 if (empty($profiles)) {
119 $types = implode(' ' . ts('or') . ' ', $this->_contactTypes
);
120 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');
121 CRM_Utils_System
::redirect($this->_userContext
);
123 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), array('' => ts('- select profile -')) +
$profiles, TRUE);
125 $this->addDefaultButtons(ts('Continue >>'));
129 * Add local and global form rules
135 function addRules() {
136 $this->addFormRule(array('CRM_Contact_Form_Task_PickProfile', 'formRule'));
140 * global validation rules for the form
142 * @param array $fields posted values of the form
144 * @return array list of errors to be posted back to the form
148 static function formRule($fields) {
149 if (CRM_Core_BAO_UFField
::checkProfileType($fields['uf_group_id'])) {
150 $errorMsg['uf_group_id'] = "You cannot select mix profile for batch update.";
153 if (!empty($errorMsg)) {
161 * process the form after the input has been submitted and validated
167 public function postProcess() {
168 $params = $this->exportValues();
170 $this->set('ufGroupId', $params['uf_group_id']);
172 // also reset the batch page so it gets new values from the db
173 $this->controller
->resetPage('Batch');