Ejemplo n.º 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;
     }
 }
Ejemplo n.º 2
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;
     }
 }