예제 #1
0
    public function index()
    {
        if (!Input::has('page')) {
            $pageNum = 1;
        } else {
            $pageNum = (int) Input::get('page');
        }
        $admin_id = Auth::admin()->get()->id;
        $arrCategories = [];
        $name = '';
        $take = $this->take;
        $skip = floor(($pageNum - 1) * $take);
        $images = VIImage::select('id', 'name', 'short_name', 'description', 'keywords', 'artist', 'model', 'gender', 'age_from', 'age_to', 'number_people', DB::raw('(SELECT COUNT(*)
																							FROM notifications
																				         	WHERE notifications.item_id = images.id
																				         		AND notifications.item_type = "Image"
																								AND notifications.admin_id = ' . $admin_id . '
																								AND notifications.read = 0 ) as new'))->withType('main')->with('categories')->with('collections');
        if (Input::has('categories')) {
            $arrCategories = (array) Input::get('categories');
            $images->whereHas('categories', function ($query) use($arrCategories) {
                $query->whereIn('id', $arrCategories);
            });
        }
        if (Input::has('name')) {
            $name = Input::get('name');
            $nameStr = '*' . $name . '*';
            $images->search($nameStr);
        }
        $images = $images->take($take)->skip($skip)->orderBy('id', 'desc')->get();
        $arrImages = [];
        if (!$images->isempty()) {
            $arrImages = $arrRemoveNew = [];
            foreach ($images as $image) {
                $image->path = URL . '/pic/large-thumb/' . $image->short_name . '-' . $image->id . '.jpg';
                $image->dimension = $image->width . 'x' . $image['height'];
                if ($image->new) {
                    $arrRemoveNew[] = $image->id;
                }
                $arrImages[$image->id] = $image;
                foreach (['arrCategories' => ['name' => 'categories', 'id' => 'id'], 'arrCollections' => ['name' => 'collections', 'id' => 'id']] as $key => $value) {
                    $arr = [];
                    foreach ($image->{$value}['name'] as $v) {
                        $arr[] = $v[$value['id']];
                    }
                    $arrImages[$image->id][$key] = $arr;
                }
                unset($arr);
            }
            if (!empty($arrRemoveNew)) {
                Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'Image')->where('admin_id', $admin_id)->update(['read' => 1]);
            }
        }
        if (Request::ajax()) {
            return $arrImages;
        }
        $this->layout->title = 'Images';
        $this->layout->content = View::make('admin.images-all')->with(['images' => $arrImages, 'pageNum' => $pageNum, 'categories' => Category::getSource(), 'name' => $name, 'arrCategories' => $arrCategories, 'collections' => Collection::getSource(), 'apiKey' => Configure::getApiKeys()]);
    }
 public function onNewGroupDocument($doc, $group)
 {
     $members = $group->members()->get();
     $member_ids = $members->lists('user_id');
     $notices = Notification::whereIn('user_id', $member_ids)->where('event', '=', MadisonEvent::NEW_GROUP_DOCUMENT)->get();
     //If we have subscriptions
     if (isset($notices)) {
         $notifications = $this->processNotices($notices, MadisonEvent::NEW_GROUP_DOCUMENT);
         $this->doNotificationActions($notifications, array('data' => array('user_id' => Auth::user()->id, 'doc' => $doc->toArray(), 'group' => $group->toArray()), 'subject' => 'One of your groups has posted a new document!', 'from_email_address' => static::FROM_EMAIL_ADDRESS, 'from_email_name' => static::FROM_EMAIL_NAME));
     }
 }
