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