Commit 12bb2afbb98f6639e399eff8f83e9c0c5024a468

Authored by nbm
1 parent c709b64f

First-pass at workflow backend i.t.o. administration.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3713 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/workflow/workflow.inc.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * Describes a workflow for a document - a set of states that the
  6 + * document can be in and a set of transitions that allow that document
  7 + * to change to other states.
  8 + *
  9 + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com
  10 + *
  11 + * This program is free software; you can redistribute it and/or modify
  12 + * it under the terms of the GNU General Public License as published by
  13 + * the Free Software Foundation; either version 2 of the License, or
  14 + * (at your option) any later version.
  15 + *
  16 + * This program is distributed in the hope that it will be useful,
  17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19 + * GNU General Public License for more details.
  20 + *
  21 + * You should have received a copy of the GNU General Public License
  22 + * along with this program; if not, write to the Free Software
  23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24 + *
  25 + * @version $Revision$
  26 + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa
  27 + */
  28 +
  29 +require_once(KT_LIB_DIR . "/ktentity.inc");
  30 +
  31 +class KTWorkflow extends KTEntity {
  32 + var $iId = -1;
  33 + var $sName;
  34 + var $sHumanName;
  35 +
  36 + var $_aFieldToSelect = array(
  37 + "iId" => "id",
  38 + "sName" => "name",
  39 + "sHumanName" => "human_name",
  40 + );
  41 +
  42 + var $_bUsePearError = true;
  43 +
  44 + function getID() { return $this->iId; }
  45 + function getName() { return $this->sName; }
  46 + function getHumanName() { return $this->sHumanName; }
  47 + function setID($iId) { $this->iId = $iId; }
  48 + function setName($sName) { $this->sName = $sName; }
  49 + function setHumanName($sHumanName) { $this->sHumanName = $sHumanName; }
  50 +
  51 + function _table () {
  52 + return KTUtil::getTableName('workflows');
  53 + }
  54 +
  55 + // STATIC
  56 + function &get($iId) {
  57 + return KTEntityUtil::get('KTWorkflow', $iId);
  58 + }
  59 +
  60 + // STATIC
  61 + function &createFromArray($aOptions) {
  62 + return KTEntityUtil::createFromArray('KTWorkflow', $aOptions);
  63 + }
  64 +
  65 + // STATIC
  66 + function &getList($sWhereClause = null) {
  67 + return KTEntityUtil::getList2('KTWorkflow', $sWhereClause);
  68 + }
  69 +
  70 + // STATIC
  71 + function &getByName($sName) {
  72 + return KTEntityUtil::getBy('KTWorkflow', 'name', $sName);
  73 + }
  74 +}
  75 +
  76 +?>
