Merge pull request #17396 from seamuslee001/use_util_mail_events
[civicrm-core.git] / CRM / Contribute / Form / Task / PickProfile.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class provides the functionality for batch profile update for contributions.
20 */
21 class CRM_Contribute_Form_Task_PickProfile extends CRM_Contribute_Form_Task {
22
23 /**
24 * The title of the group
25 *
26 * @var string
27 */
28 protected $_title;
29
30 /**
31 * Maximum contributions that should be allowed to update
32 * @var int
33 */
34 protected $_maxContributions = 100;
35
36 /**
37 * Variable to store redirect path
38 * @var string
39 */
40 protected $_userContext;
41
42 /**
43 * Build all the data structures needed to build the form.
44 */
45 public function preProcess() {
46 // initialize the task and row fields
47 parent::preProcess();
48 $session = CRM_Core_Session::singleton();
49 $this->_userContext = $session->readUserContext();
50
51 CRM_Utils_System::setTitle(ts('Update multiple contributions'));
52
53 $validate = FALSE;
54 //validations
55 if (count($this->_contributionIds) > $this->_maxContributions) {
56 CRM_Core_Session::setStatus(ts("The maximum number of contributions you can select for Update multiple contributions is %1. You have selected %2. Please select fewer contributions from your search results and try again.", [
57 1 => $this->_maxContributions,
58 2 => count($this->_contributionIds),
59 ]), ts('Update multiple records error'), 'error');
60 $validate = TRUE;
61 }
62
63 // than redirect
64 if ($validate) {
65 CRM_Utils_System::redirect($this->_userContext);
66 }
67 }
68
69 /**
70 * Build the form object.
71 */
72 public function buildQuickForm() {
73
74 $types = ['Contribution'];
75 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
76
77 if (empty($profiles)) {
78 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 contributions. Navigate to Administer CiviCRM > Customize Data and Screens > CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", [1 => $types[0]]), ts('Profile Required'), 'error');
79 CRM_Utils_System::redirect($this->_userContext);
80 }
81
82 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
83 [
84 '' => ts('- select profile -'),
85 ] + $profiles, TRUE
86 );
87 $this->addDefaultButtons(ts('Continue'));
88 }
89
90 /**
91 * Add local and global form rules.
92 */
93 public function addRules() {
94 $this->addFormRule(['CRM_Contribute_Form_Task_PickProfile', 'formRule']);
95 }
96
97 /**
98 * Global validation rules for the form.
99 *
100 * @param array $fields
101 * Posted values of the form.
102 *
103 * @return array
104 * list of errors to be posted back to the form
105 */
106 public static function formRule($fields) {
107 return TRUE;
108 }
109
110 /**
111 * Process the form after the input has been submitted and validated.
112 */
113 public function postProcess() {
114 $params = $this->exportValues();
115
116 $this->set('ufGroupId', $params['uf_group_id']);
117
118 // also reset the batch page so it gets new values from the db
119 $this->controller->resetPage('Batch');
120 }
121
122 }