コード例 #1
0
ファイル: annotate.php プロジェクト: njorth/marginalia
 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
 /**
  * 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;
     }
 }
コード例 #3
0
ファイル: annotate.php プロジェクト: GeofG/marginalia-m
 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;
     }
 }
コード例 #4
0
 function from_params($a)
 {
     global $DB;
     if (array_key_exists('text', $a)) {
         $this->text = $a['text'];
     }
     if (array_key_exists('exactmatch', $a)) {
         $this->exactmatch = $a['exactmatch'];
     }
     if (array_key_exists('all', $a)) {
         $this->all = $a['all'];
     }
     if (array_key_exists('orderby', $a)) {
         $this->orderby = $a['orderby'];
     }
     if (array_key_exists('sheet_type', $a)) {
         $this->sheet_type = $a['sheet_type'];
     }
     if (array_key_exists('user', $a)) {
         $this->user = $a['user'];
     } elseif (array_key_exists('userid', $a)) {
         $this->user = $DB->get_record('user', array('id' => (int) $a['userid']));
     }
     if (array_key_exists('ofuser', $a)) {
         $this->ofuser = $a['ofuser'];
     } elseif (array_key_exists('ofuserid', $a)) {
         $this->ofuser = $DB->get_record('user', array('id' => (int) $a['ofuserid']));
     }
     if (array_key_exists('url', $a)) {
         $this->url = $a['url'];
         $this->handler = annotation_summary_query::handler_for_url($this->url);
     }
 }
コード例 #5
0
 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;
     }
 }