| 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-2011 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 | /**␊ |
| 25 | * A comment to an issue.␊ |
| 26 | *␊ |
| 27 | * The first description of an issue is also stored as a comment.␊ |
| 28 | *␊ |
| 29 | * A comment is also tracking the changes in the main issue.␊ |
| 30 | */␊ |
| 31 | class IDF_IssueComment extends Pluf_Model␊ |
| 32 | {␊ |
| 33 | public $_model = __CLASS__;␊ |
| 34 | ␊ |
| 35 | function init()␊ |
| 36 | {␊ |
| 37 | $this->_a['table'] = 'idf_issuecomments';␊ |
| 38 | $this->_a['model'] = __CLASS__;␊ |
| 39 | $this->_a['cols'] = array(␊ |
| 40 | // It is mandatory to have an "id" column.␊ |
| 41 | 'id' =>␊ |
| 42 | array(␊ |
| 43 | 'type' => 'Pluf_DB_Field_Sequence',␊ |
| 44 | 'blank' => true,␊ |
| 45 | ),␊ |
| 46 | 'issue' =>␊ |
| 47 | array(␊ |
| 48 | 'type' => 'Pluf_DB_Field_Foreignkey',␊ |
| 49 | 'model' => 'IDF_Issue',␊ |
| 50 | 'blank' => false,␊ |
| 51 | 'verbose' => __('issue'),␊ |
| 52 | 'relate_name' => 'comments',␊ |
| 53 | ),␊ |
| 54 | 'content' =>␊ |
| 55 | array(␊ |
| 56 | 'type' => 'Pluf_DB_Field_Text',␊ |
| 57 | 'blank' => false,␊ |
| 58 | 'verbose' => __('comment'),␊ |
| 59 | ),␊ |
| 60 | 'submitter' =>␊ |
| 61 | array(␊ |
| 62 | 'type' => 'Pluf_DB_Field_Foreignkey',␊ |
| 63 | 'model' => 'Pluf_User',␊ |
| 64 | 'blank' => false,␊ |
| 65 | 'verbose' => __('submitter'),␊ |
| 66 | 'relate_name' => 'commented_issue',␊ |
| 67 | ),␊ |
| 68 | 'changes' =>␊ |
| 69 | array(␊ |
| 70 | 'type' => 'Pluf_DB_Field_Serialized',␊ |
| 71 | 'blank' => true,␊ |
| 72 | 'verbose' => __('changes'),␊ |
| 73 | 'help_text' => __('Serialized array of the changes in the issue.'),␊ |
| 74 | ),␊ |
| 75 | 'creation_dtime' =>␊ |
| 76 | array(␊ |
| 77 | 'type' => 'Pluf_DB_Field_Datetime',␊ |
| 78 | 'blank' => true,␊ |
| 79 | 'verbose' => __('creation date'),␊ |
| 80 | ),␊ |
| 81 | );␊ |
| 82 | $this->_a['idx'] = array(␊ |
| 83 | 'creation_dtime_idx' =>␊ |
| 84 | array(␊ |
| 85 | 'col' => 'creation_dtime',␊ |
| 86 | 'type' => 'normal',␊ |
| 87 | ),␊ |
| 88 | );␊ |
| 89 | }␊ |
| 90 | ␊ |
| 91 | function changedIssue()␊ |
| 92 | {␊ |
| 93 | return (is_array($this->changes) and count($this->changes) > 0);␊ |
| 94 | }␊ |
| 95 | ␊ |
| 96 | function _toIndex()␊ |
| 97 | {␊ |
| 98 | return $this->content;␊ |
| 99 | }␊ |
| 100 | ␊ |
| 101 | function preDelete()␊ |
| 102 | {␊ |
| 103 | IDF_Timeline::remove($this);␊ |
| 104 | }␊ |
| 105 | ␊ |
| 106 | function preSave($create=false)␊ |
| 107 | {␊ |
| 108 | if ($this->id == '') {␊ |
| 109 | $this->creation_dtime = gmdate('Y-m-d H:i:s');␊ |
| 110 | }␊ |
| 111 | }␊ |
| 112 | ␊ |
| 113 | function postSave($create=false)␊ |
| 114 | {␊ |
| 115 | if ($create) {␊ |
| 116 | // Check if more than one comment for this issue. We do␊ |
| 117 | // not want to insert the first comment in the timeline as␊ |
| 118 | // the issue itself is inserted.␊ |
| 119 | $sql = new Pluf_SQL('issue=%s', array($this->issue));␊ |
| 120 | $co = Pluf::factory('IDF_IssueComment')->getList(array('filter'=>$sql->gen()));␊ |
| 121 | if ($co->count() > 1) {␊ |
| 122 | IDF_Timeline::insert($this, $this->get_issue()->get_project(),␊ |
| 123 | $this->get_submitter());␊ |
| 124 | }␊ |
| 125 | }␊ |
| 126 | IDF_Search::index($this->get_issue());␊ |
| 127 | }␊ |
| 128 | ␊ |
| 129 | public function timelineFragment($request)␊ |
| 130 | {␊ |
| 131 | $issue = $this->get_issue();␊ |
| 132 | $url = Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',␊ |
| 133 | array($request->project->shortname,␊ |
| 134 | $issue->id));␊ |
| 135 | $url .= '#ic'.$this->id;␊ |
| 136 | $out = "\n".'<tr class="log"><td><a href="'.$url.'">'.␊ |
| 137 | Pluf_esc(Pluf_Template_dateAgo($this->creation_dtime, 'without')).␊ |
| 138 | '</a></td><td>';␊ |
| 139 | $stag = new IDF_Template_ShowUser();␊ |
| 140 | $user = $stag->start($this->get_submitter(), $request, '', false);␊ |
| 141 | ␊ |
| 142 | $ic = (in_array($issue->status, $request->project->getTagIdsByStatus('closed'))) ? 'issue-c' : 'issue-o';␊ |
| 143 | $out .= sprintf(__('<a href="%1$s" class="%2$s" title="View issue">Issue %3$d</a>, %4$s'), $url, $ic, $issue->id, Pluf_esc($issue->summary));␊ |
| 144 | ␊ |
| 145 | if ($this->changedIssue()) {␊ |
| 146 | $out .= '<div class="issue-changes-timeline">';␊ |
| 147 | foreach ($this->changes as $w => $v) {␊ |
| 148 | $out .= '<strong>';␊ |
| 149 | switch ($w) {␊ |
| 150 | case 'su':␊ |
| 151 | $out .= __('Summary:'); break;␊ |
| 152 | case 'st':␊ |
| 153 | $out .= __('Status:'); break;␊ |
| 154 | case 'ow':␊ |
| 155 | $out .= __('Owner:'); break;␊ |
| 156 | case 'lb':␊ |
| 157 | $out .= __('Labels:'); break;␊ |
| 158 | case 'rel':␊ |
| 159 | $out .= __('Relations:'); break;␊ |
| 160 | }␊ |
| 161 | $out .= '</strong> ';␊ |
| 162 | if ($w == 'lb' || $w == 'rel') {␊ |
| 163 | foreach ($v as $t => $ls) {␊ |
| 164 | foreach ($ls as $l) {␊ |
| 165 | if ($t == 'rem') $out .= '<s>';␊ |
| 166 | $out .= Pluf_esc($l);␊ |
| 167 | if ($t == 'rem') $out .= '</s>';␊ |
| 168 | $out .= ' ';␊ |
| 169 | }␊ |
| 170 | }␊ |
| 171 | } else {␊ |
| 172 | $out .= Pluf_esc($v);␊ |
| 173 | }␊ |
| 174 | $out .= ' ';␊ |
| 175 | }␊ |
| 176 | $out .= '</div>';␊ |
| 177 | }␊ |
| 178 | $out .= '</td></tr>';␊ |
| 179 | $out .= "\n".'<tr class="extra"><td colspan="2">␊ |
| 180 | <div class="helptext right">'.sprintf(__('Comment on <a href="%1$s" class="%2$s">issue %3$d</a>, by %4$s'), $url, $ic, $issue->id, $user).'</div></td></tr>';␊ |
| 181 | return Pluf_Template::markSafe($out);␊ |
| 182 | }␊ |
| 183 | ␊ |
| 184 | public function feedFragment($request)␊ |
| 185 | {␊ |
| 186 | $issue = $this->get_issue();␊ |
| 187 | $url = Pluf::f('url_base')␊ |
| 188 | .Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view',␊ |
| 189 | array($request->project->shortname,␊ |
| 190 | $issue->id));␊ |
| 191 | $title = sprintf(__('%1$s: Comment on issue %2$d - %3$s'),␊ |
| 192 | Pluf_esc($request->project->name),␊ |
| 193 | $issue->id, Pluf_esc($issue->summary));␊ |
| 194 | $url .= '#ic'.$this->id;␊ |
| 195 | $date = Pluf_Date::gmDateToGmString($this->creation_dtime);␊ |
| 196 | $context = new Pluf_Template_Context_Request(␊ |
| 197 | $request,␊ |
| 198 | array('url' => $url,␊ |
| 199 | 'author' => $issue->get_submitter(),␊ |
| 200 | 'title' => $title,␊ |
| 201 | 'c' => $this,␊ |
| 202 | 'issue' => $issue,␊ |
| 203 | 'date' => $date)␊ |
| 204 | );␊ |
| 205 | $tmpl = new Pluf_Template('idf/issues/feedfragment.xml');␊ |
| 206 | return $tmpl->render($context);␊ |
| 207 | }␊ |
| 208 | ␊ |
| 209 | public function get_submitter_data()␊ |
| 210 | {␊ |
| 211 | return IDF_UserData::factory($this->get_submitter());␊ |
| 212 | }␊ |
| 213 | }␊ |
| 214 | |