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 batch profile update for Activity.
21 class CRM_Activity_Form_Task_PickProfile
extends CRM_Activity_Form_Task
{
24 * The title of the group.
31 * Maximum Activities that should be allowed to update.
34 protected $_maxActivities = 100;
37 * Variable to store redirect path.
40 protected $_userContext;
43 * Build all the data structures needed to build the form.
45 public function preProcess() {
47 // Initialize the task and row fields.
49 $session = CRM_Core_Session
::singleton();
50 $this->_userContext
= $session->readUserContext();
52 CRM_Utils_System
::setTitle(ts('Update multiple activities'));
56 if (count($this->_activityHolderIds
) > $this->_maxActivities
) {
57 CRM_Core_Session
::setStatus(ts("The maximum number of activities you can select for Update multiple activities is %1. You have selected %2. Please select fewer Activities from your search results and try again.", [
58 1 => $this->_maxActivities
,
59 2 => count($this->_activityHolderIds
),
60 ]), ts('Maximum Exceeded'), 'error');
66 CRM_Utils_System
::redirect($this->_userContext
);
71 * Build the form object.
73 public function buildQuickForm() {
74 $types = ['Activity'];
75 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types, TRUE);
77 $activityTypeIds = array_flip(CRM_Core_PseudoConstant
::activityType(TRUE, FALSE, FALSE, 'name'));
78 $nonEditableActivityTypeIds = [
79 $activityTypeIds['Email'],
80 $activityTypeIds['Bulk Email'],
81 $activityTypeIds['Contribution'],
82 $activityTypeIds['Inbound Email'],
83 $activityTypeIds['Pledge Reminder'],
84 $activityTypeIds['Membership Signup'],
85 $activityTypeIds['Membership Renewal'],
86 $activityTypeIds['Event Registration'],
87 $activityTypeIds['Pledge Acknowledgment'],
90 foreach ($this->_activityHolderIds
as $activityId) {
91 $typeId = CRM_Core_DAO
::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
92 if (in_array($typeId, $nonEditableActivityTypeIds)) {
98 if (empty($profiles)) {
99 CRM_Core_Session
::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Update multiple activities. Navigate to Administer > Customize Data and Screens > Profiles to configure a Profile. Consult the online Administrator documentation for more information.", [1 => $types[0]]), ts("No Profile Configured"), "alert");
100 CRM_Utils_System
::redirect($this->_userContext
);
102 elseif ($notEditable) {
103 CRM_Core_Session
::setStatus("", ts("Some of the selected activities are not editable."), "alert");
104 CRM_Utils_System
::redirect($this->_userContext
);
107 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
109 '' => ts('- select profile -'),
112 $this->addDefaultButtons(ts('Continue'));
116 * Add local and global form rules.
118 public function addRules() {
119 $this->addFormRule(['CRM_Activity_Form_Task_PickProfile', 'formRule']);
123 * Global validation rules for the form.
125 * @param array $fields
126 * Posted values of the form.
129 * list of errors to be posted back to the form
131 public static function formRule($fields) {
136 * Process the form after the input has been submitted and validated.
138 public function postProcess() {
139 $params = $this->exportValues();
141 $this->set('ufGroupId', $params['uf_group_id']);
143 // also reset the batch page so it gets new values from the db
144 $this->controller
->resetPage('Batch');