protected function getValue() { $app = JFactory::getApplication(); if ($app->isSite() && isset($this->listing->total_comments) && !is_null($this->listing->total_comments)) { return $this->listing->total_comments; } $user = JFactory::getUser(); $db = JFactory::getDbo(); if ($app->isSite()) { $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_comments AS cm'); $query->where('listing_id =' . $this->listing_id); $query->where('level = 1'); $query->where('approved = 1'); $moderator = JUDirectoryFrontHelperModerator::getModerator($this->listing->cat_id); $getAll = false; if ($user->authorise('core.admin', 'com_judirectory')) { $getAll = true; } if (is_object($moderator)) { if ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete) { $getAll = true; } } if (!$getAll) { $query->where('published = 1'); $params = JUDirectoryHelper::getParams(null, $this->listing_id); $negative_vote_comment = $params->get('negative_vote_comment'); if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) { $query->where('(total_votes - helpful_votes) <' . $negative_vote_comment); } } } else { $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_comments AS cm'); $query->where('listing_id =' . $this->listing_id); $query->where('level = 1'); $query->where('approved = 1'); } $db->setQuery($query); $totalComments = $db->loadResult(); return $totalComments; }
public function getTotalChildComments($parentId) { $listingId = (int) $this->getState('listing.id'); $mainCategoryId = JUDirectoryFrontHelperCategory::getMainCategoryId($listingId); $user = JFactory::getUser(); $params = $this->getState('params'); $db = $this->getDbo(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judirectory_comments AS cm'); $query->where('cm.approved = 1'); $query->where('cm.parent_id = ' . $parentId); $maxLevel = $params->get('max_comment_level', 5); $query->where('cm.level <= ' . $maxLevel); $getAll = false; $isModerator = JUDirectoryFrontHelperModerator::isModerator(); if ($isModerator) { $moderator = JUDirectoryFrontHelperModerator::getModerator($mainCategoryId); if ($user->authorise('core.admin', 'com_judirectory') || $moderator && ($moderator->comment_edit || $moderator->comment_edit_state || $moderator->comment_delete)) { $getAll = true; } } if (!$getAll) { $query->where('cm.published = 1'); $negative_vote_comment = $params->get('negative_vote_comment'); if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0) { $query->where('(cm.total_votes - cm.helpful_votes) <' . $negative_vote_comment); } } $db->setQuery($query); return $db->loadResult(); }