Merge pull request #15978 from civicrm/5.20
[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 }
53
54 /**
55 * Export forms are historically tightly coupled to search forms,so this simulates
56 * the output of a search form, with an array of checkboxes for each selected entity.
57 *
58 * @param string $pageName
59 * @return array
60 */
61 public function exportValues($pageName = NULL) {
62 $values = parent::exportValues();
63 $values['radio_ts'] = 'ts_sel';
64 foreach (explode(',', $this->get('id')) as $id) {
65 if ($id) {
66 $values[CRM_Core_Form::CB_PREFIX . $id] = 1;
67 }
68 }
69 // Set the "task" selector value to Export
70 $className = 'CRM_' . $this->get('entity') . '_Task';
71 foreach ($className::tasks() as $taskId => $task) {
72 $taskForm = (array) $task['class'];
73 if ($taskForm[0] == 'CRM_Export_Form_Select') {
74 $values['task'] = $taskId;
75 }
76 }
77 return $values;
78 }
79
80 }