function listAll($offset = 0, $limit = 20) { $products = new Product(); $products->order_by('id', 'desc'); $searchKey = ""; if ($_SERVER['REQUEST_METHOD'] == "GET") { } else { $searchKey = $this->input->post("search_name"); $products->distinct(); $products->group_start(); $products->like('name_vietnamese', $searchKey); $products->or_like('seo_keyword', $searchKey); $products->group_end(); } $products->get_paged($offset, $limit, TRUE); setPagination($this->admin . 'products/listAll/', $products->paged->total_rows, $limit, 4); $dis['base_url'] = base_url(); $dis['view'] = 'products/list'; $dis['products'] = $products; $dis['menu_active'] = "Sản phẩm"; $dis['title_table'] = "Trang hiện tại:" . $products->paged->current_page . '/' . $products->paged->total_pages; $dis['title'] = "Tất cả sản phẩm"; $dis['searchKey'] = $searchKey; $dis['nav_menu'] = array(array("type" => "add", "text" => "Thêm", "link" => "{$this->admin_url}products/edit", "onclick" => "")); $this->viewadmin($dis); }
function index_get() { $filters = $this->get("filter")["filters"]; $page = $this->get('page') !== false ? $this->get('page') : 1; $limit = $this->get('limit') !== false ? $this->get('limit') : 50; $sort = $this->get("sort"); $data["results"] = array(); $data["count"] = 0; $obj = new Product(null, $this->entity); //Sort if (!empty($sort) && isset($sort)) { foreach ($sort as $value) { $obj->order_by($value["field"], $value["dir"]); } } //Filter if (!empty($filters) && isset($filters)) { $deleted = 0; foreach ($filters as $value) { if (!empty($value["operator"]) && isset($value["operator"])) { if ($value["operator"] == "where_in") { $obj->where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_in") { $obj->or_where_in($value["field"], $value["value"]); } else { if ($value["operator"] == "where_not_in") { $obj->where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "or_where_not_in") { $obj->or_where_not_in($value["field"], $value["value"]); } else { if ($value["operator"] == "like") { $obj->like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_like") { $obj->or_like($value["field"], $value["value"]); } else { if ($value["operator"] == "not_like") { $obj->not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "or_not_like") { $obj->or_not_like($value["field"], $value["value"]); } else { if ($value["operator"] == "startswith") { $obj->like($value["field"], $value["value"], "after"); } else { if ($value["operator"] == "endswith") { $obj->like($value["field"], $value["value"], "before"); } else { if ($value["operator"] == "contains") { $obj->like($value["field"], $value["value"], "both"); } else { if ($value["operator"] == "or_where") { $obj->or_where($value["field"], $value["value"]); } else { if ($value["operator"] == "by_vendor") { $obj->where_related("stock", $value["field"], $value["value"]); } else { if ($value["operator"] == "search") { $obj->like("sku", $value["value"], "after"); $obj->or_like("name", $value["value"], "both"); $obj->or_like("description", $value["value"], "both"); } else { $obj->where($value["field"] . ' ' . $value["operator"], $value["value"]); } } } } } } } } } } } } } } } else { if ($value["field"] == "deleted") { $deleted = $value["value"]; } else { $obj->where($value["field"], $value["value"]); } } } $obj->where("deleted", $deleted); } //Result $obj->get_paged_iterated($page, $limit); $data["count"] = $obj->paged->total_rows; if ($obj->result_count() > 0) { foreach ($obj as $value) { $priceList = array(); foreach ($value->price_list->get() as $p) { $priceList[] = array("id" => $p->id, "currency_id" => $p->currency_id, "product_id" => $p->product_id, "unit_id" => $p->unit_id, "price" => floatval($p->price), "unit_value" => floatval($p->unit_value), "locale" => $p->currency->get()->locale, "unit" => $p->unit->get()->name); } $cost = array(); // foreach ($value->stock->order_by("issued_date", "desc")->get() as $c) { // $cost = array( // "id" => $c->id, // "quantity" => floatval($c->quantity), // "price" => floatval($c->price), // "locale" => $c->currency->get()->locale, // "unit" => $c->unit->get()->name // ); // } $data["results"][] = array("id" => $value->id, "category_id" => $value->category_id, "unit_id" => $value->unit_id, "sku" => $value->sku, "name" => $value->name, "description" => $value->description, "on_hand" => floatval($value->on_hand), "order_point" => floatval($value->order_point), "favorite" => $value->favorite == 0 ? false : true, "image_url" => $value->image_url, "status" => $value->status == 0 ? false : true, "deleted" => $value->deleted, "unit" => $value->unit->get()->name, "cost" => $cost, "price_lists" => $priceList); } } //Response Data $this->response($data, 200); }