DAOs with singular/plural options for entity titles
[civicrm-core.git] / CRM / Export / Controller / Standalone.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Export_Controller_Standalone
14 */
15 class CRM_Export_Controller_Standalone extends CRM_Core_Controller {
16
17 /**
18 * Class constructor.
19 *
20 * @param string $title
21 * @param bool|int $action
22 * @param bool $modal
23 */
24 public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
25
26 parent::__construct($title, $modal);
27
28 $entity = ucfirst(CRM_Utils_Request::retrieve('entity', 'String', $this, TRUE));
29 $this->set('entity', $entity);
30 $id = explode(',', CRM_Utils_Request::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE));
31
32 // Check permissions
33 $perm = civicrm_api3($entity, 'get', [
34 'return' => 'id',
35 'options' => ['limit' => 0],
36 'check_permissions' => 1,
37 'id' => ['IN' => $id],
38 ]);
39
40 $this->set('id', implode(',', array_keys($perm['values'])));
41 if ($entity == 'Contact') {
42 $this->set('cids', implode(',', array_keys($perm['values'])));
43 }
44
45 $this->_stateMachine = new CRM_Export_StateMachine_Standalone($this, $action);
46
47 // create and instantiate the pages
48 $this->addPages($this->_stateMachine, $action);
49
50 // add all the actions
51 $this->addActions();
52 $dao = CRM_Core_DAO_AllCoreTables::getFullName($entity);
53 CRM_Utils_System::setTitle(ts('Export %1', [1 => $dao::getEntityTitle(TRUE)]));
54 }
55
56 /**
57 * Export forms are historically tightly coupled to search forms,so this simulates
58 * the output of a search form, with an array of checkboxes for each selected entity.
59 *
60 * @param string $pageName
61 * @return array
62 */
63 public function exportValues($pageName = NULL) {
64 $values = parent::exportValues();
65 $values['radio_ts'] = 'ts_sel';
66 foreach (explode(',', $this->get('id')) as $id) {
67 if ($id) {
68 $values[CRM_Core_Form::CB_PREFIX . $id] = 1;
69 }
70 }
71 // Set the "task" selector value to Export
72 $className = 'CRM_' . $this->getComponent($this->get('entity')) . '_Task';
73 foreach ($className::tasks() as $taskId => $task) {
74 $taskForm = (array) $task['class'];
75 if ($taskForm[0] == 'CRM_Export_Form_Select') {
76 $values['task'] = $taskId;
77 }
78 }
79 return $values;
80 }
81
82 /**
83 * Get the relevant entity name.
84 *
85 * @return string
86 */
87 public function getComponent() {
88 $components = CRM_Export_BAO_Export::getComponents();
89 return $components[$this->getEntity()];
90 }
91
92 /**
93 * Get the name used to construct the class.
94 *
95 * @return mixed
96 */
97 public function getEntity() {
98 return $this->get('entity');
99 }
100
101 }