3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
13 * Class for grant form task actions.
14 * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
16 class CRM_Grant_Form_Task
extends CRM_Core_Form_Task
{
19 * The array that holds all the grant ids.
26 * Build all the data structures needed to build the form.
32 public function preProcess() {
33 self
::preProcessCommon($this);
37 * @param \CRM_Core_Form_Task $form
39 * @throws \CRM_Core_Exception
41 public static function preProcessCommon(&$form) {
42 $form->_grantIds
= [];
44 $values = $form->getSearchFormValues();
46 $form->_task
= $values['task'];
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.'));
51 $form->assign('taskName', $tasks[$form->_task
]);
54 if ($values['radio_ts'] == 'ts_sel') {
55 foreach ($values as $name => $value) {
56 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
57 $ids[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
62 $queryParams = $form->get('queryParams');
64 if ($form->get(CRM_Utils_Sort
::SORT_ORDER
)) {
65 $sortOrder = $form->get(CRM_Utils_Sort
::SORT_ORDER
);
67 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
68 CRM_Contact_BAO_Query
::MODE_GRANT
70 $query->_distinctComponentClause
= ' civicrm_grant.id';
71 $query->_groupByComponentClause
= ' GROUP BY civicrm_grant.id ';
72 $result = $query->searchQuery(0, 0, $sortOrder);
73 while ($result->fetch()) {
74 $ids[] = $result->grant_id
;
79 $form->_componentClause
= ' civicrm_grant.id IN ( ' . implode(',', $ids) . ' ) ';
80 $form->assign('totalSelectedGrants', count($ids));
83 $form->_grantIds
= $form->_componentIds
= $ids;
85 //set the context for redirection for any task actions
86 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $form);
87 $urlParams = 'force=1';
88 if (CRM_Utils_Rule
::qfKey($qfKey)) {
89 $urlParams .= "&qfKey=$qfKey";
92 $session = CRM_Core_Session
::singleton();
93 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/grant/search', $urlParams));
97 * Given the grant id, compute the contact id
98 * since its used for things like send email
100 public function setContactIDs() {
101 $this->_contactIds
= CRM_Core_DAO
::getContactIDsFromComponent($this->_grantIds
,
107 * Simple shell that derived classes can call to add buttons to.
108 * the form with a customized title for the main Submit
110 * @param string $title
111 * Title of the main button.
112 * @param string $nextType
113 * @param string $backType
115 * @param bool $submitOnce
117 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
126 'name' => ts('Cancel'),