Commit d9684d951d5e428855a16b9afc7b7070cc7c8f77

Authored by bshuttle
1 parent ae20eb3a

Abstract base class for Workflow Triggers.



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5494 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/workflow/workflowtrigger.inc.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * $Id: workflowtrigger.inc.php 5268 2006-04-18 13:42:22Z nbm $
  4 + *
  5 + * Provides a base class for workflow triggers. This includes
  6 + * the ability to serialise configuration arrays into the db
  7 + * and to be restored.
  8 + *
  9 + * This class will be subclassed - any configuration that is performed
  10 + * should be saved through the associated KTWorkflowTriggerInstance.
  11 + *
  12 + * Copyright (c) 2005 Jam Warehouse http://www.jamwarehouse.com
  13 + *
  14 + * This program is free software; you can redistribute it and/or modify
  15 + * it under the terms of the GNU General Public License as published by
  16 + * the Free Software Foundation; using version 2 of the License.
  17 + *
  18 + *
  19 + * This program is distributed in the hope that it will be useful,
  20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22 + * GNU General Public License for more details.
  23 + *
  24 + * You should have received a copy of the GNU General Public License
  25 + * along with this program; if not, write to the Free Software
  26 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27 + *
  28 + * @version $Revision: 5268 $
  29 + * @author Brad Shuttleworth, Jam Warehouse (Pty) Ltd, South Africa
  30 + */
  31 +
  32 +//require_once(KT_LIB_DIR . '/workflow/workflowtriggerinstance');
  33 +
  34 +class KTWorkflowTrigger {
  35 + var $sNamespace = 'ktcore.workflowtriggers.abstractbase';
  36 + var $sFriendlyName;
  37 + var $sDescription;
  38 + var $oTriggerInstance;
  39 + var $aConfig = array();
  40 +
  41 + // generic requirements - both can be true
  42 + var $bIsGuard = false;
  43 + var $bIsAction = false;
  44 +
  45 + function KTWorkflowTrigger() {
  46 + $this->_oTriggerState = null; // initialise to initial state
  47 + $this->sFriendlyName = _kt('Base class for workflow triggers');
  48 + $this->sDescription = _kt('This is an abstract base class for the overall workflow trigger. It should never actually be available for installation.');
  49 + }
  50 +
  51 + function loadConfig($oTriggerInstance) {
  52 + $this->oTriggerInstance = $oTriggerInstance;
  53 + }
  54 +
  55 + function isLoaded() { return (!is_null($this->oTriggerInstance)); }
  56 +
  57 + // simple function to inform the UI/registration what kind of event this is
  58 + function getCapabilities() {
  59 + return array(
  60 + 'guard' => $this->bIsGuard,
  61 + 'action' => $this->bIsAction,
  62 + 'name' => $this->sFriendlyName,
  63 + 'description' => $this->sDescription,
  64 + );
  65 + }
  66 +
  67 + // return true for transition allowed on doc, false for transition not allowed on doc.
  68 + function allowTransition($oDocument, $oUser) {
  69 + return true; // abstract base class
  70 + }
  71 +
  72 + /*
  73 + Multiple triggers can occur on a given transition. If this trigger fails,
  74 + return a PEAR::error (the overall system -will- roll the db back -
  75 + no need to do it yourself) with a -useful- human error message.
  76 +
  77 + IF YOU SUCCEED, return a $aRollbackInfo array. This will be passed
  78 + to $this->rollbackTransition IF NEEDED (e.g. a later trigger failed.)
  79 + This is to do your best to roll back any external changes (e.g. emails
  80 + sent.)
  81 + */
  82 + function performTransition($oDocument, $oUser) {
  83 + $rollbackinfo = null;
  84 + return $rollbackinfo;
  85 + }
  86 +
  87 + // roll back the transition. $aRollbackInfo was returned by you earlier
  88 + // after ->performTransition.
  89 + //
  90 + // throw a PEAR::error to -inform- users of a critical problem, NOT to
  91 + // cause the system to rollback (that's already happened.)
  92 + function rollbackTransition($oDocument, $oUser, $aRollbackInfo = null) {
  93 + return true;
  94 + // return PEAR::raiseError(_kt('A follow-up email has been sent, informing the previous recipient that the step was cancelled.'));
  95 + }
  96 +}
  97 +
  98 +?>
... ...