CRM-21406 - Standalone export form
[civicrm-core.git] / CRM / Export / Controller / Standalone.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class CRM_Export_Controller_Standalone
30 */
31 class CRM_Export_Controller_Standalone extends CRM_Core_Controller {
32
33 /**
34 * Class constructor.
35 *
36 * @param string $title
37 * @param bool|int $action
38 * @param bool $modal
39 */
40 public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
41
42 parent::__construct($title, $modal);
43
44 $entity = ucfirst(CRM_Utils_Request::retrieve('entity', 'String', $this, TRUE));
45 $this->set('entity', $entity);
46 $id = explode(',', CRM_Utils_Request::retrieve('id', 'CommaSeparatedIntegers', $this, TRUE));
47
48 // Check permissions
49 $perm = civicrm_api3($entity, 'get', array(
50 'return' => 'id',
51 'options' => array('limit' => 0),
52 'check_permissions' => 1,
53 'id' => array('IN' => $id),
54 ));
55
56 $this->set('id', implode(',', array_keys($perm['values'])));
57 if ($entity == 'Contact') {
58 $this->set('cids', implode(',', array_keys($perm['values'])));
59 }
60
61 $this->_stateMachine = new CRM_Export_StateMachine_Standalone($this, $action);
62
63 // create and instantiate the pages
64 $this->addPages($this->_stateMachine, $action);
65
66 // add all the actions
67 $this->addActions();
68 }
69
70 /**
71 *
72 *
73 * @param string $pageName
74 * @return array
75 */
76 public function exportValues($pageName = NULL) {
77 $values = parent::exportValues();
78 $values['radio_ts'] = 'ts_sel';
79 foreach (explode(',', $this->get('id')) as $id) {
80 if ($id) {
81 $values[CRM_Core_Form::CB_PREFIX . $id] = 1;
82 }
83 }
84 $className = 'CRM_' . $this->get('entity') . '_Task';
85 foreach ($className::tasks() as $taskId => $task) {
86 $taskForm = (array) $task['class'];
87 if ($taskForm[0] == 'CRM_Export_Form_Select') {
88 $values['task'] = $taskId;
89 }
90 }
91 return $values;
92 }
93
94 }