3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class provides the functionality for Update multiple contacts
21 class CRM_Contact_Form_Task_PickProfile
extends CRM_Contact_Form_Task
{
24 * The title of the group
31 * Maximum contacts that should be allowed to update
34 protected $_maxContacts = 100;
37 * Maximum profile fields that will be displayed
40 protected $_maxFields = 9;
43 * Variable to store redirect path
46 protected $_userContext;
49 * Build all the data structures needed to build the form.
51 public function preProcess() {
52 // initialize the task and row fields
55 $session = CRM_Core_Session
::singleton();
56 $this->_userContext
= $session->readUserContext();
60 if (count($this->_contactIds
) > $this->_maxContacts
) {
61 CRM_Core_Session
::setStatus(ts("The maximum number of contacts you can select for Update multiple contacts is %1. You have selected %2. Please select fewer contacts from your search results and try again.", [
62 1 => $this->_maxContacts
,
63 2 => count($this->_contactIds
),
64 ]), ts('Maximum Exceeded'), 'error');
68 if (CRM_Contact_BAO_Contact_Utils
::checkContactType($this->_contactIds
)) {
69 CRM_Core_Session
::setStatus(ts("Update multiple contacts 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');
75 CRM_Utils_System
::redirect($this->_userContext
);
80 * Build the form object.
82 public function buildQuickForm() {
83 CRM_Utils_System
::setTitle(ts('Update multiple contacts'));
85 foreach ($this->_contactIds
as $id) {
86 $this->_contactTypes
= CRM_Contact_BAO_Contact
::getContactTypes($id);
89 //add Contact type profiles
90 $this->_contactTypes
[] = 'Contact';
92 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($this->_contactTypes
);
94 if (empty($profiles)) {
95 $types = implode(' ' . ts('or') . ' ', $this->_contactTypes
);
96 CRM_Core_Session
::setStatus(ts("The contact type selected for Update multiple contacts does not have a corresponding profile. Please set up a profile for %1s and try again.", [1 => $types]), ts('No Profile Available'), 'error');
97 CRM_Utils_System
::redirect($this->_userContext
);
99 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), ['' => ts('- select profile -')] +
$profiles, TRUE, ['class' => 'crm-select2 huge']);
101 $this->addDefaultButtons(ts('Continue'));
105 * Add local and global form rules.
107 public function addRules() {
108 $this->addFormRule(['CRM_Contact_Form_Task_PickProfile', 'formRule']);
112 * Global validation rules for the form.
114 * @param array $fields
115 * Posted values of the form.
118 * list of errors to be posted back to the form
120 public static function formRule($fields) {
121 if (CRM_Core_BAO_UFField
::checkProfileType($fields['uf_group_id'])) {
122 $errorMsg['uf_group_id'] = "You cannot select a mixed profile for Update multiple contacts.";
125 if (!empty($errorMsg)) {
133 * Process the form after the input has been submitted and validated.
135 public function postProcess() {
136 $params = $this->exportValues();
138 $this->set('ufGroupId', $params['uf_group_id']);
140 // also reset the batch page so it gets new values from the db
141 $this->controller
->resetPage('Batch');