예제 #3
0
    public function listOrder()
    {
        if (!Request::ajax()) {
            return App::abort(404);
        }
        $admin_id = Auth::admin()->get()->id;
        $start = Input::has('start') ? (int) Input::get('start') : 0;
        $length = Input::has('length') ? Input::get('length') : 10;
        $search = Input::has('search') ? Input::get('search') : [];
        $orders = Order::with('billingAddress')->with('shippingAddress')->with('user')->select(DB::raw('id, user_id, billing_address_id, shipping_address_id, status, sum_sub_total, discount, tax, sum_tax, note,
											(SELECT COUNT(*)
												FROM notifications
									         	WHERE notifications.item_id = orders.id
									         		AND notifications.item_type = "Order"
													AND notifications.admin_id = ' . $admin_id . '
													AND notifications.read = 0 ) as new'));
        if (!empty($search)) {
            foreach ($search as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                if ($key == 'status') {
                    $orders->where($key, $value);
                } else {
                    if ($key == 'full_name') {
                        $orders->whereHas('user', function ($query) use($value) {
                            $query->where(function ($q) use($value) {
                                $value = trim($value);
                                $arr_value = explode(' ', $value);
                                foreach ($arr_value as $key2 => $value2) {
                                    $q->orWhere('first_name', 'like', '%' . $value2 . '%');
                                    $q->orWhere('last_name', 'like', '%' . $value2 . '%');
                                }
                            });
                        });
                    } else {
                        if ($key == 'billing_address_id') {
                            $orders->whereHas('billing_address', function ($query) use($value) {
                                $query->where(function ($q) use($value) {
                                    $value = trim($value);
                                    $arr_value = explode(' ', $value);
                                    foreach ($arr_value as $key2 => $value2) {
                                        $q->orWhere('address1', 'like', '%' . $value2 . '%');
                                        $q->orWhere('address2', 'like', '%' . $value2 . '%');
                                    }
                                });
                            });
                        } else {
                            if ($key == 'shipping_address_id') {
                                $orders->whereHas('shipping_address', function ($query) use($value) {
                                    $query->where(function ($q) use($value) {
                                        $value = trim($value);
                                        $arr_value = explode(' ', $value);
                                        foreach ($arr_value as $key2 => $value2) {
                                            $q->orWhere('address1', 'like', '%' . $value2 . '%');
                                            $q->orWhere('address2', 'like', '%' . $value2 . '%');
                                        }
                                    });
                                });
                            } else {
                                $value = ltrim(rtrim($value));
                                $orders->where($key, 'like', '%' . $value . '%');
                            }
                        }
                    }
                }
            }
        }
        $order = Input::has('order') ? Input::get('order') : [];
        if (!empty($order)) {
            $columns = Input::has('columns') ? Input::get('columns') : [];
            foreach ($order as $value) {
                $column = $value['column'];
                if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                    continue;
                }
                $orders->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
            }
        }
        $count = $orders->count();
        if ($length > 0) {
            $orders = $orders->skip($start)->take($length);
        }
        $arrOrders = $orders->get()->toArray();
        $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Order::count(), 'recordsFiltered' => $count, 'data' => []];
        $arrRemoveNew = [];
        if (!empty($arrOrders)) {
            foreach ($arrOrders as $key => $order) {
                $order['full_name'] = $order['user']['first_name'] . ' ' . $order['user']['last_name'];
                if ($order['new']) {
                    $order['full_name'] .= '| <span class="badge badge-danger">new</span>';
                    $arrRemoveNew[] = $order['id'];
                }
                $order['billing_address'] = $order['billing_address']['address1'] . ' ' . $order['billing_address']['address2'];
                $order['shipping_address'] = $order['shipping_address']['address1'] . ' ' . $order['shipping_address']['address2'];
                $arrReturn['data'][] = array(++$start, $order['id'], $order['full_name'], $order['billing_address'], $order['shipping_address'], $order['status'], $order['sum_sub_total'], $order['discount'], $order['sum_tax'], $order['note'], htmlentities(nl2br($order['billing_address'])), htmlentities(nl2br($order['shipping_address'])));
            }
        }
        if (!empty($arrRemoveNew)) {
            Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'Order')->where('admin_id', $admin_id)->update(['read' => 1]);
        }
        $response = Response::json($arrReturn);
        $response->header('Content-Type', 'application/json');
        return $response;
    }
