private function save_category() { $maxPosition = 0; $this->load->helper('date'); $this->load->model('Category_Entity'); date_default_timezone_set($this->geoCity); $category = new Category_Entity(); $id = $this->input->post('id'); $parentId = $this->input->post('parent_category'); $where = "parent_category =" . $parentId; $maxPosition = $category->max('position', $where); if (!empty($id)) { $category->load($id); } else { $category->created_date = date('Y-m-d h:i:sa', now()); $category->position = intval($maxPosition) + 1; } $category->name = $this->input->post('name'); $category->parent_category = intval($this->input->post('parent_category')); $category->description = $this->input->post('description'); $category->displayed = $this->input->post('displayed') === 'true' ? true : false; $category->modified_date = date('Y-m-d h:i:sa', now()); $category->save(); return $category; }
private function load_all($where, $limit, $offset, $orderBy) { $productArr = array(); $this->load->model(array('Product_Entity')); $this->load->model(array('Category_Entity')); $products = $this->Product_Entity->get($limit, $offset, $where, $orderBy); foreach ($products as $product) { $categoryName = 'Home'; $catId = $product->category_id; if ($product->category_id != 0) { $cat = new Category_Entity(); $cat->load($catId); $categoryName = $cat->name; } $productArr[] = array("name" => $product->name, "displayed" => $product->displayed, "id" => $product->id, "position" => $product->position, "category" => $categoryName, "price" => $product->price, "quantity" => $product->quantity); } $data = new stdClass(); $data->data = $productArr; return $data; }