function show_atom($summary, $annotations) { global $CFG; $annotationobjs = array(); foreach ($annotations as $annotationrec) { $annotationobjs[] = annotation_globals::record_to_annotation($annotationrec); } MarginaliaHelper::generateAnnotationFeed($annotationobjs, annotation_globals::get_feed_tag_uri(), MarginaliaHelper::getLastModified($annotationObjs, annotation_globals::get_install_date()), annotation_globals::get_service_path(), annotation_globals::get_host(), $summary->get_feed_url('atom'), $CFG->wwwroot); }
function xmldb_block_marginalia_upgrade($oldversion) { global $CFG, $DB; $result = true; $dbman = $DB->get_manager(); if ($oldversion < 2008121000) { /// Define table annotation to be created $table = new xmldb_table('marginalia'); /// Adding fields to table marginalia $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('access_perms', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('start_block', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('start_xpath', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('start_line', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('start_word', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('start_char', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('end_block', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('end_xpath', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('end_line', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('end_word', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('end_char', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('note', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('quote', XMLDB_TYPE_TEXT, 'small', null, null, null, null); $table->add_field('quote_title', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('quote_author_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('action', XMLDB_TYPE_CHAR, '30', null, null, null, null); $table->add_field('link', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('link_title', XMLDB_TYPE_CHAR, '255', null, null, null, null); $table->add_field('created', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('modified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('object_type', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('object_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table marginalia $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table marginalia $table->add_index('object', XMLDB_INDEX_NOTUNIQUE, array('object_type', 'object_id')); /// Launch create table for marginalia $dbman->create_table($table); // Check for old annotation table and convert its data over if ($result) { $query = "SELECT a.*, u.id AS uid, qa.id as aid " . " FROM {annotation} a" . " JOIN {user} u ON u.username=a.userid" . " LEFT JOIN {user} qa ON qa.username=a.quote_author"; $data = $DB->get_recordset_sql($query); foreach ($data as $r) { /* // This method and the range classes are clever enough to handle // ranges in the old format. if ( array_key_exists( 'start_block', $r ) && $r->start_block !== null ) { $r->start_block = preg_replace( '/^\//', '', $r->start_block ); $r->start_block = preg_replace( '/\//', '\.', $r->start_block ); } if ( array_key_exists( 'end_block', $r ) && $r->end_block !== null ) { $r->end_block = preg_replace( '/^\//', '', $r->end_block ); $r->end_block = preg_replace( '/\//', '\.', $r->end_block ); } */ $r->username = $r->userid; $r->userid = 0; $r->quote_author_username = $r->quote_author; $annotation = annotation_globals::record_to_annotation($r); // Will handle 'public' or 'private' if (array_key_exists('access', $r)) { $annotation->setAccess($r->access); } // Fix backslashes (\' and \") in annotation and note if (AN_DBFIXBACKSLASHES) { $quote = $annotation->getQuote(); $quote = preg_replace('/\\\\\'/', "'", $quote); $quote = preg_replace('/\\\\"/', '"', $quote); $annotation->setQuote($quote); $note = $annotation->getNote(); $note = preg_replace('/\\\\\'/', "'", $note); $note = preg_replace('/\\\\"/', '"', $note); $annotation->setNote($note); } $record = annotation_globals::annotation_to_record($annotation); // Make sure start_line and end_line are not null if (!array_key_exists('start_line', $r)) { $record->start_line = 0; } if (!array_key_exists('end_line', $r)) { $record->end_line = 0; } $record->userid = $r->uid; $record->quote_author_id = $r->aid; $record->object_type = AN_OTYPE_POST; $record->object_id = $r->object_id; $DB->insert_record(AN_DBTABLE, $record, true); } $data->close(); } upgrade_mod_savepoint(true, 2008121000, 'marginalia'); // Should perhaps delete old annotation table? } if ($oldversion < 2010012800) { $table = new xmldb_table('marginalia'); /* ---- course ---- */ // Give in to Moodle's architecture and associate each annotation with a course // (I don't like that Moodle is course-centric: I think it should be user-centric instead. // I see annotations as belonging to the people who create them, not the things they // annotate or the courses they were created in. A student over the course of his or her // career accumulates knowledge and content, synthesizing it into new knowledge and practice. // In contrast, a course-oriented system is rooted in administrative structure.) $field = new xmldb_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'id'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } /* $query = "UPDATE {marginalia} a, {forum_posts} p, {forum_discussions} d" ." SET a.course=d.course" ." WHERE a.object_id=p.id AND d.id=p.discussion"; */ $query = "UPDATE {marginalia}\n SET course = \n (SELECT d.course \n FROM {forum_posts} p, {forum_discussions} d \n WHERE d.id=p.discussion \n AND {marginalia}.object_id=p.id\n )\n WHERE EXISTS (SELECT fd.id \n FROM {forum_posts} fp, {forum_discussions} fd \n WHERE fd.id=fp.discussion \n AND {marginalia}.object_id=fp.id\n )"; $DB->execute($query); // Cannot have entries where cousrse = 0 $deletequery = "DELETE FROM {marginalia} WHERE course=0"; $DB->execute($deletequery); /* ---- sheet_type ---- */ // Replace access_perms with sheet_type // private used to have access bits 0x0; now has access 0x1 $field = new xmldb_field('access_perms', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); if ($dbman->field_exists($table, $field)) { $dbman->rename_field($table, $field, 'sheet_type'); } $query = "UPDATE {marginalia} SET sheet_type=1 WHERE sheet_type=0"; $result = $DB->execute($query); /* ---- marginalia_read.* ---- */ /// Define marginalia_read table, which tracks which annotations have been read by which users $table = new xmldb_table('marginalia_read'); $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); $table->add_field('annotationid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('firstread', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); $table->add_field('lastread', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); /// Adding keys to table marginalia_read $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table marginalia_read $table->add_index('object', XMLDB_INDEX_UNIQUE, array('annotationid', 'userid')); if (!$dbman->table_exists($table)) { $dbman->create_table($table); } /* ---- user_preferences.* ---- */ // Delete obsolete preferences $DB->delete_records('user_preferences', array('name' => 'annotations.user')); $DB->delete_records('user_preferences', array('name' => 'smartcopy')); upgrade_block_savepoint(true, 2010121800, 'marginalia'); } return $result; }
function moodle_keyword_service($username) { global $CFG; KeywordService::KeywordService(annotation_globals::get_host(), annotation_globals::get_keyword_service_path(), $username, $CFG->wwwroot); $this->tablePrefix = $CFG->prefix; }
function xmldb_block_marginalia_upgrade($oldversion) { global $CFG; $result = true; if ($result && $oldversion < 2008121000) { /// Define table annotation to be created $table = new XMLDBTable('marginalia'); /// Adding fields to table annotation $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null); // $table->addFieldInfo('userid', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); // $table->addFieldInfo('access', XMLDB_TYPE_CHAR, '32', null, null, null, null, null, null); $table->addFieldInfo('access_perms', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('url', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null); $table->addFieldInfo('start_block', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('start_xpath', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('start_line', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('start_word', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('start_char', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('end_block', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('end_xpath', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('end_line', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('end_word', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('end_char', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('note', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null); $table->addFieldInfo('quote', XMLDB_TYPE_TEXT, 'small', null, null, null, null, null, null); $table->addFieldInfo('quote_title', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); // $table->addFieldInfo('quote_author', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('quote_author_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('action', XMLDB_TYPE_CHAR, '30', null, null, null, null, null, null); $table->addFieldInfo('link', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('link_title', XMLDB_TYPE_CHAR, '255', null, null, null, null, null, null); $table->addFieldInfo('created', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('modified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('object_type', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); $table->addFieldInfo('object_id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0'); /// Adding keys to table annotation $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id')); /// Adding indexes to table annotation $table->addIndexInfo('object', XMLDB_INDEX_NOTUNIQUE, array('object_type', 'object_id')); /// Launch create table for annotation $result = $result && create_table($table); // Check for old annotation table and convert its data over if ($result) { $query = "SELECT a.*, u.id AS uid, qa.id as aid " . " FROM {$CFG->prefix}annotation a" . " JOIN {$CFG->prefix}user u ON u.username=a.userid" . " LEFT JOIN {$CFG->prefix}user qa ON qa.username=a.quote_author"; $data = get_records_sql($query); if ($data) { foreach ($data as $r) { /* // This method and the range classes are clever enough to handle // ranges in the old format. if ( array_key_exists( 'start_block', $r ) && $r->start_block !== null ) { $r->start_block = preg_replace( '/^\//', '', $r->start_block ); $r->start_block = preg_replace( '/\//', '\.', $r->start_block ); } if ( array_key_exists( 'end_block', $r ) && $r->end_block !== null ) { $r->end_block = preg_replace( '/^\//', '', $r->end_block ); $r->end_block = preg_replace( '/\//', '\.', $r->end_block ); } */ $r->username = $r->userid; $r->userid = 0; $r->quote_author_username = $r->quote_author; $annotation = annotation_globals::record_to_annotation($r); // Will handle 'public' or 'private' if (array_key_exists('access', $r)) { $annotation->setAccess($r->access); } // Fix backslashes (\' and \") in annotation and note if (AN_DBFIXBACKSLASHES) { $quote = $annotation->getQuote(); $quote = preg_replace('/\\\\\'/', "'", $quote); $quote = preg_replace('/\\\\"/', '"', $quote); $annotation->setQuote($quote); $note = $annotation->getNote(); $note = preg_replace('/\\\\\'/', "'", $note); $note = preg_replace('/\\\\"/', '"', $note); $annotation->setNote($note); } $record = annotation_globals::annotation_to_record($annotation); // Make sure start_line and end_line are not null if (!array_key_exists('start_line', $r)) { $record->start_line = 0; } if (!array_key_exists('end_line', $r)) { $record->end_line = 0; } $record->userid = $r->uid; $record->quote_author_id = $r->aid; $record->object_type = AN_OTYPE_POST; $record->object_id = $r->object_id; $x = insert_record(AN_DBTABLE, $record, true); $result = $result && 0 != $x; } } } // Should perhaps delete old annotation table? } return $result; }
function doUpdateAnnotation($annotation) { $urlquerystr = ''; $annotation->setModified(time()); $record = annotation_globals::annotation_to_record($annotation); $logurl = 'annotate.php' . ($urlquerystr ? '?' . $urlquerystr : ''); add_to_log(null, 'annotation', 'update', $logurl, "{$annotation->id}"); return update_record(AN_DBTABLE, $record); }
function show() { global $CFG; $search = $this->search; $this->errorpage = array_key_exists('error', $_GET) ? $_GET['error'] : null; $query = "SELECT count(*) FROM {$CFG->prefix}marginalia_event_log"; $total_events = count_records_sql($query); $query = "SELECT e.id AS id, e.userid AS userid, e.service AS service, e.action AS action" . ", e.description AS description, e.object_type AS object_type" . ", e.object_id AS object_id, e.modified AS modified" . ", e.course as course" . ", concat(u.firstname, ' ', u.lastname) AS fullname" . ", a.sheet_type AS sheet_type" . ", a.quote AS quote" . ", a.note AS note" . ", a.object_type AS an_object_type" . ", a.object_id AS an_object_id" . ", concat(qu.firstname, ' ', qu.lastname) AS qu_fullname" . ", p.id AS p_id" . ", p.subject AS p_name" . ", p.discussion AS p_discussion" . ", p.created AS p_created" . ", d.name AS d_name" . ", d.id AS d_id" . ", c.shortname AS c_name" . " FROM {$CFG->prefix}marginalia_event_log e" . " LEFT OUTER JOIN {$CFG->prefix}course c ON c.id=e.course" . " LEFT OUTER JOIN {$CFG->prefix}marginalia_annotation_log a" . " ON (e.object_type=" . AN_OTYPE_ANNOTATION . " AND a.eventid=e.id)" . " LEFT OUTER JOIN {$CFG->prefix}user u ON u.id=e.userid" . " LEFT OUTER JOIN {$CFG->prefix}forum_posts p" . " ON (a.object_type=" . AN_OTYPE_POST . " AND p.id=a.object_id)" . " LEFT OUTER JOIN {$CFG->prefix}forum_discussions d" . " ON (a.object_type=" . AN_OTYPE_POST . " AND d.id=p.discussion)" . " LEFT OUTER JOIN {$CFG->prefix}USER qu " . " ON (e.object_type=" . AN_OTYPE_ANNOTATION . " AND qu.id=a.quote_author_id)" . " WHERE 1=1"; if ($search->course) { $query .= " AND e.course=" . (int) $search->course . "\n"; } if ($search->user) { $query .= " AND e.userid=" . (int) $search->user . "\n"; } if ($search->discussion) { $query .= " AND d.id=" . (int) $search->discussion . "\n"; } if ($search->object_type) { $query .= " AND e.object_type=" . (int) $search->object_type; if ($search->object_id) { $query .= " AND e.object_id=" . (int) $search->object_id; } $query .= "\n"; } $query .= " ORDER BY e.modified DESC"; // echo "Query: $query\n"; $events = get_records_sql($query, $search->first - 1, $this->maxrecords); echo "<p>" . $search->desc() . "</p>\n"; echo "<table id='events'>\n"; echo " <thead><tr>\n"; echo " <th>Time</th><th>Course</th><th>User</th><th>Service</th><th>Action</th><th>Description</th><th>Object</th>\n"; if ($this->extracolumns) { echo "<th>Sheet</th><th>Quote</th><th>Note</th><th>Post</th><th>Discussion</th><th>Post Author</th><th>Posted</th>\n"; } echo " </tr></thead><tbody>\n"; if ($events && count($events)) { foreach ($events as $event) { echo " <tr>\n"; echo " <td>" . s(MarginaliaHelper::timeToIso($event->modified)) . "</td>\n"; echo " <td>" . s($event->c_name) . $this->zoom_link(array('course' => $event->course)) . "</td>\n"; echo " <td>" . s($event->fullname) . $this->zoom_link(array('user' => $event->userid)) . "</td>\n"; echo " <td>" . s($event->service) . "</td>\n"; echo " <td>" . s($event->action) . "</td>\n"; echo " <td>" . s($event->description) . "</td>\n"; if (AN_OTYPE_ANNOTATION == $event->object_type) { echo "<td>annotation #" . (int) $event->object_id . $this->zoom_link(array('object_type' => $event->object_type, 'object_id' => $event->object_id)) . "</td>\n"; if ($this->extracolumns) { if (AN_OTYPE_ANNOTATION == $event->object_type) { echo "<td>" . s(annotation_globals::sheet_str($event->sheet_type)) . "</td>\n"; echo "<td>" . s($event->quote) . "</td>\n"; echo "<td>" . s($event->note) . "</td>\n"; if (AN_OTYPE_POST == $event->an_object_type) { $url = $CFG->wwwroot . '/mod/forum/permalink.php?p=' . $event->p_id; echo "<td><a href='" . s($url) . "'>" . s($event->p_id) . "</a></td>\n"; echo "<td>" . s($event->d_name) . $this->zoom_link(array('d' => $event->d_id)) . "</td>\n"; echo "<td>" . s($event->qu_fullname) . "</a></td>\n"; echo "<td>" . s(MarginaliaHelper::timeToIso($event->p_created)) . "</td>\n"; } else { echo "<td colspan='4'></td>\n"; } } else { echo "<td colspan='8'></td>\n"; } } } else { if (AN_OTYPE_POST == $event->object_type) { echo "<td>post #" . (int) $event->object_id . $this->zoom_link(array('object_type' => $event->object_type, 'object_id' => $event->object_id)) . "</td>\n"; echo "<td colspan='8'></td>\n"; } else { echo "<td colspan='9'></td>\n"; } } echo " </tr>\n"; } echo "</tbody></table>\n"; $tsearch = $search->derive(); $tsearch->first = '{first}'; marginalia_summary_lib::show_result_pages($search->first, $total_events, $this->maxrecords, $tsearch->url()); } }
function get_feed_tag_uri() { return "tag:" . annotation_globals::get_host() . ',' . date('Y-m-d', annotation_globals::get_install_date()) . ":annotation"; }