/** * 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); } } }
/** * Shows the reputation_content wall */ public function actionShow() { $forceUpdate = false; if (isset($_GET['forceUpdate'])) { $forceUpdate = true; } ReputationContent::model()->updateContentReputation($this->getSpace(), $forceUpdate); $this->render('show', array()); }
/** * Initialize configuration view * Allows the user to set a bunch of parameters for reputation settings inside this space * * @throws CException */ public function actionConfiguration() { Yii::import('reputation.forms.*'); $form = new ConfigureForm(); $space = Yii::app()->getController()->getSpace(); $spaceId = $space->id; if (isset($_POST['ajax']) && $_POST['ajax'] === 'configure-form') { echo CActiveForm::validate($form); Yii::app()->end(); } if (isset($_POST['ConfigureForm'])) { $_POST['ConfigureForm'] = Yii::app()->input->stripClean($_POST['ConfigureForm']); $form->attributes = $_POST['ConfigureForm']; if ($form->validate()) { $form->functions = SpaceSetting::Set($spaceId, 'functions', $form->functions, 'reputation'); $form->logarithmBase = SpaceSetting::Set($spaceId, 'logarithm_base', $form->logarithmBase, 'reputation'); $form->create_content = SpaceSetting::Set($spaceId, 'create_content', $form->create_content, 'reputation'); $form->smb_likes_content = SpaceSetting::Set($spaceId, 'smb_likes_content', $form->smb_likes_content, 'reputation'); $form->smb_favorites_content = SpaceSetting::Set($spaceId, 'smb_favorites_content', $form->smb_favorites_content, 'reputation'); $form->smb_comments_content = SpaceSetting::Set($spaceId, 'smb_comments_content', $form->smb_comments_content, 'reputation'); $form->daily_limit = SpaceSetting::Set($spaceId, 'daily_limit', $form->daily_limit, 'reputation'); $form->decrease_weighting = SpaceSetting::Set($spaceId, 'decrease_weighting', $form->decrease_weighting, 'reputation'); $form->cron_job = SpaceSetting::Set($spaceId, 'cron_job', $form->cron_job, 'reputation'); $form->lambda_short = SpaceSetting::Set($spaceId, 'lambda_short', $form->lambda_short, 'reputation'); $form->lambda_long = SpaceSetting::Set($spaceId, 'lambda_long', $form->lambda_long, 'reputation'); ReputationUser::model()->updateUserReputation($space, true); ReputationContent::model()->updateContentReputation($space, true); $this->redirect($this->createContainerUrl('//reputation/adminReputation/configuration')); } } else { $form->functions = SpaceSetting::Get($spaceId, 'functions', 'reputation', ReputationBase::DEFAULT_FUNCTION); $form->logarithmBase = SpaceSetting::Get($spaceId, 'logarithm_base', 'reputation', ReputationBase::DEFAULT_LOGARITHM_BASE); $form->create_content = SpaceSetting::Get($spaceId, 'create_content', 'reputation', ReputationBase::DEFAULT_CREATE_CONTENT); $form->smb_likes_content = SpaceSetting::Get($spaceId, 'smb_likes_content', 'reputation', ReputationBase::DEFAULT_SMB_LIKES_CONTENT); $form->smb_favorites_content = SpaceSetting::Get($spaceId, 'smb_favorites_content', 'reputation', ReputationBase::DEFAULT_SMB_FAVORITES_CONTENT); $form->smb_comments_content = SpaceSetting::Get($spaceId, 'smb_comments_content', 'reputation', ReputationBase::DEFAULT_SMB_COMMENTS_CONTENT); $form->daily_limit = SpaceSetting::Get($spaceId, 'daily_limit', 'reputation', ReputationBase::DEFAULT_DAILY_LIMIT); $form->decrease_weighting = SpaceSetting::Get($spaceId, 'decrease_weighting', 'reputation', ReputationBase::DEFAULT_DECREASE_WEIGHTING); $form->cron_job = SpaceSetting::Get($spaceId, 'cron_job', 'reputation', ReputationBase::DEFAULT_CRON_JOB); $form->lambda_short = SpaceSetting::Get($spaceId, 'lambda_short', 'reputation', ReputationBase::DEFAULT_LAMBDA_SHORT); $form->lambda_long = SpaceSetting::Get($spaceId, 'lambda_long', 'reputation', ReputationBase::DEFAULT_LAMBDA_LONG); } $this->render('adminReputationSettings', array('model' => $form, 'space' => $space)); }
/** * On run of integrity check command, validate all module data * * @param type $event */ public static function onIntegrityCheck($event) { $integrityChecker = $event->sender; $integrityChecker->showTestHeadline("Validating Reputation Content (" . ReputationContent::model()->count() . " entries)"); $integrityChecker->showTestHeadline("Validating Reputation User (" . ReputationUser::model()->count() . " entries)"); }