Commit 6df03d8e39fd58045b05446cd616c33b363ccd07

Authored by Jarrett Jordaan
1 parent fef6ca29

PT:2492070 : Folder structure creation wizard added

Committed by: Jarrett Jordaan

Reviewed by: Megan Watson
plugins/ktcore/KTFolderActions.php
... ... @@ -79,7 +79,7 @@ class KTFolderAddFolderAction extends KTFolderAction {
79 79  
80 80 function form_main() {
81 81 $oForm = new KTForm;
82   -
  82 +
83 83 $oForm->setOptions(array(
84 84 'context' => &$this,
85 85 'identifier' => 'ktcore.folder.add',
... ... @@ -98,6 +98,7 @@ class KTFolderAddFolderAction extends KTFolderAction {
98 98 'description' => _kt('The name for the new folder.'),
99 99 'required' => true,
100 100 'name' => 'name')),
  101 + $this->folderTemplateOptions(), // Add folder structure creation option
101 102 ));
102 103  
103 104 // Electronic Signature if enabled
... ... @@ -150,10 +151,25 @@ class KTFolderAddFolderAction extends KTFolderAction {
150 151  
151 152 }
152 153  
  154 + /**
  155 + * Create Folder template options for a folder.
  156 + *
  157 + * @return unknown
  158 + */
  159 + function folderTemplateOptions() {
  160 + if (KTPluginUtil::pluginIsActive('fs.FolderTemplatesPlugin.plugin')) { // Check if folder templates plugin is active
  161 + $oRegistry =& KTPluginRegistry::getSingleton();
  162 + $oPlugin =& $oRegistry->getPlugin('fs.FolderTemplatesPlugin.plugin'); // Get a handle on the plugin
  163 + return $oPlugin->getTemplates();
  164 + }
  165 +
  166 + return array();
  167 + }
  168 +
153 169 function do_main() {
154 170 $this->oPage->setBreadcrumbDetails(_kt("add folder"));
155 171 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/addFolder');
156   -
  172 +
157 173 $oForm = $this->form_main();
158 174  
159 175 $oTemplate->setData(array(
... ... @@ -178,15 +194,27 @@ class KTFolderAddFolderAction extends KTFolderAction {
178 194  
179 195 $this->startTransaction();
180 196  
181   - $res = KTFolderUtil::add($this->oFolder, $res['name'], $this->oUser);
  197 + $oFolder = KTFolderUtil::add($this->oFolder, $res['name'], $this->oUser);
182 198  
183 199 $aErrorOptions['defaultmessage'] = _kt("Could not create folder in the document management system");
184 200 $this->oValidator->notError($res, $aErrorOptions);
185 201  
186 202 $this->commitTransaction();
187   - controllerRedirect('browse', sprintf('fFolderId=%d', $res->getId()));
  203 + // On successful creation of a folder
  204 + // Check if a folder template needs to be applied
  205 + // TODO : Get post value templateId properly
  206 + $data = KTUtil::arrayGet($_POST, 'data',0);
  207 + $this->applyTemplate($oFolder->getId(), $data['templateId']);
  208 + controllerRedirect('browse', sprintf('fFolderId=%d', $oFolder->getId()));
  209 +
188 210 exit(0);
189 211 }
  212 +
  213 + function applyTemplate($rootId, $templateId) {
  214 + $oRegistry =& KTPluginRegistry::getSingleton();
  215 + $oPlugin =& $oRegistry->getPlugin('fs.FolderTemplatesPlugin.plugin'); // Get a handle on the plugin
  216 + $oPlugin->applyFolderTemplate($rootId, $templateId);
  217 + }
190 218 }
191 219  
192 220 ?>
... ...