3 * FusionForge Documentation Manager
5 * Copyright 2016-2017, Franck Villaume - TrivialDev
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'docman/DocumentReview.class.php';
25 require_once $gfcommon.'docman/DocumentReviewCommentFactory.class.php';
27 class DocumentReviewFactory extends FFError {
29 * The Document object.
31 * @var object $Document
36 * @var array $reviews Reviews of this document
38 var $reviews = array();
43 function __construct(&$Document) {
44 parent::__construct();
45 if (!$Document || !is_object($Document)) {
46 $this->setError(_('No Valid Document Object'));
49 if ($Document->isError()) {
50 $this->setError(_('Document')._(': ').$Document->getErrorMessage());
53 $this->Document =& $Document;
57 function getReviews($serialids = array()) {
58 $res = db_query_params('SELECT doc_review.revid as revid, created_by, statusid, docid, startdate, enddate, title, description, doc_review_version.serialid as serialid FROM doc_review, doc_review_version
59 WHERE doc_review.revid = doc_review_version.revid AND doc_review_version.serialid = ANY ($1) AND doc_review.docid = $2 ORDER BY enddate DESC',
60 array(db_int_array_to_any_clause($serialids), $this->Document->getID()));
62 while ($arr = db_fetch_array($res)) {
63 $dr = new DocumentReview($this->Document, $arr['revid']);
64 $drcf = new DocumentReviewCommentFactory($dr);
65 $arr['comments'] = $drcf->getComments();
66 foreach ($arr['comments'] as $comment) {
67 unset($comment->DocumentReview);
69 $arr['users'] = $dr->getUsers();
70 $this->reviews[] = $arr;
74 return $this->reviews;
77 function getReviewsHTML($serialids = array()) {
80 $this->getReviews($serialids);
82 if ($this->getReviewsCounter() > 0) {
83 $titleArr = array('ID', _('Version'), _('Title'), _('Created By'), _('Status'), _('Start date'), _('End date'), _('Progress'), _('Comments'), _('Actions'));
84 $classth = array('', '', '', '', '', 'unsortable');
85 $return .= $HTML->listTableTop($titleArr, array(), 'full sortable', 'sortable_docman_listreview', $classth);
86 foreach ($this->reviews as $thereview) {
87 $dr = new DocumentReview($this->Document, $thereview[0]);
89 $cells[][] = $thereview[0];
90 $cells[] = array($dr->getVersion(), 'id' => 'docversionreview'.$dr->getVersion());
91 $cells[] = array($dr->getTitle(), 'title' => $dr->getDescription());
92 $cells[][] = $dr->getCreateByRealNameLink();
93 $cells[][] = $dr->getStatusIcon();
94 $cells[][] = strftime(_('%Y-%m-%d'), $dr->getStartdate());
96 if (($dr->getStatusID() != 2 && $dr->getStatusID() != 4) && (time() > $dr->getEnddate())) {
97 $overdue = $HTML->getErrorPic(_('Review overdue'), 'overdue');
99 $cells[][] = strftime(_('%Y-%m-%d'), $dr->getEnddate()).$overdue;
100 $cells[][] = $dr->getProgressbar();
101 $drcf = new DocumentReviewCommentFactory($dr);
102 $cells[][] = $drcf->getNbComments();
104 $user = session_get_user();
105 $users = $dr->getUsers(array(1, 2));
106 if ($dr->getStatusID() != 2 && $dr->getStatusID() != 4) {
107 if ($user->getID() == $dr->getCreatedBy()) {
108 $actions .= $dr->getReminderAction().$dr->getEditAction().$dr->getCompleteAction();
111 foreach ($users as $ruser) {
112 if ($user->getID() == $ruser['userid']) {
116 if (($dr->getStatusID() == 1) && (($user->getID() == $dr->getCreatedBy()) || $userfound)) {
117 $actions .= $dr->getCommentAction();
119 if ($user->getID() == $dr->getCreatedBy()) {
120 $actions .= $dr->getDeleteAction();
123 $actions .= $dr->getReadAction();
126 $cells[][] = $actions;
127 $return .= $HTML->multiTableRow(array('id' => 'docreview'.$thereview[0]), $cells);
128 if ($dr->getStatusID() == 1) {
132 $return .= $HTML->listTableBottom();
134 $return = $HTML->information(_('No Reviews.'));
137 $return .= html_e('button', array('id' => 'doc_review_addbutton', 'type' => 'button', 'onclick' => 'javascript:controllerListFile.toggleAddReviewView()'), _('Add new review'));
143 function getReviewsCounter() {
144 return count($this->reviews);