예제 #4
0
    public function listProduct()
    {
        if (!Request::ajax()) {
            return App::abort(404);
        }
        $admin_id = Auth::admin()->get()->id;
        $start = Input::has('start') ? (int) Input::get('start') : 0;
        $length = Input::has('length') ? Input::get('length') : 10;
        $search = Input::has('search') ? Input::get('search') : [];
        $products = Product::with('mainImage')->select(DB::raw('id, name, sku, sell_price, short_description, active,
												(SELECT COUNT(*)
													FROM notifications
										         	WHERE notifications.item_id = products.id
										         		AND notifications.item_type = "Product"
														AND notifications.admin_id = ' . $admin_id . '
														AND notifications.read = 0 ) as new'));
        if (!empty($search)) {
            foreach ($search as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                if ($key == 'active') {
                    if ($value == 'yes') {
                        $value = 1;
                    } else {
                        $value = 0;
                    }
                    $products->where($key, $value);
                } else {
                    if ($key == 'sell_price') {
                        $value = trim($value);
                        if (strpos($value, '-') !== false) {
                            list($from, $to) = explode('-', $value);
                            $products->where($key, '>', (double) $from);
                            $products->where($key, '<', (double) $to);
                        } else {
                            $products->where($key, (double) $value);
                        }
                    } else {
                        if ($key == 'category' && !empty($value)) {
                            if (is_numeric($value)) {
                                $products->whereHas('categories', function ($query) use($value) {
                                    $query->where('categories.id', $value);
                                });
                            } else {
                                if (is_array($value)) {
                                    foreach ($value as $k => $v) {
                                        if (empty($v)) {
                                            unset($value[$k]);
                                        }
                                    }
                                    if (empty($value)) {
                                        continue;
                                    }
                                    $products->whereHas('categories', function ($query) use($value) {
                                        $query->whereIn('categories.id', $value);
                                    });
                                } else {
                                    $products->whereHas('categories', function ($query) use($value) {
                                        $query->where('categories.name', 'like', '%' . $value . '%');
                                    });
                                }
                            }
                        } else {
                            $value = ltrim(rtrim($value));
                            $products->where($key, 'like', '%' . $value . '%');
                        }
                    }
                }
            }
        }
        $order = Input::has('order') ? Input::get('order') : [];
        if (!empty($order)) {
            $columns = Input::has('columns') ? Input::get('columns') : [];
            foreach ($order as $value) {
                $column = $value['column'];
                if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                    continue;
                }
                $products->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
            }
        }
        $count = $products->count();
        if ($length > 0) {
            $products = $products->skip($start)->take($length);
        }
        $arrProducts = $products->get();
        $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => Product::count(), 'recordsFiltered' => $count, 'data' => []];
        $arrRemoveNew = [];
        if (!empty($arrProducts)) {
            foreach ($arrProducts as $product) {
                if (isset($product->main_image[0])) {
                    $image = URL . '/' . str_replace('/images/products', '/images/products/thumbs', $product->main_image[0]->path);
                } else {
                    $image = URL . '/assets/images/noimage/110x110.gif';
                }
                $name = $product->name;
                if ($product->new) {
                    $name .= '| <span class="badge badge-danger">new</span>';
                    $arrRemoveNew[] = $product->id;
                }
                if (empty($product->short_description)) {
                    $product->short_description = '(empty)';
                }
                $data = Product::getSmallestPrice($product, true);
                $arrReturn['data'][] = array(++$start, $product->id, $name, $product->sku, "({$data['sizew']}x{$data['sizeh']})|{$data['sell_price']}", $image, $product->short_description, $product->active);
            }
        }
        if (!empty($arrRemoveNew)) {
            Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'Product')->where('admin_id', $admin_id)->update(['read' => 1]);
        }
        $response = Response::json($arrReturn);
        $response->header('Content-Type', 'application/json');
        return $response;
    }
예제 #5
0
    public function listUser()
    {
        if (!Request::ajax()) {
            return App::abort(404);
        }
        $admin_id = Auth::admin()->get()->id;
        $start = Input::has('start') ? (int) Input::get('start') : 0;
        $length = Input::has('length') ? Input::get('length') : 10;
        $search = Input::has('search') ? Input::get('search') : [];
        $users = User::select(DB::raw('id, first_name, last_name, email, image, active, image,
											(SELECT COUNT(*)
												FROM notifications
									         	WHERE notifications.item_id = users.id
									         		AND notifications.item_type = "User"
													AND notifications.admin_id = ' . $admin_id . '
													AND notifications.read = 0 ) as new'));
        if (!empty($search)) {
            foreach ($search as $key => $value) {
                if (empty($value)) {
                    continue;
                }
                if ($key == 'active') {
                    if ($value == 'yes') {
                        $value = 1;
                    } else {
                        $value = 0;
                    }
                    $users->where($key, $value);
                } else {
                    $value = ltrim(rtrim($value));
                    $users->where($key, 'like', '%' . $value . '%');
                }
            }
        }
        $order = Input::has('order') ? Input::get('order') : [];
        if (!empty($order)) {
            $columns = Input::has('columns') ? Input::get('columns') : [];
            foreach ($order as $value) {
                $column = $value['column'];
                if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) {
                    continue;
                }
                $users->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc');
            }
        }
        $count = $users->count();
        if ($length > 0) {
            $users = $users->skip($start)->take($length);
        }
        $arrUsers = $users->get()->toArray();
        $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => User::count(), 'recordsFiltered' => $count, 'data' => []];
        $arrRemoveNew = [];
        if (!empty($arrUsers)) {
            foreach ($arrUsers as $user) {
                $firstName = $user['first_name'];
                if ($user['new']) {
                    $firstName .= '| <span class="badge badge-danger">new</span>';
                    $arrRemoveNew[] = $user['id'];
                }
                $arrReturn['data'][] = array(++$start, $user['id'], $firstName, $user['last_name'], $user['email'], $user['image'], $user['active']);
            }
        }
        if (!empty($arrRemoveNew)) {
            Notification::whereIn('item_id', $arrRemoveNew)->where('item_type', 'User')->where('admin_id', $admin_id)->update(['read' => 1]);
        }
        $response = Response::json($arrReturn);
        $response->header('Content-Type', 'application/json');
        return $response;
    }