From: eileen Date: Tue, 6 Apr 2021 11:07:40 +0000 (+1200) Subject: Expose the receipt action for standalone or searchkit use X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=813e32efc234f08517c130602ecebf6a32a0819d;p=civicrm-core.git Expose the receipt action for standalone or searchkit use Adds controller for id based tasks Supports a url like https://dmaster.localhost:32353/civicrm/contribute/task?task=receipt&id=40,41 Note the pdf option doesn't work in pop-up mode - to discuss Also note this exposes it as an action on the contribution results. That's optional. I think it has been requested / would be useful but it's mostly included to make the page accessible for testing and to work through the issue around filtering - the action only works on some statuses --- diff --git a/CRM/Contribute/Controller/Task.php b/CRM/Contribute/Controller/Task.php new file mode 100644 index 0000000000..49e2d600db --- /dev/null +++ b/CRM/Contribute/Controller/Task.php @@ -0,0 +1,52 @@ +_componentClause}"; parent::setContactIDs(); CRM_Utils_System::appendBreadCrumb($breadCrumb); CRM_Utils_System::setTitle(ts('Print Contribution Receipts')); + // Ajax submit would interfere with pdf file download + $this->preventAjaxSubmit(); } /** diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 010d05116d..4e745c54bd 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -353,6 +353,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C $qfKey, $componentContext ); + $checkLineItem = FALSE; $row = []; // Now check for lineItems @@ -445,6 +446,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C 'title' => $buttonName, ]; } + $links = $links + CRM_Contribute_Task::getContextualLinks($row); $row['action'] = CRM_Core_Action::formLink( $links, diff --git a/CRM/Contribute/Task.php b/CRM/Contribute/Task.php index eb9c057d70..01dad553a9 100644 --- a/CRM/Contribute/Task.php +++ b/CRM/Contribute/Task.php @@ -89,6 +89,12 @@ class CRM_Contribute_Task extends CRM_Core_Task { 'title' => ts('Receipts - print or email'), 'class' => 'CRM_Contribute_Form_Task_PDF', 'result' => FALSE, + 'title_single_mode' => ts('Send Receipt'), + 'name' => ts('Send Receipt'), + 'is_support_standalone' => TRUE, + 'key' => 'receipt', + 'filters' => ['contribution_status_id' => [CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed')]], + 'is_single_mode' => TRUE, ], self::PDF_THANKYOU => [ 'title' => ts('Thank-you letters - print or email'), @@ -123,6 +129,35 @@ class CRM_Contribute_Task extends CRM_Core_Task { return self::$_tasks; } + /** + * Get links appropriate to the context of the row. + * + * @param $row + * + * @return array + */ + public static function getContextualLinks($row) { + $tasks = self::tasks(); + foreach ($tasks as $key => $task) { + if (empty($task['is_single_mode'])) { + unset($tasks[$key]); + continue; + } + if (!empty($task['filters'])) { + foreach ($task['filters'] as $filter => $values) { + if (!in_array($row[$filter], $values, FALSE)) { + unset($tasks[$key]); + continue 2; + } + } + } + $tasks[$key]['url'] = 'civicrm/contribute/task'; + $tasks[$key]['qs'] = ['reset' => 1, 'id' => $row['contribution_id'], 'task' => $task['key']]; + $tasks[$key]['title'] = $task['title_single_mode'] ?? $task['title']; + } + return $tasks; + } + /** * Show tasks selectively based on the permission level * of the user diff --git a/CRM/Contribute/xml/Menu/Contribute.xml b/CRM/Contribute/xml/Menu/Contribute.xml index 7aacf023b3..9409e579bf 100644 --- a/CRM/Contribute/xml/Menu/Contribute.xml +++ b/CRM/Contribute/xml/Menu/Contribute.xml @@ -337,4 +337,10 @@ 0 true + + civicrm/contribute/task + Contribution Task + CRM_Contribute_Controller_Task + access CiviContribute + diff --git a/CRM/Core/Controller/Task.php b/CRM/Core/Controller/Task.php new file mode 100644 index 0000000000..5af9740b65 --- /dev/null +++ b/CRM/Core/Controller/Task.php @@ -0,0 +1,84 @@ +getEntity(), 'get', [ + 'return' => 'id', + 'options' => ['limit' => 0], + 'check_permissions' => 1, + 'id' => ['IN' => $id], + ])['values']; + if (empty($perm)) { + throw new CRM_Core_Exception(ts('No records available')); + } + $this->set('id', implode(',', array_keys($perm))); + $pages = array_fill_keys($this->getTaskClass(), NULL); + + $this->_stateMachine = new CRM_Core_StateMachine($this); + $this->_stateMachine->addSequentialPages($pages); + // create and instantiate the pages + $this->addPages($this->_stateMachine, $action); + // add all the actions + $this->addActions(); + } + + /** + * Get the name used to construct the class. + * + * @return string + */ + abstract public function getEntity():string; + + /** + * Get the available tasks for the entity. + * + * @return array + */ + abstract public function getAvailableTasks():array; + + /** + * Get the class for the action. + * + * @return array Array of the classes for the form controlle. + * + * @throws \CRM_Core_Exception + */ + protected function getTaskClass(): array { + $task = CRM_Utils_Request::retrieve('task', 'Alphanumeric', $this, TRUE); + foreach ($this->getAvailableTasks() as $taskAction) { + if (($taskAction['key'] ?? '') === $task) { + return (array) $taskAction['class']; + } + } + throw new CRM_Core_Exception(ts('Invalid task')); + } + +}