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 | /** | |
31aaf096 MW |
19 | * Class for member form task actions. |
20 | * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions. | |
6a488035 | 21 | */ |
31aaf096 | 22 | class CRM_Member_Form_Task extends CRM_Core_Form_Task { |
6a488035 TO |
23 | |
24 | /** | |
fe482240 | 25 | * The array that holds all the member ids. |
6a488035 TO |
26 | * |
27 | * @var array | |
28 | */ | |
29 | protected $_memberIds; | |
30 | ||
31 | /** | |
fe482240 | 32 | * Build all the data structures needed to build the form. |
6a488035 TO |
33 | * |
34 | * @param | |
35 | * | |
36 | * @return void | |
7da29bae | 37 | * @throws \CRM_Core_Exception |
6a488035 | 38 | */ |
00be9182 | 39 | public function preProcess() { |
6a488035 TO |
40 | self::preProcessCommon($this); |
41 | } | |
42 | ||
bb3a214a | 43 | /** |
2d09a0c3 | 44 | * @param \CRM_Core_Form_Task $form |
7da29bae | 45 | * |
46 | * @throws \CRM_Core_Exception | |
bb3a214a | 47 | */ |
2b089ce1 | 48 | public static function preProcessCommon(&$form) { |
be2fb01f | 49 | $form->_memberIds = []; |
6a488035 | 50 | |
2d09a0c3 | 51 | $values = $form->getSearchFormValues(); |
6a488035 TO |
52 | |
53 | $form->_task = $values['task']; | |
e335ab3b MW |
54 | $tasks = CRM_Member_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()); |
55 | if (!array_key_exists($form->_task, $tasks)) { | |
56 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); | |
57 | } | |
6a488035 | 58 | |
56752ec0 | 59 | $ids = $form->getSelectedIDs($values); |
60 | ||
61 | if (!$ids) { | |
6a488035 | 62 | $queryParams = $form->get('queryParams'); |
b09fe5ed | 63 | $sortOrder = NULL; |
353ffa53 | 64 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { |
481a74f4 | 65 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); |
6a488035 TO |
66 | } |
67 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
68 | CRM_Contact_BAO_Query::MODE_MEMBER | |
69 | ); | |
70 | $query->_distinctComponentClause = ' civicrm_membership.id'; | |
71 | $query->_groupByComponentClause = ' GROUP BY civicrm_membership.id '; | |
72 | $result = $query->searchQuery(0, 0, $sortOrder); | |
73 | ||
74 | while ($result->fetch()) { | |
75 | $ids[] = $result->membership_id; | |
76 | } | |
77 | } | |
78 | ||
79 | if (!empty($ids)) { | |
80 | $form->_componentClause = ' civicrm_membership.id IN ( ' . implode(',', $ids) . ' ) '; | |
81 | $form->assign('totalSelectedMembers', count($ids)); | |
82 | } | |
83 | ||
84 | $form->_memberIds = $form->_componentIds = $ids; | |
188bf7c3 | 85 | $form->setNextUrl('member'); |
6a488035 TO |
86 | } |
87 | ||
88 | /** | |
89 | * Given the membership id, compute the contact id | |
90 | * since its used for things like send email | |
91 | */ | |
92 | public function setContactIDs() { | |
41d0a2e7 | 93 | $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_memberIds, |
6a488035 TO |
94 | 'civicrm_membership' |
95 | ); | |
96 | } | |
97 | ||
601c941f EM |
98 | /** |
99 | * Get the token processor schema required to list any tokens for this task. | |
100 | * | |
101 | * @return array | |
102 | */ | |
103 | public function getTokenSchema(): array { | |
104 | return ['membershipId', 'contactId']; | |
105 | } | |
106 | ||
6a488035 | 107 | } |