Example #1
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));
 }
Example #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;
 }
Example #3
0
 /**
  * Set annotation fields based on parameters (e.g. from $_POST)
  * For updates, first retrieve the stored annotation, then update it here.
  * If this fails, the passed annotation object may have already been altered.
  * Different implementations may have different annotation objects.  All should
  * be compatible with this code if they have the appropriate getters and setters.
  */
 function annotationFromParams(&$annotation, &$params)
 {
     // ID
     // must be setAnnotationId, not setId, because of a conflict with a base class method in OJS
     if (array_key_exists('id', $params)) {
         $id = $params['id'];
         $annotation->setAnnotationId($id);
     }
     // UserId
     if (array_key_exists('userid', $params)) {
         $userid = $params['userid'];
         $annotation->setUserId($userid);
     }
     // UserName
     if (array_key_exists('username', $params)) {
         $userName = $params['username'];
         $annotation->setUserName($userName);
     }
     // Sequence Range
     if (array_key_exists('sequence-range', $params)) {
         $sequenceRange = new SequenceRange();
         $sequenceRange->fromString($params['sequence-range']);
         $annotation->setSequenceRange($sequenceRange);
     }
     // XPath Range
     if (array_key_exists('xpath-range', $params)) {
         $xpathRange = new XPathRange();
         $xpathRange->fromString($params['xpath-range']);
         if (!XPathPoint::isXPathSafe($xpathRange->start->getPathStr()) || !XPathPoint::isXPathSafe($xpathRange->end->getPathStr())) {
             return XPATH_SECURITY_ERROR;
         }
         $annotation->setXPathRange($xpathRange);
     }
     // URL
     if (array_key_exists('url', $params)) {
         $url = $params['url'];
         if (!$url || !MarginaliaHelper::isUrlSafe($url)) {
             return URL_SCHEME_ERROR;
         }
         $annotation->setUrl($url);
     }
     // Note
     if (array_key_exists('note', $params)) {
         $note = $params['note'];
         $annotation->setNote($note);
     }
     // Quote
     if (array_key_exists('quote', $params)) {
         $quote = $params['quote'];
         $annotation->setQuote($quote);
     }
     // QuoteTitle
     if (array_key_exists('quote_title', $params)) {
         $quoteTitle = $params['quote_title'];
         $annotation->setQuoteTitle($quoteTitle);
     }
     // QuoteAuthorId
     if (array_key_exists('quote_author_id', $params)) {
         $quoteAuthorId = $params['quote_author_id'];
         $annotation->setQuoteAuthorId($quoteAuthorId);
     }
     // QuoteAuthorName
     if (array_key_exists('quote_author_name', $params)) {
         $quoteAuthorName = $params['quote_author_name'];
         $annotation->setQuoteAuthorName($quoteAuthorName);
     }
     // Access
     if (array_key_exists('access', $params)) {
         $access = $params['access'];
         if (!Annotation::isAccessValid($access)) {
             return ACCESS_VALUE_ERROR;
         }
         $annotation->setAccess($access);
     }
     // Action
     if (array_key_exists('action', $params)) {
         $action = $params['action'];
         if (!Annotation::isActionValid($action)) {
             return ACTION_VALUE_ERROR;
         }
         $annotation->setAction($action);
     }
     // Link
     if (array_key_exists('link', $params)) {
         $link = $params['link'];
         if ($link && !MarginaliaHelper::isUrlSafe($link)) {
             return URL_SCHEME_ERROR;
         }
         $annotation->setLink($link);
     }
     // Link Title
     if (array_key_exists('link_title', $params)) {
         $title = $params['link_title'];
         $annotation->setLinkTitle($title);
     }
     // Created
     if (array_key_exists('created', $params)) {
         $created = $params['created'];
         // TODO: verify date format
         $this->setCreated($created);
     }
     // Modified
     if (array_key_exists('modified', $params)) {
         $modified = $params['modified'];
         $this->setModified($modified);
     }
     // Version
     if (array_key_exists('version', $params)) {
         $version = $params['version'];
         $this->setVersion($version);
     }
     // Ok, I know in PHP it's traditional to return True for success,
     // but that requires the triple === which drives me nuts and is
     // easy to forget (and if ( f() ) won't work), so I'll go with the
     // old C / Unix tradition and return 0.
     return 0;
 }
Example #4
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;
 }