Commit 4672f890d3ce0de363caa642bee4223e33a332e5

Authored by bshuttle
1 parent e6baa95a

fix for KTS-61: assigning workflows to folders.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4712 c91229c3-7414-0410-bfa2-8a42b809f60b
config/tableMappings.inc
... ... @@ -148,4 +148,5 @@ $default->document_metadata_version_table = "document_metadata_version";
148 148 $default->document_content_version_table = "document_content_version";
149 149 $default->trigger_selection_table = "trigger_selection";
150 150 $default->type_workflow_map_table = "type_workflow_map";
  151 +$default->folder_workflow_map_table = "folder_workflow_map";
151 152 ?>
... ...
lib/actions/folderaction.inc.php
... ... @@ -113,7 +113,9 @@ class KTFolderAction extends KTStandardDispatcher {
113 113  
114 114 function check() {
115 115 $this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']);
116   -
  116 +
  117 + if ($this->_disable()) { return false; }
  118 +
117 119 if (!is_null($this->_sShowPermission)) {
118 120 $oPermission =& KTPermission::getByName($this->_sShowPermission);
119 121 if (!PEAR::isError($oPermission)) {
... ... @@ -130,6 +132,12 @@ class KTFolderAction extends KTStandardDispatcher {
130 132 );
131 133 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
132 134 KTBrowseUtil::breadcrumbsForFolder($this->oFolder, $aOptions));
  135 +
  136 + $portlet = new KTActionPortlet(_("Folder Actions"));
  137 + $aActions = KTFolderActionUtil::getFolderActionsForFolder($this->oFolder, $this->oUser);
  138 + $portlet->setActions($aActions,null);
  139 + $this->oPage->addPortlet($portlet);
  140 +
133 141 return true;
134 142 }
135 143  
... ...
lib/templating/kt3template.inc.php
... ... @@ -178,7 +178,8 @@ class KTPage {
178 178 function setSection($sSection) {
179 179 if ($sSection == 'administration') {
180 180 $this->componentLabel = _('DMS Administration');
181   - $this->componentClass = 'administration';
  181 + $this->componentClass = 'administration';
  182 + $this->menu['administration']['active'] = 1;
182 183 } else if ($sSection == 'dashboard') {
183 184 $this->componentLabel = _('Dashboard');
184 185 $this->componentClass = 'dashboard';
... ...
plugins/ktstandard/KTWorkflowAssociation.php
... ... @@ -29,25 +29,22 @@ class KTWorkflowAssociationDelegator {
29 29 var $_document;
30 30  
31 31 function KTWorkflowAssociationDelegator() {
32   -
33 32 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
34 33 $aTriggers = $oKTTriggerRegistry->getTriggers('workflow', 'objectModification');
35   -
  34 +
36 35 // if we have _some_ triggers.
37 36 if (!empty($aTriggers)) {
38 37 $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
39 38 $sQuery .= ' WHERE event_ns = ?';
40 39 $aParams = array('ktstandard.workflowassociation.handler');
41 40 $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
42   -
  41 +
43 42 if (PEAR::isError($res)) { $this->_handler = new KTWorkflowAssociationHandler(); }
44 43  
45 44 if (array_key_exists($res, $aTriggers)) {
46 45 $this->_handler = new $aTriggers[$res][0];
47 46 }
48 47 else {
49   - global $default;
50   - $default->log->debug('KTWorkflowAssociationDelegator failed to acquire trigger selection');
51 48 $this->_handler = new KTWorkflowAssociationHandler();
52 49 }
53 50 }
... ... @@ -109,5 +106,6 @@ $oPluginRegistry->registerPlugin('KTWorkflowAssociationPlugin', 'ktstandard.work
109 106 /* include others */
110 107  
111 108 require_once('workflow/TypeAssociator.php');
  109 +require_once('workflow/FolderAssociator.php');
112 110  
113 111 ?>
... ...
plugins/ktstandard/workflow/FolderAssociator.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once(KT_DIR . '/plugins/ktstandard/KTWorkflowAssociation.php');
  4 +require_once(KT_LIB_DIR . '/workflow/workflow.inc.php');
  5 +require_once(KT_LIB_DIR . '/workflow/workflowutil.inc.php');
  6 +require_once(KT_LIB_DIR . '/dispatcher.inc.php');
  7 +
  8 +require_once(KT_LIB_DIR . '/actions/folderaction.inc.php');
  9 +
  10 +class KTFolderWorkflowAssociationPlugin extends KTPlugin {
  11 + var $sNamespace = "ktstandard.workflowassociation.folder.plugin";
  12 +
  13 + function setup() {
  14 + $this->registerTrigger('workflow', 'objectModification', 'FolderWorkflowAssociator',
  15 + 'ktstandard.triggers.workflowassociation.folder.handler');
  16 +
  17 + $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection');
  18 + $sQuery .= ' WHERE event_ns = ?';
  19 + $aParams = array('ktstandard.workflowassociation.handler');
  20 + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns');
  21 +
  22 + if ($res == 'ktstandard.triggers.workflowassociation.folder.handler') {
  23 + $this->registerAction('folderaction', 'FolderWorkflowAssignmentFolderAction',
  24 + 'ktstandard.workflowassociation.folder.action');
  25 + }
  26 + }
  27 +}
  28 +
  29 +class FolderWorkflowAssociator extends KTWorkflowAssociationHandler {
  30 + function addTrigger($oDocument) {
  31 + return $oW = $this->getWorkflowForDoc($oDocument);
  32 + }
  33 +
  34 + function editTrigger($oDocument) {
  35 + return $oW = $this->getWorkflowForDoc($oDocument);
  36 + }
  37 +
  38 + function getWorkflowForDoc($oDocument) {
  39 +
  40 + $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map');
  41 + $sQuery .= ' WHERE `folder_id` = ?';
  42 + $aParams = array($oDocument->getFolderID());
  43 + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id');
  44 +
  45 +
  46 + if (PEAR::isError($res) || (is_null($res))) {
  47 + return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if moved out.
  48 + }
  49 + return KTWorkflow::get($res);
  50 + }
  51 +}
  52 +
  53 +class FolderWorkflowAssignmentFolderAction extends KTFolderAction {
  54 + var $sDisplayName = 'Configure Workflows';
  55 + var $sName = 'ktstandard.workflowassociation.folder.action';
  56 +
  57 + var $_sShowPermission = "ktcore.permissions.addFolder";
  58 +
  59 + function do_main() {
  60 + $this->oPage->setBreadcrumbDetails(_("Configure Workflows for Folder"));
  61 + $this->oPage->setTitle(_("Configure Workflows for Folder"));
  62 + $oTemplate =& $this->oValidator->validateTemplate('ktstandard/workflow/folderconfigure');
  63 + $fields = array();
  64 +
  65 + $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL');
  66 + $aVocab = array();
  67 + $aVocab[] = _('No automatic workflow.');
  68 + foreach ($aWorkflows as $oWorkflow) {
  69 + $aVocab[$oWorkflow->getId()] = $oWorkflow->getName();
  70 + }
  71 + $fieldOptions = array("vocab" => $aVocab);
  72 +
  73 + // grab the value.
  74 + $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map');
  75 + $sQuery .= ' WHERE `folder_id` = ?';
  76 + $aParams = array($this->oFolder->getId());
  77 + $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id');
  78 + if (PEAR::isError($res)) {
  79 + $res = null;
  80 + }
  81 + $fields[] = new KTLookupWidget(_('Automatic Workflow'), _('If you specify an automatic workflow, new documents will automatically enter that workflow\'s starting state. Setting this to "No Automatic Workflow" will mean that users can choose the appropriate workflow.'), 'fWorkflowId', $res, $this->oPage, true, null, $fieldErrors, $fieldOptions);
  82 +
  83 +
  84 + $oTemplate->setData(array(
  85 + 'context' => &$this,
  86 + 'folder_id' => $this->oFolder->getId(),
  87 + 'fields' => $fields,
  88 + ));
  89 + return $oTemplate->render();
  90 + }
  91 +
  92 + function do_allocate() {
  93 + $fWorkflowId = KTUtil::arrayGet($_REQUEST, 'fWorkflowId', null);
  94 +
  95 + $this->startTransaction();
  96 +
  97 + $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folder_workflow_map') . ' WHERE folder_id = ?';
  98 + $aParams = array($this->oFolder->getId());
  99 + DBUtil::runQuery(array($sQuery, $aParams));
  100 +
  101 + if (is_null($fWorkflowId)) {
  102 + $this->successRedirectToMain(_('Workflow assignment removed.'), 'fFolderId='.$this->oFolder->getId());
  103 + }
  104 +
  105 + $aOptions = array('noid' => true);
  106 + $sTable = KTUtil::getTableName('folder_workflow_map');
  107 + if ($fWorkflowId == null) { $fWorkflowId = null; }
  108 + $res = DBUtil::autoInsert($sTable, array(
  109 + 'folder_id' => $this->oFolder->getId(),
  110 + 'workflow_id' => $fWorkflowId,
  111 + ), $aOptions);
  112 +
  113 + if (PEAR::isError($res)) {
  114 + $this->errorRedirectToMain(_('Error assigning workflow.'), 'fFolderId='.$this->oFolder->getId());
  115 + }
  116 +
  117 + $this->successRedirectToMain(_('Workflow assignment updated.'), 'fFolderId='.$this->oFolder->getId());
  118 + }
  119 +
  120 +}
  121 +
  122 +
  123 +$oPluginRegistry =& KTPluginRegistry::getSingleton();
  124 +$oPluginRegistry->registerPlugin('KTFolderWorkflowAssociationPlugin', 'ktstandard.workflowassociation.folder.plugin', __FILE__);
  125 +
  126 +
  127 +?>
0 128 \ No newline at end of file
... ...
templates/ktstandard/workflow/folderconfigure.smarty 0 → 100644
  1 +<h2>{i18n}Configure Workflows for this Folder{/i18n}</h2>
  2 +
  3 +<p class="descriptiveText">{i18n}This installation of KnowledgeTree allocates workflows
  4 +to documents by their location. To specify the workflow to be used by all documents
  5 +<strong>directly</strong> in this folder, please specify the workflow below. Otherwise,
  6 +users will be able to choose the workflow, and some documents may have no workflow
  7 +attached.{/i18n}</p>
  8 +
  9 +<p class="descriptiveText">{i18n}Note that documents which are moved into this folder
  10 +will change to use this workflow, and if their previous workflow was different
  11 +they will lose any progress they have made in that workflow.{/i18n}</p>
  12 +
  13 +<form method="POST" action="{$smarty.server.PHP_SELF}">
  14 +<input type="hidden" name="action" value="allocate" />
  15 +<input type="hidden" name="fFolderId" value="{$folder_id}" />
  16 +<fieldset>
  17 +<legend>{i18n}Select appropriate workflow{/i18n}</legend>
  18 +
  19 +{foreach item=oWidget from=$fields}
  20 + {$oWidget->render()}
  21 +{/foreach}
  22 +<div class="form_actions">
  23 + <input type="submit" value="{i18n}Assign Workflow{/i18n}" />
  24 +</div>
  25 +</fieldset>
  26 +</form>
0 27 \ No newline at end of file
... ...