/** * Recalculate content reputation for a space * * @param $space : The space where the content should be updated * @param bool $forceUpdate : Ignore cache */ public function updateContentReputation($space, $forceUpdate = false) { $spaceId = $space->id; $spaceContent = $this->getContentFromSpace($spaceId); $spaceSettings = $this->getSpaceSettings($space); $lambda_short = $spaceSettings[8]; $lambda_long = $spaceSettings[9]; foreach ($spaceContent as $content) { $cacheId = 'reputation_space_content' . '_' . $spaceId . '_' . $content->id; $contentReputation = Yii::app()->cache->get($cacheId); if ($contentReputation === false || $forceUpdate === true) { // get all reputation_content objects from this space $attributes = array('content_id' => $content->id); $contentReputation = ReputationContent::model()->findByAttributes($attributes); if ($contentReputation == null && !Yii::app()->user->isGuest) { // Create new reputation_content entry $contentReputation = new ReputationContent(); $contentReputation->content_id = $content->id; } $score = $this->calculateContentReputationScore($content, $space, $forceUpdate); $contentReputation->score = $score; $timePassed = $this->getTimeInHoursSinceContentCreation($content->created_at); $contentReputation->score_long = $this->getDecayedScore($score, $timePassed, $lambda_long); $contentReputation->score_short = $this->getDecayedScore($score, $timePassed, $lambda_short); $contentReputation->updated_at = date('Y-m-d H:i:s'); $contentReputation->save(); Yii::app()->cache->set($cacheId, $contentReputation, ReputationBase::CACHE_TIME_SECONDS); } } }