... ...
lib/workflow/workflowstate.inc.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * Describes a state for a document, representing how far along in its
  6 + * workflow it is, and providing a set of transitions to other states.
  7 + *
  8 + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify
  11 + * it under the terms of the GNU General Public License as published by
  12 + * the Free Software Foundation; either version 2 of the License, or
  13 + * (at your option) any later version.
  14 + *
  15 + * This program is distributed in the hope that it will be useful,
  16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 + * GNU General Public License for more details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program; if not, write to the Free Software
  22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23 + *
  24 + * @version $Revision$
  25 + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa
  26 + */
  27 +
  28 +require_once(KT_LIB_DIR . "/ktentity.inc");
  29 +
  30 +class KTWorkflowState extends KTEntity {
  31 + var $iId = -1;
  32 + var $iWorkflowId;
  33 + var $sName;
  34 + var $sHumanName;
  35 +
  36 + var $_aFieldToSelect = array(
  37 + "iId" => "id",
  38 + "iWorkflowId" => "workflow_id",
  39 + "sName" => "name",
  40 + "sHumanName" => "human_name",
  41 + );
  42 +
  43 + var $_bUsePearError = true;
  44 +
  45 + function getId() { return $this->iId; }
  46 + function getName() { return $this->sName; }
  47 + function getHumanName() { return $this->sHumanName; }
  48 + function getWorkflowId() { return $this->iWorkflowId; }
  49 + function setId($iId) { $this->iId = $iId; }
  50 + function setName($sName) { $this->sName = $sName; }
  51 + function setHumanName($sHumanName) { $this->sHumanName = $sHumanName; }
  52 + function setWorkflowId($iWorkflowId) { $this->iWorkflowId = $iWorkflowId; }
  53 +
  54 + function _table () {
  55 + return KTUtil::getTableName('workflow_states');
  56 + }
  57 +
  58 + // STATIC
  59 + function &get($iId) {
  60 + return KTEntityUtil::get('KTWorkflowState', $iId);
  61 + }
  62 +
  63 + // STATIC
  64 + function &createFromArray($aOptions) {
  65 + return KTEntityUtil::createFromArray('KTWorkflowState', $aOptions);
  66 + }
  67 +
  68 + // STATIC
  69 + function &getList($sWhereClause = null) {
  70 + return KTEntityUtil::getList2('KTWorkflowState', $sWhereClause);
  71 + }
  72 +
  73 + // STATIC
  74 + function &getByName($sName) {
  75 + return KTEntityUtil::getBy('KTWorkflowState', 'name', $sName);
  76 + }
  77 +
  78 + // STATIC
  79 + function &getByWorkflow($oWorkflow) {
  80 + $iWorkflowId = KTUtil::getId($oWorkflow);
  81 +
  82 + $aOptions = array('multi' => true);
  83 + return KTEntityUtil::getBy('KTWorkflowState', 'workflow_id', $iWorkflowId, $aOptions);
  84 + }
  85 +}
  86 +
  87 +?>
... ...
lib/workflow/workflowtransition.inc.php 0 โ†’ 100644
  1 +<?php
  2 +/**
  3 + * $Id$
  4 + *
  5 + * Describes a transition to another state, available from some other
  6 + * states, subject to permissions and user-providable scripts.
  7 + *
  8 + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com
  9 + *
  10 + * This program is free software; you can redistribute it and/or modify
  11 + * it under the terms of the GNU General Public License as published by
  12 + * the Free Software Foundation; either version 2 of the License, or
  13 + * (at your option) any later version.
  14 + *
  15 + * This program is distributed in the hope that it will be useful,
  16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 + * GNU General Public License for more details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program; if not, write to the Free Software
  22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23 + *
  24 + * @version $Revision$
  25 + * @author Neil Blakey-Milner, Jam Warehouse (Pty) Ltd, South Africa
  26 + */
  27 +
  28 +require_once(KT_LIB_DIR . "/ktentity.inc");
  29 +require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php");
  30 +
  31 +class KTWorkflowTransition extends KTEntity {
  32 + var $iId = -1;
  33 + var $iWorkflowId;
  34 + var $sName;
  35 + var $sHumanName;
  36 + var $iTargetStateId;
  37 + var $iGuardPermissionId;
  38 +
  39 + var $_aFieldToSelect = array(
  40 + "iId" => "id",
  41 + "iWorkflowId" => "workflow_id",
  42 + "sName" => "name",
  43 + "sHumanName" => "human_name",
  44 + "iTargetStateId" => "target_state_id",
  45 + "iGuardPermissionId" => "guard_permission_id",
  46 + );
  47 +
  48 + var $_bUsePearError = true;
  49 +
  50 + function getId() { return $this->iId; }
  51 + function getName() { return $this->sName; }
  52 + function getHumanName() { return $this->sHumanName; }
  53 + function getWorkflowId() { return $this->iWorkflowId; }
  54 + function getTargetStateId() { return $this->iTargetStateId; }
  55 + function getGuardPermissionId() { return $this->iGuardPermissionId; }
  56 +
  57 + function setId($iId) { $this->iId = $iId; }
  58 + function setName($sName) { $this->sName = $sName; }
  59 + function setHumanName($sHumanName) { $this->sHumanName = $sHumanName; }
  60 + function setWorkflowId($iWorkflowId) { $this->iWorkflowId = $iWorkflowId; }
  61 + function setTargetStateId($iTargetStateId) { $this->iTargetStateId = $iTargetStateId; }
  62 + function setGuardPermissionId($iGuardPermissionId) { $this->iGuardPermissionId = $iGuardPermissionId; }
  63 +
  64 + function _table () {
  65 + return KTUtil::getTableName('workflow_transitions');
  66 + }
  67 +
  68 + // STATIC
  69 + function &get($iId) {
  70 + return KTEntityUtil::get('KTWorkflowTransition', $iId);
  71 + }
  72 +
  73 + // STATIC
  74 + function &createFromArray($aOptions) {
  75 + return KTEntityUtil::createFromArray('KTWorkflowTransition', $aOptions);
  76 + }
  77 +
  78 + // STATIC
  79 + function &getList($sWhereClause = null) {
  80 + return KTEntityUtil::getList2('KTWorkflowTransition', $sWhereClause);
  81 + }
  82 +
  83 + // STATIC
  84 + function &getByName($sName) {
  85 + return KTEntityUtil::getBy('KTWorkflowTransition', 'name', $sName);
  86 + }
  87 +
  88 + // STATIC
  89 + function &getByWorkflow($oWorkflow) {
  90 + $iWorkflowId = KTUtil::getId($oWorkflow);
  91 +
  92 + $aOptions = array(
  93 + 'multi' => true,
  94 + );
  95 + return KTEntityUtil::getBy('KTWorkflowTransition', 'workflow_id', $iWorkflowId, $aOptions);
  96 + }
  97 +
  98 + // STATIC
  99 + function &getByTargetState($oState) {
  100 + $iStateId = KTUtil::getId($oState);
  101 +
  102 + $aOptions = array(
  103 + 'multi' => true,
  104 + );
  105 + return KTEntityUtil::getBy('KTWorkflowTransition', 'target_state_id', $iStateId, $aOptions);
  106 + }
  107 +
  108 + // STATIC
  109 + function &getBySourceState($oState) {
  110 + return KTWorkflowUtil::getTransitionsFrom($oState);
  111 + }
  112 +}
  113 +
  114 +?>
