示例#1
0
 function doListAnnotations($url, $username, $block, $all)
 {
     $handler = annotation_summary_query::handler_for_url($url);
     $user = get_record('user', 'username', $username);
     $summary = new annotation_summary_query($url, $handler, null, $user, null, false, $all);
     if ($summary->error) {
         $this->httpError(400, 'Bad Request', 'Bad URL 1');
         return null;
     } elseif (!isloggedin() && ANNOTATION_REQUIRE_USER) {
         $this->httpError(403, 'Forbidden', 'Anonymous listing not allowed');
         return null;
     } else {
         $querysql = $summary->sql('section_type, section_name, quote_title, start_block, start_line, start_word, start_char, end_block, end_line, end_word, end_char');
         $annotation_set = get_records_sql($querysql);
         $annotations = array();
         if ($annotation_set) {
             $i = 0;
             foreach ($annotation_set as $r) {
                 $annotations[$i++] = annotation_globals::record_to_annotation($r);
             }
         }
         $format = $this->getQueryParam('format', 'atom');
         $logurl = 'annotate.php?format=' . $format . ($user ? '&user='******'') . '&url=' . $url;
         add_to_log($summary->handler->courseid, 'annotation', 'list', $logurl);
         return $annotations;
     }
 }
示例#2
0
 function annotation_summary_page($first = 1)
 {
     $this->moodlemia = moodle_marginalia::get_instance();
     $this->first = $first;
     $this->logger = $this->moodlemia->logger;
     $this->summary = new annotation_summary_query(annotation_summary_query::map_params($_GET));
 }
示例#3
0
 function show()
 {
     $this->errorpage = array_key_exists('error', $_GET) ? $_GET['error'] : null;
     $summary = annotation_summary_query::from_params();
     if (null == $summary) {
         header('HTTP/1.1 400 Bad Request');
         echo '<h1>400 Bad Request</h1>';
     } elseif (!MarginaliaHelper::isUrlSafe($summary->url)) {
         header('HTTP/1.1 400 Bad Request');
         echo '<h1>400 Bad Request</h1>Bad url parameter';
     } else {
         // Display individual annotations
         // Dunno if the range sorting is working
         $sql = $summary->sql('section_type, section_name, a.url, start_block, start_word, start_char, end_block, end_word, end_char');
         // echo "SQL: $sql\n";	// uncomment for debugging
         $annotations = get_records_sql($sql);
         $format = array_key_exists('format', $_GET) ? $_GET['format'] : 'html';
         if ('atom' == $format) {
             $this->show_atom($summary, $annotations);
         } else {
             $this->show_html($summary, $annotations);
         }
     }
 }
