Merge pull request #3179 from webpartners/master
[civicrm-core.git] / CRM / Core / Controller / Simple.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 * 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
35 * @copyright CiviCRM LLC (c) 2004-2014
36 * $Id$
37 *
38 */
39 class CRM_Core_Controller_Simple extends CRM_Core_Controller {
40
41 /**
42 * constructor
43 *
44 * @param null $path
45 * @param bool $title
46 * @param string path the class Path of the form being implemented
47 * @param bool $imageUpload
48 * @param bool $addSequence
49 * @param bool $ignoreKey
50 * @param bool $attachUpload
51 *
52 * @internal param \addSequence $boolean should we add a unique sequence number to the end of the key
53 * @internal param \ignoreKey $boolean should we not set a qfKey for this controller (for standalone forms)
54 *
55 * @return \CRM_Core_Controller_Simple
56 @access public
57 */
58 function __construct(
59 $path,
60 $title,
61 $mode = NULL,
62 $imageUpload = FALSE,
63 $addSequence = FALSE,
64 $ignoreKey = FALSE,
65 $attachUpload = FALSE
66 ) {
67 // by definition a single page is modal :). We use the form name as the scope for this controller
68 parent::__construct($title, TRUE, $mode, $path, $addSequence, $ignoreKey);
69
70 $this->_stateMachine = new CRM_Core_StateMachine($this);
71
72 $params = array($path => NULL);
73
74 $savedAction = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL);
75 if (!empty($savedAction) &&
76 $savedAction != $mode
77 ) {
78 $mode = $savedAction;
79 }
80
81
82 $this->_stateMachine->addSequentialPages($params, $mode);
83
84 $this->addPages($this->_stateMachine, $mode);
85
86 //changes for custom data type File
87 $uploadNames = $this->get('uploadNames');
88
89 $config = CRM_Core_Config::singleton();
90
91 if (is_array($uploadNames) && !empty($uploadNames)) {
92 $uploadArray = $uploadNames;
93 $this->addActions($config->customFileUploadDir, $uploadArray);
94 $this->set('uploadNames', NULL);
95 }
96 else {
97 // always allow a single upload file with same name
98 if ($attachUpload) {
99 $this->addActions($config->uploadDir,
100 CRM_Core_BAO_File::uploadNames()
101 );
102 }
103 elseif ($imageUpload) {
104 $this->addActions($config->imageUploadDir, array('uploadFile'));
105 }
106 else {
107 $this->addActions();
108 }
109 }
110 }
111
112 /**
113 * @param $parent
114 */
115 public function setParent($parent) {
116 $this->_parent = $parent;
117 }
118
119 /**
120 * @return mixed
121 */
122 public function getTemplateFileName() {
123 // there is only one form here, so should be quite easy
124 $actionName = $this->getActionName();
125 list($pageName, $action) = $actionName;
126
127 return $this->_pages[$pageName]->getTemplateFileName();
128 }
129
130 /**
131 * A wrapper for getTemplateFileName that includes calling the hook to
132 * prevent us from having to copy & paste the logic of calling the hook
133 */
134 function getHookedTemplateFileName() {
135 $pageTemplateFile = $this->getTemplateFileName();
136 CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile);
137 return $pageTemplateFile;
138 }
139 }
140