Merge pull request #9536 from twomice/CRM-19447_activity_details_search
[civicrm-core.git] / CRM / Contribute / Form / Task / PickProfile.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
fa938177 31 * @copyright CiviCRM LLC (c) 2004-2016
6a488035
TO
32 */
33
34/**
07f8d162 35 * This class provides the functionality for batch profile update for contributions.
6a488035
TO
36 */
37class CRM_Contribute_Form_Task_PickProfile extends CRM_Contribute_Form_Task {
38
39 /**
100fef9d 40 * The title of the group
6a488035
TO
41 *
42 * @var string
43 */
44 protected $_title;
45
46 /**
100fef9d 47 * Maximum contributions that should be allowed to update
6a488035
TO
48 */
49 protected $_maxContributions = 100;
50
51 /**
100fef9d 52 * Variable to store redirect path
6a488035
TO
53 */
54 protected $_userContext;
55
56 /**
fe482240 57 * Build all the data structures needed to build the form.
6a488035 58 */
00be9182 59 public function preProcess() {
d424ffde 60 // initialize the task and row fields
6a488035
TO
61 parent::preProcess();
62 $session = CRM_Core_Session::singleton();
63 $this->_userContext = $session->readUserContext();
64
b581842f 65 CRM_Utils_System::setTitle(ts('Update multiple contributions'));
6a488035
TO
66
67 $validate = FALSE;
68 //validations
69 if (count($this->_contributionIds) > $this->_maxContributions) {
b581842f 70 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.", array(
353ffa53 71 1 => $this->_maxContributions,
389bcebf 72 2 => count($this->_contributionIds),
ec5b3633 73 )), ts('Update multiple records error'), 'error');
6a488035
TO
74 $validate = TRUE;
75 }
76
77 // than redirect
78 if ($validate) {
79 CRM_Utils_System::redirect($this->_userContext);
80 }
81 }
82
83 /**
fe482240 84 * Build the form object.
6a488035 85 */
00be9182 86 public function buildQuickForm() {
6a488035
TO
87
88 $types = array('Contribution');
89 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
90
91 if (empty($profiles)) {
b581842f 92 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.", array(1 => $types[0])), ts('Profile Required'), 'error');
6a488035
TO
93 CRM_Utils_System::redirect($this->_userContext);
94 }
95
96 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
97 array(
389bcebf 98 '' => ts('- select profile -'),
353ffa53 99 ) + $profiles, TRUE
6a488035 100 );
f212d37d 101 $this->addDefaultButtons(ts('Continue'));
6a488035
TO
102 }
103
104 /**
fe482240 105 * Add local and global form rules.
6a488035 106 */
00be9182 107 public function addRules() {
6a488035
TO
108 $this->addFormRule(array('CRM_Contribute_Form_Task_PickProfile', 'formRule'));
109 }
110
111 /**
fe482240 112 * Global validation rules for the form.
6a488035 113 *
014c4014
TO
114 * @param array $fields
115 * Posted values of the form.
6a488035 116 *
a6c01b45
CW
117 * @return array
118 * list of errors to be posted back to the form
6a488035 119 */
00be9182 120 public static function formRule($fields) {
6a488035
TO
121 return TRUE;
122 }
123
124 /**
fe482240 125 * Process the form after the input has been submitted and validated.
6a488035
TO
126 */
127 public function postProcess() {
128 $params = $this->exportValues();
129
130 $this->set('ufGroupId', $params['uf_group_id']);
131
132 // also reset the batch page so it gets new values from the db
133 $this->controller->resetPage('Batch');
134 }
96025800 135
6a488035 136}