private function _get_user_coupons($ids)
 {
     global $ids_check;
     $ids_check = $ids;
     $coupons = Coupon::leftJoin("clients", "coupons.client_id", "=", "clients.id")->where("clients.user_id", "=", Auth::user()->id)->get("coupons.id");
     $user_coupons = array_map(function ($object) {
         global $ids_check;
         return in_array($object->id, $ids_check) ? $object->id : false;
     }, $coupons);
     return $user_coupons;
 }
示例#2
0
 /**
  * coupon function.
  * 
  * @access public
  * @param int $limit (default: 10)
  * @description Devuelve los datos de un cupon
  * @return void
  */
 public function getCoupon($id = 0)
 {
     $coupon = Coupon::leftJoin('categories', 'coupons.category_id', '=', 'categories.id')->leftJoin('coupons_premium', 'coupons_premium.coupon_id', '=', 'coupons.id')->where('coupons.id', '=', $id)->get(array('coupons.id', 'coupons.title', 'categories.name as category', 'coupons.description', 'coupons.restriction', 'coupons.latitude', 'coupons.longitude', DB::raw('IF(coupons_premium.coupon_id, 1, 0) AS premium')))->toArray();
     if (count($coupon) == 0) {
         return Response::json(array());
     }
     $coupon = $coupon[0];
     $coupon['ratings'] = (double) Rating::where("coupon_id", "=", $coupon['id'])->avg('value');
     $coupon['redems'] = (double) Scan::where("coupon_id", "=", $coupon['id'])->count();
     $coupon['comments'] = (double) Comment::where("coupon_id", "=", $coupon['id'])->where("disabled", "=", 0)->count();
     return Response::json($coupon);
 }