Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
67.56% covered (warning)
67.56%
202 / 299
50.00% covered (danger)
50.00%
12 / 24
CRAP
0.00% covered (danger)
0.00%
0 / 1
SeedDMS_Core_Group
67.56% covered (warning)
67.56%
202 / 299
50.00% covered (danger)
50.00%
12 / 24
566.54
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getInstance
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
6.01
 getAllInstances
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
5.02
 isType
100.00% covered (success)
100.00%
1 / 1
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
 getDMS
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 getComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setComment
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 getUsers
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
5
 getManagers
93.75% covered (success)
93.75%
15 / 16
0.00% covered (danger)
0.00%
0 / 1
4.00
 addUser
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
 removeUser
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
 isMember
69.23% covered (warning)
69.23%
9 / 13
0.00% covered (danger)
0.00%
0 / 1
11.36
 toggleManager
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
4
 remove
0.00% covered (danger)
0.00%
0 / 64
0.00% covered (danger)
0.00%
0 / 1
272
 getReviewStatus
91.30% covered (success)
91.30%
21 / 23
0.00% covered (danger)
0.00%
0 / 1
8.04
 getApprovalStatus
90.91% covered (success)
90.91%
20 / 22
0.00% covered (danger)
0.00%
0 / 1
8.05
 getReceiptStatus
85.71% covered (warning)
85.71%
18 / 21
0.00% covered (danger)
0.00%
0 / 1
9.24
 getRevisionStatus
