Commit | Line | Data |
---|---|---|
78b22ce9 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
78b22ce9 | 5 | | | |
bc77d7c0 TO |
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 | | |
78b22ce9 CW |
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 | |
be2fb01f | 33 | $perm = civicrm_api3($entity, 'get', [ |
78b22ce9 | 34 | 'return' => 'id', |
be2fb01f | 35 | 'options' => ['limit' => 0], |
78b22ce9 | 36 | 'check_permissions' => 1, |
be2fb01f CW |
37 | 'id' => ['IN' => $id], |
38 | ]); | |
78b22ce9 CW |
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 | /** | |
f227c593 CW |
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. | |
78b22ce9 CW |
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 | } | |
f227c593 | 69 | // Set the "task" selector value to Export |
78b22ce9 CW |
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 | } |