/** * Recalculate user and content reputation every hour * Only do this in spaces where reputation module is enabled * * @param $event * @throws CException */ public static function onCronHourlyRun($event) { Yii::import('application.modules.reputation.models.*'); $cron = $event->sender; foreach (Space::model()->findAll() as $space) { if ($space->isModuleEnabled('reputation')) { $cronJobEnabled = SpaceSetting::Get($space->id, 'cron_job', 'reputation', ReputationBase::DEFAULT_CRON_JOB); if ($cronJobEnabled) { print "- Recalculating reputation for space: {$space->id} {$space->name}\n"; ReputationUser::model()->updateUserReputation($space, true); ReputationContent::model()->updateContentReputation($space, true); } } } }
/** * Disables a module * * Which means delete all (user-) data created by the module. * */ public function disable() { if (!$this->isEnabled() || $this->isCoreModule) { return false; } // Check this module is a SpaceModule if ($this->isSpaceModule()) { foreach ($this->getSpaceModuleSpaces() as $space) { $space->disableModule($this->getId()); } } // Check this module is a UserModule if ($this->isUserModule()) { foreach ($this->getUserModuleUsers() as $user) { $user->disableModule($this->getId()); } } // Disable module in database $moduleEnabled = ModuleEnabled::model()->findByPk($this->getId()); if ($moduleEnabled != null) { $moduleEnabled->delete(); } HSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); SpaceSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); UserSetting::model()->deleteAllByAttributes(array('module_id' => $this->getId())); // Delete also records with disabled state from SpaceApplicationModule Table foreach (SpaceApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $sam) { $sam->delete(); } // Delete also records with disabled state from UserApplicationModule Table foreach (UserApplicationModule::model()->findAllByAttributes(array('module_id' => $this->getId())) as $uam) { $uam->delete(); } ModuleManager::flushCache(); return true; }
public function testSet() { SpaceSetting::Set(1, 'globalSetting', 'xyz2'); $this->assertEquals(SpaceSetting::Get(1, 'globalSetting', 'core'), 'xyz2'); }
/** * 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)); }
/** * Returns a settings record by Name and Module Id * The result is cached. * * @param type $spaceId * @param type $name * @param type $moduleId * @return \HSetting */ private static function GetRecord($spaceId, $name, $moduleId = "core") { if ($moduleId == "") { $moduleId = "core"; } $cacheId = 'SpaceSetting_' . $spaceId . '_' . $name . '_' . $moduleId; // Check if stored in Runtime Cache if (RuntimeCache::Get($cacheId) !== false) { return RuntimeCache::Get($cacheId); } // Check if stored in Cache $cacheValue = Yii::app()->cache->get($cacheId); if ($cacheValue !== false) { return $cacheValue; } $condition = ""; $params = array('name' => $name, 'space_id' => $spaceId); if ($moduleId != "") { $params['module_id'] = $moduleId; } else { $condition = "module_id IS NULL"; } $record = SpaceSetting::model()->findByAttributes($params, $condition); if ($record == null) { $record = new SpaceSetting(); $record->space_id = $spaceId; $record->module_id = $moduleId; $record->name = $name; } else { $expireTime = 3600; if ($record->name != 'expireTime' && $record->module_id != "cache") { $expireTime = HSetting::Get('expireTime', 'cache'); } Yii::app()->cache->set($cacheId, $record, $expireTime); RuntimeCache::Set($cacheId, $record); } return $record; }
/** * Before deletion of a Space */ protected function beforeDelete() { foreach (SpaceSetting::model()->findAllByAttributes(array('space_id' => $this->id)) as $spaceSetting) { $spaceSetting->delete(); } // Disable all enabled modules foreach ($this->getAvailableModules() as $moduleId => $module) { if ($this->isModuleEnabled($moduleId)) { $this->disableModule($moduleId); } } HSearch::getInstance()->deleteModel($this); $this->getProfileImage()->delete(); // Remove all Follwers UserFollow::model()->deleteAllByAttributes(array('object_id' => $this->id, 'object_model' => 'Space')); //Delete all memberships: //First select, then delete - done to make sure that SpaceMembership::beforeDelete() is triggered $spaceMemberships = SpaceMembership::model()->findAllByAttributes(array('space_id' => $this->id)); foreach ($spaceMemberships as $spaceMembership) { $spaceMembership->delete(); } UserInvite::model()->deleteAllByAttributes(array('space_invite_id' => $this->id)); // Delete all content objects of this space foreach (Content::model()->findAllByAttributes(array('space_id' => $this->id)) as $content) { $content->delete(); } // When this workspace is used in a group as default workspace, delete the link foreach (Group::model()->findAllByAttributes(array('space_id' => $this->id)) as $group) { $group->space_id = ""; $group->save(); } Wall::model()->deleteAllByAttributes(array('id' => $this->wall_id)); return parent::beforeDelete(); }
/** * Sets an SpaceSetting * * @param String $name * @param String $value * @param String $moduleId */ public function setSetting($name, $value, $moduleId = "") { SpaceSetting::Set($this->getOwner()->id, $name, $value, $moduleId); }
/** * Return an array with all space settings * @param $space * @return array */ protected function getSpaceSettings($space) { $function = SpaceSetting::Get($space->id, 'functions', 'reputation', ReputationBase::DEFAULT_FUNCTION); $logarithmBase = SpaceSetting::Get($space->id, 'logarithm_base', 'reputation', ReputationBase::DEFAULT_LOGARITHM_BASE); $create_content = SpaceSetting::Get($space->id, 'create_content', 'reputation', ReputationBase::DEFAULT_CREATE_CONTENT); $smb_likes_content = SpaceSetting::Get($space->id, 'smb_likes_content', 'reputation', ReputationBase::DEFAULT_SMB_LIKES_CONTENT); $smb_favorites_content = SpaceSetting::Get($space->id, 'smb_favorites_content', 'reputation', ReputationBase::DEFAULT_SMB_FAVORITES_CONTENT); $smb_comments_content = SpaceSetting::Get($space->id, 'smb_comments_content', 'reputation', ReputationBase::DEFAULT_SMB_COMMENTS_CONTENT); $daily_limit = SpaceSetting::Get($space->id, 'daily_limit', 'reputation', ReputationBase::DEFAULT_DAILY_LIMIT); $decrease_weighting = SpaceSetting::Get($space->id, 'decrease_weighting', 'reputation', ReputationBase::DEFAULT_DECREASE_WEIGHTING); $lambda_short = SpaceSetting::Get($space->id, 'lambda_short', 'reputation', ReputationBase::DEFAULT_LAMBDA_SHORT); $lambda_long = SpaceSetting::Get($space->id, 'lambda_long', 'reputation', ReputationBase::DEFAULT_LAMBDA_LONG); $ranking_new_period = SpaceSetting::Get($space->id, 'ranking_new_period', 'reputation', ReputationBase::DEFAULT_RANKING_NEW_PERIOD); $spaceSettings = array($function, $logarithmBase, $create_content, $smb_likes_content, $smb_favorites_content, $smb_comments_content, $daily_limit, $decrease_weighting, $lambda_short, $lambda_long, $ranking_new_period); return $spaceSettings; }
<?php $space = $reputation->space; if ($space == null || $reputation->visibility == 0 && Yii::app()->user->id != $reputation->user_id) { continue; } ?> <?php // Hidden field to get users on this page echo CHtml::hiddenField("reputationUsers[" . $reputation->space_id . "]", $reputation->space_id); // Hidden field to get users on this page echo CHtml::hiddenField('reputationUser_' . $reputation->space_id . "[placeholder]", 1); ?> <?php $function = SpaceSetting::Get($space->id, 'functions', 'reputation', ReputationUser::DEFAULT_FUNCTION); ?> <tr> <td width="28px" style="vertical-align: middle"> <a href="<?php echo $user->getUrl(); ?> "> <img class="media-object img-rounded" src="<?php echo $space->getProfileImage()->getUrl(); ?> " width="24" height="24" alt="24x24" data-src="holder.js/24x24"