示例#1
0
 function recordToAnnotation($r)
 {
     $annotation = new Annotation();
     $annotation->setAnnotationId($r->id);
     $annotation->setUserId($r->userid);
     if ($r->access) {
         $annotation->setAccess($r->access);
     }
     if ($r->url) {
         $annotation->setUrl($r->url);
     }
     if ($r->note) {
         $annotation->setNote($r->note);
     }
     if ($r->quote) {
         $annotation->setQuote($r->quote);
     }
     if ($r->quote_title) {
         $annotation->setQuoteTitle($r->quote_title);
     }
     if ($r->quote_author) {
         $annotation->setQuoteAuthor($r->quote_author);
     }
     if ($r->link) {
         $annotation->setLink($r->link);
     }
     if ($r->link_title) {
         $annotation->setLinkTitle($r->link_title);
     }
     $annotation->setCreated($r->created);
     if ($r->start_block !== null) {
         $range = new SequenceRange();
         $range->setStart(new SequencePoint($r->start_block, $r->start_word, $r->start_char));
         $range->setEnd(new SequencePoint($r->end_block, $r->end_word, $r->end_char));
         $annotation->setSequenceRange($range);
     } else {
         if (!empty($r->range)) {
             $range = new SequenceRange();
             $range->fromString($r->range);
             $annotation->setSequenceRange($range);
         }
     }
     if ($r->start_xpath !== null) {
         $range = new XPathRange();
         $range->setStart(new XPathPoint($r->start_xpath, $r->start_word, $r->start_char));
         $range->setEnd(new XpathPoint($r->end_xpath, $r->end_word, $r->end_char));
         $annotation->setXPathRange($range);
     }
     return $annotation;
 }
示例#2
0
 /**
  * Remember: This the Annotation class does not store Moodle user IDs, so
  * you must be sure to query for username and quote_author_username if you
  * want userid and quoteAuthorId set.
  */
 function record_to_annotation($r)
 {
     $annotation = new Annotation();
     $annotation->setAnnotationId($r->id);
     if (array_key_exists('userid', $r)) {
         $annotation->setUserId($r->userid);
     }
     if (array_key_exists('firstname', $r)) {
         $annotation->setUserName($this->fullname2($r->firstname, $r->lastname));
     }
     if (array_key_exists('sheet_type', $r)) {
         $annotation->setSheet($this->sheet_str($r->sheet_type));
     }
     if (array_key_exists('url', $r)) {
         $annotation->setUrl($r->url);
     }
     if (array_key_exists('note', $r)) {
         $annotation->setNote($r->note);
     }
     if (array_key_exists('quote', $r)) {
         $annotation->setQuote($r->quote);
     }
     if (array_key_exists('quote_title', $r)) {
         $annotation->setQuoteTitle($r->quote_title);
     }
     if (array_key_exists('quote_author_id', $r)) {
         $annotation->setQuoteAuthorId($r->quote_author_id);
     } elseif (array_key_exists('quote_author', $r)) {
         // to support old mdl_annotation table
         $annotation->setQuoteAuthorId($r->quote_author);
     }
     if (array_key_exists('quote_author_firstname', $r)) {
         $annotation->setQuoteAuthorName($this->fullname2($r->quote_author_firstname, $r->quote_author_lastname));
     }
     if (array_key_exists('link', $r)) {
         $annotation->setLink($r->link);
     }
     if (array_key_exists('link_title', $r)) {
         $annotation->setLinkTitle($r->link_title);
     }
     if (array_key_exists('created', $r)) {
         $annotation->setCreated((int) $r->created);
     }
     if (array_key_exists('modified', $r)) {
         $annotation->setModified((int) $r->modified);
     }
     if (array_key_exists('lastread', $r)) {
         $annotation->setLastRead((int) $r->lastread);
     }
     $start_line = array_key_exists('start_line', $r) ? $r->start_line : 0;
     $end_line = array_key_exists('end_line', $r) ? $r->end_line : 0;
     // The second and subsequente lines of the test are to catch cases where everything is blank,
     // which can happen if the range is really old and uses the range field
     if (array_key_exists('start_block', $r) && $r->start_block !== null && (!array_key_exists('range', $r) || ($start_line || $end_line || $r->start_block || $r->end_block || $r->start_word || $r->end_word || $r->start_char || $r->end_char))) {
         $range = new SequenceRange();
         $range->setStart(new SequencePoint($r->start_block, $start_line, $r->start_word, $r->start_char));
         $range->setEnd(new SequencePoint($r->end_block, $end_line, $r->end_word, $r->end_char));
         $annotation->setSequenceRange($range);
     } else {
         if (array_key_exists('range', $r) && $r->range !== null) {
             $range = new SequenceRange();
             $range->fromString($r->range);
             $annotation->setSequenceRange($range);
         }
     }
     if (array_key_exists('start_xpath', $r) && $r->start_xpath !== null) {
         $range = new XPathRange();
         $range->setStart(new XPathPoint($r->start_xpath, $start_line, $r->start_word, $r->start_char));
         $range->setEnd(new XpathPoint($r->end_xpath, $end_line, $r->end_word, $r->end_char));
         $annotation->setXPathRange($range);
     }
     return $annotation;
 }
示例#3
0
 /**
  * Internal function to fill in the passed annotation object from the row.
  * @param $annotation Annotation output annotation
  * @param $row array input row
  */
 function _annotationFromRow(&$annotation, &$row)
 {
     $annotation->setAnnotationId($row['id']);
     $annotation->setUserId($row['userlogin']);
     $annotation->setUserName($row['username']);
     $annotation->setUrl($row['url']);
     $annotation->setNote($row['note']);
     $annotation->setAction($row['action']);
     $annotation->setQuote($row['quote']);
     $annotation->setQuoteTitle($row['quote_title']);
     $annotation->setQuoteAuthorId($row['quote_author_id']);
     $annotation->setQuoteAuthorName($row['quote_author_name']);
     $annotation->setLink($row['link']);
     $annotation->setLinkTitle($row['link_title']);
     $annotation->setCreated($row['created']);
     $annotation->setModified($row['modified']);
     $access = $row['access_perms'];
     $annotation->setAccess($access & AN_ACCESS_PUBLIC ? 'public' : 'private');
     $start_line = $row['start_line'];
     $start_word = $row['start_word'];
     $start_char = $row['start_char'];
     $end_line = $row['end_line'];
     $end_word = $row['end_word'];
     $end_char = $row['end_char'];
     // Create the block range
     if ($row['start_block']) {
         $range = new SequenceRange();
         $range->setStart(new SequencePoint($row['start_block'], $start_line, $start_word, $start_char));
         $range->setEnd(new SequencePoint($row['end_block'], $end_line, $end_word, $end_char));
         $annotation->setSequenceRange($range);
     } elseif (array_key_exists('range', $row) && $row['range']) {
         $range = new SequenceRange();
         $range->fromString($row['range']);
         $annotation->setSequenceRange($range);
     }
     // Create the xpath range
     if ($row['start_xpath']) {
         $range = new XPathRange();
         $range->setStart(new XPathPoint($row['start_xpath'], $start_line, $start_word, $start_char));
         $range->setEnd(new XPathPoint($row['end_xpath'], $end_line, $end_word, $end_char));
         $annotation->setXPathRange($range);
     }
     HookRegistry::call('AnnotationDAO::_returnAnnotationFromRow', array(&$annotation, &$row));
 }