1. shonn piersol
  2. Newbie area
  3. Monday, 10 June 2013
  4.  Subscribe via email
I was able to get alpha user points to work on user submitted comments by adding to the comment.php file inside models folder. I tried to get the points to work for Voting a comment up or down, to reward participation but while its in this code below its not working :( But at least the submitting of a comment does work.

<?php
/**
* @author Daniel Dimitrov - compojoom.com
* @date: 11.04.13
*
* @copyright Copyright (C) 2008 - 2013 compojoom.com . All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.modellegacy');


class ccommentModelComment extends JModelLegacy
{
public function getComments($contentId, $component, $start = 0)
{

$db = JFactory::getDBO();
$query = $db->getQuery(true);
$settings = ccommentConfig::getConfig($component);
$tree = $settings->get('layout.tree', 0);
$limit = $settings->get('layout.comments_per_page', 0);

$start = ($start != 0 && $start != 1) ? ($start-1) * $limit : 0;

if ($settings->get('layout.sort', 0)) {
$sort = 'DESC'; /* new first */
} else {
$sort = 'ASC'; /* last first */
}

$query->select('c.*, u.name AS user_realname, u.username AS user_username');
$query->from('#__comment AS c');
$query->leftJoin('#__users as u ON c.userid = u.id');
$query->where('contentid=' . $db->quote($contentId));
$query->where('component=' . $db->quote($component));
if(!ccommentHelperSecurity::isModerator($contentId)) {
$query->where('published=' . $db->quote(1));
}

if ($tree) {
$query->where('parentid<=0');
}

$query->order('id ' . $sort);
$db->setQuery($query, $start, $limit);
$comments = $db->loadObjectList();

if ($tree) {
$query->clear('where');
$query->where('contentid=' . $db->quote($contentId));
$query->where('component=' . $db->quote($component));
$query->where('parentid>0');

$query->clear('order');
$query->order('id ASC');
// don't change the ordering here - otherwise nested comments won't be sorted right
$db->setQuery($query);
$childrenComments = $db->loadObjectList();

$comments = ($comments && count($childrenComments) > 0) ? array_merge($comments, $childrenComments) : $comments;
}
return $comments;
}

public function getComment($id)
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('c.*, u.username as user_username, u.name as user_realname');
$query->from('#__comment AS c');
$query->leftJoin('#__users AS u ON c.userid = u.id');
$query->where('c.id = ' . $db->q($id));
$db->setQuery($query);
$comment = $db->loadObject();
return $comment;
}

public function countComments($contentId, $component, $pagination = false, $filter = '')
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('#__comment')
->where('contentid=' . $db->quote($contentId))
->where('component=' . $db->quote($component));

if(!ccommentHelperSecurity::isModerator($contentId)) {
$query->where('published=1');
}

if($filter) {
$query->where($filter);
}
if ($pagination) {
$query->where('parentid=-1');
}

$db->setQuery($query);
$countNumber = $db->loadResult();
if (!$countNumber) {
$countNumber = 0;
}
return $countNumber;
}

public function getPreviewComments($contentId, $component)
{
$db = JFactory::getDBO();
$settings = ccommentConfig::getConfig($component);
$query = $db->getQuery(true);
$query->select('*')->from('#__comment')
->where('contentid=' . $db->quote($contentId))
->where('component=' . $db->quote($component))
->where('published=' . $db->quote(1))
->order('date DESC');
$db->setQuery($query, 0, $settings->get('template_params.preview_lines'));
return $db->loadObjectList();
}

public function insert($data)
{
JPluginHelper::importPlugin('compojoomcomment');
$dispatcher = JDispatcher::getInstance();

$table = JTable::getInstance('comment', 'ccommentTable');
$table->bind($data);
// BEGIN AUP
$api_AUP = JPATH_SITE.DS.'components'.DS.'com_alphauserpoints'.DS.'helper.php';
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
AlphaUserPointsHelper::newpoints( 'plgaup_comments.addComment', '', '', '' );
}
// END AUP
if(!$table->store()) {
return false;
}

$dispatcher->trigger('onAfterCommentSave', array('com_comment.comment', $table));

return $table->id;

}