88.89% covered (warning)
88.89%
24 / 27
0.00% covered (danger)
0.00%
0 / 1
12.20
 getWorkflowStatus
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
56
 getNotifications
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
5.01
1<?php
2declare(strict_types=1);
3
4/**
5 * Implementation of the group 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) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe,
13 *             2010 Uwe Steinmann
14 * @version    Release: @package_version@
15 */
16
17/**
18 * Class to represent a user group in the document management system
19 *
20 * @category   DMS
21 * @package    SeedDMS_Core
22 * @author     Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
23 * @copyright  Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, 2010 Uwe Steinmann
24 * @version    Release: @package_version@
25 */
26class SeedDMS_Core_Group { /* {{{ */
27    /**
28     * The id of the user group
29     *
30     * @var integer
31     */
32    protected $_id;
33
34    /**
35     * The name of the user group
36     *
37     * @var string
38     */
39    protected $_name;
40
41    /**
42     * @var SeedDMS_Core_User[]
43     */
44    protected $_users;
45
46    /**
47     * The comment of the user group
48     *
49     * @var string
50     */
51    protected $_comment;
52
53    /**
54     * Back reference to DMS this user group belongs to
55     *
56     * @var SeedDMS_Core_DMS
57     */
58    protected $_dms;
59
60    function __construct($id, $name, $comment) { /* {{{ */
61        $this->_id = $id;
62        $this->_name = $name;
63        $this->_comment = $comment;
64        $this->_dms = null;
65    } /* }}} */
66
67    /**
68     * Return an instance of a group object
69     *
70     * @param string|integer $id Id, name of group, depending
71     * on the 3rd parameter.
72     * @param SeedDMS_Core_DMS $dms instance of dms
73     * @param string $by search by group name if set to 'name'. 
74     * Search by Id of group if left empty.
75     * @return SeedDMS_Core_Group|bool instance of class SeedDMS_Core_Group if group was
76     * found, null if group was not found, false in case of error
77     */
78    public static function getInstance($id, $dms, $by='') { /* {{{ */
79        $db = $dms->getDB();
80
81        switch($by) {
82        case 'name':
83            $queryStr = "SELECT * FROM `tblGroups` WHERE `name` = ".$db->qstr($id);
84            break;
85        default:
86            $queryStr = "SELECT * FROM `tblGroups` WHERE `id` = " . (int) $id;
87        }
88
89        $resArr = $db->getResultArray($queryStr);
90        if (is_bool($resArr) && $resArr == false)
91            return false;
92        else if (count($resArr) != 1) //wenn, dann wohl eher 0 als > 1 ;-)
93            return null;
94
95        $resArr = $resArr[0];
96
97        $group = new self($resArr["id"], $resArr["name"], $resArr["comment"]);
98        $group->setDMS($dms);
99        return $group;
100    } /* }}} */
101
102    /**
103     * @param $orderby
104     * @param SeedDMS_Core_DMS $dms
105     * @return array|bool
106     */
107    public static function getAllInstances($orderby, $dms) { /* {{{ */
108        $db = $dms->getDB();
109
110        switch($orderby) {
111        default:
112            $queryStr = "SELECT * FROM `tblGroups` ORDER BY `name`";
113        }
114        $resArr = $db->getResultArray($queryStr);
115
116        if (is_bool($resArr) && $resArr == false)
117            return false;
118
119        $groups = array();
120        for ($i = 0; $i < count($resArr); $i++) {
121            $group = new self($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["comment"]);
122            $group->setDMS($dms);
123            $groups[$i] = $group;
124        }
125
126        return $groups;
127    } /* }}} */
128
129    /**
130     * Check if this object is of type 'group'.
131     *
132     * @param string $type type of object
133     */
134    public function isType($type) { /* {{{ */
135        return $type == 'group';
136    } /* }}} */
137
138    /**
139     * @param SeedDMS_Core_DMS $dms
140     */
141    function setDMS($dms) { /* {{{ */
142        $this->_dms = $dms;
143    } /* }}} */
144
145    /**
146     * @return SeedDMS_Core_DMS $dms
147     */
148    function getDMS() {
149        return $this->_dms;
150    }
151
152    /**
153     * @return int
154     */
155    function getID() { return $this->_id; }
156
157    /**
158     * @return string
159     */
160    function getName() { return $this->_name; }
161
162    /**
163     * @param $newName
164     * @return bool
165     */
166    function setName($newName) { /* {{{ */
167        $newName = trim($newName);
168        if(!$newName)
169            return false;
170
171        $db = $this->_dms->getDB();
172
173        $queryStr = "UPDATE `tblGroups` SET `name` = ".$db->qstr($newName)." WHERE `id` = " . $this->_id;
174        if (!$db->getResult($queryStr))
175            return false;
176
177        $this->_name = $newName;
178        return true;
179    } /* }}} */
180
181    /**
182     * @return string
183     */
184    function getComment() { return $this->_comment; }
185
186    /**
187     * @param $newComment
188     * @return bool
189     */
190    function setComment($newComment) { /* {{{ */
191        $db = $this->_dms->getDB();
192
193        $queryStr = "UPDATE `tblGroups` SET `comment` = ".$db->qstr($newComment)." WHERE `id` = " . $this->_id;
194        if (!$db->getResult($queryStr))
195            return false;
196
197        $this->_comment = $newComment;
198        return true;
199    } /* }}} */
200
201    /**
202     * @return SeedDMS_Core_User[]|bool
203     */
204    function getUsers() { /* {{{ */
205        $db = $this->_dms->getDB();
206
207        if (!isset($this->_users)) {
208            $queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ".
209                "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
210                "WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."'";
211            $resArr = $db->getResultArray($queryStr);
212            if (is_bool($resArr) && $resArr == false)
213                return false;
214
215            $this->_users = array();
216
217            $classnamerole = $this->_dms->getClassname('role');
218            $classname = $this->_dms->getClassname('user');
219            foreach ($resArr as $row) {
220                /** @var SeedDMS_Core_User $user */
221                $role = $classnamerole::getInstance($row['role'], $this->_dms);
222                $user = new $classname($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $role, $row['hidden']);
223                $user->setDMS($this->_dms);
224                array_push($this->_users, $user);
225            }
226        }
227        return $this->_users;
228    } /* }}} */
229
230    /**
231     * @return SeedDMS_Core_User[]|bool
232     */
233    function getManagers() { /* {{{ */
234        $db = $this->_dms->getDB();
235
236        $queryStr = "SELECT `tblUsers`.* FROM `tblUsers` ".
237            "LEFT JOIN `tblGroupMembers` ON `tblGroupMembers`.`userID`=`tblUsers`.`id` ".
238            "WHERE `tblGroupMembers`.`groupID` = '". $this->_id ."' AND `tblGroupMembers`.`manager` = 1";
239        $resArr = $db->getResultArray($queryStr);
240        if (is_bool($resArr) && $resArr == false)
241            return false;
242
243        $managers = array();
244
245        $classnamerole = $this->_dms->getClassname('role');
246        $classname = $this->_dms->getClassname('user');
247        foreach ($resArr as $row) {
248            /** @var SeedDMS_Core_User $user */
249            $role = $classnamerole::getInstance($row['role'], $this->_dms);
250            $user = new $classname($row["id"], $row["login"], $row["pwd"], $row["fullName"], $row["email"], $row["language"], $row["theme"], $row["comment"], $role, $row['hidden']);
251            $user->setDMS($this->_dms);
252            array_push($managers, $user);
253        }
254        return $managers;
255    } /* }}} */
256
257    /**
258     * @param SeedDMS_Core_User $user
259     * @param bool $asManager
260     * @return bool
261     */
262    function addUser($user,$asManager=false) { /* {{{ */
263        $db = $this->_dms->getDB();
264
265        $queryStr = "INSERT INTO `tblGroupMembers` (`groupID`, `userID`, `manager`) VALUES (".$this->_id.", ".$user->getID(). ", " . ($asManager?"1":"0") ." )";
266        $res = $db->getResult($queryStr);
267
268        if (!$res) return false;
269
270        unset($this->_users);
271        return true;
272    } /* }}} */
273
274    /**
275     * @param SeedDMS_Core_User $user
276     * @return bool
277     */
278    function removeUser($user) { /* {{{ */
279        $db = $this->_dms->getDB();
280
281        $queryStr = "DELETE FROM `tblGroupMembers` WHERE `groupID` = ".$this->_id." AND `userID` = ".$user->getID();
282        $res = $db->getResult($queryStr);
283
284        if (!$res) return false;
285        unset($this->_users);
286        return true;
287    } /* }}} */
288
289    /**
290     * Check if user is member of group
291     *
292     * @param SeedDMS_Core_User $user user to be checked
293     * @param boolean $asManager also check whether user is manager of group if
294     * set to true, otherwise does not care about manager status
295     * @return boolean true if user is member, otherwise false
296     */
297    function isMember($user, $asManager=false) { /* {{{ */
298        if (isset($this->_users)&&!$asManager) {
299            foreach ($this->_users as $usr)
300                if ($usr->getID() == $user->getID())
301                    return true;
302            return false;
303        }
304
305        $db = $this->_dms->getDB();
306        $queryStr = "SELECT * FROM `tblGroupMembers` WHERE `groupID` = " . $this->_id . " AND `userID` = " . $user->getID();
307        if ($asManager)
308             $queryStr .= " AND `manager` = 1";
309
310        $resArr = $db->getResultArray($queryStr);
311
312        if (is_bool($resArr) && $resArr == false) return false;
313        if (count($resArr) != 1) return false;
314
315        return true;
316    } /* }}} */
317
318    /**
319     * Toggle manager status of user
320     *
321     * @param SeedDMS_Core_User $user
322     * @return boolean true if operation was successful, otherwise false
323     */
324    function toggleManager($user) { /* {{{ */
325        $db = $this->_dms->getDB();
326
327        if (!$this->isMember($user)) return false;
328
329        if ($this->isMember($user,true)) $queryStr = "UPDATE `tblGroupMembers` SET `manager` = 0 WHERE `groupID` = ".$this->_id." AND `userID` = ".$user->getID();
330        else $queryStr = "UPDATE `tblGroupMembers` SET `manager` = 1 WHERE `groupID` = ".$this->_id." AND `userID` = ".$user->getID();
331
332        if (!$db->getResult($queryStr)) return false;
333        return true;
334    } /* }}} */
335
336    /**
337     * Delete user group
338     * This function deletes the user group and all it references, like access
339     * control lists, notifications, as a child of other groups, etc.
340     *
341     * @param SeedDMS_Core_User $user the user doing the removal (needed for entry in
342     *        review log.
343     * @return boolean true on success or false in case of an error
344     */
345    function remove($user) { /* {{{ */
346        $db = $this->_dms->getDB();
347
348        $db->startTransaction();
349
350        $queryStr = "DELETE FROM `tblGroupMembers` WHERE `groupID` = " . $this->_id;
351        if (!$db->getResult($queryStr)) {
352            $db->rollbackTransaction();
353            return false;
354        }
355        $queryStr = "DELETE FROM `tblACLs` WHERE `groupID` = " . $this->_id;
356        if (!$db->getResult($queryStr)) {
357            $db->rollbackTransaction();
358            return false;
359        }
360        $queryStr = "DELETE FROM `tblNotify` WHERE `groupID` = " . $this->_id;
361        if (!$db->getResult($queryStr)) {
362            $db->rollbackTransaction();
363            return false;
364        }
365        $queryStr = "DELETE FROM `tblMandatoryReviewers` WHERE `reviewerGroupID` = " . $this->_id;
366        if (!$db->getResult($queryStr)) {
367            $db->rollbackTransaction();
368            return false;
369        }
370        $queryStr = "DELETE FROM `tblMandatoryApprovers` WHERE `approverGroupID` = " . $this->_id;
371        if (!$db->getResult($queryStr)) {
372            $db->rollbackTransaction();
373            return false;
374        }
375        $queryStr = "DELETE FROM `tblWorkflowTransitionGroups` WHERE `groupid` = " . $this->_id;
376        if (!$db->getResult($queryStr)) {
377            $db->rollbackTransaction();
378            return false;
379        }
380        $queryStr = "DELETE FROM `tblGroups` WHERE `id` = " . $this->_id;
381        if (!$db->getResult($queryStr)) {
382            $db->rollbackTransaction();
383            return false;
384        }
385
386        // TODO : update document status if reviewer/approver has been deleted
387
388
389        $reviewStatus = $this->getReviewStatus();
390        foreach ($reviewStatus as $r) {
391            $queryStr = "INSERT INTO `tblDocumentReviewLog` (`reviewID`, `status`, `comment`, `date`, `userID`) ".
392                "VALUES ('". $r["reviewID"] ."', '-2', 'Review group removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
393            $res=$db->getResult($queryStr);
394            if(!$res) {
395                $db->rollbackTransaction();
396                return false;
397            }
398        }
399
400        $approvalStatus = $this->getApprovalStatus();
401        foreach ($approvalStatus as $a) {
402            $queryStr = "INSERT INTO `tblDocumentApproveLog` (`approveID`, `status`, `comment`, `date`, `userID`) ".
403                "VALUES ('". $a["approveID"] ."', '-2', 'Approval group removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
404            $res=$db->getResult($queryStr);
405            if(!$res) {
406                $db->rollbackTransaction();
407                return false;
408            }
409        }
410
411        $receiptStatus = $this->getReceiptStatus();
412        foreach ($receiptStatus as $r) {
413            $queryStr = "INSERT INTO `tblDocumentReceiptLog` (`receiptID`, `status`, `comment`, `date`, `userID`) ".
414                "VALUES ('". $r["receiptID"] ."', '-2', 'Recipients group removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
415            $res=$db->getResult($queryStr);
416            if(!$res) {
417                $db->rollbackTransaction();
418                return false;
419            }
420        }
421
422        $revisionStatus = $this->getRevisionStatus();
423        foreach ($revisionStatus as $r) {
424            $queryStr = "INSERT INTO `tblDocumentRevisionLog` (`revisionID`, `status`, `comment`, `date`, `userID`) ".
425                "VALUES ('". $r["revisionID"] ."', '-2', 'Revisors group removed from process', ".$db->getCurrentDatetime().", '". $user->getID() ."')";
426            $res=$db->getResult($queryStr);
427            if(!$res) {
428                $db->rollbackTransaction();
429                return false;
430            }
431        }
432
433        $db->commitTransaction();
434
435        return true;
436    } /* }}} */
437
438    function getReviewStatus($documentID=null, $version=null) { /* {{{ */
439        $db = $this->_dms->getDB();
440
441        if (!$db->createTemporaryTable("ttreviewid")) {
442            return false;
443        }
444
445        $status = array();
446
447        // See if the group is assigned as a reviewer.
448        $queryStr = "SELECT `tblDocumentReviewers`.*, `tblDocumentReviewLog`.`status`, ".
449            "`tblDocumentReviewLog`.`comment`, `tblDocumentReviewLog`.`date`, ".
450            "`tblDocumentReviewLog`.`userID` ".
451            "FROM `tblDocumentReviewers` ".
452            "LEFT JOIN `tblDocumentReviewLog` USING (`reviewID`) ".
453            "LEFT JOIN `ttreviewid` on `ttreviewid`.`maxLogID` = `tblDocumentReviewLog`.`reviewLogID` ".
454            "WHERE `ttreviewid`.`maxLogID`=`tblDocumentReviewLog`.`reviewLogID` ".
455            ($documentID==null ? "" : "AND `tblDocumentReviewers`.`documentID` = '". (int) $documentID ."' ").
456            ($version==null ? "" : "AND `tblDocumentReviewers`.`version` = '". (int) $version ."' ").
457            "AND `tblDocumentReviewers`.`type`='1' ".
458            "AND `tblDocumentReviewers`.`required`='". $this->_id ."' ".
459            "ORDER BY `tblDocumentReviewLog`.`reviewLogID` DESC";
460        $resArr = $db->getResultArray($queryStr);
461        if (is_bool($resArr) && $resArr == false)
462            return false;
463        if (count($resArr)>0) {
464            foreach ($resArr as $res)
465                $status[] = $res;
466        }
467        return $status;
468    } /* }}} */
469
470    function getApprovalStatus($documentID=null, $version=null) { /* {{{ */
471        $db = $this->_dms->getDB();
472
473        if (!$db->createTemporaryTable("ttapproveid")) {
474            return false;
475        }
476
477        $status = array();
478
479        // See if the group is assigned as an approver.
480        $queryStr = "SELECT `tblDocumentApprovers`.*, `tblDocumentApproveLog`.`status`, ".
481            "`tblDocumentApproveLog`.`comment`, `tblDocumentApproveLog`.`date`, ".
482            "`tblDocumentApproveLog`.`userID` ".
483            "FROM `tblDocumentApprovers` ".
484            "LEFT JOIN `tblDocumentApproveLog` USING (`approveID`) ".
485            "LEFT JOIN `ttapproveid` on `ttapproveid`.`maxLogID` = `tblDocumentApproveLog`.`approveLogID` ".
486            "WHERE `ttapproveid`.`maxLogID`=`tblDocumentApproveLog`.`approveLogID` ".
487            ($documentID==null ? "" : "AND `tblDocumentApprovers`.`documentID` = '". (int) $documentID ."' ").
488            ($version==null ? "" : "AND `tblDocumentApprovers`.`version` = '". (int) $version ."' ").
489            "AND `tblDocumentApprovers`.`type`='1' ".
490            "AND `tblDocumentApprovers`.`required`='". $this->_id ."' ";
491        $resArr = $db->getResultArray($queryStr);
492        if (is_bool($resArr) && $resArr == false)
493            return false;
494        if (count($resArr)>0) {
495            foreach ($resArr as $res)
496                $status[] = $res;
497        }
498
499        return $status;
500    } /* }}} */
501
502    function getReceiptStatus($documentID=null, $version=null) { /* {{{ */
503        $db = $this->_dms->getDB();
504
505        $status = array();
506
507        // See if the group is assigned as a recipient.
508        $queryStr = "SELECT `tblDocumentRecipients`.*, `tblDocumentReceiptLog`.`status`, ".
509            "`tblDocumentReceiptLog`.`comment`, `tblDocumentReceiptLog`.`date`, ".
510            "`tblDocumentReceiptLog`.`userID` ".
511            "FROM `tblDocumentRecipients` ".
512            "LEFT JOIN `tblDocumentReceiptLog` USING (`receiptID`) ".
513            "WHERE `tblDocumentRecipients`.`type`='1' ".
514            ($documentID==null ? "" : "AND `tblDocumentRecipients`.`documentID` = '". (int) $documentID ."' ").
515            ($version==null ? "" : "AND `tblDocumentRecipients`.`version` = '". (int) $version ."' ").
516            "AND `tblDocumentRecipients`.`required`='". $this->_id ."' ";
517        $resArr = $db->getResultArray($queryStr);
518        if (is_bool($resArr) && $resArr == false)
519            return false;
520        if (count($resArr)>0) {
521            foreach ($resArr as $res) {
522                if(isset($status[$res['documentID']])) {
523                    if($status[$res['documentID']]['date'] < $res['date']) {
524                        $status[$res['documentID']] = $res;
525                    }
526                } else {
527                    $status[$res['documentID']] = $res;
528                }
529            }
530        }
531        return $status;
532    } /* }}} */
533
534    function getRevisionStatus($documentID=null, $version=null) { /* {{{ */
535        $db = $this->_dms->getDB();
536
537        $status = array();
538
539        if (!$db->createTemporaryTable("ttcontentid")) {
540            return false;
541        }
542        // See if the group is assigned as a revisor.
543        $queryStr = "SELECT `tblDocumentRevisors`.*, `tblDocumentRevisionLog`.`status`, ".
544            "`tblDocumentRevisionLog`.`comment`, `tblDocumentRevisionLog`.`date`, ".
545            "`tblDocumentRevisionLog`.`userID` ".
546            "FROM `tblDocumentRevisors` ".
547            "LEFT JOIN `tblDocumentRevisionLog` USING (`revisionID`) ".
548            "LEFT JOIN `ttcontentid` ON `ttcontentid`.`maxVersion` = `tblDocumentRevisors`.`version` AND `ttcontentid`.`document` = `tblDocumentRevisors`.`documentID` ".
549            "WHERE `tblDocumentRevisors`.`type`='1' ".
550            ($documentID==null ? "" : "AND `tblDocumentRevisors`.`documentID` = '". (int) $documentID ."' ").
551            ($version==null ? "" : "AND `tblDocumentRevisors`.`version` = '". (int) $version ."' ").
552            ($documentID==null && $version==null ? "AND `ttcontentid`.`maxVersion` = `tblDocumentRevisors`.`version` " : "").
553            "AND `tblDocumentRevisors`.`required`='". $this->_id ."' ".
554            "ORDER BY `tblDocumentRevisionLog`.`revisionLogID` DESC";
555        $resArr = $db->getResultArray($queryStr);
556        if ($resArr === false)
557            return false;
558        if (count($resArr)>0) {
559            foreach ($resArr as $res) {
560                if($res['date']) {
561                    if(isset($status[$res['documentID']])) {
562                        if($status[$res['documentID']]['date'] < $res['date']) {
563                            $status[$res['documentID']] = $res;
564                        }
565                    } else {
566                        $status[$res['documentID']] = $res;
567                    }
568                }
569            }
570        }
571        return $status;
572    } /* }}} */
573
574    /**
575     * Get a list of documents with a workflow
576     *
577     * @param int $documentID optional document id for which to retrieve the
578     *        reviews
579     * @param int $version optional version of the document
580     * @return bool|array list of all workflows
581     */
582    function getWorkflowStatus($documentID=null, $version=null) { /* {{{ */
583        $db = $this->_dms->getDB();
584
585        $queryStr = 'select distinct d.*, c.`groupid` from `tblWorkflowTransitions` a left join `tblWorkflows` b on a.`workflow`=b.`id` left join `tblWorkflowTransitionGroups` c on a.`id`=c.`transition` left join `tblWorkflowDocumentContent` d on b.`id`=d.`workflow` where d.`document` is not null and a.`state`=d.`state` and c.`groupid`='.$this->_id;
586        if($documentID) {
587            $queryStr .= ' AND d.`document`='.(int) $documentID;
588            if($version)
589                $queryStr .= ' AND d.`version`='.(int) $version;
590        }
591        $resArr = $db->getResultArray($queryStr);
592        if (is_bool($resArr) && $resArr == false)
593            return false;
594        $result = array();
595        if (count($resArr)>0) {
596            foreach ($resArr as $res) {
597                $result[] = $res;
598            }
599        }
600        return $result;
601    } /* }}} */
602
603    /**
604     * Get all notifications of group
605     *
606     * @param integer $type type of item (T_DOCUMENT or T_FOLDER)
607     * @return SeedDMS_Core_Notification[]|bool array of notifications
608     */
609    function getNotifications($type=0) { /* {{{ */
610        $db = $this->_dms->getDB();
611        $queryStr = "SELECT `tblNotify`.* FROM `tblNotify` ".
612         "WHERE `tblNotify`.`groupID` = ". $this->_id;
613        if($type) {
614            $queryStr .= " AND `tblNotify`.`targetType` = ". (int) $type;
615        }
616
617        $resArr = $db->getResultArray($queryStr);
618        if (is_bool($resArr) && !$resArr)
619            return false;
620
621        $notifications = array();
622        foreach ($resArr as $row) {
623            $not = new SeedDMS_Core_Notification($row["target"], $row["targetType"], $row["userID"], $row["groupID"]);
624            $not->setDMS($this->_dms);
625            array_push($notifications, $not);
626        }
627
628        return $notifications;
629    } /* }}} */
630
631} /* }}} */