Commit c6ed75829394b4d6295c73e3943bcfa9a47006ce
1 parent
d9684d95
basic api for workflow triggers.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5495 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
5 changed files
with
153 additions
and
2 deletions
docs/VERSION.txt
lib/workflow/workflowtrigger.inc.php
| ... | ... | @@ -55,7 +55,7 @@ class KTWorkflowTrigger { |
| 55 | 55 | function isLoaded() { return (!is_null($this->oTriggerInstance)); } |
| 56 | 56 | |
| 57 | 57 | // simple function to inform the UI/registration what kind of event this is |
| 58 | - function getCapabilities() { | |
| 58 | + function getInfo() { | |
| 59 | 59 | return array( |
| 60 | 60 | 'guard' => $this->bIsGuard, |
| 61 | 61 | 'action' => $this->bIsAction, | ... | ... |
lib/workflow/workflowtriggerinstance.inc.php
0 → 100644
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * $Id: workflowtriggerinstance.inc.php 5268 2006-04-18 13:42:22Z nbm $ | |
| 4 | + * | |
| 5 | + * Provides both association between a transition and a trigger, and a | |
| 6 | + * way to store the configuration for that instance. | |
| 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; using version 2 of the License. | |
| 13 | + * | |
| 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: 5268 $ | |
| 25 | + * @author Brad Shuttleworth, Jam Warehouse (Pty) Ltd, South Africa | |
| 26 | + */ | |
| 27 | + | |
| 28 | +require_once(KT_LIB_DIR . "/ktentity.inc"); | |
| 29 | + | |
| 30 | +class KTWorkflowTriggerInstance extends KTEntity { | |
| 31 | + var $iId = -1; | |
| 32 | + var $sConfigArrayText; | |
| 33 | + var $sNamespace; | |
| 34 | + var $iTransitionId; | |
| 35 | + | |
| 36 | + var $_aFieldToSelect = array( | |
| 37 | + "iId" => "id", | |
| 38 | + "sConfigArrayText" => "config_array", | |
| 39 | + "sNamespace" => "namespace", | |
| 40 | + "iTransitionId" => "workflow_transition_id", | |
| 41 | + ); | |
| 42 | + | |
| 43 | + var $_bUsePearError = true; | |
| 44 | + | |
| 45 | + function getTransitionId() { return $this->iTransitionId; } | |
| 46 | + function setTransitionId($iNewValue) { $this->iTransitionId = $iNewValue; } | |
| 47 | + function getNamespace() { return $this->sNamespace; } | |
| 48 | + function setNamespace($sNewValue) { $this->sNamespace = $sNewValue; } | |
| 49 | + function getConfigArrayText() { return $this->sConfigArrayText; } | |
| 50 | + function setConfigArrayText($sNewValue) { $this->sConfigArrayText = $sNewValue; } | |
| 51 | + function getConfig() { return unserialize($this->sConfigArrayText); } | |
| 52 | + function setConfig($aNewValue) { $this->sConfigArrayText = serialize($aNewValue); } | |
| 53 | + | |
| 54 | + function _table () { | |
| 55 | + return KTUtil::getTableName('workflow_trigger_instances'); | |
| 56 | + } | |
| 57 | + | |
| 58 | + // STATIC | |
| 59 | + function &get($iId) { return KTEntityUtil::get('KTWorkflowTriggerInstance', $iId); } | |
| 60 | + function &createFromArray($aOptions) { | |
| 61 | + $aOptions['configarraytext'] = serialize($aOptions['config']); | |
| 62 | + return KTEntityUtil::createFromArray('KTWorkflowTriggerInstance', $aOptions); | |
| 63 | + } | |
| 64 | + function &getList($sWhereClause = null) { return KTEntityUtil::getList2('KTWorkflowTriggerInstance', $sWhereClause); } | |
| 65 | + function &getByTransition($oTransition, $aOptions = null) { | |
| 66 | + $iTransitionId = KTUtil::getId($oTransition); | |
| 67 | + $aOptions = KTUtil::meldOptions($aOptions, array( | |
| 68 | + 'multi' => true, | |
| 69 | + )); | |
| 70 | + return KTEntityUtil::getByDict('KTWorkflowTriggerInstance', array( | |
| 71 | + 'workflow_transition_id' => $iTransitionId, | |
| 72 | + ), $aOptions); | |
| 73 | + } | |
| 74 | + | |
| 75 | +} | |
| 76 | + | |
| 77 | +?> | ... | ... |
lib/workflow/workflowutil.inc.php
| ... | ... | @@ -29,6 +29,8 @@ |
| 29 | 29 | require_once(KT_LIB_DIR . '/workflow/workflow.inc.php'); |
| 30 | 30 | require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php'); |
| 31 | 31 | require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php'); |
| 32 | +require_once(KT_LIB_DIR . '/workflow/workflowtrigger.inc.php'); | |
| 33 | +require_once(KT_LIB_DIR . '/workflow/workflowtriggerinstance.inc.php'); | |
| 32 | 34 | |
| 33 | 35 | require_once(KT_LIB_DIR . '/permissions/permissionutil.inc.php'); |
| 34 | 36 | require_once(KT_LIB_DIR . '/groups/GroupUtil.php'); |
| ... | ... | @@ -644,5 +646,63 @@ class KTWorkflowUtil { |
| 644 | 646 | return KTPermissionUtil::getAllowedForDescriptor($iDescriptorId); |
| 645 | 647 | } |
| 646 | 648 | // }}} |
| 649 | + | |
| 650 | + // retrieves the triggers for a given transition in their WorkflowTrigger form. | |
| 651 | + function getTriggersForTransition($oTransition) { | |
| 652 | + $oKTWorkflowTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton(); | |
| 653 | + $aTriggers = array(); | |
| 654 | + $aTriggerInstances = KTWorkflowTriggerInstance::getByTransition($oTransition); | |
| 655 | + foreach ($aTriggerInstances as $oTriggerInstance) { | |
| 656 | + $oTrigger = $oKTWorkflowTriggerRegistry->getWorkflowTrigger($oTriggerInstance->getNamespace()); | |
| 657 | + if (PEAR::isError($oTrigger)) { | |
| 658 | + return $oTrigger; | |
| 659 | + } | |
| 660 | + $oTrigger->loadConfig($oTriggerInstance); | |
| 661 | + $aTriggers[] = $oTrigger; | |
| 662 | + } | |
| 663 | + return $aTriggers; | |
| 664 | + } | |
| 665 | +} | |
| 666 | + | |
| 667 | +class KTWorkflowTriggerRegistry { | |
| 668 | + var $triggers; | |
| 669 | + | |
| 670 | + // {{{ getSingleton | |
| 671 | + function &getSingleton () { | |
| 672 | + if (!KTUtil::arrayGet($GLOBALS['_KT_PLUGIN'], 'oKTWorkflowTriggerRegistry')) { | |
| 673 | + $GLOBALS['_KT_PLUGIN']['oKTWorkflowTriggerRegistry'] = new KTWorkflowTriggerRegistry; | |
| 674 | + } | |
| 675 | + return $GLOBALS['_KT_PLUGIN']['oKTWorkflowTriggerRegistry']; | |
| 676 | + } | |
| 677 | + // }}} | |
| 678 | + | |
| 679 | + function registerWorkflowTrigger($sNamespace, $sClassname, $sPath) { | |
| 680 | + $this->triggers[$sNamespace] = array('class' => $sClassname, 'path' => $sPath); | |
| 681 | + } | |
| 682 | + | |
| 683 | + function getWorkflowTrigger($sNamespace) { | |
| 684 | + $aInfo = KTUtil::arrayGet($this->triggers, $sNamespace, null); | |
| 685 | + if (is_null($aInfo)) { | |
| 686 | + return PEAR::raiseError(sprintf(_kt("Unable to find workflow trigger: %s"), $sNamespace)); | |
| 687 | + } | |
| 688 | + | |
| 689 | + if (file_exists($aInfo['path'])) { | |
| 690 | + require_once($aInfo['path']); | |
| 691 | + } | |
| 692 | + | |
| 693 | + return new $sClassname; | |
| 694 | + } | |
| 695 | + | |
| 696 | + // get a keyed list of workflow triggers | |
| 697 | + | |
| 698 | + function listWorkflowTriggers() { | |
| 699 | + $triggerlist = array(); | |
| 700 | + foreach ($this->triggers as $sNamespace => $aTrigInfo) { | |
| 701 | + $oTriggerObj = $this->getWorkflowTrigger($sNamespace); | |
| 702 | + $triggerlist[$sNamespace] = $oTriggerObj->getInfo(); | |
| 703 | + } | |
| 704 | + // FIXME do we want to order this alphabetically? | |
| 705 | + return $triggerlist; | |
| 706 | + } | |
| 647 | 707 | } |
| 648 | 708 | ... | ... |
sql/mysql/upgrade/3.0.3.1/workflow-triggers.sql
0 → 100644
| 1 | +CREATE TABLE workflow_trigger_instances ( | |
| 2 | + id int(10) unsigned NOT NULL default '0', | |
| 3 | + workflow_transition_id int(11) NOT NULL default '0', | |
| 4 | + namespace char(255) NOT NULL default '', | |
| 5 | + config_array text, | |
| 6 | + PRIMARY KEY (id), | |
| 7 | + KEY workflow_transition_id (workflow_transition_id), | |
| 8 | + KEY namespace (namespace) | |
| 9 | +) TYPE=InnoDB; | |
| 10 | + | |
| 11 | +CREATE TABLE zseq_workflow_trigger_instances ( | |
| 12 | + id int(10) unsigned NOT NULL auto_increment, | |
| 13 | + PRIMARY KEY (id) | |
| 14 | +) TYPE=MyISAM; | ... | ... |