3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class provides the functionality for batch profile update for case
36 abstract class CRM_Core_Form_Task_PickProfile
extends CRM_Core_Form_Task
{
39 * The title of the group
46 * Maximum entities that should be allowed to update
50 protected $_maxEntities = 100;
53 * Variable to store redirect path
57 protected $_userContext;
60 * Must be set to entity table name (eg. civicrm_participant) by child class
64 public static $tableName = NULL;
67 * Must be set to entity shortname (eg. event)
71 public static $entityShortname = NULL;
74 * Build all the data structures needed to build the form.
78 public function preProcess() {
79 // initialize the task and row fields
81 $session = CRM_Core_Session
::singleton();
82 $this->_userContext
= $session->readUserContext();
84 CRM_Utils_System
::setTitle(ts('Update multiple ' . $this::$entityShortname . 's'));
87 if (count($this->_entityIds
) > $this->_maxEntities
) {
88 CRM_Core_Session
::setStatus(ts("The maximum number of %3 you can select for Update multiple %3 is %1. You have selected %2. Please select fewer %3 from your search results and try again.", [
89 1 => $this->_maxEntities
,
90 2 => count($this->_entityIds
),
91 3 => $this::$entityShortname . 's',
92 ]), ts('Update multiple records error'), 'error');
93 CRM_Utils_System
::redirect($this->_userContext
);
98 * Build the form object.
102 public function buildQuickForm() {
103 $types = [ucfirst($this::$entityShortname)];
104 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types, TRUE);
106 if (empty($profiles)) {
107 CRM_Core_Session
::setStatus(
108 ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Update multiple %2. Navigate to Administer > Customize Data and Screens > Profiles to configure a Profile. Consult the online Administrator documentation for more information.",
111 2 => $this::$entityShortname . 's',
113 ts('Update multiple records error'),
116 CRM_Utils_System
::redirect($this->_userContext
);
121 ts('Select Profile'),
123 '' => ts('- select profile -'),
127 $this->addDefaultButtons(ts('Continue'));
129 $taskComponent['lc'] = $this::$entityShortname;
130 $taskComponent['ucfirst'] = ucfirst($this::$entityShortname);
131 $this->assign('taskComponent', $taskComponent);
135 * Add local and global form rules.
139 public function addRules() {
140 $this->addFormRule(['CRM_' . ucfirst($this::$entityShortname) . '_Form_Task_PickProfile', 'formRule']);
144 * Global validation rules for the form.
146 * @param array $fields
147 * Posted values of the form.
150 * true if no errors, else array of errors
152 public static function formRule($fields) {
157 * Process the form after the input has been submitted and validated.
161 public function postProcess() {
162 $params = $this->exportValues();
164 $this->set('ufGroupId', $params['uf_group_id']);
166 // also reset the batch page so it gets new values from the db
167 $this->controller
->resetPage('Batch');