[marginalia commit] r335 - moodle/trunk/moodle/annotation

0 views
Skip to first unread message

codesite...@google.com

unread,
Nov 28, 2008, 2:24:39 AM11/28/08
to marginali...@googlegroups.com
Author: geof.glass
Date: Thu Nov 27 23:23:55 2008
New Revision: 335

Modified:
moodle/trunk/moodle/annotation/AnnotationSummaryQuery.php
moodle/trunk/moodle/annotation/summary-styles.php
moodle/trunk/moodle/annotation/summary.php

Log:
More cleanup of summary page


Modified: moodle/trunk/moodle/annotation/AnnotationSummaryQuery.php
==============================================================================
--- moodle/trunk/moodle/annotation/AnnotationSummaryQuery.php (original)
+++ moodle/trunk/moodle/annotation/AnnotationSummaryQuery.php Thu Nov 27
23:23:55 2008
@@ -16,7 +16,7 @@
var $error; // Any error encountered by the constructor

/** Construct an immutable summary query */
- function AnnotationSummaryQuery( $url, $searchUser, $searchOf,
$searchQuery, $all=False )
+ function AnnotationSummaryQuery( $url, $searchUser, $searchOf,
$searchQuery, $exactMatch=False, $all=False )
{
global $CFG, $USER;

@@ -24,6 +24,7 @@
$this->searchUser = $searchUser;
$this->searchOf = $searchOf;
$this->searchQuery = $searchQuery;
+ $this->exactMatch = $exactMatch;
$this->accessAll = $all; // get access beyond normal privacy limitations
(admin only)

if ( '' == $this->searchUser )
@@ -108,6 +109,8 @@
$a->author = $this->searchOf;
$a->search = $this->searchQuery;

+ $a->match = get_string( $this->exactMatch ? 'matching' : 'containing',
ANNOTATION_STRINGS );
+
if ( null != $this->searchQuery && '' != $this->searchQuery )
$s = ( null != $this->searchOf
) ? 'annotation_desc_authorsearch' : 'annotation_desc_search';
else
@@ -124,34 +127,59 @@
global $USER;

$this->handler->fetchMetadata( );
+ $title = ( null == $title ) ? $this->handler->title : $title;
+ $a->title = $title;

- $a->title = ( null == $title ) ? $this->handler->title : $title;
+ // Show link to parent search
+ if ( null != $this->parentSummaryTitle( ) )
+ {
+ $url = $this->getSummaryUrl( $this->parentSummaryUrl( ),
$this->searchUser, $this->searchOf, $this->searchQuery, $this->exactMatch );
+ $a->title = '<a class="opt-link" href="'.htmlspecialchars($url)
+ . '" title="'.htmlspecialchars( get_string( 'unzoom_url_hover',
ANNOTATION_STRINGS ) ).'">'
+ . '<span class="current">'.htmlspecialchars($title).'</span>'
+ . '<span class="alt">'.htmlspecialchars($this->parentSummaryTitle(
)).'</span></a>';
+ }

// Access restrictions. Need to look up actual user names in DB.
if ( ! $this->searchUser )
$a->who = 'anyone';
else
{
- $url = $this->getSummaryUrl( $this->url, '', $this->searchOf,
$this->searchQuery );
+ $url = $this->getSummaryUrl( $this->url, '', $this->searchOf,
$this->searchQuery, $this->exactMatch );
if ( '*students' == $this->searchUser )
$s = 'students';
elseif ( '*teachers' == $this->searchUser )
$s = 'teachers';
else
$s = $this->searchUser;
- $a->who = '<a class="opt-link" href="'.htmlspecialchars($url).'"><span
class="current">'.$s.'</span><span class="alt">anyone</a></a>';
+ $a->who = '<a class="opt-link" href="'.htmlspecialchars($url)
+ .'" title="'.htmlspecialchars( get_string( 'unzoom_user_hover',
ANNOTATION_STRINGS ) )
+ .'"><span class="current">'.htmlspecialchars($s).'</span><span
class="alt">'
+ .htmlspecialchars( get_string( 'anyone', ANNOTATION_STRINGS )
).'</a></a>';
}

if ( $this->searchOf )
{
- $url = $this->getSummaryUrl( $this->url, $this->searchUser, '',
$this->searchQuery );
- $a->author = '<a class="opt-link"
href="'.htmlspecialchars($url).'"><span
class="current">'.$this->searchOf.'</span><span
class="alt">anyone</span></a>';
+ $url = $this->getSummaryUrl( $this->url, $this->searchUser, '',
$this->searchQuery, $this->exactMatch );
+ $a->author = '<a class="opt-link" href="'.htmlspecialchars($url)
+ .'" title="'.htmlspecialchars( get_string( 'unzoom_author_hover',
ANNOTATION_STRINGS ) )
+ .'"><span
class="current">'.htmlspecialchars($this->searchOf).'</span><span
class="alt">'
+ .htmlspecialchars( get_string( 'anyone', ANNOTATION_STRINGS )
).'</span></a>';
}
else
$a->author = null;

$a->search = $this->searchQuery;

+ $url = $this->getSummaryUrl( $this->url, $this->searchUser, '',
$this->searchQuery, ! $this->exactMatch );
+ $hover = get_string(
$this->exactMatch ? 'unzoom_match_hover' : 'zoom_match_hover',
ANNOTATION_STRINGS );
+ $m1 = get_string( $this->exactMatch ? 'matching' : 'containing',
ANNOTATION_STRINGS );
+ $m2 = get_string( $this->exactMatch ? 'containing' : 'matching',
ANNOTATION_STRINGS );
+ $a->match = '<a class="opt-link" href="'.htmlspecialchars($url)
+ .'" title="'.htmlspecialchars( $hover )
+ .'"><span class="current">'.htmlspecialchars( $m1 )
+ .'</span><span class="alt">'.htmlspecialchars( $m2 ).'</span></a>';
+
if ( null != $this->searchQuery && '' != $this->searchQuery )
$s = ( null != $this->searchOf
) ? 'annotation_desc_authorsearch' : 'annotation_desc_search';
else
@@ -270,19 +298,24 @@
// add to them also those a page of this type might use.
if ( null != $this->searchQuery && '' != $this->searchQuery )
{
- $search_cond = '';
- $add_search_fields = $handler->getSearchFields( );
- $search_cond = '';
- $queryWords = split( ' ', $this->searchQuery );
- foreach ( $queryWords as $word )
+ if ( $this->exactMatch )
+ $q_std_where .= "\n AND a.note='".addslashes($this->searchQuery)."'";
+ else
{
- $sWord = addslashes( $word );
- foreach ( $std_search_fields as $field )
- $search_cond .= ( $search_cond == '' ) ? "$field LIKE '%$sWord%'" : "
OR $field LIKE '%$sWord%'";
- foreach ( $add_search_fields as $field )
- $search_cond .= " OR $field LIKE '%$sWord%'";
+ $search_cond = '';
+ $add_search_fields = $handler->getSearchFields( );
+ $search_cond = '';
+ $queryWords = split( ' ', $this->searchQuery );
+ foreach ( $queryWords as $word )
+ {
+ $sWord = addslashes( $word );
+ foreach ( $std_search_fields as $field )
+ $search_cond .= ( $search_cond == '' ) ? "$field
LIKE '%$sWord%'" : " OR $field LIKE '%$sWord%'";
+ foreach ( $add_search_fields as $field )
+ $search_cond .= " OR $field LIKE '%$sWord%'";
+ }
+ $q_std_where .= "\n AND ($search_cond)";
}
- $q_std_where .= "\n AND ($search_cond)";
}

// The handler must construct the query, which might be a single SELECT
or a UNION of multiple SELECTs
@@ -303,7 +336,7 @@
}

