| 1 | <?php |
| 2 | /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 3 | /* |
| 4 | # ***** BEGIN LICENSE BLOCK ***** |
| 5 | # This file is part of InDefero, an open source project management application. |
| 6 | # Copyright (C) 2008 Céondo Ltd and contributors. |
| 7 | # |
| 8 | # InDefero is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # InDefero is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program; if not, write to the Free Software |
| 20 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | # |
| 22 | # ***** END LICENSE BLOCK ***** */ |
| 23 | |
| 24 | Pluf::loadFunction('Pluf_HTTP_URL_urlForView'); |
| 25 | Pluf::loadFunction('Pluf_Template_dateAgo'); |
| 26 | |
| 27 | /** |
| 28 | * Base definition of a code review. |
| 29 | * |
| 30 | * A code review has a status, submitter, summary, description and is |
| 31 | * associated to a project. |
| 32 | * |
| 33 | * The real content of the review is in the IDF_Review_Patch which |
| 34 | * contains a given patch and associated comments from reviewers. |
| 35 | * |
| 36 | * Basically the hierarchy of the models is: |
| 37 | * - Review > Patch > Comment > Comment on file |
| 38 | * |
| 39 | * For each review, one can have several patches. Each patch, is |
| 40 | * getting a series of comments. A comment is tracking the state |
| 41 | * change in the review (like the issue comments). For each comment, |
| 42 | * we have a series of file comments. The file comments are associated |
| 43 | * to the a given modified file in the patch. |
| 44 | */ |
| 45 | class IDF_Review extends Pluf_Model |
| 46 | { |
| 47 | public $_model = __CLASS__; |
| 48 | |
| 49 | function init() |
| 50 | { |
| 51 | $this->_a['table'] = 'idf_reviews'; |
| 52 | $this->_a['model'] = __CLASS__; |
| 53 | $this->_a['cols'] = array( |
| 54 | // It is mandatory to have an "id" column. |
| 55 | 'id' => |
| 56 | array( |
| 57 | 'type' => 'Pluf_DB_Field_Sequence', |
| 58 | 'blank' => true, |
| 59 | ), |
| 60 | 'project' => |
| 61 | array( |
| 62 | 'type' => 'Pluf_DB_Field_Foreignkey', |
| 63 | 'model' => 'IDF_Project', |
| 64 | 'blank' => false, |
| 65 | 'verbose' => __('project'), |
| 66 | 'relate_name' => 'reviews', |
| 67 | ), |
| 68 | 'summary' => |
| 69 | array( |
| 70 | 'type' => 'Pluf_DB_Field_Varchar', |
| 71 | 'blank' => false, |
| 72 | 'size' => 250, |
| 73 | 'verbose' => __('summary'), |
| 74 | ), |
| 75 | 'submitter' => |
| 76 | array( |
| 77 | 'type' => 'Pluf_DB_Field_Foreignkey', |
| 78 | 'model' => 'Pluf_User', |
| 79 | 'blank' => false, |
| 80 | 'verbose' => __('submitter'), |
| 81 | 'relate_name' => 'submitted_review', |
| 82 | ), |
| 83 | 'interested' => |
| 84 | array( |
| 85 | 'type' => 'Pluf_DB_Field_Manytomany', |
| 86 | 'model' => 'Pluf_User', |
| 87 | 'blank' => true, |
| 88 | 'help_text' => 'Interested users will get an email notification when the review is changed.', |
| 89 | ), |
| 90 | 'tags' => |
| 91 | array( |
| 92 | 'type' => 'Pluf_DB_Field_Manytomany', |
| 93 | 'blank' => true, |
| 94 | 'model' => 'IDF_Tag', |
| 95 | 'verbose' => __('labels'), |
| 96 | ), |
| 97 | 'status' => |
| 98 | array( |
| 99 | 'type' => 'Pluf_DB_Field_Foreignkey', |
| 100 | 'blank' => false, |
| 101 | 'model' => 'IDF_Tag', |
| 102 | 'verbose' => __('status'), |
| 103 | ), |
| 104 | 'creation_dtime' => |
| 105 | array( |
| 106 | 'type' => 'Pluf_DB_Field_Datetime', |
| 107 | 'blank' => true, |
| 108 | 'verbose' => __('creation date'), |
| 109 | ), |
| 110 | 'modif_dtime' => |
| 111 | array( |
| 112 | 'type' => 'Pluf_DB_Field_Datetime', |
| 113 | 'blank' => true, |
| 114 | 'verbose' => __('modification date'), |
| 115 | ), |
| 116 | ); |
| 117 | $this->_a['idx'] = array( |
| 118 | 'modif_dtime_idx' => |
| 119 | array( |
| 120 | 'col' => 'modif_dtime', |
| 121 | 'type' => 'normal', |
| 122 | ), |
| 123 | ); |
| 124 | $table = $this->_con->pfx.'idf_review_idf_tag_assoc'; |
| 125 | $this->_a['views'] = array( |
| 126 | 'join_tags' => |
| 127 | array( |
| 128 | 'join' => 'LEFT JOIN '.$table |
| 129 | .' ON idf_review_id=id', |
| 130 | ), |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Iterate through the patches and comments to get the reviewers. |
| 136 | */ |
| 137 | function getReviewers() |
| 138 | { |
| 139 | $rev = new ArrayObject(); |
| 140 | foreach ($this->get_patches_list() as $p) { |
| 141 | foreach ($p->get_comments_list() as $c) { |
| 142 | $rev[] = $c->get_submitter(); |
| 143 | } |
| 144 | } |
| 145 | return Pluf_Model_RemoveDuplicates($rev); |
| 146 | } |
| 147 | |
| 148 | function __toString() |
| 149 | { |
| 150 | return $this->id.' - '.$this->summary; |
| 151 | } |
| 152 | |
| 153 | function _toIndex() |
| 154 | { |
| 155 | return ''; |
| 156 | } |
| 157 | |
| 158 | function preDelete() |
| 159 | { |
| 160 | IDF_Timeline::remove($this); |
| 161 | IDF_Search::remove($this); |
| 162 | } |
| 163 | |
| 164 | function preSave($create=false) |
| 165 | { |
| 166 | if ($create) { |
| 167 | $this->creation_dtime = gmdate('Y-m-d H:i:s'); |
| 168 | } |
| 169 | $this->modif_dtime = gmdate('Y-m-d H:i:s'); |
| 170 | } |
| 171 | |
| 172 | function postSave($create=false) |
| 173 | { |
| 174 | // At creation, we index after saving the associated patch. |
| 175 | if (!$create) IDF_Search::index($this); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Returns an HTML fragment used to display this review in the |
| 180 | * timeline. |
| 181 | * |
| 182 | * The request object is given to be able to check the rights and |
| 183 | * as such create links to other items etc. You can consider that |
| 184 | * if displayed, you can create a link to it. |
| 185 | * |
| 186 | * @param Pluf_HTTP_Request |
| 187 | * @return Pluf_Template_SafeString |
| 188 | */ |
| 189 | public function timelineFragment($request) |
| 190 | { |
| 191 | return ''; |
| 192 | } |
| 193 | |
| 194 | public function feedFragment($request) |
| 195 | { |
| 196 | return ''; |
| 197 | } |
| 198 | } |