Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -N -r8546 -r8586 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 8546) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 8586) @@ -466,6 +466,39 @@ // original item is not changed here, because it is already enabled (thrus pending copy is visible to item's owner or admin with permission) return true; } + + function RegisterHit() + { + $already_viewed = $this->Application->RecallVar($this->getPrefixSpecial().'_already_viewed'); + $already_viewed = $already_viewed ? unserialize($already_viewed) : Array (); + + $id = $this->GetID(); + if (!in_array($id, $already_viewed)) { + $property_map = $this->Application->getUnitOption($this->Prefix, 'ItemPropertyMappings'); + if (!$property_map) { + return ; + } + $hits_field = $property_map['ClickField']; + $new_hits = $this->GetDBField($hits_field) + 1; + + $sql = 'SELECT MAX('.$hits_field.') + FROM '.$this->TableName.' + WHERE FLOOR('.$hits_field.') = '.$new_hits; + $max_hits = $this->Conn->GetOne($sql); + if ($max_hits) { + $new_hits = $max_hits + 0.000001; + } + + $fields_hash = Array ( + $hits_field => $new_hits, + ); + $this->Conn->doUpdate($fields_hash, $this->TableName, $this->IDField.' = '.$id); + + array_push($already_viewed, $id); + $this->Application->StoreVar($this->getPrefixSpecial().'_already_viewed', serialize($already_viewed)); + } + } + } ?> \ No newline at end of file