示例#4
0
 /**
  * Figure out whether annotation is permitted on a given page
  * Should be refactored - same code is in annotate.php
  * #geof# should go into a mia_page_profile
  */
 function can_annotate($url)
 {
     global $USER;
     if (isguestuser() or !isloggedin()) {
         return false;
     }
     $handler = annotation_summary_query::handler_for_url($url);
     if (!$handler) {
         return false;
     }
     $handler->fetch_metadata();
     if ($handler->modulename && $handler->courseid) {
         $cm = get_coursemodule_from_instance($handler->modulename, $handler->modinstanceid, $handler->courseid);
         if ($cm) {
             $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
             //				if ( has_capability('moodle/legacy:guest', $context, $USER->id, false ) )
             //					return false;
             if (!$handler->capannotate) {
                 return false;
             } else {
                 return has_capability($handler->capannotate, $modcontext);
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
示例#5
0
 function doListAnnotations($url, $sheet, $block, $all, $mark)
 {
     global $USER, $DB;
     $moodlemia = moodle_marginalia::get_instance();
     $handler = annotation_summary_query::handler_for_url($url);
     $sheet_type = $moodlemia->sheet_type($sheet);
     $summary = new annotation_summary_query(array('url' => $url, 'sheet_type' => $sheet_type, 'all' => $all));
     if ($summary->error) {
         $this->httpError(400, 'Bad Request', 'Bad URL 1');
         return null;
     } elseif (!isloggedin() && ANNOTATION_REQUIRE_USER) {
         $this->httpError(403, 'Forbidden', 'Anonymous listing not allowed');
         return null;
     } else {
         $queryparams = array();
         $querysql = $summary->sql($queryparams);
         //echo "QUERY: $querysql\n";
         //echo "PARAMS: \n";
         //foreach ( $queryparams as $key => $value )
         //	echo "  $key => $value\n";
         $annotations = array();
         $annotations_read = array();
         $annotations_unread = array();
         $i = 0;
         // Prep as much possible now for lastread updates
         $now = time();
         // lastread time
         // Open the record set
         /*echo "Query: $querysql<br/>";
         		/echo "Params: $queryparams<br/>";
         		foreach ( $queryparams as $p => $v )
         		{
         			echo "Param: $p = $v<br/>";
         		}*/
         $annotation_set = $DB->get_recordset_sql($querysql, $queryparams);
         foreach ($annotation_set as $r) {
             $annotations[$i] = $moodlemia->record_to_annotation($r);
             $annotation = $annotations[$i];
             if ('read' == $mark) {
                 // Will do a bulk update later
                 if ($annotation->getLastRead()) {
                     $annotations_read[] = $annotation->id;
                 } else {
                     $annotations_unread[] = $annotation->id;
                 }
             }
             $i++;
         }
         // Close the recordset
         $annotation_set->close();
         // Bulk update of lastread
         if ('read' == $mark) {
             if ($annotations_read && count($annotations_read)) {
                 list($in_sql, $in_params) = $DB->get_in_or_equal($annotations_read, SQL_PARAMS_NAMED);
                 $query = 'UPDATE {' . AN_READ_TABLE . '}' . "\n SET lastread=:lastread" . "\n WHERE userid=:userid AND annotationid {$in_sql}";
                 $query_params = array('userid' => $USER->id, 'lastread' => (int) $now);
                 $params = array_merge($in_params, $query_params);
                 $DB->execute($query, $params);
             }
             if ($annotations_unread && count($annotations_unread)) {
                 list($in_sql, $in_params) = $DB->get_in_or_equal($annotations_unread, SQL_PARAMS_NAMED);
                 $query = 'INSERT INTO {' . AN_READ_TABLE . '}' . "\n (annotationid, userid, firstread, lastread)" . "\n SELECT a.id, :userid, :now1, :now2" . "\n FROM {" . AN_DBTABLE . "} a" . "\n WHERE a.id {$in_sql}";
                 $query_params = array('userid' => $USER->id, 'now1' => (int) $now, 'now2' => (int) $now);
                 $params = array_merge($in_params, $query_params);
                 $DB->execute($query, $params);
             }
         }
         if ($this->extService) {
             $extService = $this->extService;
             $extService->listAnnotations($url, $sheet, $block, $all, $mark);
         }
         $format = $this->getQueryParam('format', 'atom');
         $moodlemia->moodle_log('list', 'annotate.php?format=' . $format . '&url=' . $url);
         return $annotations;
     }
 }
 function derive($a)
 {
     $summary_query = new annotation_summary_query(array('text' => $this->text, 'exactmatch' => $this->exactmatch, 'all' => $this->all, 'orderby' => $this->orderby, 'sheet_type' => $this->sheet_type, 'user' => $this->user, 'ofuser' => $this->ofuser, 'url' => $this->url));
     if ($a) {
         $summary_query->from_params($a);
     }
     return $summary_query;
 }
 function for_parent()
 {
     $this->handler->fetch_metadata();
     if ($this->handler->parenturl) {
         return new annotation_summary_query($this->handler->parenturl, annotation_summary_query::handler_for_url($this->handler->parenturl), $this->text, $this->user, $this->ofuser, $this->exactmatch, $this->all);
     } else {
         return null;
     }
 }
示例#8
0
文件: lib.php 项目: njorth/marginalia
 function show_user_dropdown($refurl)
 {
     global $USER;
     $summary = annotation_summary_query::from_url($refurl);
     $userlist = get_records_sql($summary->list_users_sql());
     $annotationuserid = moodle_marginalia::get_userid();
     $showannotationspref = moodle_marginalia::get_show_annotations_pref() == 'true';
     echo "<select name='anuser' id='anuser' onchange='window.moodleMarginalia.changeAnnotationUser(this,\"{$refurl}\");'>\n";
     $selected = $showannotationspref ? '' : " selected='selected' ";
     echo " <option {$selected} value=''>" . get_string('hide_annotations', ANNOTATION_STRINGS) . "</option>\n";
     if (!isguest()) {
         $selected = $showannotationspref && ($USER->username == $annotationuserid ? "selected='selected' " : '') ? " selected='selected' " : '';
         echo " <option {$selected}" . "value='" . s($USER->username) . "'>" . get_string('my_annotations', ANNOTATION_STRINGS) . "</option>\n";
     }
     if ($userlist) {
         foreach ($userlist as $user) {
             if ($user->username != $USER->username) {
                 $selected = $showannotationspref && ($user->id == $annotationuserid ? "selected='selected' " : '') ? " selected='selected' " : '';
                 echo " <option {$selected}" . "value='" . s($user->username) . "'>" . s($user->firstname . ' ' . $user->lastname) . "</option>\n";
             }
         }
     }
     // Show item for all users
     if (true) {
         $selected = $showannotationspref && ('*' == $annotationuserid ? "selected='selected' " : '') ? " selected='selected' " : '';
         echo " <option {$selected} value='*'>" . get_string('all_annotations', ANNOTATION_STRINGS) . "</option>\n";
     }
     echo "</select>\n";
 }