public function index() { //initialize $filters = null; if (Input::has('q')) { $filters = ['name' => Input::get('q')]; $this->page_attributes->search = Input::get('q'); } //sort if (Input::has('sort')) { $sort_item = explode('-', Input::get('sort')); $sort = [$sort_item[0] => $sort_item[1]]; } else { $sort = ['name' => 'asc']; } //get curent page if (is_null(Input::get('page'))) { $page = 1; } else { $page = Input::get('page'); } // data here $APILabel = new APILabel(); $labels = $APILabel->getIndex(['search' => ['name' => Input::get('q')], 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]); $this->page_attributes->data = ['data' => []]; foreach ($labels['data']['data'] as $key => $value) { $this->page_attributes->data['data'] = array_merge($this->page_attributes->data['data'], [$key => ['id' => $value['label'], 'name' => ucwords(str_replace('_', ' ', $value['label']))]]); } //sorting $SortList = new SortList(); $this->page_attributes->sorts = ['titles' => ['label'], 'label' => $SortList->getSortingList('label')]; //breadcrumb $breadcrumb = []; //paginate $this->paginate(route('goods.label.index'), $labels['data']['count'], $page); //generate View $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb); $this->page_attributes->source = $this->page_attributes->source . 'index'; return $this->generateView(); }
/** * Display all discount * * 1. Check filter * 2. Check page * 3. Get data from API * 4. Generate paginator * 5. Generate breadcrumb * 6. Generate view * @param page, q * @return Object View */ public function index() { //1. Check filter $search = ['discount' => true]; if (Input::has('q')) { $search['name'] = Input::get('q'); $this->page_attributes->search = Input::get('q'); } else { $searchResult = null; } if (Input::has('category')) { $search['categories'] = str_replace(" ", "-", Input::get('category')); } if (Input::has('tag')) { $search['tags'] = str_replace(" ", "-", Input::get('tag')); } if (Input::has('label')) { $search['labelname'] = str_replace(" ", "_", Input::get('label')); } if (Input::has('sort')) { $sort_item = explode('-', Input::get('sort')); $sort = [$sort_item[0] => $sort_item[1]]; } else { $sort = ['name' => 'asc']; } //2. Check page if (is_null(Input::get('page'))) { $page = 1; } else { $page = Input::get('page'); } //3. Get data from API $APIProduct = new APIProduct(); $product = $APIProduct->getIndex(['search' => $search, 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]); $this->page_attributes->data = ['product' => $product]; //4. Generate paginator $this->paginate(route('promote.discount.index'), $product['data']['count'], $page); //5. Generate breadcrumb $breadcrumb = []; $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb); //6. Generate View $filterTitles = ['tag', 'kategori', 'label']; $filterTags = []; $filterCategories = []; $filterLabels = []; $APITag = new APITag(); $tmpTag = $APITag->getIndex()['data']['data']; $key = 0; foreach ($tmpTag as $value) { if ($value['category_id'] != 0) { $filterTags[$key] = ucwords(str_replace("-", " ", $value['slug'])); $key++; } } $APICategory = new APICategory(); $tmpCategory = $APICategory->getIndex()['data']['data']; $key = 0; foreach ($tmpCategory as $value) { if ($value['category_id'] != 0) { $filterCategories[$key] = ucwords(str_replace("-", " ", $value['name'])); $key++; } } $APILabel = new APILabel(); $tmpLabel = $APILabel->getIndex()['data']['data']; $key = 0; foreach ($tmpLabel as $value) { $filterLabels[$key] = ucwords(str_replace("_", " ", $value['label'])); $key++; } $SortList = new SortList(); $this->page_attributes->sorts = ['titles' => ['nama', 'harga', 'promo', 'discount'], 'nama' => $SortList->getSortingList('nama'), 'harga' => $SortList->getSortingList('harga'), 'promo' => $SortList->getSortingList('promo'), 'discount' => $SortList->getSortingList('discount')]; $this->page_attributes->filters = ['titles' => $filterTitles, 'tag' => $filterTags, 'kategori' => $filterCategories, 'label' => $filterLabels]; $this->page_attributes->source = $this->page_attributes->source . 'index'; return $this->generateView(); }