Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.32% covered (warning)
63.32%
240 / 379
41.10% covered (danger)
41.10%
30 / 73
CRAP
0.00% covered (danger)
0.00%
0 / 7
SeedDMS_Core_Workflow
80.82% covered (warning)
80.82%
118 / 146
36.84% covered (danger)
36.84%
7 / 19
78.12
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 getInitState
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setInitState
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 getTransitions
85.71% covered (warning)
85.71%
12 / 14
0.00% covered (danger)
0.00%
0 / 1
5.07
 getStates
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
5.03
 getTransition
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 getNextTransitions
84.62% covered (warning)
84.62%
11 / 13
0.00% covered (danger)
0.00%
0 / 1
5.09
 getPreviousTransitions
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
4.01
 getTransitionsByStates
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
4.01
 removeTransition
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 addTransition
60.00% covered (warning)
60.00%
12 / 20
0.00% covered (danger)
0.00%
0 / 1
8.30
 isUsed
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 penetrate
80.00% covered (warning)
80.00%
8 / 10
0.00% covered (danger)
0.00%
0 / 1
5.20
 checkForCycles
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 remove
61.11% covered (warning)
61.11%
11 / 18
0.00% covered (danger)
0.00%
0 / 1
6.47
SeedDMS_Core_Workflow_State
68.66% covered (warning)
68.66%
46 / 67
50.00% covered (danger)
50.00%
7 / 14
44.24
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 getMaxTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMaxTime
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getPreCondFunc
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPreCondFunc
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getDocumentStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDocumentStatus
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 isUsed
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 getTransitions
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
4.01
 remove
70.00% covered (warning)
70.00%
7 / 10
0.00% covered (danger)
0.00%
0 / 1
3.24
SeedDMS_Core_Workflow_Action
60.00% covered (warning)
60.00%
24 / 40
50.00% covered (danger)
50.00%
4 / 8
32.38
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setName
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 isUsed
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 getTransitions
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 remove
70.00% covered (warning)
70.00%
7 / 10
0.00% covered (danger)
0.00%
0 / 1
3.24
SeedDMS_Core_Workflow_Transition
36.08% covered (danger)
36.08%
35 / 97
31.25% covered (danger)
31.25%
5 / 16
374.43
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getID
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWorkflow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setWorkflow
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getState
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setState
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getNextState
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNextState
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setAction
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getMaxTime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMaxTime
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 getUsers
70.00% covered (warning)
70.00%
14 / 20
0.00% covered (danger)
0.00%
0 / 1
9.73
 getGroups
