Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * We use QFC for both single page and multi page wizards. We want to make | |
30 | * creation of single page forms as easy and as seamless as possible. This | |
31 | * class is used to optimize and make single form pages a relatively trivial | |
32 | * process | |
33 | * | |
34 | * @package CRM | |
f299f7db | 35 | * @copyright CiviCRM LLC (c) 2004-2020 |
6a488035 | 36 | * $Id$ |
6a488035 TO |
37 | */ |
38 | class CRM_Core_Controller_Simple extends CRM_Core_Controller { | |
39 | ||
40 | /** | |
ee0ce2ef | 41 | * Constructor. |
6a488035 | 42 | * |
77b97be7 | 43 | * @param null $path |
db7de9c1 | 44 | * The class Path of the form being implemented |
77b97be7 | 45 | * @param bool $title |
db7de9c1 | 46 | * @param string $mode |
77b97be7 | 47 | * @param bool $imageUpload |
6a0b768e TO |
48 | * @param bool $addSequence |
49 | * Should we add a unique sequence number to the end of the key. | |
50 | * @param bool $ignoreKey | |
51 | * Should we not set a qfKey for this controller (for standalone forms). | |
77b97be7 | 52 | * @param bool $attachUpload |
6a488035 | 53 | * |
77b97be7 | 54 | * @return \CRM_Core_Controller_Simple |
6a488035 | 55 | */ |
d8689418 | 56 | public function __construct( |
6a488035 TO |
57 | $path, |
58 | $title, | |
2aa397bc TO |
59 | $mode = NULL, |
60 | $imageUpload = FALSE, | |
61 | $addSequence = FALSE, | |
62 | $ignoreKey = FALSE, | |
6a488035 TO |
63 | $attachUpload = FALSE |
64 | ) { | |
65 | // by definition a single page is modal :). We use the form name as the scope for this controller | |
66 | parent::__construct($title, TRUE, $mode, $path, $addSequence, $ignoreKey); | |
67 | ||
68 | $this->_stateMachine = new CRM_Core_StateMachine($this); | |
69 | ||
be2fb01f | 70 | $params = [$path => NULL]; |
6a488035 TO |
71 | |
72 | $savedAction = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL); | |
73 | if (!empty($savedAction) && | |
74 | $savedAction != $mode | |
75 | ) { | |
76 | $mode = $savedAction; | |
77 | } | |
78 | ||
6a488035 TO |
79 | $this->_stateMachine->addSequentialPages($params, $mode); |
80 | ||
81 | $this->addPages($this->_stateMachine, $mode); | |
82 | ||
83 | //changes for custom data type File | |
84 | $uploadNames = $this->get('uploadNames'); | |
85 | ||
86 | $config = CRM_Core_Config::singleton(); | |
87 | ||
88 | if (is_array($uploadNames) && !empty($uploadNames)) { | |
89 | $uploadArray = $uploadNames; | |
90 | $this->addActions($config->customFileUploadDir, $uploadArray); | |
91 | $this->set('uploadNames', NULL); | |
92 | } | |
93 | else { | |
94 | // always allow a single upload file with same name | |
95 | if ($attachUpload) { | |
96 | $this->addActions($config->uploadDir, | |
97 | CRM_Core_BAO_File::uploadNames() | |
98 | ); | |
99 | } | |
100 | elseif ($imageUpload) { | |
be2fb01f | 101 | $this->addActions($config->imageUploadDir, ['uploadFile']); |
6a488035 TO |
102 | } |
103 | else { | |
104 | $this->addActions(); | |
105 | } | |
106 | } | |
107 | } | |
108 | ||
a0ee3941 | 109 | /** |
db7de9c1 EM |
110 | * Set parent. |
111 | * | |
a0ee3941 EM |
112 | * @param $parent |
113 | */ | |
6a488035 TO |
114 | public function setParent($parent) { |
115 | $this->_parent = $parent; | |
116 | } | |
117 | ||
a0ee3941 | 118 | /** |
5c9ff055 EM |
119 | * Get template file name. |
120 | * | |
121 | * @return string | |
a0ee3941 | 122 | */ |
6a488035 TO |
123 | public function getTemplateFileName() { |
124 | // there is only one form here, so should be quite easy | |
125 | $actionName = $this->getActionName(); | |
126 | list($pageName, $action) = $actionName; | |
127 | ||
128 | return $this->_pages[$pageName]->getTemplateFileName(); | |
129 | } | |
073aa90f | 130 | |
131 | /** | |
d8689418 EM |
132 | * A wrapper for getTemplateFileName. |
133 | * | |
134 | * This includes calling the hook to prevent us from having to copy & paste | |
135 | * the logic of calling the hook | |
073aa90f | 136 | */ |
00be9182 | 137 | public function getHookedTemplateFileName() { |
073aa90f | 138 | $pageTemplateFile = $this->getTemplateFileName(); |
139 | CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile); | |
140 | return $pageTemplateFile; | |
141 | } | |
96025800 | 142 | |
6a488035 | 143 | } |