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 | 11 | |
6a488035 | 12 | /** |
31aaf096 MW |
13 | * Class for grant form task actions. |
14 | * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions. | |
6a488035 | 15 | */ |
31aaf096 | 16 | class CRM_Grant_Form_Task extends CRM_Core_Form_Task { |
6a488035 TO |
17 | |
18 | /** | |
fe482240 | 19 | * The array that holds all the grant ids. |
6a488035 TO |
20 | * |
21 | * @var array | |
22 | */ | |
23 | protected $_grantIds; | |
24 | ||
25 | /** | |
fe482240 | 26 | * Build all the data structures needed to build the form. |
6a488035 TO |
27 | * |
28 | * @param | |
29 | * | |
30 | * @return void | |
95ea96be | 31 | */ |
608e6658 | 32 | public function preProcess() { |
6a488035 TO |
33 | self::preProcessCommon($this); |
34 | } | |
35 | ||
e0ef6999 | 36 | /** |
2d09a0c3 | 37 | * @param \CRM_Core_Form_Task $form |
38 | * | |
39 | * @throws \CRM_Core_Exception | |
e0ef6999 | 40 | */ |
2b089ce1 | 41 | public static function preProcessCommon(&$form) { |
be2fb01f | 42 | $form->_grantIds = []; |
6a488035 | 43 | |
2d09a0c3 | 44 | $values = $form->getSearchFormValues(); |
6a488035 TO |
45 | |
46 | $form->_task = $values['task']; | |
7b9bce60 MW |
47 | $tasks = CRM_Grant_Task::tasks(); |
48 | if (!array_key_exists($form->_task, $tasks)) { | |
49 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); | |
50 | } | |
6a488035 | 51 | |
be2fb01f | 52 | $ids = []; |
6a488035 TO |
53 | if ($values['radio_ts'] == 'ts_sel') { |
54 | foreach ($values as $name => $value) { | |
55 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
56 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
57 | } | |
58 | } | |
59 | } | |
60 | else { | |
61 | $queryParams = $form->get('queryParams'); | |
1afc557a | 62 | $sortOrder = NULL; |
353ffa53 | 63 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { |
481a74f4 | 64 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); |
6a488035 TO |
65 | } |
66 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
67 | CRM_Contact_BAO_Query::MODE_GRANT | |
68 | ); | |
69 | $query->_distinctComponentClause = ' civicrm_grant.id'; | |
70 | $query->_groupByComponentClause = ' GROUP BY civicrm_grant.id '; | |
71 | $result = $query->searchQuery(0, 0, $sortOrder); | |
72 | while ($result->fetch()) { | |
73 | $ids[] = $result->grant_id; | |
74 | } | |
75 | } | |
76 | ||
77 | if (!empty($ids)) { | |
78 | $form->_componentClause = ' civicrm_grant.id IN ( ' . implode(',', $ids) . ' ) '; | |
79 | $form->assign('totalSelectedGrants', count($ids)); | |
80 | } | |
81 | ||
82 | $form->_grantIds = $form->_componentIds = $ids; | |
83 | ||
188bf7c3 | 84 | $form->setNextUrl('grant'); |
6a488035 TO |
85 | } |
86 | ||
87 | /** | |
88 | * Given the grant id, compute the contact id | |
89 | * since its used for things like send email | |
90 | */ | |
91 | public function setContactIDs() { | |
5d0cc3e0 | 92 | $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_grantIds, |
6a488035 TO |
93 | 'civicrm_grant' |
94 | ); | |
95 | } | |
96 | ||
97 | /** | |
fe482240 | 98 | * Simple shell that derived classes can call to add buttons to. |
6a488035 TO |
99 | * the form with a customized title for the main Submit |
100 | * | |
85511635 TO |
101 | * @param string $title |
102 | * Title of the main button. | |
77b97be7 EM |
103 | * @param string $nextType |
104 | * @param string $backType | |
105 | * | |
ea3ddccf | 106 | * @param bool $submitOnce |
6a488035 | 107 | */ |
00be9182 | 108 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
be2fb01f | 109 | $this->addButtons([ |
7e8c8317 SL |
110 | [ |
111 | 'type' => $nextType, | |
112 | 'name' => $title, | |
113 | 'isDefault' => TRUE, | |
114 | ], | |
115 | [ | |
116 | 'type' => $backType, | |
117 | 'name' => ts('Cancel'), | |
118 | ], | |
119 | ]); | |
6a488035 | 120 | } |
96025800 | 121 | |
6a488035 | 122 | } |