50.00% covered (danger)
50.00%
10 / 20
0.00% covered (danger)
0.00%
0 / 1
16.00
 remove
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
SeedDMS_Core_Workflow_Transition_User
83.33% covered (warning)
83.33%
5 / 6
75.00% covered (warning)
75.00%
3 / 4
4.07
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTransition
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
SeedDMS_Core_Workflow_Transition_Group
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 5
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 setDMS
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTransition
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGroup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNumOfUsers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
SeedDMS_Core_Workflow_Log
80.00% covered (warning)
80.00%
12 / 15
57.14% covered (warning)
57.14%
4 / 7
7.39
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 setDMS
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTransition
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getWorkflow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare(strict_types=1);
3
4/**
5 * Implementation of the workflow object in the document management system
6 *
7 * @category   DMS
8 * @package    SeedDMS_Core
9 * @license    GPL 2
10 * @version    @version@
11 * @author     Uwe Steinmann <uwe@steinmann.cx>
12 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
13 * @version    Release: @package_version@
14 */
15
16/**
17 * Class to represent an workflow in the document management system
18 *
19 * @category   DMS
20 * @package    SeedDMS_Core
21 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
22 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
23 * @version    Release: @package_version@
24 */
25class SeedDMS_Core_Workflow { /* {{{ */
26    /**
27     * @var integer id of workflow
28     *
29     * @access protected
30     */
31    protected $_id;
32
33    /**
34     * @var string name of the workflow
35     *
36     * @access protected
37     */
38    protected $_name;
39
40    /**
41     * @var SeedDMS_Core_Workflow_State initial state of the workflow
42     *
43     * @access protected
44     */
45    protected $_initstate;
46
47    /**
48     * @var SeedDMS_Core_Workflow_Transition[] name of the workflow state
49     *
50     * @access protected
51     */
52    protected $_transitions;
53
54    /**
55     * @var SeedDMS_Core_DMS reference to the dms instance this attribute belongs to
56     *
57     * @access protected
58     */
59    protected $_dms;
60
61    /**
62     * SeedDMS_Core_Workflow constructor.
63     * @param int $id
64     * @param string $name
65     * @param SeedDMS_Core_Workflow_State $initstate
66     */
67    public function __construct($id, $name, $initstate) { /* {{{ */
68        $this->_id = $id;
69        $this->_name = $name;
70        $this->_initstate = $initstate;
71        $this->_transitions = null;
72        $this->_dms = null;
73    } /* }}} */
74
75    /**
76     * @param SeedDMS_Core_DMS $dms
77     */
78    public function setDMS($dms) { /* {{{ */
79        $this->_dms = $dms;
80    } /* }}} */
81
82    /**
83     * @return int
84     */
85    public function getID() {
86        return $this->_id;
87    }
88
89    /**
90     * @return string
91     */
92    public function getName() { return $this->_name; }
93
94    /**
95     * @param $newName
96     * @return bool
97     */
98    public function setName($newName) { /* {{{ */
99        $db = $this->_dms->getDB();
100
101        $queryStr = "UPDATE `tblWorkflows` SET `name` = ".$db->qstr($newName)." WHERE `id` = " . $this->_id;
102        $res = $db->getResult($queryStr);
103        if (!$res) {
104            return false;
105        }
106
107        $this->_name = $newName;
108        return true;
109    } /* }}} */
110
111    /**
112     * @return SeedDMS_Core_Workflow_State
113     */
114    public function getInitState() { return $this->_initstate; }
115
116    /**
117     * @param SeedDMS_Core_Workflow_State $state
118     * @return bool
119     */
120    public function setInitState($state) { /* {{{ */
121        $db = $this->_dms->getDB();
122
123        $queryStr = "UPDATE `tblWorkflows` SET `initstate` = ".$state->getID()." WHERE `id` = " . $this->_id;
124        $res = $db->getResult($queryStr);
125        if (!$res) {
126            return false;
127        }
128
129        $this->_initstate = $state;
130        return true;
131    } /* }}} */
132
133    /**
134     * @return SeedDMS_Core_Workflow_Transition[]|bool
135     */
136    public function getTransitions() { /* {{{ */
137        $db = $this->_dms->getDB();
138
139        if ($this->_transitions) {
140            return $this->_transitions;
141        }
142
143        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `workflow`=".$this->_id;
144        $resArr = $db->getResultArray($queryStr);
145        if (is_bool($resArr) && $resArr == false) {
146            return false;
147        }
148
149        $wkftransitions = array();
150        for ($i = 0; $i < count($resArr); $i++) {
151            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this, $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
152            $wkftransition->setDMS($this->_dms);
153            $wkftransitions[$resArr[$i]["id"]] = $wkftransition;
154        }
155
156        $this->_transitions = $wkftransitions;
157
158        return $this->_transitions;
159    } /* }}} */
160
161    /**
162     * Get all states this workflow at some point may reach
163     *
164     * It basically iterates through all transistions and makes a unique
165     * list of the start and end state.
166     *
167     * @return array list of states
168     */
169    public function getStates() { /* {{{ */
170        /** @noinspection PhpUnusedLocalVariableInspection */
171        $db = $this->_dms->getDB();
172
173        if (!$this->_transitions) {
174            $this->getTransitions();
175        }
176
177        $states = array();
178        foreach ($this->_transitions as $transition) {
179            if (!isset($states[$transition->getState()->getID()])) {
180                $states[$transition->getState()->getID()] = $transition->getState();
181            }
182            if (!isset($states[$transition->getNextState()->getID()])) {
183                $states[$transition->getNextState()->getID()] = $transition->getNextState();
184            }
185        }
186
187        return $states;
188    } /* }}} */
189
190    /**
191     * Get the transition by its id
192     *
193     * @param integer $id id of transition
194     * @return bool|SeedDMS_Core_Workflow_Transition
195     */
196    public function getTransition($id) { /* {{{ */
197        /** @noinspection PhpUnusedLocalVariableInspection */
198        $db = $this->_dms->getDB();
199
200        if (!$this->_transitions) {
201            $this->getTransitions();
202        }
203
204        if ($this->_transitions[$id]) {
205            return $this->_transitions[$id];
206        }
207
208        return false;
209    } /* }}} */
210
211    /**
212     * Get the transitions that can be triggered while being in the given state
213     *
214     * @param SeedDMS_Core_Workflow_State $state current workflow state
215     * @return SeedDMS_Core_Workflow_Transition[]|bool
216     */
217    public function getNextTransitions($state) { /* {{{ */
218        $db = $this->_dms->getDB();
219
220        if (!$state) {
221            return false;
222        }
223
224        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `workflow`=".$this->_id." AND `state`=".$state->getID();
225        $resArr = $db->getResultArray($queryStr);
226        if (is_bool($resArr) && $resArr == false) {
227            return false;
228        }
229
230        $wkftransitions = array();
231        for ($i = 0; $i < count($resArr); $i++) {
232            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this, $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
233            $wkftransition->setDMS($this->_dms);
234            $wkftransitions[$i] = $wkftransition;
235        }
236
237        return $wkftransitions;
238    } /* }}} */
239
240    /**
241     * Get the transitions that lead to the given state
242     *
243     * @param SeedDMS_Core_Workflow_State $state current workflow state
244     * @return SeedDMS_Core_Workflow_Transition[]|bool
245     */
246    public function getPreviousTransitions($state) { /* {{{ */
247        $db = $this->_dms->getDB();
248
249        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `workflow`=".$this->_id." AND `nextstate`=".$state->getID();
250        $resArr = $db->getResultArray($queryStr);
251        if (is_bool($resArr) && $resArr == false) {
252            return false;
253        }
254
255        $wkftransitions = array();
256        for ($i = 0; $i < count($resArr); $i++) {
257            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this, $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
258            $wkftransition->setDMS($this->_dms);
259            $wkftransitions[$i] = $wkftransition;
260        }
261
262        return $wkftransitions;
263    } /* }}} */
264
265    /**
266     * Get all transitions from one state into another state
267     *
268     * @param SeedDMS_Core_Workflow_State $state state to start from
269     * @param SeedDMS_Core_Workflow_State $nextstate state after transition
270     * @return SeedDMS_Core_Workflow_Transition[]|bool
271     */
272    public function getTransitionsByStates($state, $nextstate) { /* {{{ */
273        $db = $this->_dms->getDB();
274
275        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `workflow`=".$this->_id." AND `state`=".$state->getID()." AND `nextstate`=".$nextstate->getID();
276        $resArr = $db->getResultArray($queryStr);
277        if (is_bool($resArr) && $resArr == false) {
278            return false;
279        }
280
281        $wkftransitions = array();
282        for ($i = 0; $i < count($resArr); $i++) {
283            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this, $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
284            $wkftransition->setDMS($this->_dms);
285            $wkftransitions[$i] = $wkftransition;
286        }
287
288        return $wkftransitions;
289    } /* }}} */
290
291    /**
292     * Remove a transition from a workflow
293     * Deprecated! User SeedDMS_Core_Workflow_Transition::remove() instead.
294     *
295     * @param SeedDMS_Core_Workflow_Transition $transition
296     * @return boolean true if no error occured, otherwise false
297     */
298    public function removeTransition($transition) { /* {{{ */
299        return $transition->remove();
300    } /* }}} */
301
302    /**
303     * Add new transition to workflow
304     *
305     * @param SeedDMS_Core_Workflow_State $state
306     * @param SeedDMS_Core_Workflow_Action $action
307     * @param SeedDMS_Core_Workflow_State $nextstate
308     * @param SeedDMS_Core_User[] $users
309     * @param SeedDMS_Core_Group[] $groups
310     * @return SeedDMS_Core_Workflow_Transition|bool instance of new transition
311     */
312    public function addTransition($state, $action, $nextstate, $users, $groups) { /* {{{ */
313        $db = $this->_dms->getDB();
314        
315        $db->startTransaction();
316        $queryStr = "INSERT INTO `tblWorkflowTransitions` (`workflow`, `state`, `action`, `nextstate`) VALUES (".$this->_id.", ".$state->getID().", ".$action->getID().", ".$nextstate->getID().")";
317        if (!$db->getResult($queryStr)) {
318            $db->rollbackTransaction();
319            return false;
320        }
321
322        /* force reloading all transitions otherwise getTransition() will fail if two
323         * transitions are added in a row, without reloading the workflow
324         */
325        $this->_transitions = array();
326        $transition = $this->getTransition($db->getInsertID('tblWorkflowTransitions'));
327
328        foreach ($users as $user) {
329            $queryStr = "INSERT INTO `tblWorkflowTransitionUsers` (`transition`, `userid`) VALUES (".$transition->getID().", ".$user->getID().")";
330            if (!$db->getResult($queryStr)) {
331                $db->rollbackTransaction();
332                return false;
333            }
334        }
335
336        foreach ($groups as $group) {
337            $queryStr = "INSERT INTO `tblWorkflowTransitionGroups` (`transition`, `groupid`, `minusers`) VALUES (".$transition->getID().", ".$group->getID().", 1)";
338            if (!$db->getResult($queryStr)) {
339                $db->rollbackTransaction();
340                return false;
341            }
342        }
343
344        $db->commitTransaction();
345        return $transition;
346    } /* }}} */
347
348    /**
349     * Check if workflow is currently used by any document
350     *
351     * @return boolean true if workflow is used, otherwise false
352     */
353    public function isUsed() { /* {{{ */
354        $db = $this->_dms->getDB();
355        
356        $queryStr = "SELECT * FROM `tblWorkflowDocumentContent` WHERE `workflow`=".$this->_id;
357        $resArr = $db->getResultArray($queryStr);
358        if (is_array($resArr) && count($resArr) == 0) {
359            return false;
360        }
361        return true;
362    } /* }}} */
363
364    /**
365     * @param SeedDMS_Core_Workflow_State[] $laststates
366     * @return SeedDMS_Core_Workflow_State[]|bool
367     */
368    private function penetrate($laststates) {
369        $state = end($laststates);
370        $transitions = $this->getNextTransitions($state);
371        foreach ($transitions as $transition) {
372            $nextstate = $transition->getNextState();
373            /* Check if nextstate is already in list of previous states */
374            foreach ($laststates as $laststate) {
375                if ($laststate->getID() == $nextstate->getID()) {
376                    return array_merge($laststates, array($nextstate));
377                }
378            }
379            if ($ret = $this->penetrate(array_merge($laststates, array($nextstate)))) {
380                return $ret;
381            }
382        }
383        return false;
384    }
385
386    /**
387     * Check if workflow contains cycles
388     *
389     * @return boolean list of states if workflow contains cycles, otherwise false
390     */
391    public function checkForCycles() { /* {{{ */
392        /** @noinspection PhpUnusedLocalVariableInspection */
393        $db = $this->_dms->getDB();
394        
395        $initstate = $this->getInitState();
396
397        return $this->penetrate(array($initstate));
398    } /* }}} */
399
400    /**
401     * Remove the workflow and all its transitions
402     * Do not remove actions and states of the workflow
403     *
404     * @return boolean true on success or false in case of an error
405     *         false is also returned if the workflow is currently in use
406     */
407    public function remove() { /* {{{ */
408        $db = $this->_dms->getDB();
409
410        if ($this->isUsed()) {
411            return false;
412        }
413
414        $db->startTransaction();
415
416        $queryStr = "DELETE FROM `tblWorkflowTransitions` WHERE `workflow` = " . $this->_id;
417        if (!$db->getResult($queryStr)) {
418            $db->rollbackTransaction();
419            return false;
420        }
421
422        $queryStr = "DELETE FROM `tblWorkflowMandatoryWorkflow` WHERE `workflow` = " . $this->_id;
423        if (!$db->getResult($queryStr)) {
424            $db->rollbackTransaction();
425            return false;
426        }
427
428        // Delete workflow itself
429        $queryStr = "DELETE FROM `tblWorkflows` WHERE `id` = " . $this->_id;
430        if (!$db->getResult($queryStr)) {
431            $db->rollbackTransaction();
432            return false;
433        }
434
435        $db->commitTransaction();
436
437        return true;
438    } /* }}} */
439
440} /* }}} */
441
442/**
443 * Class to represent a workflow state in the document management system
444 *
445 * @category   DMS
446 * @package    SeedDMS_Core
447 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
448 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
449 * @version    Release: @package_version@
450 */
451class SeedDMS_Core_Workflow_State { /* {{{ */
452    /**
453     * @var integer id of workflow state
454     *
455     * @access protected
456     */
457    protected $_id;
458
459    /**
460     * @var string name of the workflow state
461     *
462     * @access protected
463     */
464    protected $_name;
465
466    /**
467     * @var int maximum of seconds allowed in this state
468     *
469     * @access protected
470     */
471    protected $_maxtime;
472
473    /**
474     * @var int maximum of seconds allowed in this state
475     *
476     * @access protected
477     */
478    protected $_precondfunc;
479
480    /**
481     * @var int matching documentstatus when this state is reached
482     *
483     * @access protected
484     */
485    protected $_documentstatus;
486
487    /**
488     * @var SeedDMS_Core_DMS reference to the dms instance this attribute belongs to
489     *
490     * @access protected
491     */
492    protected $_dms;
493
494    /**
495     * SeedDMS_Core_Workflow_State constructor.
496     * @param $id
497     * @param $name
498     * @param $maxtime
499     * @param $precondfunc
500     * @param $documentstatus
501     */
502    public function __construct($id, $name, $maxtime, $precondfunc, $documentstatus) {
503        $this->_id = $id;
504        $this->_name = $name;
505        $this->_maxtime = $maxtime;
506        $this->_precondfunc = $precondfunc;
507        $this->_documentstatus = $documentstatus;
508        $this->_dms = null;
509    }
510
511    /**
512     * @param $dms
513     */
514    public function setDMS($dms) {
515        $this->_dms = $dms;
516    }
517
518    /**
519     * @return int
520     */
521    public function getID() { return $this->_id; }
522
523    /**
524     * @return string
525     */
526    public function getName() { return $this->_name; }
527
528    /**
529     * @param string $newName
530     * @return bool
531     */
532    public function setName($newName) { /* {{{ */
533        $db = $this->_dms->getDB();
534
535        $queryStr = "UPDATE `tblWorkflowStates` SET `name` = ".$db->qstr($newName)." WHERE `id` = " . $this->_id;
536        $res = $db->getResult($queryStr);
537        if (!$res) {
538            return false;
539        }
540
541        $this->_name = $newName;
542        return true;
543    } /* }}} */
544
545    /**
546     * @return int maximum
547     */
548    public function getMaxTime() { return $this->_maxtime; }
549
550    /**
551     * @param $maxtime
552     * @return bool
553     */
554    public function setMaxTime($maxtime) { /* {{{ */
555        $db = $this->_dms->getDB();
556
557        $queryStr = "UPDATE `tblWorkflowStates` SET `maxtime` = ".intval($maxtime)." WHERE `id` = " . $this->_id;
558        $res = $db->getResult($queryStr);
559        if (!$res) {
560            return false;
561        }
562
563        $this->_maxtime = $maxtime;
564        return true;
565    } /* }}} */
566
567    /**
568     * @return int maximum
569     */
570    public function getPreCondFunc() { return $this->_precondfunc; }
571
572    /**
573     * @param $precondfunc
574     * @return bool
575     */
576    public function setPreCondFunc($precondfunc) { /* {{{ */
577        $db = $this->_dms->getDB();
578
579        $queryStr = "UPDATE `tblWorkflowStates` SET `precondfunc` = ".$db->qstr($precondfunc)." WHERE id = " . $this->_id;
580        $res = $db->getResult($queryStr);
581        if (!$res) {
582            return false;
583        }
584
585        /** @noinspection PhpUndefinedVariableInspection */
586        $this->_precondfunc = $precondfunc; /* @todo fix me */
587        return true;
588    } /* }}} */
589
590    /**
591     * Get the document status which is set when this state is reached
592     *
593     * The document status uses the define states S_REJECTED and S_RELEASED
594     * Only those two states will update the document status
595     *
596     * @return integer document status
597     */
598    public function getDocumentStatus() { return $this->_documentstatus; }
599
600    /**
601     * @param $docstatus
602     * @return bool
603     */
604    public function setDocumentStatus($docstatus) { /* {{{ */
605        $db = $this->_dms->getDB();
606
607        $queryStr = "UPDATE `tblWorkflowStates` SET `documentstatus` = ".intval($docstatus)." WHERE id = " . $this->_id;
608        $res = $db->getResult($queryStr);
609        if (!$res) {
610            return false;
611        }
612
613        $this->_documentstatus = $docstatus;
614        return true;
615    } /* }}} */
616
617    /**
618     * Check if workflow state is currently used by any workflow transition
619     *
620     * @return boolean true if workflow is used, otherwise false
621     */
622    public function isUsed() { /* {{{ */
623        $db = $this->_dms->getDB();
624        
625        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `state`=".$this->_id. " OR `nextstate`=".$this->_id;
626        $resArr = $db->getResultArray($queryStr);
627        if (is_array($resArr) && count($resArr) == 0) {
628            return false;
629        }
630        return true;
631    } /* }}} */
632
633    /**
634     * Return workflow transitions the status is being used in
635     *
636     * @return SeedDMS_Core_Workflow_Transition[]|boolean array of workflow transitions or false in case of an error
637     */
638    public function getTransitions() { /* {{{ */
639        $db = $this->_dms->getDB();
640        
641        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `state`=".$this->_id. " OR `nextstate`=".$this->_id;
642        $resArr = $db->getResultArray($queryStr);
643        if (is_array($resArr) && count($resArr) == 0) {
644            return false;
645        }
646
647        $wkftransitions = array();
648        for ($i = 0; $i < count($resArr); $i++) {
649            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this->_dms->getWorkflow($resArr[$i]["workflow"]), $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
650            $wkftransition->setDMS($this->_dms);
651            $wkftransitions[$resArr[$i]["id"]] = $wkftransition;
652        }
653
654        return $wkftransitions;
655    } /* }}} */
656
657    /**
658     * Remove the workflow state
659     *
660     * @return boolean true on success or false in case of an error
661     *         false is also returned if the workflow state is currently in use
662     */
663    public function remove() { /* {{{ */
664        $db = $this->_dms->getDB();
665
666        if ($this->isUsed()) {
667            return false;
668        }
669
670        $db->startTransaction();
671
672        // Delete workflow state itself
673        $queryStr = "DELETE FROM `tblWorkflowStates` WHERE `id` = " . $this->_id;
674        if (!$db->getResult($queryStr)) {
675            $db->rollbackTransaction();
676            return false;
677        }
678
679        $db->commitTransaction();
680
681        return true;
682    } /* }}} */
683
684} /* }}} */
685
686/**
687 * Class to represent a workflow action in the document management system
688 *
689 * @category   DMS
690 * @package    SeedDMS_Core
691 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
692 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
693 * @version    Release: @package_version@
694 */
695class SeedDMS_Core_Workflow_Action { /* {{{ */
696    /**
697     * @var integer id of workflow action
698     *
699     * @access protected
700     */
701    protected $_id;
702
703    /**
704     * @var string name of the workflow action
705     *
706     * @access protected
707     */
708    protected $_name;
709
710    /**
711     * @var SeedDMS_Core_DMS reference to the dms instance this attribute belongs to
712     *
713     * @access protected
714     */
715    protected $_dms;
716
717    /**
718     * SeedDMS_Core_Workflow_Action constructor.
719     * @param $id
720     * @param $name
721     */
722    public function __construct($id, $name) {
723        $this->_id = $id;
724        $this->_name = $name;
725        $this->_dms = null;
726    }
727
728    /**
729     * @param $dms
730     */
731    public function setDMS($dms) {
732        $this->_dms = $dms;
733    }
734
735    /**
736     * @return int
737     */
738    public function getID() { return $this->_id; }
739
740    /**
741     * @return string name
742     */
743    public function getName() { return $this->_name; }
744
745    /**
746     * @param $newName
747     * @return bool
748     */
749    public function setName($newName) { /* {{{ */
750        $db = $this->_dms->getDB();
751
752        $queryStr = "UPDATE `tblWorkflowActions` SET `name` = ".$db->qstr($newName)." WHERE `id` = " . $this->_id;
753        $res = $db->getResult($queryStr);
754        if (!$res) {
755            return false;
756        }
757
758        $this->_name = $newName;
759        return true;
760    } /* }}} */
761
762    /**
763     * Check if workflow action is currently used by any workflow transition
764     *
765     * @return boolean true if workflow action is used, otherwise false
766     */
767    public function isUsed() { /* {{{ */
768        $db = $this->_dms->getDB();
769        
770        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `action`=".$this->_id;
771        $resArr = $db->getResultArray($queryStr);
772        if (is_array($resArr) && count($resArr) == 0) {
773            return false;
774        }
775        return true;
776    } /* }}} */
777
778    /**
779     * Return workflow transitions the action is being used in
780     *
781     * @return SeedDMS_Core_Workflow_Transition[]|boolean array of workflow transitions or false in case of an error
782     */
783    public function getTransitions() { /* {{{ */
784        $db = $this->_dms->getDB();
785        
786        $queryStr = "SELECT * FROM `tblWorkflowTransitions` WHERE `action`=".$this->_id;
787        $resArr = $db->getResultArray($queryStr);
788        if (is_array($resArr) && count($resArr) == 0) {
789            return false;
790        }
791
792        $wkftransitions = array();
793        for ($i = 0; $i < count($resArr); $i++) {
794            $wkftransition = new SeedDMS_Core_Workflow_Transition($resArr[$i]["id"], $this->_dms->getWorkflow($resArr[$i]["workflow"]), $this->_dms->getWorkflowState($resArr[$i]["state"]), $this->_dms->getWorkflowAction($resArr[$i]["action"]), $this->_dms->getWorkflowState($resArr[$i]["nextstate"]), $resArr[$i]["maxtime"]);
795            $wkftransition->setDMS($this->_dms);
796            $wkftransitions[$resArr[$i]["id"]] = $wkftransition;
797        }
798
799        return $wkftransitions;
800    } /* }}} */
801
802    /**
803     * Remove the workflow action
804     *
805     * @return boolean true on success or false in case of an error
806     *         false is also returned if the workflow action is currently in use
807     */
808    public function remove() { /* {{{ */
809        $db = $this->_dms->getDB();
810
811        if ($this->isUsed()) {
812            return false;
813        }
814
815        $db->startTransaction();
816
817        // Delete workflow state itself
818        $queryStr = "DELETE FROM `tblWorkflowActions` WHERE `id` = " . $this->_id;
819        if (!$db->getResult($queryStr)) {
820            $db->rollbackTransaction();
821            return false;
822        }
823
824        $db->commitTransaction();
825
826        return true;
827    } /* }}} */
828
829} /* }}} */
830
831/**
832 * Class to represent a workflow transition in the document management system
833 *
834 * @category   DMS
835 * @package    SeedDMS_Core
836 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
837 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
838 * @version    Release: @package_version@
839 */
840class SeedDMS_Core_Workflow_Transition { /* {{{ */
841    /**
842     * @var integer id of workflow transition
843     *
844     * @access protected
845     */
846    protected $_id;
847
848    /**
849     * @var SeedDMS_Core_Workflow workflow this transition belongs to
850     *
851     * @access protected
852     */
853    protected $_workflow;
854
855    /**
856     * @var SeedDMS_Core_Workflow_State of the workflow transition
857     *
858     * @access protected
859     */
860    protected $_state;
861
862    /**
863     * @var SeedDMS_Core_Workflow_State next state of the workflow transition
864     *
865     * @access protected
866     */
867    protected $_nextstate;
868
869    /**
870     * @var SeedDMS_Core_Workflow_Action of the workflow transition
871     *
872     * @access protected
873     */
874    protected $_action;
875
876    /**
877     * @var integer maximum of seconds allowed until this transition must be triggered
878     *
879     * @access protected
880     */
881    protected $_maxtime;
882
883    /**
884     * @var SeedDMS_Core_User[] of users allowed to trigger this transaction
885     *
886     * @access protected
887     */
888    protected $_users;
889
890    /**
891     * @var SeedDMS_Core_Group[] of groups allowed to trigger this transaction
892     *
893     * @access protected
894     */
895    protected $_groups;
896
897    /**
898     * @var SeedDMS_Core_DMS reference to the dms instance this attribute belongs to
899     *
900     * @access protected
901     */
902    protected $_dms;
903
904    /**
905     * SeedDMS_Core_Workflow_Transition constructor.
906     * @param $id
907     * @param $workflow
908     * @param $state
909     * @param $action
910     * @param $nextstate
911     * @param $maxtime
912     */
913    public function __construct($id, $workflow, $state, $action, $nextstate, $maxtime) {
914        $this->_id = $id;
915        $this->_workflow = $workflow;
916        $this->_state = $state;
917        $this->_action = $action;
918        $this->_nextstate = $nextstate;
919        $this->_maxtime = $maxtime;
920        $this->_dms = null;
921    }
922
923    /**
924     * @param $dms
925     */
926    public function setDMS($dms) {
927        $this->_dms = $dms;
928    }
929
930    /**
931     * @return int
932     */
933    public function getID() { return $this->_id; }
934
935    /**
936     * @return SeedDMS_Core_Workflow
937     */
938    public function getWorkflow() { return $this->_workflow; }
939
940    /**
941     * @param SeedDMS_Core_Workflow $newWorkflow
942     * @return bool
943     */
944    public function setWorkflow($newWorkflow) { /* {{{ */
945        $db = $this->_dms->getDB();
946
947        $queryStr = "UPDATE `tblWorkflowTransitions` SET `workflow` = ".$newWorkflow->getID()." WHERE `id` = " . $this->_id;
948        $res = $db->getResult($queryStr);
949        if (!$res) {
950            return false;
951        }
952
953        $this->_workflow = $newWorkflow;
954        return true;
955    } /* }}} */
956
957
958    /**
959     * @return SeedDMS_Core_Workflow_State
960     */
961    public function getState() { return $this->_state; }
962
963    /**
964     * @param SeedDMS_Core_Workflow_State $newState
965     * @return bool
966     */
967    public function setState($newState) { /* {{{ */
968        $db = $this->_dms->getDB();
969
970        $queryStr = "UPDATE `tblWorkflowTransitions` SET `state` = ".$newState->getID()." WHERE `id` = " . $this->_id;
971        $res = $db->getResult($queryStr);
972        if (!$res) {
973            return false;
974        }
975
976        $this->_state = $newState;
977        return true;
978    } /* }}} */
979
980    /**
981     * @return SeedDMS_Core_Workflow_State
982     */
983    public function getNextState() { return $this->_nextstate; }
984
985    /**
986     * @param SeedDMS_Core_Workflow_State $newNextState
987     * @return bool
988     */
989    public function setNextState($newNextState) { /* {{{ */
990        $db = $this->_dms->getDB();
991
992        $queryStr = "UPDATE `tblWorkflowTransitions` SET `nextstate` = ".$newNextState->getID()." WHERE `id` = " . $this->_id;
993        $res = $db->getResult($queryStr);
994        if (!$res) {
995            return false;
996        }
997
998        $this->_nextstate = $newNextState;
999        return true;
1000    } /* }}} */
1001
1002    /**
1003     * @return SeedDMS_Core_Workflow_Action
1004     */
1005    public function getAction() { return $this->_action; }
1006
1007    /**
1008     * @param SeedDMS_Core_Workflow_Action $newAction
1009     * @return bool
1010     */
1011    public function setAction($newAction) { /* {{{ */
1012        $db = $this->_dms->getDB();
1013
1014        $queryStr = "UPDATE `tblWorkflowTransitions` SET `action` = ".$newAction->getID()." WHERE `id` = " . $this->_id;
1015        $res = $db->getResult($queryStr);
1016        if (!$res) {
1017            return false;
1018        }
1019
1020        $this->_action = $newAction;
1021        return true;
1022    } /* }}} */
1023
1024    /**
1025     * @return int
1026     */
1027    public function getMaxTime() { return $this->_maxtime; }
1028
1029    /**
1030     * @param $maxtime
1031     * @return bool
1032     */
1033    public function setMaxTime($maxtime) { /* {{{ */
1034        $db = $this->_dms->getDB();
1035
1036        $queryStr = "UPDATE `tblWorkflowTransitions` SET `maxtime` = ".intval($maxtime)." WHERE `id` = " . $this->_id;
1037        $res = $db->getResult($queryStr);
1038        if (!$res) {
1039            return false;
1040        }
1041
1042        $this->_maxtime = $maxtime;
1043        return true;
1044    } /* }}} */
1045
1046    /**
1047     * Get all users allowed to trigger this transition
1048     *
1049     * @return SeedDMS_Core_User[]|bool list of users
1050     */
1051    public function getUsers() { /* {{{ */
1052        $db = $this->_dms->getDB();
1053
1054        if ($this->_users) {
1055            return $this->_users;
1056        }
1057
1058        $queryStr = "SELECT * FROM `tblWorkflowTransitionUsers` WHERE `transition`=".$this->_id;
1059        $resArr = $db->getResultArray($queryStr);
1060        if (is_bool($resArr) && $resArr == false) {
1061            return false;
1062        }
1063
1064        $users = array();
1065        for ($i = 0; $i < count($resArr); $i++) {
1066            $user = new SeedDMS_Core_Workflow_Transition_User($resArr[$i]['id'], $this, $this->_dms->getUser($resArr[$i]['userid']));
1067            $user->setDMS($this->_dms);
1068            $users[$i] = $user;
1069        }
1070
1071        /* Check if 'onFilterTransitionUsers' callback is set */
1072        if (isset($this->_dms->callbacks['onFilterTransitionUsers'])) {
1073            foreach ($this->_dms->callbacks['onFilterTransitionUsers'] as $callback) {
1074                $ret = call_user_func($callback[0], $callback[1], $this, $users);
1075                if (is_bool($ret)) {
1076                    return $ret;
1077                }
1078                $users = $ret;
1079            }
1080        }
1081
1082        $this->_users = $users;
1083
1084        return $this->_users;
1085    } /* }}} */
1086
1087    /**
1088     * Get all users allowed to trigger this transition
1089     *
1090     * @return SeedDMS_Core_Group[]|bool list of users
1091     */
1092    public function getGroups() { /* {{{ */
1093        $db = $this->_dms->getDB();
1094
1095        if ($this->_groups) {
1096            return $this->_groups;
1097        }
1098
1099        $queryStr = "SELECT * FROM `tblWorkflowTransitionGroups` WHERE `transition`=".$this->_id;
1100        $resArr = $db->getResultArray($queryStr);
1101        if (is_bool($resArr) && $resArr == false) {
1102            return false;
1103        }
1104
1105        $groups = array();
1106        for ($i = 0; $i < count($resArr); $i++) {
1107            $group = new SeedDMS_Core_Workflow_Transition_Group($resArr[$i]['id'], $this, $this->_dms->getGroup($resArr[$i]['groupid']), $resArr[$i]['minusers']);
1108            $group->setDMS($this->_dms);
1109            $groups[$i] = $group;
1110        }
1111
1112        /* Check if 'onFilterTransitionGroups' callback is set */
1113        if (isset($this->_dms->callbacks['onFilterTransitionGroups'])) {
1114            foreach ($this->_dms->callbacks['onFilterTransitionGroups'] as $callback) {
1115                $ret = call_user_func($callback[0], $callback[1], $this, $groups);
1116                if (is_bool($ret)) {
1117                    return $ret;
1118                }
1119                $groups = $ret;
1120            }
1121        }
1122
1123        $this->_groups = $groups;
1124
1125        return $this->_groups;
1126    } /* }}} */
1127
1128    /**
1129     * Remove the workflow transition
1130     *
1131     * @return boolean true on success or false in case of an error
1132     *         false is also returned if the workflow action is currently in use
1133     */
1134    public function remove() { /* {{{ */
1135        $db = $this->_dms->getDB();
1136
1137        $db->startTransaction();
1138
1139        // Delete workflow transition itself
1140        $queryStr = "DELETE FROM `tblWorkflowTransitions` WHERE `id` = " . $this->_id;
1141        if (!$db->getResult($queryStr)) {
1142            $db->rollbackTransaction();
1143            return false;
1144        }
1145
1146        $db->commitTransaction();
1147
1148        return true;
1149    } /* }}} */
1150
1151} /* }}} */
1152
1153/**
1154 * Class to represent a user allowed to trigger a workflow transition
1155 *
1156 * @category   DMS
1157 * @package    SeedDMS_Core
1158 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
1159 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
1160 * @version    Release: @package_version@
1161 */
1162class SeedDMS_Core_Workflow_Transition_User { /* {{{ */
1163    /**
1164     * @var integer id of workflow transition
1165     *
1166     * @access protected
1167     */
1168    protected $_id;
1169
1170    /**
1171     * @var object reference to the transtion this user belongs to
1172     *
1173     * @access protected
1174     */
1175    protected $_transition;
1176
1177    /**
1178     * @var object user allowed to trigger a transition
1179     *
1180     * @access protected
1181     */
1182    protected $_user;
1183
1184    /**
1185     * @var object reference to the dms instance this attribute belongs to
1186     _Core_Workflow_Transition_Group
1187     * @access protected
1188     */
1189    protected $_dms;
1190
1191    /**
1192     * SeedDMS_Core_Workflow_Transition_User constructor.
1193     * @param $id
1194     * @param $transition
1195     * @param $user
1196     */
1197    public function __construct($id, $transition, $user) {
1198        $this->_id = $id;
1199        $this->_transition = $transition;
1200        $this->_user = $user;
1201    }
1202
1203    /**
1204     * @param $dms
1205     */
1206    public function setDMS($dms) { /* {{{ */
1207        $this->_dms = $dms;
1208    } /* }}} */
1209
1210    /**
1211     * Get the transtion itself
1212     *
1213     * @return object group
1214     */
1215    public function getTransition() { /* {{{ */
1216        return $this->_transition;
1217    } /* }}} */
1218
1219    /**
1220     * Get the user who is allowed to trigger the transition
1221     *
1222     * @return object user
1223     */
1224    public function getUser() { /* {{{ */
1225        return $this->_user;
1226    } /* }}} */
1227} /* }}} */
1228
1229/**
1230 * Class to represent a group allowed to trigger a workflow transition
1231 *
1232 * @category   DMS
1233 * @package    SeedDMS_Core
1234 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
1235 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
1236 * @version    Release: @package_version@
1237 */
1238class SeedDMS_Core_Workflow_Transition_Group { /* {{{ */
1239    /**
1240     * @var integer id of workflow transition
1241     *
1242     * @access protected
1243     */
1244    protected $_id;
1245
1246    /**
1247     * @var object reference to the transtion this group belongs to
1248     *
1249     * @access protected
1250     */
1251    protected $_transition;
1252    
1253    /**
1254     * @var integer number of users how must trigger the transition
1255     *
1256     * @access protected
1257     */
1258    protected $_numOfUsers;
1259
1260    /**
1261     * @var object group of users
1262     *
1263     * @access protected
1264     */
1265    protected $_group;
1266
1267    /**
1268     * @var object reference to the dms instance this attribute belongs to
1269     *
1270     * @access protected
1271     */
1272    protected $_dms;
1273
1274    /**
1275     * SeedDMS_Core_Workflow_Transition_Group constructor.
1276     * @param $id
1277     * @param $transition
1278     * @param $group
1279     * @param $numOfUsers
1280     */
1281    public function __construct($id, $transition, $group, $numOfUsers) { /* {{{ */
1282        $this->_id = $id;
1283        $this->_transition = $transition;
1284        $this->_group = $group;
1285        $this->_numOfUsers = $numOfUsers;
1286    } /* }}} */
1287
1288    /**
1289     * @param $dms
1290     */
1291    public function setDMS($dms) { /* {{{ */
1292        $this->_dms = $dms;
1293    } /* }}} */
1294
1295    /**
1296     * Get the transtion itself
1297     *
1298     * @return object group
1299     */
1300    public function getTransition() { /* {{{ */
1301        return $this->_transition;
1302    } /* }}} */
1303
1304    /**
1305     * Get the group whose user are allowed to trigger the transition
1306     *
1307     * @return object group
1308     */
1309    public function getGroup() { /* {{{ */
1310        return $this->_group;
1311    } /* }}} */
1312
1313    /**
1314     * Returns the number of users of this group needed to trigger the transition
1315     *
1316     * @return integer number of users
1317     */
1318    public function getNumOfUsers() { /* {{{ */
1319        return $this->_numOfUsers;
1320    } /* }}} */
1321
1322} /* }}} */
1323
1324/**
1325 * Class to represent a group allowed to trigger a workflow transition
1326 *
1327 * @category   DMS
1328 * @package    SeedDMS_Core
1329 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
1330 * @copyright  Copyright (C) 2012-2024 Uwe Steinmann
1331 * @version    Release: @package_version@
1332 */
1333class SeedDMS_Core_Workflow_Log { /* {{{ */
1334    /**
1335     * @var integer id of workflow log
1336     *
1337     * @access protected
1338     */
1339    protected $_id;
1340
1341    /**
1342     * @var object document this log entry belongs to
1343     *
1344     * @access protected
1345     */
1346    protected $_document;
1347
1348    /**
1349     * @var integer version of document this log entry belongs to
1350     *
1351     * @access protected
1352     */
1353    protected $_version;
1354
1355    /**
1356     * @var object workflow
1357     *
1358     * @access protected
1359     */
1360    protected $_workflow;
1361
1362    /**
1363     * @var object user initiating this log entry
1364     *
1365     * @access protected
1366     */
1367    protected $_user;
1368
1369    /**
1370     * @var object transition
1371     *
1372     * @access protected
1373     */
1374    protected $_transition;
1375
1376    /**
1377     * @var string date
1378     *
1379     * @access protected
1380     */
1381    protected $_date;
1382
1383    /**
1384     * @var string comment
1385     *
1386     * @access protected
1387     */
1388    protected $_comment;
1389
1390    /**
1391     * @var object reference to the dms instance this attribute belongs to
1392     *
1393     * @access protected
1394     */
1395    protected $_dms;
1396
1397    /**
1398     * SeedDMS_Core_Workflow_Log constructor.
1399     * @param $id
1400     * @param $document
1401     * @param $version
1402     * @param $workflow
1403     * @param $user
1404     * @param $transition
1405     * @param $date
1406     * @param $comment
1407     */
1408    public function __construct($id, $document, $version, $workflow, $user, $transition, $date, $comment) {
1409        $this->_id = $id;
1410        $this->_document = $document;
1411        $this->_version = $version;
1412        $this->_workflow = $workflow;
1413        $this->_user = $user;
1414        $this->_transition = $transition;
1415        $this->_date = $date;
1416        $this->_comment = $comment;
1417        $this->_dms = null;
1418    }
1419
1420    /**
1421     * @param $dms
1422     */
1423    public function setDMS($dms) { /* {{{ */
1424        $this->_dms = $dms;
1425    } /* }}} */
1426
1427    /**
1428     * @return object
1429     */
1430    public function getTransition() { /* {{{ */
1431        return $this->_transition;
1432    } /* }}} */
1433
1434    /**
1435     * @return object
1436     */
1437    public function getWorkflow() { /* {{{ */
1438        return $this->_workflow;
1439    } /* }}} */
1440
1441    /**
1442     * @return object
1443     */
1444    public function getUser() { /* {{{ */
1445        return $this->_user;
1446    } /* }}} */
1447
1448    /**
1449     * @return string
1450     */
1451    public function getComment() { /* {{{ */
1452        return $this->_comment;
1453    } /* }}} */
1454
1455    /**
1456     * @return string
1457     */
1458    public function getDate() { /* {{{ */
1459        return $this->_date;
1460    } /* }}} */
1461
1462} /* }}} */