/** * Builds an enlist for information (not chooseable) * * @author Max Milbers * * @param array $idList ids * @param string $table vmTable to use * @param string $name fieldname for the name * @param string $view view for the links * @param bool $tableXref the xref table * @param bool $tableSecondaryKey the fieldname of the xref table * @param int $quantity * @param bool $translate * @return string */ static public function renderGuiList ($idList, $table, $name, $view, $tableXref = false, $tableSecondaryKey = false, $quantity = 3, $translate = true ) { $list = ''; $ttip = ''; $link = ''; if ($view != 'user' and $view != 'shoppergroup') { $cid = 'cid'; } else if ($view == 'user'){ $cid = 'virtuemart_user_id'; } else { $cid = 'virtuemart_shoppergroup_id'; } $model = new VmModel(); $table = $model->getTable($table); if(!is_array($idList)){ $db = JFactory::getDBO (); $q = 'SELECT `' . $table->getPKey() . '` FROM `#__virtuemart_' . $db->escape ($tableXref) . '` WHERE ' . $db->escape ($tableSecondaryKey) . ' = "' . (int)$idList . '"'; $db->setQuery ($q); $idList = $db->loadColumn (); } $i = 0; foreach($idList as $id ){ $item = $table->load ((int)$id); if($translate) $item->$name = vmText::_($item->$name); $link = ', '.JHtml::_('link', JRoute::_('index.php?option=com_virtuemart&view='.$view.'&task=edit&'.$cid.'[]='.$id,false), $item->$name); if($i<$quantity and $i<=count($idList)){ $list .= $link; } else if ($i==$quantity and $i<count($idList)){ $list .= ',...'; } $ttip .= ', '.$item->$name; if($i>($quantity + 6)) { $ttip .= ',...'; break; } $i++; } $list = substr ($list, 2); $ttip = substr ($ttip, 2); return '<span class="hasTip" title="'.$ttip.'" >' . $list . '</span>'; }
/** * Save a rating * @author Max Milbers */ public function saveRating($data = 0) { //Check user_rating $maxrating = VmConfig::get('vm_maximum_rating_scale', 5); $virtuemart_product_id = vRequest::getInt('virtuemart_product_id', 0); $app = JFactory::getApplication(); if ($app->isSite()) { $user = JFactory::getUser(); $userId = $user->id; $allowReview = $this->allowReview($virtuemart_product_id); $allowRating = $this->allowRating($virtuemart_product_id); } else { $userId = $data['created_by']; $allowReview = true; $allowRating = true; } if (!empty($virtuemart_product_id)) { //if ( !empty($data['virtuemart_product_id']) && !empty($userId)){ if (empty($data)) { $data = vRequest::getPost(); } if ($allowRating) { //normalize the rating if ($data['vote'] < 0) { $data['vote'] = 0; } if ($data['vote'] > $maxrating + 1) { $data['vote'] = $maxrating; } $data['lastip'] = $_SERVER['REMOTE_ADDR']; $data['vote'] = (int) $data['vote']; $rating = $this->getRatingByProduct($data['virtuemart_product_id']); vmdebug('$rating', $rating); $vote = $this->getVoteByProduct($data['virtuemart_product_id'], $userId); vmdebug('$vote', $vote); $data['virtuemart_rating_vote_id'] = empty($vote->virtuemart_rating_vote_id) ? 0 : $vote->virtuemart_rating_vote_id; if (isset($data['vote'])) { $votesTable = $this->getTable('rating_votes'); $votesTable->bindChecknStore($data, TRUE); $errors = $votesTable->getErrors(); foreach ($errors as $error) { vmError(get_class($this) . '::Error store votes ' . $error); } } if (!empty($rating->rates) && empty($vote)) { $data['rates'] = $rating->rates + $data['vote']; $data['ratingcount'] = $rating->ratingcount + 1; } else { if (!empty($rating->rates) && !empty($vote->vote)) { $data['rates'] = $rating->rates - $vote->vote + $data['vote']; $data['ratingcount'] = $rating->ratingcount; } else { $data['rates'] = $data['vote']; $data['ratingcount'] = 1; } } if (empty($data['rates']) || empty($data['ratingcount'])) { $data['rating'] = 0; } else { $data['rating'] = $data['rates'] / $data['ratingcount']; } $data['virtuemart_rating_id'] = empty($rating->virtuemart_rating_id) ? 0 : $rating->virtuemart_rating_id; vmdebug('saveRating $data', $data); $rating = $this->getTable('ratings'); $rating->bindChecknStore($data, TRUE); $errors = $rating->getErrors(); foreach ($errors as $error) { vmError(get_class($this) . '::Error store rating ' . $error); } } if ($allowReview and !empty($data['comment'])) { //if(!empty($data['comment'])){ $data['comment'] = substr($data['comment'], 0, VmConfig::get('vm_reviews_maximum_comment_length', 2000)); // no HTML TAGS but permit all alphabet $value = preg_replace('@<[\\/\\!]*?[^<>]*?>@si', '', $data['comment']); //remove all html tags $value = (string) preg_replace('#on[a-z](.+?)\\)#si', '', $value); //replace start of script onclick() onload()... $value = trim(str_replace('"', ' ', $value), "'"); $data['comment'] = (string) preg_replace('#^\'#si', '', $value); //replace ' at start $data['comment'] = nl2br($data['comment']); // keep returns //set to defaut value not used (prevent hack) $data['review_ok'] = 0; $data['review_rating'] = 0; $data['review_editable'] = 0; // Check if ratings are auto-published (set to 0 prevent injected by user) // $app = JFactory::getApplication(); if ($app->isSite()) { if (VmConfig::get('reviews_autopublish', 1)) { $data['published'] = 1; } else { $model = new VmModel(); $product = $model->getTable('products'); $product->load($data['virtuemart_product_id']); $vendorId = VmConfig::isSuperVendor(); if (!$user->authorise('core.admin', 'com_virtuemart') and !$user->authorise('core.manage', 'com_virtuemart') or $vendorId != $product->virtuemart_vendor_id) { $data['published'] = 0; } } } $review = $this->getReviewByProduct($data['virtuemart_product_id'], $userId); if (!empty($review->review_rates)) { $data['review_rates'] = $review->review_rates + $data['vote']; } else { $data['review_rates'] = $data['vote']; } if (!empty($review->review_ratingcount)) { $data['review_ratingcount'] = $review->review_ratingcount + 1; } else { $data['review_ratingcount'] = 1; } $data['review_rating'] = $data['review_rates'] / $data['review_ratingcount']; $data['virtuemart_rating_review_id'] = empty($review->virtuemart_rating_review_id) ? 0 : $review->virtuemart_rating_review_id; $reviewTable = $this->getTable('rating_reviews'); $reviewTable->bindChecknStore($data, TRUE); $errors = $reviewTable->getErrors(); foreach ($errors as $error) { vmError(get_class($this) . '::Error store review ' . $error); } } return $data['virtuemart_rating_review_id']; } else { vmError('Cant save rating/review/vote without vote/product_id'); return FALSE; } }
public function deleteCart() { $model = new VmModel(); $carts = $model->getTable('carts'); if (!empty($this->virtuemart_cart_id)) { $carts->delete($this->virtuemart_cart_id, 'virtuemart_cart_id'); } else { $currentUser = JFactory::getUser(); if (!empty($currentUser->id)) { $carts->delete($currentUser->id); } } }
public function deleteCart() { $currentUser = JFactory::getUser(); if (!$currentUser->guest) { $model = new VmModel(); $carts = $model->getTable('carts'); $carts->delete($currentUser->id); } }