public function index_get() { $status = 404; $return["result"] = "NOOK"; $category = $this->get("categoryId"); if ($category) { $subcategories = CI_Subcategory::getByCategory($category); } else { $subcategories = CI_Subcategory::getSubcategories(); } if ($subcategories) { $status = 200; $return["result"] = "OK"; $return["data"] = ""; foreach ($subcategories as $key => $subcategory) { $mySubcategory = CI_Subcategory::getData($subcategory); $return["data"][$key] = $mySubcategory; } } $this->response($return, $status); }
public static function getByCategory($categoryId) { $CI =& get_instance(); $CI->load->model('subcategory_model'); $results = $CI->subcategory_model->getByCategory($categoryId); $return = array(); if (!empty($results)) { foreach ($results as $result) { $return[] = CI_Subcategory::getInstance($result); } } return $return; }
protected static function getInstance($row) { if (!$row instanceof stdClass) { show_error("El row debe ser una instancia de stdClass."); } $publication = new stdClass(); $publication->id = isset($row->publication_id) ? $row->publication_id : 0; $publication->title = isset($row->title) ? $row->title : ''; $publication->description = isset($row->description) ? $row->description : ''; $publication->category = isset($row->category_id) ? CI_Category::getById($row->category_id) : ''; $publication->subcategory = isset($row->subcategory_id) ? CI_Subcategory::getById($row->category_id, $row->subcategory_id) : ''; $publication->object = isset($row->object_id) ? CI_Object::getById($row->object_id) : ''; $publication->quantity = isset($row->quantity) ? $row->quantity : ''; $publication->views = isset($row->views) ? $row->views : ''; $publication->processState = isset($row->process_state_id) ? CI_ProcessState::getById($row->process_state_id) : ''; $publication->creationDate = isset($row->creation_date) ? $row->creation_date : ''; $publication->expirationDate = isset($row->expiration_date) ? $row->expiration_date : ''; $publication->image = isset($row->publication_id) ? CI_Image::getByPublicationId($row->publication_id) : ''; if (isset($row->isFavorite)) { $publication->isFavorite = isset($row->isFavorite) ? $row->isFavorite : ''; } if (isset($row->isOwner)) { $publication->isOwner = isset($row->isOwner) ? $row->isOwner : ''; } if (isset($row->user_id)) { $publication->userId = isset($row->user_id) ? $row->user_id : ''; } return $publication; }