Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
07f8d162 | 19 | * This class provides the functionality for batch profile update for contributions. |
6a488035 TO |
20 | */ |
21 | class CRM_Contribute_Form_Task_PickProfile extends CRM_Contribute_Form_Task { | |
22 | ||
23 | /** | |
100fef9d | 24 | * The title of the group |
6a488035 TO |
25 | * |
26 | * @var string | |
27 | */ | |
28 | protected $_title; | |
29 | ||
30 | /** | |
100fef9d | 31 | * Maximum contributions that should be allowed to update |
1330f57a | 32 | * @var int |
6a488035 TO |
33 | */ |
34 | protected $_maxContributions = 100; | |
35 | ||
36 | /** | |
100fef9d | 37 | * Variable to store redirect path |
1330f57a | 38 | * @var string |
6a488035 TO |
39 | */ |
40 | protected $_userContext; | |
41 | ||
42 | /** | |
fe482240 | 43 | * Build all the data structures needed to build the form. |
6a488035 | 44 | */ |
00be9182 | 45 | public function preProcess() { |
d424ffde | 46 | // initialize the task and row fields |
6a488035 TO |
47 | parent::preProcess(); |
48 | $session = CRM_Core_Session::singleton(); | |
49 | $this->_userContext = $session->readUserContext(); | |
50 | ||
b581842f | 51 | CRM_Utils_System::setTitle(ts('Update multiple contributions')); |
6a488035 TO |
52 | |
53 | $validate = FALSE; | |
54 | //validations | |
55 | if (count($this->_contributionIds) > $this->_maxContributions) { | |
be2fb01f | 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.", [ |
1330f57a SL |
57 | 1 => $this->_maxContributions, |
58 | 2 => count($this->_contributionIds), | |
59 | ]), ts('Update multiple records error'), 'error'); | |
6a488035 TO |
60 | $validate = TRUE; |
61 | } | |
62 | ||
63 | // than redirect | |
64 | if ($validate) { | |
65 | CRM_Utils_System::redirect($this->_userContext); | |
66 | } | |
67 | } | |
68 | ||
69 | /** | |
fe482240 | 70 | * Build the form object. |
6a488035 | 71 | */ |
00be9182 | 72 | public function buildQuickForm() { |
6a488035 | 73 | |
be2fb01f | 74 | $types = ['Contribution']; |
6a488035 TO |
75 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE); |
76 | ||
77 | if (empty($profiles)) { | |
be2fb01f | 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'); |
6a488035 TO |
79 | CRM_Utils_System::redirect($this->_userContext); |
80 | } | |
81 | ||
82 | $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'), | |
be2fb01f | 83 | [ |
389bcebf | 84 | '' => ts('- select profile -'), |
be2fb01f | 85 | ] + $profiles, TRUE |
6a488035 | 86 | ); |
f212d37d | 87 | $this->addDefaultButtons(ts('Continue')); |
6a488035 TO |
88 | } |
89 | ||
90 | /** | |
fe482240 | 91 | * Add local and global form rules. |
6a488035 | 92 | */ |
00be9182 | 93 | public function addRules() { |
be2fb01f | 94 | $this->addFormRule(['CRM_Contribute_Form_Task_PickProfile', 'formRule']); |
6a488035 TO |
95 | } |
96 | ||
97 | /** | |
fe482240 | 98 | * Global validation rules for the form. |
6a488035 | 99 | * |
014c4014 TO |
100 | * @param array $fields |
101 | * Posted values of the form. | |
6a488035 | 102 | * |
a6c01b45 CW |
103 | * @return array |
104 | * list of errors to be posted back to the form | |
6a488035 | 105 | */ |
00be9182 | 106 | public static function formRule($fields) { |
6a488035 TO |
107 | return TRUE; |
108 | } | |
109 | ||
110 | /** | |
fe482240 | 111 | * Process the form after the input has been submitted and validated. |
6a488035 TO |
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 | } | |
96025800 | 121 | |
6a488035 | 122 | } |