Esempio n. 1
0
 public function saveDocumentEdits($documentId)
 {
     if (!Auth::check()) {
         return Redirect::to('documents')->with('error', 'You must be logged in');
     }
     $content = Input::get('content');
     $contentId = Input::get('content_id');
     if (empty($content)) {
         return Redirect::to('documents')->with('error', "You must provide content to save");
     }
     if (!empty($contentId)) {
         $docContent = DocContent::find($contentId);
     } else {
         $docContent = new DocContent();
     }
     if (!$docContent instanceof DocContent) {
         return Redirect::to('documents')->with('error', 'Could not locate document to save');
     }
     $document = Doc::find($documentId);
     if (!$document instanceof Doc) {
         return Redirect::to('documents')->with('error', "Could not locate the document");
     }
     if (!$document->canUserEdit(Auth::user())) {
         return Redirect::to('documents')->with('error', 'You are not authorized to save that document.');
     }
     $docContent->doc_id = $documentId;
     $docContent->content = $content;
     try {
         \DB::transaction(function () use($docContent, $content, $documentId, $document) {
             $docContent->save();
         });
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "There was an error saving the document: {$e->getMessage()}");
     }
     //Fire document edited event for admin notifications
     $doc = Doc::find($docContent->doc_id);
     Event::fire(MadisonEvent::DOC_EDITED, $doc);
     try {
         $document->indexContent($docContent);
     } catch (\Exception $e) {
         return Redirect::to('documents')->with('error', "Document saved, but there was an error with Elasticsearch: {$e->getMessage()}");
     }
     return Redirect::to('documents')->with('success_message', 'Document Saved Successfully');
 }
Esempio n. 2
0
 public function getRestoreDoc($docId)
 {
     $doc = Doc::withTrashed()->find($docId);
     if ($doc->publish_state == Doc::PUBLISH_STATE_DELETED_ADMIN) {
         if (!Auth::user()->hasRole('admin')) {
             return Response('Unauthorized.', 403);
         }
     }
     if (!$doc->canUserEdit(Auth::user())) {
         return Response('Unauthorized.', 403);
     }
     DocMeta::withTrashed()->where('doc_id', $docId)->restore();
     DocContent::withTrashed()->where('doc_id', $docId)->restore();
     Annotation::withTrashed()->where('doc_id', $docId)->restore();
     Comment::withTrashed()->where('doc_id', $docId)->restore();
     $doc->restore();
     $doc->publish_state = Doc::PUBLISH_STATE_UNPUBLISHED;
     $doc->save();
     return Response::json($doc);
 }
Esempio n. 3
0
 public function get_content($format = null)
 {
     $path = $this->get_file_path($format);
     try {
         return \File::get($path);
     } catch (Illuminate\Filesystem\FileNotFoundException $e) {
         $content = DocContent::where('doc_id', '=', $this->attributes['id'])->where('parent_id')->first()->content;
         if ($format == 'html') {
             $content = Markdown::render($content);
         }
         return $content;
     }
 }
 public function deleteContent($docId, $page)
 {
     $doc_content = DocContent::where('doc_id', $docId)->where('page', $page)->first();
     if ($doc_content) {
         $doc_content->delete();
         DocContent::where('doc_id', $docId)->where('page', '>', $page)->decrement('page');
         $doc = Doc::find($docId)->enableCounts();
         Event::fire(MadisonEvent::DOC_EDITED, $doc);
         return Response::json($doc->toArray());
     }
 }
Esempio n. 5
0
 /**
  * 	Recursive function to save children of a given node as DocContent items.
  */
 public function saveChildren($node, $parent_id, $child_priority)
 {
     if (!isset($parent_id) || $parent_id == 0) {
         throw new Exception("Error saving content.");
     }
     //Check the node is in the document structure elements
     @($valid = in_array($node->tagName, $this->structure));
     if (!$valid) {
         //If the node has no children, return
         if (!$node->hasChildNodes()) {
             return;
         } else {
             //Otherwise save the children, passing on the parent id ( this isn't a valid parent )
             $c = 0;
             foreach ($node->childNodes as $child) {
                 $this->saveChildren($child, $parent_id, $c++);
             }
             return;
         }
     }
     //Save this item
     $contentItem = new DocContent();
     $contentItem->doc_id = $this->bill->id;
     $contentItem->content = $this->getNodeContent($node);
     $contentItem->child_priority = $child_priority;
     $contentItem->parent_id = $parent_id;
     $contentItem->save();
     if ($node->childNodes->length == 0) {
         return;
     }
     $c = 0;
     foreach ($node->childNodes as $child) {
         $this->saveChildren($child, $contentItem->id, $c++);
     }
 }