diff --git a/plugins/ktstandard/workflow/FolderAssociator.php b/plugins/ktstandard/workflow/FolderAssociator.php index ce3b6cd..6efcf19 100644 --- a/plugins/ktstandard/workflow/FolderAssociator.php +++ b/plugins/ktstandard/workflow/FolderAssociator.php @@ -6,7 +6,7 @@ * License Version 1.1.2 ("License"); You may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.knowledgetree.com/KPL - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and @@ -17,9 +17,9 @@ * (ii) the KnowledgeTree copyright notice * in the same form as they appear in the distribution. See the License for * requirements. - * + * * The Original Code is: KnowledgeTree Open Source - * + * * The Initial Developer of the Original Code is The Jam Warehouse Software * (Pty) Ltd, trading as KnowledgeTree. * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright @@ -38,22 +38,22 @@ require_once(KT_LIB_DIR . '/actions/folderaction.inc.php'); class KTFolderWorkflowAssociationPlugin extends KTPlugin { var $sNamespace = "ktstandard.workflowassociation.folder.plugin"; - + function KTFolderWorkflowAssociationPlugin($sFilename = null) { $res = parent::KTPlugin($sFilename); $this->sFriendlyName = _kt('Workflow allocation by location'); return $res; - } + } function setup() { $this->registerTrigger('workflow', 'objectModification', 'FolderWorkflowAssociator', 'ktstandard.triggers.workflowassociation.folder.handler'); - + $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' WHERE event_ns = ?'; $aParams = array('ktstandard.workflowassociation.handler'); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns'); - + if ($res == 'ktstandard.triggers.workflowassociation.folder.handler') { $this->registerAction('folderaction', 'FolderWorkflowAssignmentFolderAction', 'ktstandard.workflowassociation.folder.action'); @@ -62,23 +62,27 @@ class KTFolderWorkflowAssociationPlugin extends KTPlugin { } class FolderWorkflowAssociator extends KTWorkflowAssociationHandler { - function addTrigger($oDocument) { - return $this->getWorkflowForDoc($oDocument); + function addTrigger($oDocument) { + return $this->getWorkflowForDoc($oDocument); + } + + function editTrigger($oDocument) { + return $this->getWorkflowForDoc($oDocument); } - - function editTrigger($oDocument) { - return $this->getWorkflowForDoc($oDocument); + + function moveTrigger($oDocument) { + return $this->getWorkflowForDoc($oDocument); } - + function getWorkflowForDoc($oDocument) { - + $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map'); $sQuery .= ' WHERE `folder_id` = ?'; $aParams = array($oDocument->getFolderID()); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id'); - - - if (PEAR::isError($res) || (is_null($res))) { + + + if (PEAR::isError($res) || (is_null($res))) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if moved out. } return KTWorkflow::get($res); @@ -99,15 +103,15 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction { $this->oPage->setTitle(_kt("Configure Workflows for Folder")); $oTemplate =& $this->oValidator->validateTemplate('ktstandard/workflow/folderconfigure'); $fields = array(); - + $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1'); $aVocab = array(); $aVocab[] = _kt('No automatic workflow.'); foreach ($aWorkflows as $oWorkflow) { - $aVocab[$oWorkflow->getId()] = $oWorkflow->getName(); + $aVocab[$oWorkflow->getId()] = $oWorkflow->getName(); } $fieldOptions = array("vocab" => $aVocab); - + // grab the value. $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map'); $sQuery .= ' WHERE `folder_id` = ?'; @@ -117,8 +121,8 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction { $res = null; } $fields[] = new KTLookupWidget(_kt('Automatic Workflow'), _kt('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); - - + + $oTemplate->setData(array( 'context' => &$this, 'folder_id' => $this->oFolder->getId(), @@ -129,17 +133,17 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction { function do_allocate() { $fWorkflowId = KTUtil::arrayGet($_REQUEST, 'fWorkflowId', null); - + $this->startTransaction(); - + $sQuery = 'DELETE FROM ' . KTUtil::getTableName('folder_workflow_map') . ' WHERE folder_id = ?'; $aParams = array($this->oFolder->getId()); DBUtil::runQuery(array($sQuery, $aParams)); - + if (is_null($fWorkflowId)) { $this->successRedirectToMain(_kt('Workflow assignment removed.'), 'fFolderId='.$this->oFolder->getId()); } - + $aOptions = array('noid' => true); $sTable = KTUtil::getTableName('folder_workflow_map'); if ($fWorkflowId == null) { $fWorkflowId = null; } @@ -147,11 +151,11 @@ class FolderWorkflowAssignmentFolderAction extends KTFolderAction { 'folder_id' => $this->oFolder->getId(), 'workflow_id' => $fWorkflowId, ), $aOptions); - + if (PEAR::isError($res)) { $this->errorRedirectToMain(_kt('Error assigning workflow.'), 'fFolderId='.$this->oFolder->getId()); } - + $this->successRedirectToMain(_kt('Workflow assignment updated.'), 'fFolderId='.$this->oFolder->getId()); } diff --git a/plugins/ktstandard/workflow/TypeAssociator.php b/plugins/ktstandard/workflow/TypeAssociator.php index 6b8fd85..ddb6bcf 100644 --- a/plugins/ktstandard/workflow/TypeAssociator.php +++ b/plugins/ktstandard/workflow/TypeAssociator.php @@ -6,7 +6,7 @@ * License Version 1.1.2 ("License"); You may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.knowledgetree.com/KPL - * + * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights and @@ -17,9 +17,9 @@ * (ii) the KnowledgeTree copyright notice * in the same form as they appear in the distribution. See the License for * requirements. - * + * * The Original Code is: KnowledgeTree Open Source - * + * * The Initial Developer of the Original Code is The Jam Warehouse Software * (Pty) Ltd, trading as KnowledgeTree. * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright @@ -39,45 +39,49 @@ class KTDocTypeWorkflowAssociationPlugin extends KTPlugin { $res = parent::KTPlugin($sFilename); $this->sFriendlyName = _kt('Workflow allocation by document type'); return $res; - } + } function setup() { $this->registerTrigger('workflow', 'objectModification', 'DocumentTypeWorkflowAssociator', 'ktstandard.triggers.workflowassociation.documenttype.handler'); - + $sQuery = 'SELECT selection_ns FROM ' . KTUtil::getTableName('trigger_selection'); $sQuery .= ' WHERE event_ns = ?'; $aParams = array('ktstandard.workflowassociation.handler'); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'selection_ns'); - + if ($res == 'ktstandard.triggers.workflowassociation.documenttype.handler') { - $this->registerAdminPage('workflow_type_allocation', 'WorkflowTypeAllocationDispatcher', - 'documents', _kt('Workflow Allocation by Document Types'), - _kt('This installation assigns workflows by Document Type. Configure this process here.'), __FILE__); + $this->registerAdminPage('workflow_type_allocation', 'WorkflowTypeAllocationDispatcher', + 'documents', _kt('Workflow Allocation by Document Types'), + _kt('This installation assigns workflows by Document Type. Configure this process here.'), __FILE__); $this->registeri18n('knowledgeTree', KT_DIR . '/i18n'); } - + } } class DocumentTypeWorkflowAssociator extends KTWorkflowAssociationHandler { - function addTrigger($oDocument) { - return $oW = $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); + function addTrigger($oDocument) { + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); } - - function editTrigger($oDocument) { - return $oW = $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); + + function editTrigger($oDocument) { + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); } - + + function moveTrigger($oDocument) { + return $this->getWorkflowForType($oDocument->getDocumentTypeID(), $oDocument); + } + function getWorkflowForType($iDocTypeId, $oDocument) { if (is_null($iDocTypeId)) { return null; } - + $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('type_workflow_map'); $sQuery .= ' WHERE `document_type_id` = ?'; $aParams = array($iDocTypeId); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id'); - if (PEAR::isError($res) || (is_null($res))) { + if (PEAR::isError($res) || (is_null($res))) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if type changed out. } return KTWorkflow::get($res); @@ -91,19 +95,19 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher { function check() { $res = parent::check(); if (!$res) { return false; } - + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name'=> _kt('Workflow Allocation by Document Types')); - + return true; } - function do_main() { + function do_main() { $sQuery = 'SELECT document_type_id, workflow_id FROM ' . KTUtil::getTableName('type_workflow_map'); $aParams = array(); $res = DBUtil::getResultArray(array($sQuery, $aParams)); $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1'); $aTypes = DocumentType::getList(); - + $aTypeMapping = array(); if (PEAR::isError($res)) { $this->oPage->addError(_kt('Failed to get type mapping: ') . $res->getMessage()); @@ -112,7 +116,7 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher { $aTypeMapping[$aRow['document_type_id']] = $aRow['workflow_id']; } } - + $oTemplate =& $this->oValidator->validateTemplate('ktstandard/workflow/type_allocation'); $oTemplate->setData(array( 'context' => $this, @@ -122,24 +126,24 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher { )); return $oTemplate->render(); } - + function isActiveWorkflow($oType, $oWorkflow, $types_mapping) { if (!array_key_exists($oType->getId(), $types_mapping)) { return false; } else { return $types_mapping[$oType->getId()] == $oWorkflow->getId(); } } - + function do_update() { $types_mapping = (array) KTUtil::arrayGet($_REQUEST, 'fDocumentTypeAssignment'); - + $aWorkflows = KTWorkflow::getList(); $aTypes = DocumentType::getList(); - + $sQuery = 'DELETE FROM ' . KTUtil::getTableName('type_workflow_map'); $aParams = array(); DBUtil::runQuery(array($sQuery, $aParams)); - + $aOptions = array('noid' => true); $sTable = KTUtil::getTableName('type_workflow_map'); foreach ($aTypes as $oType) { @@ -150,7 +154,7 @@ class WorkflowTypeAllocationDispatcher extends KTAdminDispatcher { 'workflow_id' => $t, ), $aOptions); } - + $this->successRedirectToMain(_kt('Type mapping updated.')); } }