×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Alpha User Points for 5.x

Alpha User Points for 5.x 11 years 5 months ago #21172

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
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()
	}
 
}

Alpha User Points for 5.x 11 years 5 months ago #21174

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Give me some time today and I'll write the integration.

Alpha User Points for 5.x 11 years 5 months ago #21185

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Would you please download the latest dev. releasea and test the integration?
compojoom.com/component/ars/repository/d...mment-pro/git7cf5e19

The docs are here:
compojoom.com/support/documentation/ccomment/ch03s03s02

Thanks in advance!
Daniel
The following user(s) said Thank You: shonn piersol

Alpha User Points for 5.x 11 years 5 months ago #21197

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
Yes the git7cfe19 version did apply points with your directions. Its a small detail further, but not necessary, but the Detail field is blank and doesnt say what article title they voted or commented on. Notice how the "new user" plugin and read articles plug etc will show the article title, it makes for easy for them to know how they earned points without backtracking. but yes, it does at least work and i thank you kindly.

Date Action points Expire Detail Approved
Monday, 10 June 2013 17:47 CComment positive vote 4 -
Monday, 10 June 2013 17:46 CComment comment 10 -
Monday, 10 June 2013 17:33 New user 0 - Welcome!

Alpha User Points for 5.x 11 years 5 months ago #21209

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Okay, I don't know AUP that well so I didn't know that one can show the title of the article or anything else there. Will have a look at this again.

Alpha User Points for 5.x 11 years 5 months ago #21227

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Just released RC2 - it shows "Made a comment in "title with link" and also "Voted in "title + link":
compojoom.com/downloads/official-release...ment/ccomment-5-0rc2

Cheers,
Daniel

Alpha User Points for 5.x 11 years 5 months ago #21230

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
Not sure whats happened, i upgraded and now im not getting any points awarded. Please visit massageindy.com/login-register to test if you like.

Alpha User Points for 5.x 11 years 5 months ago #21237

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Are you sure that you are testing with a user that is not the admin? (happened to me that is why I mention it).

I just tested it on my localhost and here is what I get:
awesomescreenshot.com/0c01dzge3f

Alpha User Points for 5.x 11 years 5 months ago #21262

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
yes just tried with registered user, just in case and it didnt give points for commenting in ccomments version 5.0rc2

Alpha User Points for 5.x 11 years 5 months ago #21282

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Okay could you please open a private ticket and provide me with backend access, a frontend user that is not admin and eventually ftp access?
I cannot reproduce the problem on my localhost and I'll have to test what you have.

Daniel

Alpha User Points for 5.x 11 years 5 months ago #21294

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
I installed the latest dev release and it is all working fine. No reason to return to the beta release and troubleshoot. The latest Dev release has AUP working for comments and voting! you did wonderful, thank you. I have posted review in JED.

Alpha User Points for 5.x 11 years 5 months ago #21295

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Shonn,
I'm confused because of the other thread "hwd ...". Is this thing working or not? There is no beta release -> there is a release candidate.

The release candidate shares the same code as the dev releases -> so it should work. You should see the user activity + message:
PLG_COMPOJOOMCOMMENT_AUP_MADE_COMMENT="Made a comment in <a href='%s'>%s</a>"
PLG_COMPOJOOMCOMMENT_AUP_VOTED_ON_COMMENT="Voted on a comment in <a href='%s'>%s</a>"

Do you get such a message? I'll close the HWD thread -> let us continue with this issue just here.

Regards,
Daniel

Alpha User Points for 5.x 11 years 5 months ago #21323

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
Notice how the info under DETAILS column is blank for the comment. So the points are calculated and it does say its from the Comment plugin, but it doesnt say WHAT item is commented upon, its blank.

If it cant determine article title, video title, picture title, etc because its crossing multiple components, then perhaps it could pull page title and that would apply to all components.
Attachments:

Alpha User Points for 5.x 11 years 5 months ago #21324

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Shonn,
Above I said:

Okay could you please open a private ticket and provide me with backend access, a frontend user that is not admin and eventually ftp access?


Actually the plugin should show the title with a link -> this is the way it works in the RC and the latest dev release. I have no idea why it doesn't work the same way for you, but without access to your site I won't be able to help you.

Also -> your user has 30 points? did he receive that 30 points for comments? or was it something else? In jomsocial there is an option to merge the same activity, but I'm not aware of such a feature in AUP. If this is possible maybe that is the reason why there is no detail shown.

Regards,
Daniel

Alpha User Points for 5.x 11 years 5 months ago #21326

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
My users get 30 points from the AUP plugin for posting a comment. Can you take a screen shot of it working in the RC? I have installed on separate sites, and it isnt posting linked titles of whats been commented. Again this isnt worth a lot of time as at least points are awarded. Many AUP plugins fail to send the details so this isnt unusual.

Before we go into my site particularly lets make sure the RC install actually is posting correctly. It would be nice if you had a demo site that was always updated with latest RC as we can all see the fixes as we go and save much time.

Alpha User Points for 5.x 11 years 5 months ago #21327

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Online
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
I thought that I already shared a screenshot. Anyway:
awesomescreenshot.com/0731eeuebc

I'm not making things up :)

Alpha User Points for 5.x 11 years 5 months ago #21328

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
I am so sorry i didnt mean to imply that, just making sure we didnt lose concept in translation :) But yes as you have it in your screen shot is ideal. I will make sure im using latest install and try again.

Alpha User Points for 5.x 11 years 5 months ago #21330

  • shonn piersol
  • shonn piersol's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 30
  • Thank you received: 0
I am so thankful! I used RC2 pro this time (apparently last i use core) and it does indeed work as it should and I am so impressed with your efforts and thorough detail. You did so much work based on my personal request (though beneficial to many) and for that I am greatful. My review in JED reflects such great work.
  • Page:
  • 1
Time to create page: 0.157 seconds