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