Merge branch '4.6' into 'master'
[civicrm-core.git] / CRM / Contribute / Form / Task / PickProfile.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * This class provides the functionality for batch profile update for contributions.
36 */
37 class CRM_Contribute_Form_Task_PickProfile extends CRM_Contribute_Form_Task {
38
39 /**
40 * The title of the group
41 *
42 * @var string
43 */
44 protected $_title;
45
46 /**
47 * Maximum contributions that should be allowed to update
48 */
49 protected $_maxContributions = 100;
50
51 /**
52 * Variable to store redirect path
53 */
54 protected $_userContext;
55
56 /**
57 * Build all the data structures needed to build the form.
58 *
59 * @return void
60 */
61 public function preProcess() {
62 // initialize the task and row fields
63 parent::preProcess();
64 $session = CRM_Core_Session::singleton();
65 $this->_userContext = $session->readUserContext();
66
67 CRM_Utils_System::setTitle(ts('Batch Update Contributions Via Profile'));
68
69 $validate = FALSE;
70 //validations
71 if (count($this->_contributionIds) > $this->_maxContributions) {
72 CRM_Core_Session::setStatus(ts("The maximum number of contributions you can select for Batch Update is %1. You have selected %2. Please select fewer contributions from your search results and try again.", array(
73 1 => $this->_maxContributions,
74 2 => count($this->_contributionIds),
75 )), ts('Batch Update Error'), 'error');
76 $validate = TRUE;
77 }
78
79 // than redirect
80 if ($validate) {
81 CRM_Utils_System::redirect($this->_userContext);
82 }
83 }
84
85 /**
86 * Build the form object.
87 *
88 *
89 * @return void
90 */
91 public function buildQuickForm() {
92
93 $types = array('Contribution');
94 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
95
96 if (empty($profiles)) {
97 CRM_Core_Session::setStatus(ts("You will need to create a Profile containing the %1 fields you want to edit before you can use Batch Update via Profile. Navigate to Administer CiviCRM > Customize Data and Screens > CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts('Profile Required'), 'error');
98 CRM_Utils_System::redirect($this->_userContext);
99 }
100
101 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
102 array(
103 '' => ts('- select profile -'),
104 ) + $profiles, TRUE
105 );
106 $this->addDefaultButtons(ts('Continue'));
107 }
108
109 /**
110 * Add local and global form rules.
111 *
112 *
113 * @return void
114 */
115 public function addRules() {
116 $this->addFormRule(array('CRM_Contribute_Form_Task_PickProfile', 'formRule'));
117 }
118
119 /**
120 * Global validation rules for the form.
121 *
122 * @param array $fields
123 * Posted values of the form.
124 *
125 * @return array
126 * list of errors to be posted back to the form
127 */
128 public static function formRule($fields) {
129 return TRUE;
130 }
131
132 /**
133 * Process the form after the input has been submitted and validated.
134 *
135 *
136 * @return void
137 */
138 public function postProcess() {
139 $params = $this->exportValues();
140
141 $this->set('ufGroupId', $params['uf_group_id']);
142
143 // also reset the batch page so it gets new values from the db
144 $this->controller->resetPage('Batch');
145 }
146
147 }