Ejemplo n.º 1
0
 /**
  *  Displays a form to add a single note
  *
  *  @param   integer  $outlineId  Outline id
  *
  *  @return  Response
  */
 public function getCreate($outlineId = 0)
 {
     if ($outlineId > 0) {
         try {
             $outline = Outline::findOrFail($outlineId);
             // Eager load tags
             $outline->tags;
             // Display form to create a new note
             return view('notes.create', ['outline' => $outline]);
         } catch (ModelNotFoundException $e) {
             // Okay, obviously we don't have an outline. Just return the view.
             return view('notes.create', ['outline' => null]);
         }
     }
     // No outline? Just return the view.
     return view('notes.create', ['outline' => null]);
 }
Ejemplo n.º 2
0
 /**
  *  Attach an element to an outline
  *
  *  @param   int  $outlineID       The ID describing the outline
  *  @param   string  $attachmentType  'custom' or 'note'
  *  @param   mixed  $requestContent  int or string depending on $attachmentType
  *  @param   int  $index           The index that this function should assign to the element
  *  @param   string  $type            Only necessary for custom elements, the HTML tag ("p" or "h2")
  *
  *  @return  mixed                   Response, CustomField or Note depending on params
  */
 public function getOutlineAttach($outlineID, $attachmentType, $requestContent, $index, $type = "p")
 {
     // First catch the outline
     try {
         $outline = Outline::findOrFail($outlineID);
     } catch (ModelNotFoundException $e) {
         return response()->json(['message', 'Could not find outline'], 404);
     }
     if ($attachmentType == "custom") {
         $field = new CustomField();
         $field->type = $type;
         // type is the HTML tag (i.e. p, h3, div)
         $field->content = nl2br($requestContent);
         // What goes inside the tag
         $field->index = $index;
         // The index inside the outliner
         $outline->customFields()->save($field);
         return $field;
     } else {
         // attachmentType = note
         // $type is now omittable
         // $requestContent now contains our ID
         try {
             $note = Note::findOrFail($requestContent);
         } catch (ModelNotFoundException $e) {
             return response()->json(['message', 'Could not find note'], 404);
         }
         $outline->notes()->attach($note, ['index' => $index]);
         return $note;
     }
 }
Ejemplo n.º 3
0
 /**
  *  Removes an outline, detaches its notes and removes its custom fields
  *
  *  @param   integer  $id  Outline id
  *
  *  @return  Response
  */
 public function delete($id)
 {
     try {
         $outline = Outline::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return redirect('/outlines');
     }
     $outline->notes()->detach();
     $outline->customFields()->delete();
     $outline->delete();
     return redirect('/outlines');
 }