×

Notice

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

TOPIC: very easy to count all comments a user made

very easy to count all comments a user made 15 years 2 months ago #7179

  • Chris Zurlinden
  • Chris Zurlinden's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
i would like to count all comments a user made

Thats why i hacked your code a bit.
First i had to add a field jos_users.comments

then in comment.class.php i added the following
function setUser()
    {
        $database =& JFactory::getDBO();
 
        /* also in post ! and notification */
        $query = "SELECT * FROM jos_users WHERE id='".$this->_userid."' LIMIT 1";
        $database->SetQuery($query);
        $result = $database->loadAssocList();
        if ($result) {
            $user = $result[0];
            $this->_usertype  = $user['usertype'];
            $this->_tname     = $this->_use_name ? $user['name'] : $user['username'];
            $this->_temail    = $user['email'];
            $this->_tcomments = $user['comments'];# added by zurli
        }
 
    }

and then more below i changed this
#Commentscounter edit by zurli
		$this->_tcomments = $this->_tcomments+1;
		$query = "
			UPDATE jos_users SET
			comments=$this->_tcomments
			WHERE id=$userid";
        $database->SetQuery($query);
        $database->Query() or die(_JOOMLACOMMENT_EDITINGFAILED . "\n $query");
		#End Commentscounter edit by zurli
 
        $database->SetQuery("
            INSERT INTO jos_comment
            (contentid,component,ip,userid,usertype,date,name,email,website,notify,title,comment,published,voting_yes,voting_no,parentid)
            VALUES(
            '$this->_content_id',
            '$com',
            '$ip',
            '$userid',
            '',
            '$createdate',
            '$name',
            '$email',
            '$website',
            '$notify',
            '$title',
            '$comment',
            '$published',
            '0',
            '0',
            '$parent_id'
            )");
        $result=$database->Query() or die(_JOOMLACOMMENT_SAVINGFAILED); //.$database->getQuery());
 

what you think about solution

very easy to count all comments a user made 15 years 2 months ago #7184

  • JonusC
  • JonusC's Avatar
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 785
  • Thank you received: 48
What's the purpose of this? I don't see it being very useful...

...Unless you put a new field on CB Profiles called "User's Total Comments" and make it grab this comment count value ;)

very easy to count all comments a user made 15 years 2 months ago #7188

  • Chris Zurlinden
  • Chris Zurlinden's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
Hey Jonus

This is exactly what i would like to do. The table is already showing the amount of subited documents in fabrik.

I will take a look if i can do the same with positive ranking and negative ranking of a comment.

Regards Zurli

very easy to count all comments a user made 15 years 2 months ago #7190

  • JonusC
  • JonusC's Avatar
  • Offline
  • Platinum Boarder
  • Platinum Boarder
  • Posts: 785
  • Thank you received: 48
If I may ask, I myself have never actually added a custom field to Community Builder from another extension. How is it done? If it is in the Manual let me know (I am a subscriber to Joomlapolis). But I would like to know. I was planning to add better CB support in the next release, now somebody has done half the work for us! :laugh: You will be credited in documentation for your code sharing :)

Looking forward to the vote one. What will it display? A new "Comment Karma" which calculates the average number of all votes on their comments to make a "global score" for them? That's what I had on my mind with Voting but i'm curious as to what you are planning.

very easy to count all comments a user made 15 years 2 months ago #7195

  • Chris Zurlinden
  • Chris Zurlinden's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
I implemented fabrik to my website.

There i just installed the fabrik cb plugin and linked the plugin to my jos_users table.

but the code is not that stable. so i maybe try to get the data out of jos_users by direct enter sql in cb. but i don't know how yet.

as soon as i get a solution i will post

very easy to count all comments a user made 15 years 2 months ago #7197

  • Chris Zurlinden
  • Chris Zurlinden's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
I played around with crating a own plugin.
This is what i have done so far.

If someone would like to make it better feel free and post.

mydata.xml
<?xml version="1.0" encoding="utf-8"?>
<cbinstall version="4.5.3" type="plugin" group="user">
	<name>MyData</name>
	<description>Provides a User Tab for displaying some data.</description>
	<files>
		<filename plugin="mydata">mydata.php</filename>
		<filename>index.html</filename>
	</files>
    <params>
    </params>	    
	<tabs>
		<tab name="My Data" description="Provides a User Tab for displaying some data." class="getMyDataTab" fields="1" position="cb_tabmain" displaytype="tab">
			<params>
			</params>
		</tab>
	</tabs>
</cbinstall>

mydata.php
<?php
if ( ! ( defined( '_VALID_CB' ) || defined( '_JEXEC' ) || defined( '_VALID_MOS' ) ) ) { die( 'Direct Access to this location is not allowed.' ); }
 
 
class getMyDataTab extends cbTabHandler {
	/**
	* Constructor
	*/
	function getMyDataTab() {
		$this->cbTabHandler();
	}
 
	function getDisplayTab($tab,$user,$ui) {
		global $_CB_database;
		if ($user->id){
			$query = 'SELECT field FROM jos_users WHERE id='. $user->id;
			$_CB_database->setQuery( $query );
			$mydata = $_CB_database->loadResult();
			$return='<div><p>Fieldname: '.$mydata.'</p></div>';
		} else {
		    $return='';
		}
		return $return;
  }
}
?>

added an empty index.html file and packed all together to a mydata.zip and installed the plugin using cb plugin manager.

very easy to count all comments a user made 15 years 2 months ago #7198

  • Chris Zurlinden
  • Chris Zurlinden's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 11
  • Thank you received: 0
update

if you want to display more fields use this SQL
$_CB_database->setQuery("SELECT field1, field2 FROM jos_users WHERE id=$user->id");
$rows = $_CB_database->loadObjectList();
$row = $rows[0];
$field1 = $row->field1;
$field2 = $row->field2;
$return='<div><p>Name1: '.$field1.'</p><p>Name2: '.$field2.'</p></div>';

:woohoo:
  • Page:
  • 1
Time to create page: 0.170 seconds