public function findById($id) { $data = $this->db->getEntityById(self::CATEGORIES_TABLENAME, $id); if ($data == null) { return null; } $category = new Category($data); return $category; }
/** * @param $id * @return User */ public function findById($id) { $data = $this->db->getEntityById(self::USERS_TABLENAME, $id); if ($data == null) { return null; } $user = new UserViewModel($data); return $user; }
public function removeProductFromPromotion($id) { $condition = "id={$id}"; $promotion = $this->db->getAllEntitiesWithCondition(self::PRODUCTS_PROMO_TABLENAME, $condition, 'id'); $discount = $promotion[0]['discount']; var_dump($promotion); $product = $this->db->getEntityById(self::PRODUCTS_TABLENAME, $promotion[0]['product_id']); $restoredPrice = $product['price'] + $product['price'] * ($discount / 100); $isUpdated = $this->db->updateEntityById(self::PRODUCTS_TABLENAME, array("price" => $restoredPrice), $product['id']); if (!$isUpdated) { throw new InvalidUserOperationException("Error during remove promo"); } if ($isUpdated) { $isDeleted = $this->db->deleteEntityById(self::PRODUCTS_PROMO_TABLENAME, $id); } return $isDeleted; }