/** Generate a summary URL corresponding to this query */
- function getSummaryUrl( $url, $searchUser, $searchOf, $searchQuery )
+ function getSummaryUrl( $url, $searchUser, $searchOf, $searchQuery,
$exactMatch=false )
{
global $CFG;
$s = "{$CFG->wwwroot}/annotation/summary.php?url=".urlencode($url);
@@ -313,6 +346,8 @@
$s .= '&u='.urlencode($searchUser);
if ( null != $searchOf && '' != $searchOf )
$s .= '&search-of='.urlencode($searchOf);
+ if ( $exactMatch )
+ $s .= '&match=exact';
return $s;
/* global $CFG;
$s = "{$CFG->wwwroot}/annotation/summary.php?url=".urlencode($this->url);

Modified: moodle/trunk/moodle/annotation/summary-styles.php
==============================================================================
--- moodle/trunk/moodle/annotation/summary-styles.php (original)
+++ moodle/trunk/moodle/annotation/summary-styles.php Thu Nov 27 23:23:55
2008
@@ -154,14 +154,19 @@
color: red;
}

-table.annotations a.zoom-user {
+table.annotations a.zoom {
visibility: hidden;
margin-left: 1ex;
font-size: 120%;
}

-table.annotations tr:hover a.zoom-user {
+table.annotations tr:hover a.zoom {
visibility: visible;
+}
+
+table.annotations a.zoom:hover {
+ font-weight: bold;
+ text-decoration: none;
}

Modified: moodle/trunk/moodle/annotation/summary.php
==============================================================================
--- moodle/trunk/moodle/annotation/summary.php (original)
+++ moodle/trunk/moodle/annotation/summary.php Thu Nov 27 23:23:55 2008
@@ -9,9 +9,11 @@
require_once( "../config.php" );
require_once( "marginalia-php/MarginaliaHelper.php" );
require_once( 'marginalia-php/Annotation.php' );
+require_once( 'marginalia-php/Keyword.php' );
require_once( 'config.php' );
require_once( 'AnnotationGlobals.php' );
require_once( "AnnotationSummaryQuery.php" );
+require_once( "KeywordsDB.php" );

global $CFG;

@@ -84,6 +86,7 @@
$this->searchQuery = array_key_exists( 'q', $_GET ) ? $_GET[ 'q' ] :
null;
$this->searchUser = array_key_exists( 'u', $_GET ) ? $_GET[ 'u' ] : null;
$this->searchOf = array_key_exists( 'search-of', $_GET ) ?
$_GET[ 'search-of' ] : null;
+ $this->exactMatch = array_key_exists( 'match', $_GET ) ? 'exact' ==
$_GET[ 'match' ] : false;
}

function show( )
@@ -96,7 +99,7 @@
}
else
{
- $query = new AnnotationSummaryQuery( $this->summaryUrl,
$this->searchUser, $this->searchOf, $this->searchQuery );
+ $query = new AnnotationSummaryQuery( $this->summaryUrl,
$this->searchUser, $this->searchOf, $this->searchQuery, $this->exactMatch );
if ( $query->error )
{
header( 'HTTP/1.1 400 Bad Request' );
@@ -168,6 +171,14 @@

$this->showHeader( );

+ $keywords = AnnotationKeywordsDB::listKeywords( $USER->username );
+ $keywordHash = array( );
+ for ( $i = 0; $i < count( $keywords ); ++$i )
+ {
+ $keyword = $keywords[ $i ];
+ $keywordHash[ $keyword->name ] = true;
+ }
+
// print search header
// * my annotations
// * shared annotations
@@ -285,8 +296,8 @@
// Link to filter only annotations by this user
if ( $annotation->quote_author_id != $query->searchOf )
{
- $turl = $query->getSummaryUrl( $query->url, $query->searchUser,
$annotation->quote_author_id, $query->searchQuery );
- echo "<a class='zoom-user' title='Show only annotations of work
by ".htmlspecialchars($annotation->quote_author)."'
href='$turl'>&#9756;</a>\n";
+ $turl = $query->getSummaryUrl( $query->url, $query->searchUser,
$annotation->quote_author_id, $query->searchQuery, $query->exactMatch );
+ echo "<a class='zoom'
title='".htmlspecialchars(get_string( 'zoom_author_hover',
ANNOTATION_STRINGS, $annotation))."' href='$turl'>&#9756;</a>\n";
}
echo "</span>\n";
}
@@ -318,7 +329,22 @@

// Show the note
if ( ! in_array( 'note', $excludeFields ) )
- echo "<td class='note'>" . htmlspecialchars( $annotation->note
) . "&#160;</td>\n";
+ {
+ echo "<td class='note'>";
+ if ( ! $annotation->note )
+ echo '&#160;';
+ else
+ echo htmlspecialchars( $annotation->note );
+
+ if ( ! $this->exactMatch && $keywordHash[ $annotation->note ] )
+ {
+ $turl = $query->getSummaryUrl( $query->url, $query->searchUser,
$query->searchOf, $annotation->note, true );
+ echo "<a class='zoom' title='"
+ .htmlspecialchars(get_string( 'zoom_match_hover',
ANNOTATION_STRINGS, $annotation) )
+ ."' href='".htmlspecialchars($turl)."'>&#9756;</a>\n";
+ }
+ echo "</td>\n";
+ }

// Show edit controls or the user who created the annotation
if ( ! in_array( 'controls', $excludeFields ) || ! in_array( 'user',
$excludeFields ) )
@@ -358,8 +384,8 @@
// Link to filter only annotations by this user
if ( $annotation->userid != $query->searchUser )
{
- $turl = $query->getSummaryUrl( $query->url, $annotation->userid,
$query->searchOf, $query->searchQuery );
- echo "<a class='zoom-user' title='Show only annotations
by ".htmlspecialchars($annotation->note_author)."'
href='".htmlspecialchars($turl)."'>&#9756;</a>\n";
+ $turl = $query->getSummaryUrl( $query->url, $annotation->userid,
$query->searchOf, $query->searchQuery, $query->exactMatch );
+ echo "<a class='zoom'
title='".htmlspecialchars(get_string( 'zoom_user_hover',
ANNOTATION_STRINGS, $annotation) )."'
href='".htmlspecialchars($turl)."'>&#9756;</a>\n";
}
echo "</td>\n";
}
@@ -392,30 +418,6 @@

//$moodlePath = getMoodlePath( );

- // Show link to search of all users
- if ( '' != $query->searchUser )
- {
- $link = $this->getSummaryLink( 'Include annotations by all users', '',
$query,
- $query->url, '', $query->searchOf, $query->searchQuery );
- echo "<p>$link</p>\n";
- }
-
- // Show link to search of annotations of works by all users
- if ( '' != $query->searchOf )
- {
- $link = $this->getSummaryLink( 'Include annotations of works by all
users', '', $query,
- $query->url, $query->searchUser, '', $query->searchQuery );
- echo "<p>$link</p>\n";
- }
-
- // Show link to parent search
- if ( null != $query->parentSummaryTitle() )
- {
- $link =
$this->getSummaryLink( 'Show '.$query->desc($query->parentSummaryTitle()), '',
$query,
- $query->parentSummaryUrl(), $query->searchUser, $query->searchOf,
$query->searchQuery );
- echo "<p>$link</p>\n";
- }
-
// Provide a feed URL. I don't know how to do authentication for the
feed, so for now
// if a login is required I won't include the feature.
if ( ! ANNOTATION_REQUIRE_USER )
@@ -433,9 +435,9 @@
add_to_log(
null, 'annotation', 'summary', 'summary.php'.($logUrl?'?'.$logUrl:''),
$query->desc(null) );
}

- function getSummaryLink( $text, $title, $query, $url, $searchUser,
$searchOf, $searchQuery )
+ function getSummaryLink( $text, $title, $query, $url, $searchUser,
$searchOf, $searchQuery, $exactMatch )
{
- $turl = $query->getSummaryUrl( $url, $searchUser, $searchOf,
$searchQuery );
+ $turl = $query->getSummaryUrl( $url, $searchUser, $searchOf,
$searchQuery, $exactMatch );
return "<a href='".htmlspecialchars($turl)."'
title='".htmlspecialchars($title)."'>"
. htmlspecialchars($text)."</a>";
}

Reply all
Reply to author
Forward
0 new messages