Merge pull request #23080 from eileenmcnaughton/isset
[civicrm-core.git] / CRM / Member / Form / Task / PickProfile.php
CommitLineData
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/**
19 * This class provides the functionality for batch profile update for membership
20 */
21class CRM_Member_Form_Task_PickProfile extends CRM_Member_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 members that should be allowed to update
971e129b 32 * @var int
6a488035
TO
33 */
34 protected $_maxMembers = 100;
35
36 /**
100fef9d 37 * Variable to store redirect path
971e129b 38 * @var string
6a488035
TO
39 */
40 protected $_userContext;
41
42 /**
fe482240 43 * Build all the data structures needed to build the form.
6a488035
TO
44 *
45 * @return void
6a488035 46 */
00be9182 47 public function preProcess() {
c490a46a 48 // initialize the task and row fields
6a488035
TO
49 parent::preProcess();
50 $session = CRM_Core_Session::singleton();
51 $this->_userContext = $session->readUserContext();
52
203b4734 53 $this->setTitle(ts('Update multiple memberships'));
6a488035
TO
54
55 $validate = FALSE;
56 //validations
57 if (count($this->_memberIds) > $this->_maxMembers) {
be2fb01f 58 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.", [
c5c263ca
AH
59 1 => $this->_maxMembers,
60 2 => count($this->_memberIds),
be2fb01f 61 ]), ts('Update multiple records error'), 'error');
6a488035
TO
62 $validate = TRUE;
63 }
64
65 // than redirect
66 if ($validate) {
67 CRM_Utils_System::redirect($this->_userContext);
68 }
69 }
70
71 /**
fe482240 72 * Build the form object.
6a488035 73 *
6a488035
TO
74 *
75 * @return void
76 */
00be9182 77 public function buildQuickForm() {
be2fb01f 78 $types = ['Membership'];
6a488035
TO
79 $profiles = CRM_Core_BAO_UFGroup::getProfiles($types, TRUE);
80
81 if (empty($profiles)) {
be2fb01f 82 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.", [1 => $types[0]]), ts('Update multiple records error'), 'error');
6a488035
TO
83 CRM_Utils_System::redirect($this->_userContext);
84 }
85
86 $ufGroupElement = $this->add('select', 'uf_group_id', ts('Select Profile'),
be2fb01f 87 [
87a890cc 88 '' => ts('- select profile -'),
be2fb01f 89 ] + $profiles, TRUE
6a488035 90 );
f212d37d 91 $this->addDefaultButtons(ts('Continue'));
6a488035
TO
92 }
93
94 /**
fe482240 95 * Add local and global form rules.
6a488035 96 *
6a488035
TO
97 *
98 * @return void
99 */
00be9182 100 public function addRules() {
be2fb01f 101 $this->addFormRule(['CRM_Member_Form_Task_PickProfile', 'formRule']);
6a488035
TO
102 }
103
104 /**
fe482240 105 * Global validation rules for the form.
6a488035 106 *
b2363ea8
TO
107 * @param array $fields
108 * Posted values of the form.
6a488035 109 *
a6c01b45
CW
110 * @return array
111 * list of errors to be posted back to the form
6a488035 112 */
00be9182 113 public static function formRule($fields) {
6a488035
TO
114 return TRUE;
115 }
116
117 /**
fe482240 118 * Process the form after the input has been submitted and validated.
6a488035 119 *
6a488035 120 *
355ba699 121 * @return void
6a488035
TO
122 */
123 public function postProcess() {
124 $params = $this->exportValues();
125
126 $this->set('ufGroupId', $params['uf_group_id']);
127
128 // also reset the batch page so it gets new values from the db
129 $this->controller->resetPage('Batch');
130 }
96025800 131
6a488035 132}