/** * Calculates the new rating * * @param class_module_rating_rate $objSourceRate The rating-record to update * @param float $floatNewRating The rating fired by the user * * @return float the new rating */ public function doRating(class_module_rating_rate $objSourceRate, $floatNewRating) { //calc the rating's midpoint depending on the maximum rating value $floatRatingMidpoint = (class_module_rating_rate::$intMaxRatingValue + 1) / 2; $floatAssessedRating = 0; if ($floatNewRating == $floatRatingMidpoint) { //the rating exactly matches the average rating value //it doesn't need to be assessed $floatAssessedRating = $floatNewRating; } else { //determine the interval between assessed ratings //the number 0.5 is to the maximum change which is applied to a rating during assessment //a more probable rating and a higher number of ratings will make this interval less meaningful $floatAssessmentInterval = 0.5 / ($floatRatingMidpoint - 1); //calc the assessment on the current rating $floatAssessedRating = ($floatRatingMidpoint - $floatNewRating) * $floatAssessmentInterval + $floatNewRating; //add or subtract a bonus depending on the number of already existing ratings $intAdditionSign = 1; if ($floatNewRating < $floatRatingMidpoint) { $intAdditionSign = -1; } $floatAssessedRating = $floatAssessedRating + $intAdditionSign * ($objSourceRate->getIntHits() / class_module_rating_algo_gaussian::$intAssessmentSoftenerFactor * 2); //reset the final assessed ratings if they should exceed the user's rating //this could only happen with a high number of ratings on an object if ($floatNewRating < $floatRatingMidpoint && $floatAssessedRating < $floatNewRating || $floatNewRating > $floatRatingMidpoint && $floatAssessedRating > $floatNewRating) { $floatAssessedRating = $floatNewRating; } } //calc the new rating $floatNewRating = ($objSourceRate->getFloatRating() * $objSourceRate->getIntHits() + $floatAssessedRating) / ($objSourceRate->getIntHits() + 1); return $floatNewRating; }
/** * Removes the elements / modules handled by the current installer. * Use the reference param to add a human readable logging. * * @param string &$strReturn * * @return bool */ public function remove(&$strReturn) { /** @var class_module_rating_rate $objOneObject */ foreach (class_module_rating_rate::getObjectList() as $objOneObject) { $strReturn .= "Deleting object '" . $objOneObject->getStrDisplayName() . "' ...\n"; if (!$objOneObject->deleteObjectFromDatabase()) { $strReturn .= "Error deleting object, aborting.\n"; return false; } } //delete the module-node $strReturn .= "Deleting the module-registration...\n"; $objModule = class_module_system_module::getModuleByName($this->objMetadata->getStrTitle(), true); if (!$objModule->deleteObjectFromDatabase()) { $strReturn .= "Error deleting module, aborting.\n"; return false; } //delete the tables foreach (array("rating", "rating_history") as $strOneTable) { $strReturn .= "Dropping table " . $strOneTable . "...\n"; if (!$this->objDB->_pQuery("DROP TABLE " . $this->objDB->encloseTableName(_dbprefix_ . $strOneTable) . "", array())) { $strReturn .= "Error deleting table, aborting.\n"; return false; } } return true; }
/** * Number of rating for the current file * * @see interface_sortable_rating * @return int * * @todo: with php5.4, ths could be moved to traits */ public function getIntRatingHits() { $intHits = 0; $objModule = class_module_system_module::getModuleByName("rating"); if ($objModule != null) { $objRating = class_module_rating_rate::getRating($this->getSystemid()); if ($objRating != null) { $intHits = $objRating->getIntHits(); } else { return 0; } } return $intHits; }
/** * Saves a rating to a passed rating-file * * @return string the new rating for the passed file * @permissions view */ protected function actionSaveRating() { //rating already existing? $objRating = class_module_rating_rate::getRating($this->getSystemid()); if ($objRating == null) { $objRating = new class_module_rating_rate(); $objRating->setStrRatingSystemid($this->getSystemid()); $objRating->updateObjectToDb(); } $strReturn = "<rating>"; $objRating->saveRating($this->getParam("rating")); $objRating->updateObjectToDb(); $strReturn .= round($objRating->getFloatRating(), 2); $strReturn .= "</rating>"; return $strReturn; }
/** * Calculates the new rating * * @param class_module_rating_rate $objSourceRate The rating-record to update * @param float $floatNewRating The rating fired by the user * * @return float the new rating */ public function doRating(class_module_rating_rate $objSourceRate, $floatNewRating) { //calc the new rating $floatNewRating = ($objSourceRate->getFloatRating() * $objSourceRate->getIntHits() + $floatNewRating) / ($objSourceRate->getIntHits() + 1); return $floatNewRating; }