Ejemplo n.º 1
0
 public function getSearch()
 {
     $categoryId = Input::get('categoryid');
     $search = Input::get('query');
     $objects = null;
     if ($categoryId) {
         // Category Image
         if ($featuredImageId = ObjectMeta::getValue($categoryId, '_featured_image')) {
             $featuredImageUrl = getImageSrc($featuredImageId, 'thumbnail');
         }
         // Get objects where in category
         $objects = Object::Where('type', 'object_type')->whereExists(function ($query) use($categoryId) {
             $query->select(DB::raw(1))->from('object_meta')->whereRaw(DB::getTablePrefix() . 'object_meta.object_id = ' . DB::getTablePrefix() . 'objects.id')->where('meta_key', '_category_id')->where('meta_value', $categoryId);
         })->select(DB::raw('substr(name, 14) as field_name'))->get()->toArray();
         $types = array_map(function ($v) {
             return $v['field_name'];
         }, $objects);
         if (!empty($types)) {
             $objects = Object::whereIn('type', $types);
         }
     }
     if ($objects) {
         $objects = $objects->select(array('objects.id', DB::raw('"/uploads/' . $featuredImageUrl . '"' . ' as featured_image'), 'objects.name', 'objects.title', 'objects.excerpt'))->get();
     }
     return $objects;
 }
Ejemplo n.º 2
0
 public function getSearch()
 {
     $categoryId = Input::get('categoryid');
     $index = Input::get('index') ?: 0;
     $search = Input::get('query');
     $objects = null;
     if ($categoryId) {
         // Category Image
         if ($categoryFeaturedImageId = ObjectMeta::getValue($categoryId, '_featured_image')) {
             $featuredImageUrl = getImageSrc($categoryFeaturedImageId, 'thumbnail');
         }
         // Get objects where in category
         $objects = Object::Where('type', 'object_type')->whereExists(function ($query) use($categoryId) {
             $query->select(DB::raw(1))->from('object_meta')->whereRaw(DB::getTablePrefix() . 'object_meta.object_id = ' . DB::getTablePrefix() . 'objects.id')->where('meta_key', '_category_id')->where('meta_value', $categoryId);
         })->select(DB::raw('substr(name, 14) as field_name'))->get()->toArray();
         $types = array_map(function ($v) {
             return $v['field_name'];
         }, $objects);
         $objects = DB::table('objects')->whereIn('type', $types)->select(array('objects.id', DB::raw('"/uploads/' . $featuredImageUrl . '"' . ' as featured_image'), 'objects.name', 'objects.title', 'objects.excerpt'));
         $objects = DB::table('objects')->whereIn('type', $types)->select(array('objects.id', DB::raw('"/uploads/' . $featuredImageUrl . '"' . ' as featured_image'), 'objects.name', 'objects.title', 'objects.excerpt'))->whereExists(function ($query) {
             $query->select(DB::raw(1))->from('object_meta')->whereRaw(DB::getTablePrefix() . 'object_meta.object_id = ' . DB::getTablePrefix() . 'objects.id')->where('meta_key', '_field_promoted')->where('meta_value', '1');
         })->union($objects);
     } else {
         if ($search) {
             $objects = Object::whereNotIn('type', ['object_type', 'image'])->where(function ($query) use($search) {
                 $query->where('title', 'LIKE', '%' . $search . '%')->orWhere('name', 'LIKE', '%' . $search . '%');
             })->select('id', 'type', 'title')->get();
             return response($objects);
         }
     }
     if ($objects) {
         $objects = $objects->skip($index)->take(50)->get();
         foreach ($objects as $object) {
             $this->processObject($object);
         }
     }
     return $objects;
 }