/** * Method to handle document RSS feeds. * * @param string $slug * * @return view $feed->render() */ public function getFeed($slug) { $doc = Doc::where('slug', $slug)->with('comments', 'annotations', 'userSponsor', 'groupSponsor')->first(); $feed = Feed::make(); $feed->title = $doc->title; $feed->description = "Activity feed for '" . $doc->title . "'"; $feed->link = URL::to('docs/' . $slug); $feed->pubdate = $doc->updated_at; $feed->lang = 'en'; $activities = $doc->comments->merge($doc->annotations); $activities = $activities->sort(function ($a, $b) { return strtotime($a['updated_at']) > strtotime($b['updated_at']) ? -1 : 1; }); foreach ($activities as $activity) { $item = $activity->getFeedItem(); array_push($feed->items, $item); } return $feed->render('atom'); }
public function getActions($docId) { $doc = Doc::where('id', $docId)->first(); if ($doc) { $skip_ids = $doc->sponsorIds; $actions = DocAction::where('doc_id', $docId)->whereNotIn('user_id', $skip_ids)->with('user')->orderBy('created_at')->get(); if ($actions) { if (Input::get('download') === 'csv') { $csv = Writer::createFromFileObject(new \SplTempFileObject()); $fields = array('first_name', 'last_name', 'email', 'quote', 'text', 'type', 'created_at'); // Headings. $csv->insertOne($fields); foreach ($actions as $action) { $actionRow = $action->toArray(); $actionRow['first_name'] = $actionRow['user']['fname']; $actionRow['last_name'] = $actionRow['user']['lname']; $actionRow['email'] = $actionRow['user']['email']; // Rearrange our columns $saveRow = array(); foreach ($fields as $field) { $saveRow[$field] = $actionRow[$field]; } $csv->insertOne($saveRow); } $csv->output('actions.csv'); return; } else { return Response::json($actions->toArray()); } } } return Response::notFound(); }
public function deleteImage($docId) { $doc = Doc::where('id', $docId)->first(); $image_path = $doc->getImagePathFromUrl($doc->thumbnail); if (Storage::has($image_path)) { try { Storage::delete($image_path); } catch (Exception $e) { Log::error("Error deleting document featured image for document id {$docId}"); Log::error($e); } } $doc->thumbnail = null; $doc->save(); return Response::json($this->growlMessage('Image deleted successfully', 'success')); }
public function getDocCount() { $doc = Doc::where('publish_state', '=', Doc::PUBLISH_STATE_PUBLISHED)->where('is_template', '!=', '1'); if (Input::has('category')) { $doc->whereHas('categories', function ($q) { $category = Input::get('category'); $q->where('categories.name', 'LIKE', "%{$category}%"); }); } if (Input::has('title')) { $title = Input::get('title'); $doc->where('title', 'LIKE', "%{$title}%"); } $docCount = $doc->count(); return Response::json(['count' => $docCount]); }
public function deleteImage($docId) { $doc = Doc::where('id', $docId)->first(); $image_path = public_path() . $doc->thumbnail; try { File::delete($image_path); $doc->thumbnail = null; $doc->save(); } catch (Exception $e) { Log::error("Error deleting document featured image for document id {$docId}"); Log::error($e); } return Response::json($this->growlMessage('Image deleted successfully', 'success')); }