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
36 class CRM_Core_Form_Task_Batch
extends CRM_Core_Form_Task
{
39 * The title of the group.
46 * Maximum profile fields that will be displayed.
48 protected $_maxFields = 9;
51 * @var array Fields that belong to this UF Group
55 // Must be set to entity table name (eg. civicrm_participant) by child class
56 static $tableName = NULL;
57 // Must be set to entity shortname (eg. event)
58 static $entityShortname = NULL;
61 * Build all the data structures needed to build the form.
65 public function preProcess() {
66 // initialize the task and row fields
69 // get the contact read only fields to display.
70 $readOnlyFields = array_merge(array('sort_name' => ts('Name')),
71 CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
72 'contact_autocomplete_options',
73 TRUE, NULL, FALSE, 'name', TRUE
76 // get the read only field data.
77 $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1);
78 $contactDetails = CRM_Contact_BAO_Contact_Utils
::contactDetails($this->_entityIds
,
79 'Civi' . ucfirst($this::$entityShortname), $returnProperties
82 $this->assign('contactDetails', $contactDetails);
83 $this->assign('readOnlyFields', $readOnlyFields);
87 * Build the form object.
92 public function buildQuickForm() {
93 $ufGroupId = $this->get('ufGroupId');
96 throw new InvalidArgumentException('ufGroupId is missing');
98 $this->_title
= ts("Update multiple %1s", array(1 => $this::$entityShortname)) . ' - ' . CRM_Core_BAO_UFGroup
::getTitle($ufGroupId);
99 CRM_Utils_System
::setTitle($this->_title
);
101 $this->addDefaultButtons(ts('Save'));
102 $this->_fields
= CRM_Core_BAO_UFGroup
::getFields($ufGroupId, FALSE, CRM_Core_Action
::VIEW
);
104 // remove file type field and then limit fields
105 $suppressFields = FALSE;
106 $removeHtmlTypes = array('File');
107 foreach ($this->_fields
as $name => $field) {
108 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name) &&
109 in_array($this->_fields
[$name]['html_type'], $removeHtmlTypes)
111 $suppressFields = TRUE;
112 unset($this->_fields
[$name]);
115 //fix to reduce size as we are using this field in grid
116 if (is_array($field['attributes']) && !empty($this->_fields
[$name]['attributes']['size']) && $this->_fields
[$name]['attributes']['size'] > 19) {
117 //shrink class to "form-text-medium"
118 $this->_fields
[$name]['attributes']['size'] = 19;
122 $this->_fields
= array_slice($this->_fields
, 0, $this->_maxFields
);
124 $this->addButtons(array(
127 'name' => ts('Update ' . ucfirst($this::$entityShortname) . 's)'),
132 'name' => ts('Cancel'),
136 $this->assign('profileTitle', $this->_title
);
137 $this->assign('componentIds', $this->_entityIds
);
139 $customFields = CRM_Core_BAO_CustomField
::getFields(ucfirst($this::$entityShortname));
140 foreach ($this->_entityIds
as $entityId) {
141 $typeId = CRM_Core_DAO
::getFieldValue('CRM_' . ucfirst($this::$entityShortname) . '_DAO_' . ucfirst($this::$entityShortname), $entityId, $this::$entityShortname . '_type_id');
142 foreach ($this->_fields
as $name => $field) {
143 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
144 $customValue = CRM_Utils_Array
::value($customFieldID, $customFields);
145 $entityColumnValue = array();
146 if (!empty($customValue['extends_entity_column_value'])) {
147 $entityColumnValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
148 $customValue['extends_entity_column_value']
151 if ((CRM_Utils_Array
::value($typeId, $entityColumnValue)) ||
152 CRM_Utils_System
::isNull($entityColumnValue[$typeId])
154 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, NULL, $entityId);
158 // handle non custom fields
159 CRM_Core_BAO_UFGroup
::buildProfile($this, $field, NULL, $entityId);
164 $this->assign('fields', $this->_fields
);
166 // don't set the status message when form is submitted.
167 $buttonName = $this->controller
->getButtonName('submit');
168 if ($suppressFields && $buttonName != '_qf_Batch_next') {
169 CRM_Core_Session
::setStatus(ts("File type field(s) in the selected profile are not supported for Update multiple %1s", array(1 => $this::$entityShortname)), ts('Unsupported Field Type'), 'error');
172 $this->addDefaultButtons(ts('Update ' . ucfirst($this::$entityShortname) . 's'));
174 $taskComponent['lc'] = $this::$entityShortname;
175 $taskComponent['ucfirst'] = ucfirst($this::$entityShortname);
176 $this->assign('taskComponent', $taskComponent);
180 * Set default values for the form.
182 * @return array $defaults
184 public function setDefaultValues() {
185 if (empty($this->_fields
)) {
190 foreach ($this->_entityIds
as $entityId) {
191 CRM_Core_BAO_UFGroup
::setProfileDefaults(NULL, $this->_fields
, $defaults, FALSE, $entityId, ucfirst($this::$entityShortname));
198 * Process the form after the input has been submitted and validated.
199 * Normally the child class will override this
203 public function postProcess() {
204 $params = $this->exportValues();
206 if (!isset($params['field'])) {
207 CRM_Core_Session
::setStatus(ts("No updates have been saved."), ts('Not Saved'), 'alert');