public function getFeaturedShort() { $docs = array(); $featuredSetting = Setting::where(array('meta_key' => 'featured-doc'))->first(); if ($featuredSetting) { // Make sure our featured document can be viewed by the public. $featuredIds = explode(',', $featuredSetting->meta_value); $docQuery = Doc::with('statuses')->whereIn('id', $featuredIds)->where('is_template', '!=', '1'); $docs = $docQuery->get(); if ($docs) { // Reorder based on our previous list. $tempDocs = array(); $orderList = array_flip($featuredIds); foreach ($docs as $key => $doc) { $tempDocs[(int) $orderList[$doc->id]] = $doc; } // If you set the key of an array value as we do above, // PHP will internally store the object as an associative // array (hash), not as a list, and will return the elements // in the order assigned, not by the key order. // This means our attempt to re-order the object will fail. // The line below will restore the order. Ugh. ksort($tempDocs); $docs = $tempDocs; } } return Response::json($docs); }
public static function getEager() { return Doc::with('categories')->with('userSponsors')->with('groupSponsors')->with('statuses')->with('dates'); }
public function getFeatured() { $featuredSetting = Setting::where('meta_key', '=', 'featured-doc')->first(); if ($featuredSetting) { // Make sure our featured document can be viewed by the public. $featuredIds = explode(',', $featuredSetting->meta_value); $docs = Doc::with('categories')->with('userSponsors')->with('groupSponsors')->with('statuses')->with('dates')->whereIn('id', $featuredIds)->where('publish_state', '=', Doc::PUBLISH_STATE_PUBLISHED)->where('is_template', '!=', '1')->get(); if ($docs) { // Reorder based on our previous list. $tempDocs = array(); $orderList = array_flip($featuredIds); foreach ($docs as $key => $doc) { $tempDocs[(int) $orderList[$doc->id]] = $doc; } // If you set the key of an array value as we do above, // PHP will internally store the object as an associative // array (hash), not as a list, and will return the elements // in the order assigned, not by the key order. // This means our attempt to re-order the object will fail. // The line below will restore the order. Ugh. ksort($tempDocs); $docs = $tempDocs; } } // If we don't have a document, just find anything recent. if (empty($docs)) { $docs = array(Doc::with('categories')->with('userSponsors')->with('groupSponsors')->with('statuses')->with('dates')->where('publish_state', '=', Doc::PUBLISH_STATE_PUBLISHED)->where('is_template', '!=', '1')->orderBy('created_at', 'desc')->first()); } // If we still don't have a document, give up. if (empty($docs)) { return Response::make(null, 404); } $return_docs = array(); foreach ($docs as $key => $doc) { $doc->enableCounts(); $doc->enableSponsors(); $return_doc = $doc->toArray(); $return_doc['introtext'] = $doc->introtext()->first()['meta_value']; $return_doc['updated_at'] = date('c', strtotime($return_doc['updated_at'])); $return_doc['created_at'] = date('c', strtotime($return_doc['created_at'])); if (!$return_doc['thumbnail']) { $return_doc['thumbnail'] = '/img/default/default.jpg'; } $return_docs[] = $return_doc; } return Response::json($return_docs); }
public function getAllStatuses() { $doc = Doc::with('statuses')->first(); $statuses = $doc->statuses; return Response::json($statuses); }
Route::put('api/groups/verify/{groupId}', 'GroupsApiController@putVerify'); // User Login / Signup AJAX requests Route::get('api/user/login', 'UserManageApiController@getLogin'); Route::post('api/user/login', 'UserManageApiController@postLogin'); Route::get('api/user/signup', 'UserManageApiController@getSignup'); Route::post('api/user/signup', 'UserManageApiController@postSignup'); //Auth Token Route Route::get('/auth/token', 'AuthController@token'); Route::get('/api/user/login', 'AuthController@login'); Route::get('/api/user/logout', 'AuthController@logout'); /** * RSS Feed Route. */ Route::get('docs/feed', function () { //Grab all documents $docs = Doc::with('sponsor', 'content')->orderBy('updated_at', 'DESC')->take(20)->get(); $feed = Feed::make(); $feed->title = 'Madison Documents'; $feed->description = 'Latest 20 documents in Madison'; $feed->link = URL::to('rss'); $feed->pubdate = $docs->first()->updated_at; $feed->lang = 'en'; foreach ($docs as $doc) { $sponsor = $doc->sponsor->first(); if ($sponsor instanceof User) { $display_name = $sponsor->fname . ' ' . $sponsor->lname; } elseif ($sponsor instanceof Group) { $display_name = $sponsor->display_name; } else { $display_name = ''; }