Esempio n. 1
0
 public function addComment($comment)
 {
     $es = $this->es;
     $comment['created'] = Carbon::now('America/New_York')->toRFC2822String();
     $comment['updated'] = Carbon::now('America/New_York')->toRFC2822String();
     array_push($this->comments, $comment);
     foreach ($this->comments as $index => &$comment) {
         $comment['id'] = $index + 1;
     }
     $retval = $this->update(false);
     $dbComment = new AnnotationComment();
     $dbComment->text = $comment['text'];
     $dbComment->user_id = $comment['user']['id'];
     $dbComment->id = $comment['id'];
     $dbComment->annotation_id = $this->id;
     $dbComment->save();
     return $retval;
 }
Esempio n. 2
0
 public function addOrUpdateComment(array $comment)
 {
     $obj = new AnnotationComment();
     $obj->text = $comment['text'];
     $obj->user_id = $comment['user']['id'];
     if (isset($comment['id'])) {
         $obj->id = $comment['id'];
     }
     $obj->annotation_id = $this->id;
     $obj->save();
     $obj->load('user');
     return $obj;
 }
 /**
  * Create a new annotation.
  *
  * @param document ID $doc
  *
  * @throws Exception
  *
  * @return 303 redirect to annotation link
  */
 public function postIndex($doc)
 {
     $body = Input::all();
     $body['doc_id'] = $doc;
     $is_edit = false;
     //Check for edit tag
     if (in_array('edit', $body['tags'])) {
         $is_edit = true;
         //If no explanation present, throw error
         if (!isset($body['explanation'])) {
             throw new Exception('Explanation required for edits');
         }
     }
     $id = \DB::transaction(function () use($body, $doc, $is_edit) {
         $annotation = new Annotation();
         $annotation->doc_id = $doc;
         $annotation->user_id = Auth::user()->id;
         $annotation->quote = $body['quote'];
         $annotation->text = $body['text'];
         $annotation->uri = $body['uri'];
         $annotation->save();
         foreach ($body['ranges'] as $range) {
             $rangeObj = new AnnotationRange();
             $rangeObj->annotation_id = $annotation->id;
             $rangeObj->start_offset = $range['startOffset'];
             $rangeObj->end_offset = $range['endOffset'];
             $rangeObj->start = $range['start'];
             $rangeObj->end = $range['end'];
             $rangeObj->save();
         }
         $permissions = new AnnotationPermission();
         $permissions->annotation_id = $annotation->id;
         $permissions->user_id = Auth::user()->id;
         $permissions->read = 1;
         $permissions->update = 0;
         $permissions->delete = 0;
         $permissions->admin = 0;
         $permissions->save();
         foreach ($body['tags'] as $tag) {
             $tagObj = new AnnotationTag();
             $tagObj->annotation_id = $annotation->id;
             $tagObj->tag = $tag;
             $tagObj->save();
         }
         if ($is_edit) {
             $comment = new AnnotationComment();
             $comment->text = $body['explanation'];
             $comment->user_id = $annotation->user_id;
             $comment->annotation_id = $annotation->id;
             $comment->save();
         }
         //$annotation->updateSearchIndex();
         return $annotation->id;
     });
     $annotation = Annotation::find($id);
     Event::fire(MadisonEvent::DOC_ANNOTATED, $annotation);
     return Redirect::to('/api/docs/' . $doc . '/annotations/' . $id, 303);
 }