style fixes based upon updated phpcs Drupal standard
[civicrm-core.git] / CRM / Member / Form / Task / PickProfile.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * This class provides the functionality for batch profile update for membership
38 */
39class CRM_Member_Form_Task_PickProfile extends CRM_Member_Form_Task {
40
41 /**
100fef9d 42 * The title of the group
6a488035
TO
43 *
44 * @var string
45 */
46 protected $_title;
47
48 /**
100fef9d 49 * Maximum members that should be allowed to update
6a488035
TO
50 */
51 protected $_maxMembers = 100;
52
53 /**
100fef9d 54 * Variable to store redirect path
6a488035
TO
55 */
56 protected $_userContext;
57
58 /**
fe482240 59 * Build all the data structures needed to build the form.
6a488035
TO
60 *
61 * @return void
6a488035 62 */
00be9182 63 public function preProcess() {
c490a46a 64 // initialize the task and row fields
6a488035
TO
65 parent::preProcess();
66 $session = CRM_Core_Session::singleton();
67 $this->_userContext = $session->readUserContext();
68
b581842f 69 CRM_Utils_System::setTitle(ts('Update multiple memberships'));
6a488035
TO
70
71 $validate = FALSE;
72 //validations
73 if (count($this->_memberIds) > $this->_maxMembers) {
b581842f 74 CRM_Core_Session::setStatus(ts("The maximum number of members you can select for Update multiple memberships is %1. You have selected %2. Please select fewer members from your search results and try again.", array(
c5c263ca
AH
75 1 => $this->_maxMembers,
76 2 => count($this->_memberIds),
77 )), ts('Update multiple records error'), 'error');
6a488035
TO
78 $validate = TRUE;
79 }
80
81 // than redirect
82 if ($validate) {
83 CRM_Utils_System::redirect($this->_userContext);
84 }
85 }
86
87 /**
fe482240 88 * Build the form object.
6a488035 89 *
6a488035
TO
90 *
91 * @return void
92 */
00be9182 93 public function buildQuickForm() {
6a488035
TO
94 $types = array('Membership');
95 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
96
97 if (empty($profiles)) {
ec5b3633 98 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 memberships. Navigate to Administer CiviCRM >> CiviCRM Profile to configure a Profile. Consult the online Administrator documentation for more information.", array(1 => $types[0])), ts('Update multiple records error'), 'error');
6a488035
TO
99 CRM_Utils_System::redirect($this->_userContext);
100 }
101
102 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
103 array(
87a890cc 104 '' => ts('- select profile -'),
353ffa53 105 ) + $profiles, TRUE
6a488035 106 );
f212d37d 107 $this->addDefaultButtons(ts('Continue'));
6a488035
TO
108 }
109
110 /**
fe482240 111 * Add local and global form rules.
6a488035 112 *
6a488035
TO
113 *
114 * @return void
115 */
00be9182 116 public function addRules() {
6a488035
TO
117 $this->addFormRule(array('CRM_Member_Form_Task_PickProfile', 'formRule'));
118 }
119
120 /**
fe482240 121 * Global validation rules for the form.
6a488035 122 *
b2363ea8
TO
123 * @param array $fields
124 * Posted values of the form.
6a488035 125 *
a6c01b45
CW
126 * @return array
127 * list of errors to be posted back to the form
6a488035 128 */
00be9182 129 public static function formRule($fields) {
6a488035
TO
130 return TRUE;
131 }
132
133 /**
fe482240 134 * Process the form after the input has been submitted and validated.
6a488035 135 *
6a488035 136 *
355ba699 137 * @return void
6a488035
TO
138 */
139 public function postProcess() {
140 $params = $this->exportValues();
141
142 $this->set('ufGroupId', $params['uf_group_id']);
143
144 // also reset the batch page so it gets new values from the db
145 $this->controller->resetPage('Batch');
146 }
96025800 147
6a488035 148}