Back to PhocacartReview class

Method addReview

public static
addReview
(mixed &$error, mixed $approveReview, mixed $productId, mixed $userId, mixed $userName, mixed $rating, mixed $review)

Method addReview - Source code

public static function addReview(&$error, $approveReview, $productId, $userId, $userName, $rating, $review)
{
    if ((int) $productId > 0 && (int) $userId > 0 && $userName != '' && (int) $rating > 0 && $review != '') {
        $db = Factory::getDBO();
        $published = 0;
        if ($approveReview == 0) {
            $published = 1;
        }
        // Check if user added some review to the product
        $query = 'SELECT a.id FROM #__phocacart_reviews AS a' . ' WHERE a.product_id = ' . (int) $productId . ' AND a.user_id = ' . (int) $userId . ' ORDER BY a.id';
        $db->setQuery($query);
        $reviewed = $db->loadColumn();
        if (!empty($reviewed)) {
            $error = 1;
            return false;
        }
        $date = Factory::getDate()->toSql();
        $query = ' INSERT INTO #__phocacart_reviews (product_id, user_id, name, rating, review, published, date)' . ' VALUES (' . (int) $productId . ', ' . (int) $userId . ', ' . $db->quote(strip_tags($userName)) . ', ' . (int) $rating . ', ' . $db->quote(strip_tags($review)) . ', ' . (int) $published . ', ' . $db->quote($date) . ')';
        $db->setQuery($query);
        $db->execute();
        return true;
    } else {
        $error = 2;
        return false;
    }
}