| 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 | * $Id$ |
| 21 | */ |
| 22 | class CRM_Core_Controller_Simple extends CRM_Core_Controller { |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | * |
| 27 | * @param null $path |
| 28 | * The class Path of the form being implemented |
| 29 | * @param bool $title |
| 30 | * @param string $mode |
| 31 | * @param bool $imageUpload |
| 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). |
| 36 | * @param bool $attachUpload |
| 37 | * |
| 38 | * @return \CRM_Core_Controller_Simple |
| 39 | */ |
| 40 | public function __construct( |
| 41 | $path, |
| 42 | $title, |
| 43 | $mode = NULL, |
| 44 | $imageUpload = FALSE, |
| 45 | $addSequence = FALSE, |
| 46 | $ignoreKey = FALSE, |
| 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 | |
| 54 | $params = [$path => NULL]; |
| 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 | |
| 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) { |
| 85 | $this->addActions($config->imageUploadDir, ['uploadFile']); |
| 86 | } |
| 87 | else { |
| 88 | $this->addActions(); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Set parent. |
| 95 | * |
| 96 | * @param $parent |
| 97 | */ |
| 98 | public function setParent($parent) { |
| 99 | $this->_parent = $parent; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get template file name. |
| 104 | * |
| 105 | * @return string |
| 106 | */ |
| 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 | } |
| 114 | |
| 115 | /** |
| 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 |
| 120 | */ |
| 121 | public function getHookedTemplateFileName() { |
| 122 | $pageTemplateFile = $this->getTemplateFileName(); |
| 123 | CRM_Utils_Hook::alterTemplateFile(get_class($this), $this, 'page', $pageTemplateFile); |
| 124 | return $pageTemplateFile; |
| 125 | } |
| 126 | |
| 127 | } |