1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
5 // partly - event.toHTML is borked... - we should use templating for this..
6 require_once 'MTrackWeb/Ticket.php';
8 class MTrackWeb_Events extends MTrackWeb_Ticket
19 $this->id = $pi ? $pi: (isset($_GET['id']) ? $_GET['id'] : 0);
20 $this->id = (int) $this->id ;
27 $start = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
28 $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit'] : 100;
32 DB_DataObject::debugLevel(1);
33 $d = DB_DataObject::factory('mtrack_change');
34 $d->ontable = 'mtrack_ticket';
36 $d->orderBy('changedate ASC'); // last first?
37 $d->limit ($start, $limit);
41 $this->events = array();
43 $this->events[$d->id] = clone($d);
46 $d = DB_DataObject::factory('mtrack_change_audit');
47 $d->whereAddIn('change_id', array_keys($this->events), 'int');
51 $this->events[$d->change_id]->audit[] = clone($d);
55 foreach($this->events as $c) {
56 echo $this->eventToHtml($c);
59 //$this->renderEvents();
62 function eventToHtml($e)
69 $cid = "comment:{$e->change_id}";
71 // tidied up by jquery..
72 $timestamp = $link->date($e->changedate, false);
77 // default is that something changed..
83 $comment_fields = array();
85 foreach ($e->audit as $citem) {
89 $ar = explode(':', $citem['fieldname'], 3);
90 if (count($ar) != 3) {
93 list($tbl,,$field) = $ar;
95 if ($tbl != 'ticket') {
96 // can get here if we created a new keyword, for example
103 $comments[] = $citem['value'];
104 $type = 'Comment added';
105 $comment_title = array_shift(explode("\n", $citem['value']));
114 $comment_fields[] = $field;
115 $ar = MTrackComponent::loadByIds($citem['value']);
116 $ar = array_map( function($e) { return $e->toHtml(); }, $ar);
117 $citem['value'] = join(', ', $ar);
123 $comment_fields[] = $field;
124 $citem['value'] = $e->get_milestones_list($citem['value']);
130 $comment_fields[] = $field;
131 $ar = MTrackKeyword::loadByIds($citem['value']);
132 $ar = array_map( function($e) { return $e->toHtml(); }, $ar);
133 $citem['value'] = join(', ', $ar);
137 $comment_fields[] = $field;
138 if ($citem['value'] !== null) {
139 $citem['value'] += 0;
141 if ($citem['oldvalue'] !== null) {
142 $citem['oldvalue'] += 0;
147 $comment_fields[] = $field;
148 if ($field[0] == '@') {
149 $main = isset($pseudo_fields[$field]) ? $pseudo_fields[$field] : '';
150 $field = substr($field, 1, -1);
152 $main = $e->issue->$field;
158 require_once 'MTrack/Ticket_CustomFields.php';
159 $f = MTrackTicket_CustomFields::getInstance()->fieldByName($field);
164 $label = htmlentities($f->label, ENT_QUOTES, 'utf-8');
166 if ($field == 'attachment' && strlen($citem['oldvalue'])) {
167 $label = "Attachment: $citem[oldvalue]";
169 $label = ucfirst($field);
173 if ($citem['oldvalue'] == null) {
174 /* don't bother printing out a set if this is the initial thing
175 * and if the field values are currently the same */
177 if ($main != $citem['value'] || $e->change_id != 'top') {
179 /* Special case for description; since it is multi-line and often
180 * very large, render it as a diff against the current ticket
181 * description field */
182 if ($field == 'description') {
183 if ($this->issue->description == $citem['value']) {
184 $comment_body .= "<b>Description</b>: no longer empty; see above<br>";
188 $initial_lines = count(explode("\n", $this->issue->description));
189 $diff = $this->diff_strings($this->issue->description, $citem['value']);
192 foreach (explode("\n", $diff) as $line) {
193 if (!strlen($line)) continue;
194 if ($line[0] == '-') {
196 } else if ($line[0] == '+') {
200 if (abs($diff_add - $diff_rem) > $initial_lines / 2) {
201 $comment_body .= "<b>initial $label</b><br>" .
202 MTrack_Wiki::format_to_html($citem['value']);
204 $diff = $this->collapse_diff($diff);
205 $comment_body .= "<b>initial $label</b> (diff to above):<br>$diff\n";
208 $comment_body .= "<b>$label</b> $citem[value]<br>\n";
214 if ($citem['action'] == 'changed') {
215 $lines = explode("\n", $citem['value'], 3);
216 if (count($lines) >= 2) {
217 $diff = $this->diff_strings($citem['oldvalue'], $citem['value']);
218 $diff = $this->collapse_diff($diff);
219 $comment_body .= "<b>$label</b> $citem[action]\n$diff\n";
221 $comment_body .= "<b>$label</b> $citem[action] to $citem[value]<br>\n";
226 $comment_body .= "<b>$label</b> $citem[action]<br>\n";
230 $commit_info = array();
231 if ($comment_title &&
232 preg_match('/\(In \[changeset:([^,]+),([a-z0-9]+)\]\)(.*)$/i', $comment_title, $commit_info)) {
236 $comment_title = '<a class="changesetlink" href="'. $GLOBALS['ABSWEB'] . 'changeset.php/'.
237 $commit_info[1].'/'.$commit_info[2]. '">[' . $commit_info[2] . ']</a>'.$commit_info[3];
241 if ($this->cid == $this->issue->created) {
243 $comment_title = 'Issue Created';
251 <div class="ticketevent">
252 <span class="ticketevent-expand" id="ticketevent-expand-' . $this->cid . '">+ ' . $type.'</span>
253 <a class="pmark" href="#'.$cid.'">#'.$this->cid.'</a>
255 <span class="ticketevent-expand" id="ticketevent-expand-title-' . $this->cid . '">' .
256 (strlen($comment_title) ? $comment_title : implode(', ', $comment_fields)) . '
259 <span style="float:right">' .
260 $link->username($this->who, array('no_image' => true, 'fullname' => true)) . '
261 - <a name="'.$cid.'">'.$timestamp.'</a>
265 <div class="ticketchangeinfo" id="ticketchangeinfo-' . $this->cid . '">' .
266 $link->username($this->who, array('no_name' => true, 'size' => 48));
271 foreach ($this->effort as $eff) {
272 $exp = (float)$eff['expended'];
273 if ($eff['expended'] != 0) {
274 $comment_body .= "<b>spent</b> $exp hours<br>\n";
285 foreach ($comments as $cid => $text) {
286 // look for changesets in the comments..
287 // and display them as expandable linsk..
288 $html .= MTrack_Wiki::format_to_html($text);
297 // list the files that where changed...
298 //$html.= print_r($M, true);
299 $rp = '/' . $commit_info[1] . '/' . $commit_info[2];
301 $repo = MTrackSCM::factory($rp);
302 $cd = $repo->historyWithChangelog(null, 1, 'rev', $rp);
306 if (!is_array($cd->ent->files) || !count($cd->ent->files)) {
310 $num = count(array_keys($cd->ent->files));
317 $file_summary = array();
318 foreach($map as $k=>$v) {
321 foreach ($cd->ent->files as $id => $file) {
324 $type = isset($map[$file->status]) ? $map[$file->status] : '??? '. $file->status;
328 // will bork on unknown...
335 <div class="ticketevent ticketevent-fileitem">
336 <span class="ticketevent-expand" id="ticketevent-expand-' . $this->cid . '.' . $id .'">+ ' . $type.'</span>
337 <span title="' . $fullrp . '?part=' . $id. '" class="ticketevent-expand" id="ticketevent-expand-title-' . $this->cid . '.' . $id . '">' .
338 $file->nameToHtml() . '
340 <span title="' . $fullrp . '?part=' . $id. '" class="ticketevent-expand-diff changesetlink">[View Diff]</span>
341 <span title="' . $fullrp . '" class="ticketevent-expand-view changesetlink">[View File]</span>
342 <span title="' . $fullrp . '" class="ticketevent-expand-view changesetlink">[View History]</span>
344 <div class="ticketchangeinfo" id="ticketchangeinfo-' . $this->cid . '.' . $id . '"></div>
353 foreach($summary as $k=>$v) {
357 $ar[] = $v . ' ' . $k;
360 <div class="ticketevent ticketevent-fileitem">
361 <span class="ticketevent-expand" id="ticketevent-expand-' . $this->cid . '.0">+ MULTIPLE FILES: </span>
362 <span title="' . $fullrp . '?part=' . 0 . '" class="ticketevent-expand" id="ticketevent-expand-title-' . $this->cid . '.' . $id . '">' .
363 implode(', ', $ar) . '
365 <span title="' . $fullrp . '" class="ticketevent-expand-diff changesetlink">[View Diff]</span>
366 <span title="' . $fullrp . '" class="ticketevent-expand-view changesetlink">[View File]</span>
367 <span title="' . $fullrp . '" class="ticketevent-expand-view changesetlink">[View History]</span>
369 <div class="ticketchangeinfo" id="ticketchangeinfo-' . $this->cid . '"></div>
374 //$html .= print_r($cd, true);