/**
  * 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();
 }
 public function destroy($id)
 {
     $APITag = new APITag();
     //api
     $result = $APITag->deleteData($id);
     //response
     if ($result['status'] != 'success') {
         $this->errors = $result['message'];
     }
     //return
     $this->page_attributes->success = "Data telah dihapus";
     return $this->generateRedirectRoute('goods.tag.index');
 }
示例#3
0
 /**
  * function to generate view and display products of balin
  * 
  * 1. Check filter
  * 2. Check page
  * 3. Get data from API
  * 4. Generate paginator
  * 5. Generate breadcrumb
  * 6. Generate view
  * @return view
  */
 public function index()
 {
     //1. Check filter
     $filters = null;
     $search = [];
     //1a. Filter of name
     if (Input::has('q')) {
         $search = ['name' => Input::get('q')];
         $filters = ['name' => Input::get('q')];
     }
     //1b. Filter of category
     if (Input::has('category')) {
         $search['categories'] = Input::get('category');
     }
     //1c. Filter of tag
     if (Input::has('tag')) {
         $search['tags'] = Input::get('tag');
     }
     //1d. Filter of label
     if (Input::has('label')) {
         $search['labelname'] = Input::get('label');
     }
     //1e. Filter for sorting
     if (Input::has('sort')) {
         $sort_item = explode('-', Input::get('sort'));
         $sort = [$sort_item[0] => $sort_item[1]];
     } else {
         $sort = ['name' => 'asc'];
     }
     //1f. Get filter remove
     $searchresult = [];
     $index = '';
     foreach (Input::all() as $key => $value) {
         if (in_array($key, ['tag', 'label', 'category', 'q'])) {
             $query_string = Input::all();
             unset($query_string['page']);
             unset($query_string[$key]);
             $searchresult[$value] = route('balin.product.index', $query_string);
             $index = $index . ' ' . $value;
         }
     }
     //2. Check page
     if (is_null(Input::get('page'))) {
         $page = 1;
     } else {
         $page = Input::get('page');
     }
     //3. Get data from API
     //3a. API Product
     $APIProduct = new APIProduct();
     $product = $APIProduct->getIndex(['search' => $search, 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]);
     //3b. API Category
     $API_category = new APICategory();
     $get_api_category = $API_category->getIndex(['search' => [], 'sort' => ['path' => 'asc']]);
     //3c. API Tag
     $API_tag = new APITag();
     $get_api_tag = $API_tag->getIndex(['search' => [], 'sort' => ['path' => 'asc']]);
     $color_chart = $this->getcolorchart();
     foreach ($get_api_tag['data']['data'] as $k => $v) {
         if (isset($v['tag']) && strtolower($v['tag']['slug']) == 'warna') {
             $get_api_tag['data']['data'][$k]['code'] = isset($color_chart[strtolower($v['name'])]) ? $color_chart[strtolower($v['name'])] : '#000';
         }
     }
     //3e. Manage data in collection
     $collection_category = new Collection();
     $collection_category->add($get_api_category['data']['data']);
     $collection_tag = new Collection();
     $collection_tag->add($get_api_tag['data']['data']);
     $category = $collection_category->sortBy('name')->all();
     $tag = $collection_tag->sortBy('name')->all();
     //4. Generate paginator
     $this->paginate(route('balin.product.index'), $product['data']['count'], $page);
     //5. Generate breadcrumb
     $breadcrumb = ['Produk' => route('balin.product.index')];
     if (Input::has('page') && Input::get('page') > 1) {
         $breadcrumb['Halaman ' . Input::get('page')] = route('balin.product.index', ['page' => Input::get('page')]);
     }
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     //6. Generate view
     $this->page_attributes->search = $searchresult;
     $this->page_attributes->subtitle = 'Produk Batik Modern ' . $index . ' ' . (Input::has('page') ? 'Halaman ' . Input::get('page') : '');
     $this->page_attributes->controller_name = $this->controller_name;
     $this->page_attributes->data = ['product' => $product, 'tag' => $tag, 'category' => $category];
     $this->page_attributes->source = $this->page_attributes->source . 'index';
     return $this->generateView();
 }