Various phpdoc fixes
[civicrm-core.git] / CRM / Core / Controller / Simple.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
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
19 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 */
21 class CRM_Core_Controller_Simple extends CRM_Core_Controller {
22
23 /**
24 * Constructor.
25 *
26 * @param string $path
27 * The class Path of the form being implemented
28 * @param bool $title
29 * @param string $mode
30 * @param bool $imageUpload
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).
35 * @param bool $attachUpload
36 *
37 * @return \CRM_Core_Controller_Simple
38 */
39 public function __construct(
40 $path,
41 $title,
42 $mode = NULL,
43 $imageUpload = FALSE,
44 $addSequence = FALSE,
45 $ignoreKey = FALSE,
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
53 $params = [$path => NULL];
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
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) {
84 $this->addActions($config->imageUploadDir, ['uploadFile']);
85 }
86 else {
87 $this->addActions();
88 }
89 }
90 }
91
92 /**
93 * Set parent.
94 *
95 * @param $parent
96 */
97 public function setParent($parent) {
98 $this->_parent = $parent;
99 }
100
101 /**
102 * Get template file name.
103 *
104 * @return string
105 */
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 }
113
114 /**
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
119 */
120 public function getHookedTemplateFileName() {
121 $pageTemplateFile = $this->getTemplateFileName();
122 CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile);
123 return $pageTemplateFile;
124 }
125
126 }