[TYPO3-english] Getting rid of default css in Dmitrys comments extension

Steffen Ritter info at rs-websystems.de
Wed Feb 25 16:40:10 CET 2009


Morten Kjems schrieb:
It is very popular with reviews to give a an overall star rating for a 
product. I wonder if it is possible to ad this feature.

it's possible, not in a "straight forward/clean" way... Do you have any 
fields you do not use in comments? like Location?
Misuse it and save your rating in it...
Depending on your extension displaying your product, there are several 
ways to  "display" the rating...

first way:
add a field to your products table "rating", installing db-trigger 
calculating your new value for this special product on every 
update/insert of comments.
Display the field in the frontend by ts or hook, whatever the ext can.
It will be the fastest since it is on sql. But not very transparent.


second way: hook into comments like this:
	/**
	  * Function for Hook "processSubmission"
	  * allows to manipulate Saving of Record	
	  */
	function saveComment(&$params, &$pObj) {

	if($pObj->foreignTableName == 'YOURTABLE') {
			list($currentRatings) = 
$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('COUNT(uid) AS count, 
SUM(RATINGFIELD) AS 
sum','tx_comments_comments','external_ref='.$pObj->foreignTableName.'_'.$pObj->externalUid 
.' AND deleted=0');
		
			if(!is_array($currentRatings)) {
				$currentRatings = array();
				$currentRatings['sum'] = $pObj->piVars['rating'];
				$currentRatings['count'] = 1;
			} else {
				$currentRatings['sum'] += $pObj->piVars['rating'];
				$currentRatings['count']++;
			}
		
			$currentRate = $currentRatings['sum'] /$currentRatings['count'];
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_your_product','uid='.$pObj->externalUid,array('ratingfield'=>$currentRate,'tstamp'=>time()),FALSE);
			
		}


If you need all fields in comments, just add one ;)

have fun,
since i copied this from a live/client-test-pending website, and changed 
some parts to simplify it, and - morover - deleted not belonging stuff, 
i can't garantuee that this will work out of the box...
kind regards

Steffen


More information about the TYPO3-english mailing list