db = $db; // database handler $this->id = $id; // get product data from db $query = sprintf(" SELECT product.id, product.name, product.code, product.category_id, product_category.name AS category FROM product LEFT JOIN product_category ON product_category.id = product.category_id WHERE product.id = %d", $this->id); $result = $this->db->get_row($query); $this->name = $result->name; $this->code = $result->code; $this->category = $result->category; } else { $this->id = $id->id; $this->name = $id->name; $this->code = $id->code; $this->category = $id->category; } } /** * these functions return characteristics of the object * @access PUBLIC * @return STRING */ function getId() { return $this->id; } function getName() { return $this->name; } function getCode() { return $this->code; } function getCategory() { return $this->category; } /** * return list of products * @access STATIC * @return ARRAY */ function getListByCategory($categoryId) { global $db; // get all products into array $query = sprintf(" SELECT product.id, product.name, product.code, product.category_id, product_category.name AS category FROM product LEFT JOIN product_category ON product_category.id = product.category_id WHERE category_id = %d ORDER BY id ASC", $categoryId); $result = $db->get_results($query); // init $productList = array(); foreach ($result as $key => $obj) { $productList[] = new Product($obj); } return $productList; } } ?>