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