/** * Convert a Comment array into a Comment object. * * @param array $aComment Comment. * * @return Comment converted object. */ private static function convertToObject($aComment) { $oComment = new Comment(); $oComment->setComment($aComment['comment']); $oComment->setMark(intval($aComment['mark'])); $oComment->setDate($aComment['date']); $oComment->setName($aComment['name']); $oUser = new User(); $oUser->setEmail($aComment['user_email']); $oComment->setUser(UserManager::get($oUser)); $oComment->setProduct(ProductManager::get($aComment['product_id'])); return $oComment; }
private function commentAction() { $name = $_POST['name']; $comment = $_POST['comment']; $iMark = $_POST['stars']; $productId = $_POST['product-id']; $oProduct = ProductManager::get($productId); $oUser = UserManager::getCurrent(); $oComment = new Comment(); $oComment->setDate(date('Y-m-d H:i:s')); $oComment->setMark($iMark); $oComment->setName($name); $oComment->setComment($comment); $oComment->setProduct($oProduct); $oComment->setUser($oUser); try { $result = CommentManager::create($oComment); } catch (\Exception $e) { $result = $e->getMessage(); } echo $result; }