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 CRM_Export_Controller_Standalone
15 abstract class CRM_Core_Controller_Task
extends CRM_Core_Controller
{
20 * @param string $title
21 * @param bool|int $action
24 * @throws \CRM_Core_Exception
25 * @throws \CiviCRM_API3_Exception
27 public function __construct($title = NULL, $action = CRM_Core_Action
::NONE
, $modal = TRUE) {
29 parent
::__construct($title, $modal);
30 $id = explode(',', CRM_Utils_Request
::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE));
33 $perm = civicrm_api3($this->getEntity(), 'get', [
35 'options' => ['limit' => 0],
36 'check_permissions' => 1,
37 'id' => ['IN' => $id],
40 throw new CRM_Core_Exception(ts('No records available'));
42 $this->set('id', implode(',', array_keys($perm)));
43 $pages = array_fill_keys($this->getTaskClass(), NULL);
45 $this->_stateMachine
= new CRM_Core_StateMachine($this);
46 $this->_stateMachine
->addSequentialPages($pages);
47 // create and instantiate the pages
48 $this->addPages($this->_stateMachine
, $action);
49 // add all the actions
54 * Get the name used to construct the class.
58 abstract public function getEntity():string;
61 * Get the available tasks for the entity.
65 abstract public function getAvailableTasks():array;
68 * Get the class for the action.
70 * @return array Array of the classes for the form controlle.
72 * @throws \CRM_Core_Exception
74 protected function getTaskClass(): array {
75 $task = CRM_Utils_Request
::retrieve('task_item', 'Alphanumeric', $this);
77 $task = CRM_Utils_Request
::retrieve('task', 'Alphanumeric', $this, TRUE);
79 foreach ($this->getAvailableTasks() as $taskAction) {
80 if (($taskAction['key'] ??
'') === $task) {
81 return (array) $taskAction['class'];
84 throw new CRM_Core_Exception(ts('Invalid task'));