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