/** * Show the application dashboard to the user. * * @return Response */ public function index() { $articles = Article::with('author')->orderBy('position', 'DESC')->orderBy('created_at', 'DESC')->limit(4)->get(); // TODO: abstract to model $sliders = Photo::join('photo_albums', 'photo_albums.id', '=', 'photos.photo_album_id')->where('photos.slider', 1)->orderBy('photos.position', 'DESC')->orderBy('photos.created_at', 'DESC')->select('photos.filename', 'photos.name', 'photos.description', 'photo_albums.folder_id')->get(); $photoAlbums = PhotoAlbum::select(array('photo_albums.id', 'photo_albums.name', 'photo_albums.description', 'photo_albums.folder_id', DB::raw('(select filename from ' . DB::getTablePrefix() . 'photos WHERE album_cover=TRUE and ' . DB::getTablePrefix() . 'photos.photo_album_id=' . DB::getTablePrefix() . 'photo_albums.id LIMIT 1) AS album_image'), DB::raw('(select filename from ' . DB::getTablePrefix() . 'photos WHERE ' . DB::getTablePrefix() . 'photos.photo_album_id=' . DB::getTablePrefix() . 'photo_albums.id ORDER BY position ASC, id ASC LIMIT 1) AS album_image_first')))->limit(8)->get(); $videoAlbums = VideoAlbum::select(array('video_albums.id', 'video_albums.name', 'video_albums.description', 'video_albums.folder_id', DB::raw('(select youtube from ' . DB::getTablePrefix() . 'videos WHERE album_cover=TRUE and ' . DB::getTablePrefix() . 'videos.video_album_id=' . DB::getTablePrefix() . 'video_albums.id LIMIT 1) AS album_image'), DB::raw('(select youtube from ' . DB::getTablePrefix() . 'videos WHERE ' . DB::getTablePrefix() . 'videos.video_album_id=' . DB::getTablePrefix() . 'video_albums.id ORDER BY position ASC, id ASC LIMIT 1) AS album_image_first')))->limit(8)->get(); $categoriesArray = Object::where('type', 'category')->get(); $categories = array(); foreach ($categoriesArray as $category) { $categories[] = array($category->title); } $categories = Object::where('type', 'category')->get(); global $types; $types = Object::getTypes()->select(array('id', DB::raw("REPLACE(name, '_object_type_', '') as name"), DB::raw("REPLACE(title, 'Object Type: ', '') as title"), 'created_at'))->get(); return view('pages.home', compact('articles', 'sliders', 'videoAlbums', 'photoAlbums', 'categories', 'types')); //return view('pages.welcome'); }
public function getCategories($id = null) { //Config::set('laravel-debugbar::config.enabled', false); $categories = Object::where('objects.type', 'category')->where('parent_id', $id)->select(array('objects.id', 'objects.title', 'objects.name'))->get(); $response = $categories; foreach ($categories as $category) { if ($contentImageId = ObjectMeta::getValue($category->id, '_content_image')) { if ($contentImageUrl = getImageSrc($contentImageId, 'medium')) { $category['contentImageUrl'] = '/uploads/' . $contentImageUrl; } } if ($featuredImageId = ObjectMeta::getValue($category->id, '_featured_image')) { if ($featuredImageUrl = getImageSrc($featuredImageId, 'thumbnail')) { $category['featuredImageUrl'] = '/uploads/' . $featuredImageUrl; } } $category['childrenCount'] = Object::where('objects.type', 'category')->where('parent_id', $category['id'])->count(); $category['itemsCount'] = ObjectMeta::join('objects', 'object_meta.object_id', '=', 'objects.id')->where('meta_key', '_category_id')->where('meta_value', $category['id'])->where('objects.type', '<>', 'category')->groupBy('object_id')->count(); } // $categories = Object::leftJoin('objects as t1', function($join) { // $join->on('objects.id', '=', 't1.parent_id'); // }) // ->where('objects.type', 'category') // //->whereNull('objects.parent_id') // ->where('t1.parent_id', $id) // ->select(DB::raw('jini_t1.*')) // ->get(); //print_r($categories); // // $response = array( // 'categories' => $categories // //'contentImage' => // ); return response()->json($categories); }
public function update($sessionId, $objects) { foreach ($objects as $object) { $gameObject = \App\Object::where('session_id', '=', $sessionId)->where('log', '=', $object['name'])->first(); if (is_null($gameObject)) { continue; } // there is no status 0 - its a C! if ($object['status'] == '0' && !starts_with($object['name'], 'BMA')) { $object['status'] = 'C'; } // status 9 means patrol for police which // means free on radio if ($object['status'] == '9') { $object['status'] = '1'; } $gameObject->status = $object['status']; $gameObject->save(); } return $sessionId; }
public function getCategories($id = null) { //Config::set('laravel-debugbar::config.enabled', false); $categories = Object::where('objects.type', 'category')->where('parent_id', $id)->select(array('objects.id', 'objects.title', 'objects.name'))->get(); $response = $categories; foreach ($categories as $category) { $this->processCategory($category); } // $categories = Object::leftJoin('objects as t1', function($join) { // $join->on('objects.id', '=', 't1.parent_id'); // }) // ->where('objects.type', 'category') // //->whereNull('objects.parent_id') // ->where('t1.parent_id', $id) // ->select(DB::raw('jini_t1.*')) // ->get(); //print_r($categories); // // $response = array( // 'categories' => $categories // //'contentImage' => // ); return response()->json($categories); }
public function update($sessionId, $objects) { foreach ($objects as $object) { $gameObject = \App\Object::where('session_id', '=', $sessionId)->where('log', '=', $object['name'])->first(); if (is_null($gameObject)) { continue; } // there is no status 0 - its a C! if ($object['status'] == '0' && !starts_with($object['name'], 'BMA')) { $object['status'] = 'C'; } // status 9 means patrol for police which // means free on radio if ($object['status'] == '9') { $object['status'] = '1'; } $client = new \phpcent\Client(env('CENT_HOST')); $client->setSecret(env('CENT_SECRET')); $client->publish($sessionId, ['payload' => $object, 'id' => $gameObject->id]); $gameObject->status = $object['status']; $gameObject->save(); } return $sessionId; }
public function getCategories($id = null) { //Config::set('laravel-debugbar::config.enabled', false); $categories = Object::where('type', 'category')->where('parent_id', $id)->get(); return response()->json($categories); }
/** * Show a list of all the languages posts formatted for Datatables. * * @return Datatables JSON */ public function data() { $type = html_entity_decode(Input::get('type')); $objects = Object::where('type', '<>', 'object_type')->where('type', '<>', 'image')->where('type', '<>', 'category'); if (!empty($type)) { $objects = $objects->where('type', $type); } $objects = $objects->select(array('id', 'title', 'type', 'status', 'created_at')); //;// object::select(array('object_types.id','object_types.name','object_types.display_name', 'object_types.created_at')); return Datatables::of($objects)->add_column('actions', '@if ($id>"4")<a href="{{{ URL::to(\'admin/objects/\' . $id . \'/edit\' ) }}}" class="btn btn-success btn-sm" ><span class="glyphicon glyphicon-pencil"></span> {{ trans("admin/modal.edit") }}</a> <a href="{{{ URL::to(\'admin/objects/\' . $id . \'/delete\' ) }}}" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans("admin/modal.delete") }}</a> @endif')->remove_column('id')->make(); // $objects = object::select(array('object_types.id','object_types.name','object_types.display_name', 'object_types.created_at')); // // return Datatables::of($objects) // ->add_column('actions', '@if ($id>"4")<a href="{{{ URL::to(\'admin/object-types/\' . $id . \'/edit\' ) }}}" class="btn btn-success btn-sm" ><span class="glyphicon glyphicon-pencil"></span> {{ trans("admin/modal.edit") }}</a> // <a href="{{{ URL::to(\'admin/object-types/\' . $id . \'/delete\' ) }}}" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans("admin/modal.delete") }}</a> // @endif') // ->remove_column('id') // // ->make(); }
public function getSearch() { $categoryId = Input::get('categoryid'); $index = Input::get('index') ?: 0; $search = Input::get('query'); $offset = (int) Input::get('offset'); $limit = 10; $objects = null; if ($categoryId) { // Category Image $featuredImageUrl = ''; if ($categoryFeaturedImageId = ObjectMeta::getValue($categoryId, '_featured_image')) { // $featuredImageUrl = getImageSrc($categoryFeaturedImageId, 'thumbnail'); $featuredImageUrl = 'cropped/' . getTheImageSize(getImageSrc($categoryFeaturedImageId), '_featured_image'); } $objects = Object::whereNotIn('objects.type', ['object_type', 'image', 'category'])->where(function ($query) use($search) { $query->where('objects.title', 'LIKE', '%' . $search . '%')->orWhere('objects.content', 'LIKE', '%' . $search . '%')->orWhere('keywords.content', 'LIKE', '%' . $search . '%'); })->join('objects as obj', function ($join) { $join->on('obj.name', '=', DB::raw("concat( '_object_type_', objects.type )")); })->leftJoin('keywords', function ($join) { $join->on('obj.id', '=', 'object_id')->orOn('objects.id', '=', 'object_id'); })->join('object_meta', function ($join) { $join->on('object_meta.object_id', '=', 'obj.id')->where('object_meta.meta_key', '=', '_category_id'); })->join('objects as cat', function ($join) { $join->on('cat.id', '=', 'object_meta.meta_value'); })->where('object_meta.meta_value', $categoryId)->select(DB::raw("'{$featuredImageUrl}' AS featured_image"), 'cat.id AS catID', 'cat.title AS catTitle', 'cat.name AS catName', 'obj.id AS objID', 'obj.name AS objName', 'objects.id', 'objects.excerpt', 'objects.parent_id', 'objects.name', 'objects.type', 'objects.title', 'objects.score')->orderBy('objects.score', 'DESC')->orderBy('objects.title', 'ASC')->groupBy('objects.id')->take($limit)->skip($offset); // dd($objects->toSql()); $objects = $objects->get(); foreach ($objects as $object) { $this->processObject($object); } foreach ($objects as &$object) { unset($object['address']); unset($object['address_city']); unset($object['address_country']); unset($object['address_street']); unset($object['catID']); // unset($object['catName']); unset($object['catTitle']); unset($object['email']); unset($object['objID']); unset($object['objName']); unset($object['occupation']); unset($object['parent_id']); unset($object['phone']); unset($object['promoted']); unset($object['type']); if ($featuredImageUrl == $object['featured_image']) { unset($object['featured_image']); } } // dd($objects->toArray()); return ['items' => $objects, 'offset' => count($objects) >= $limit ? $offset + $limit : 0]; } else { if ($search) { $objects = Object::whereNotIn('objects.type', ['object_type', 'image'])->where(function ($query) use($search) { $query->where('objects.title', 'LIKE', '%' . $search . '%')->orWhere('objects.content', 'LIKE', '%' . $search . '%')->orWhere('keywords.content', 'LIKE', '%' . $search . '%'); })->leftJoin('objects as obj', function ($join) { $join->on('obj.name', '=', DB::raw("concat( '_object_type_', objects.type )")); })->leftJoin('keywords', function ($join) { $join->on('obj.id', '=', 'object_id')->orOn('objects.id', '=', 'object_id'); })->select('objects.id', 'objects.parent_id', 'objects.name', 'objects.type', 'objects.title', 'objects.score')->orderBy(DB::raw("objects.type = 'category'"), 'DESC')->orderBy('objects.score', 'DESC')->orderBy('objects.title', 'ASC')->groupBy('objects.id')->take(50)->get(); $objects->each(function ($v) { if ($v->type != 'category') { $parentObject = Object::where('type', 'object_type')->where('name', '_object_type_' . $v->type)->first(); if ($parentObject) { $parentCategories = Object::where('type', 'category')->whereExists(function ($query) use($parentObject) { $query->select(DB::raw(1))->from('object_meta')->whereRaw(DB::getTablePrefix() . 'object_meta.meta_value = ' . DB::getTablePrefix() . 'objects.id')->where('meta_key', '_category_id')->where('object_id', $parentObject->id); })->first(); $v->category = array('id' => $parentCategories ? $parentCategories->id : '0', 'name' => $parentCategories ? $parentCategories->name : 'Home'); } } return $v; }); // dd($objects); return response($objects); } } // dd($objects); //dd($objects->toSql()); if ($objects) { $objects = $objects->skip($index)->take(50)->get(); foreach ($objects as $object) { $this->processObject($object); } } return $objects; }
/** * Fetches active roles * * @param Object $query Query object * * @return Object */ public function scopeActive($query) { return $query->where('isActive', '=', '1'); }
private function fetchCategories() { if (!$this->items) { $this->items = Object::where('objects.type', 'category')->leftJoin('objects as parent', 'parent.id', '=', 'objects.parent_id')->select(array('objects.id', 'objects.title', 'objects.name', 'objects.parent_id', 'objects.url', 'objects.target', 'parent.parent_id as grandParentID'))->orderBy(DB::raw('objects.id = 4'), 'DESC')->orderBy('objects.id', 'ASC')->get(); } return $this->items; }
protected function getObject() { return \App\Object::where('status', \App\Object::STATUS_NEW)->orderBy('created_at')->first(); }
public static function getType($name) { return Object::where('name', '=', "_object_type_{$name}"); }
public function getCategories($id) { if ($objectType = Object::find($id)) { $categories = ObjectMeta::where('object_id', $id)->where('meta_key', '_category_id')->select(array('id', 'meta_value'))->get(); //$cc $c = array(); foreach ($categories as $categoryId) { $c[] = $categoryId->meta_value; } $categories = Object::where('type', 'category')->whereIn('id', $c)->select('id', 'title')->get(); return Datatables::of($categories)->add_column('actions', '<a href="{{{ URL::to(\'admin/object-types/\' . $id . \'/delete\' ) }}}" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans("admin/modal.delete") }}</a>')->remove_column('id')->make(); } // $objecttypes = ObjectType::select(array('object_types.id','object_types.name','object_types.display_name', 'object_types.created_at')); // // return Datatables::of($objecttypes) // ->add_column('actions', '@if ($id>"4")<a href="{{{ URL::to(\'admin/object-types/\' . $id . \'/edit\' ) }}}" class="btn btn-success btn-sm" ><span class="glyphicon glyphicon-pencil"></span> {{ trans("admin/modal.edit") }}</a> // <a href="{{{ URL::to(\'admin/object-types/\' . $id . \'/delete\' ) }}}" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span> {{ trans("admin/modal.delete") }}</a> // @endif') // ->remove_column('id') // // ->make(); }