... ...
lib/workflow/workflowutil.inc.php 0 โ†’ 100644
  1 +<?php
  2 +
  3 +class KTWorkflowUtil {
  4 + function saveTransitionsFrom($oState, $aTransitionIds) {
  5 + $sTable = KTUtil::getTableName('workflow_state_transitions');
  6 + $aQuery = array(
  7 + "DELETE FROM $sTable WHERE state_id = ?",
  8 + array($oState->getId()),
  9 + );
  10 + $res = DBUtil::runQuery($aQuery);
  11 + if (PEAR::isError($res)) {
  12 + return $res;
  13 + }
  14 + $aOptions = array('noid' => true);
  15 + foreach ($aTransitionIds as $iTransitionId) {
  16 + $res = DBUtil::autoInsert($sTable, array(
  17 + 'state_id' => $oState->getId(),
  18 + 'transition_id' => $iTransitionId,
  19 + ), $aOptions);
  20 + if (PEAR::isError($res)) {
  21 + return $res;
  22 + }
  23 + }
  24 + return;
  25 + }
  26 +
  27 + function getTransitionsFrom($oState, $aOptions) {
  28 + $bIds = KTUtil::arrayGet($aOptions, 'ids');
  29 + $sTable = KTUtil::getTableName('workflow_state_transitions');
  30 + $aQuery = array(
  31 + "SELECT transition_id FROM $sTable WHERE state_id = ?",
  32 + array($oState->getId()),
  33 + );
  34 + $aTransitionIds = DBUtil::getResultArrayKey($aQuery, 'transition_id');
  35 + if (PEAR::isError($aTransitionIds)) {
  36 + return $aTransitionIds;
  37 + }
  38 + if ($bIds) {
  39 + return $aTransitionIds;
  40 + }
  41 + $aRet = array();
  42 + foreach ($aTransitionIds as $iId) {
  43 + $aRet[] =& KTWorkflowTransition::get($iId);
  44 + }
  45 + return $aRet;
  46 + }
  47 +}
  48 +
... ...