--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Class CRM_Export_Controller_Standalone
+ */
+class CRM_Contribute_Controller_Task extends CRM_Core_Controller_Task {
+
+ /**
+ * Get the name used to construct the class.
+ *
+ * @return string
+ */
+ public function getEntity():string {
+ return 'Contribution';
+ }
+
+ /**
+ * Get the available tasks for the entity.
+ *
+ * @return array
+ */
+ public function getAvailableTasks():array {
+ return CRM_Contribute_Task::tasks();
+ }
+
+ /**
+ * Override parent to avoid e-notice if the page is 'Search'.
+ *
+ * There are no form values for Search when the standalone processor is used
+ * - move along.
+ *
+ * @param string $pageName
+ *
+ * @return array
+ */
+ public function exportValues($pageName = NULL) {
+ if ($pageName === 'Search') {
+ return [];
+ }
+ return parent::exportValues($pageName);
+ }
+
+}
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();
}
/**
$qfKey,
$componentContext
);
+
$checkLineItem = FALSE;
$row = [];
// Now check for lineItems
'title' => $buttonName,
];
}
+ $links = $links + CRM_Contribute_Task::getContextualLinks($row);
$row['action'] = CRM_Core_Action::formLink(
$links,
'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'),
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
<weight>0</weight>
<is_public>true</is_public>
</item>
+ <item>
+ <path>civicrm/contribute/task</path>
+ <title>Contribution Task</title>
+ <page_callback>CRM_Contribute_Controller_Task</page_callback>
+ <access_arguments>access CiviContribute</access_arguments>
+ </item>
</menu>
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * Class CRM_Export_Controller_Standalone
+ */
+abstract class CRM_Core_Controller_Task extends CRM_Core_Controller {
+
+ /**
+ * Class constructor.
+ *
+ * @param string $title
+ * @param bool|int $action
+ * @param bool $modal
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ */
+ public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
+
+ parent::__construct($title, $modal);
+ $id = explode(',', CRM_Utils_Request::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE));
+
+ // Check permissions
+ $perm = civicrm_api3($this->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'));
+ }
+
+}