Permalink
Browse files

Grouped notes on activity page by user and scan

  • Loading branch information...
1 parent 5fdc043 commit a7873c247c130d85606cfc2a09d9f15c0ecc7146 Michal Migurski committed Apr 5, 2012
Showing with 68 additions and 6 deletions.
  1. +37 −6 site/templates/print.html.tpl
  2. +31 −0 site/www/print.php
@@ -287,8 +287,8 @@
<ul>
{foreach from=$activity item="event"}
- <li>
- {if $event.type == "print"}
+ {if $event.type == "print"}
+ <li>
{assign var="print" value=$event.print}
{if $print.user_name}
@@ -306,8 +306,10 @@
<br>
<span class="details">18 pages + satellite and labels + portrait + map/notes layout, 2-up + <a>imported MBTiles</a></span>
*}
+ </li>
- {elseif $event.type == "scan"}
+ {elseif $event.type == "scan"}
+ <li>
{assign var="scan" value=$event.scan}
{if $scan.user_name}
@@ -329,8 +331,37 @@
<br>
<img>
*}
+ </li>
- {elseif $event.type == "note"}
+ {elseif $event.type == "notes"}
+ <li>
+ {assign var="notes" value=$event.notes}
+ {assign var="note" value=$notes.0}
+ {assign var="scan" value=$note.scan}
+ {assign var="count" value=$notes|@count}
+
+ {if $note.user_name}
+ <a href="{$base_dir}/person.php?id={$note.user_id|escape}">{$note.user_name|escape}</a>
+ {else}
+ Someone anonymous
+ {/if}
+
+ {if $count == 1}
+ added <a href="{$base_dir}/snapshot.php?id={$scan.id|escape}">a note about page {$scan.print_page_number|escape}</a>
+ {else}
+ added <a href="{$base_dir}/snapshot.php?id={$scan.id|escape}">{$count} notes about page {$scan.print_page_number|escape}</a>
+ {/if}
+ <a class="date">- {$note.age|nice_relativetime|escape}</a>
+
+ <ol>
+ {foreach from=$notes item="note"}
+ <li>{$note.note|escape}</li>
+ {/foreach}
+ </ol>
+ </li>
+
+ {elseif $event.type == "note"}
+ <li>
{assign var="note" value=$event.note}
{assign var="scan" value=$note.scan}
@@ -360,8 +391,8 @@
<li>Best eggs in the city</li>
</ol>
*}
- {/if}
- </li>
+ </li>
+ {/if}
{/foreach}
</ul>
</div>
View
@@ -87,6 +87,37 @@
}
array_multisort($times, SORT_ASC, $activity);
+
+ $scan_note_indexes = array();
+
+ // group notes into lists by scan, ending on the latest
+ for($i = count($activity) - 1; $i >= 0; $i--)
+ {
+ if($activity[$i]['type'] != 'note')
+ continue;
+
+ $note = $activity[$i]['note'];
+ $group = "{$note['scan']['id']}-{$note['user_id']}";
+
+ if(isset($scan_note_indexes[$group])) {
+ //
+ // Add this note to the existing array in the activity list.
+ //
+ $index = $scan_note_indexes[$group];
+ array_unshift($activity[$index]['notes'], $note);
+ $activity[$i] = array('type' => false);
+
+ } else {
+ //
+ // Most-recent note by this person on this scan;
+ // prepare an array of notes in the activity list.
+ //
+ $scan_note_indexes[$group] = $i;
+ $activity[$i] = array('type' => 'notes', 'notes' => array($note));
+ }
+ }
+
+ unset($scan_note_indexes);
$context->sm->assign('activity', $activity);
if($context->type == 'text/html') {

0 comments on commit a7873c2

Please sign in to comment.