/**
* @param $state - the new comment state
* @param $id - the comment id
* @throws Exception
* @return bool
*/
public function changeState($state, $id)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
if ($state != -1) {
$query->update($db->qn('#__comment'))->set($db->qn('published') . '=' . $db->q((int)$state));
} else {
$query->delete($db->qn('#__comment'));
}

$query->where($db->qn('id') . '=' . $db->q($id));

$db->setQuery($query);
if (!$db->query()) {
throw new Exception('Unable to execute query', 500);
}

return true;
}

/**
* @param $vote
* @param $id
* @return bool - true if the vote was correctly processed, false otherwise
* @throws Exception
*/
public function vote($vote, $id)
{
if ($vote !== -1 && $vote !== 1) {
throw new Exception('Invalid value provided for vote', 500);
}
if ($id === 0) {
throw new Exception('Invalid comment id provided', 500);
}

$db = JFactory::getDBO();
$query = $db->getQuery('true');

JPluginHelper::importPlugin('compojoomcomment');
$dispatcher = JDispatcher::getInstance();

// delete old votes
$t = time() - 3 * 86400;
$query->delete('#__comment_voting')->where($db->qn('time') . '<' . $db->q($t));
$db->setQuery($query);
$db->execute();

// check if we have a recent vote for this comment
$query->clear();
$query->select('COUNT(*)')->from($db->qn('#__comment_voting'))
->where($db->qn('id') . '=' . $db->q($id))
->where($db->qn('ip') . '=' . $db->q($_SERVER['REMOTE_ADDR']));
$db->setQuery($query);


$exists = $db->loadResult();

if (!$exists) {
$field = '';
if ($vote == -1) {
$field = 'voting_no';
} else if ($vote == 1) {
$field = 'voting_yes';
}
if ($field) {
// update the comment vote
$query->clear();
$query->update($db->qn('#__comment'))->set($db->qn($field) . '=' . $db->qn($field) . '+1')
->where($db->qn('id') . '=' . $id);
$db->setQuery($query);
if (!$db->execute()) {
throw new Exception('Unable to update vote field', 500);
}

// insert in the voting table
$query->clear();
$query->insert($db->qn('#__comment_voting'))->columns(array($db->qn('id'), $db->qn('ip'), $db->qn('time')))
->values($db->q($id) . ',' . $db->q($_SERVER['REMOTE_ADDR']) . ',' . $db->q(time()));
if (!$db->execute()) {
throw new Exception('Unable to insert data in voting', 500);
}

$dispatcher->trigger('onAfterCommentVote', array($this->getComment($id), $vote));

return true;

}
if ( file_exists($api_AUP))
{
require_once ($api_AUP);
AlphaUserPointsHelper::newpoints( 'plgaup_comments.CommentVote', '', '', '' );
}
}

return false;
}

public function search($id, $word, $component) {
$db = JFactory::getDbo();
$db->getQuery(true);

// $query->select('*')->from('#__comment')
// ->where()
}

}
Responses (17)


There are %s replies to this question. If you want to see them you need a valid subscription.
If you have a valid subscription, please login now.
Visit store now

Last questions

Hotspots Pro 6.0.13 compatability with Joomla 5.3.
Running Hotspots Pro 6.0.13 on Joomla 4.4.13 and want to upgrade to Joomla 5.3.1...
2 Replies
Posted on Friday, 04 July 2025
  • New
  • some questions on Hotspots
    Hi, On Hotspots extension : 1) is it possible to add our own map layer / v...
    0 Replies
    Posted on Thursday, 03 July 2025
  • New
  • Trying to resize the image in the comments
    Hey everyone, Basically I am trying to make the images in the comments smalle...
    9 Replies
    Posted on Wednesday, 12 August 2009
    J5 compatibility for Hotspots
    Hi guys, Just started to update my old J3x website. Is there J5 compatibility p...
    2 Replies
    Posted on Monday, 24 February 2025
    • #Hotspots
    • #hotspots Joomla 5
    error message when adding/cofiguring email address
    When configuring the email plugin that send a email message to admin when a new ...
    0 Replies
    Posted on Friday, 09 May 2025