/**
  * Returns the RoomMembership Record for this Room
  *
  * If none Record is found, null is given
  */
 public function getMembership($userId = "")
 {
     if ($userId == "") {
         $userId = Yii::app()->user->id;
     }
     $rCacheId = 'RoomMembership_' . $userId . "_" . $this->getOwner()->id;
     $rCacheRes = RuntimeCache::Get($rCacheId);
     if ($rCacheRes != null) {
         return $rCacheRes;
     }
     $dbResult = RoomMembership::model()->findByAttributes(array('user_id' => $userId, 'room_id' => $this->getOwner()->id));
     RuntimeCache::Set($rCacheId, $dbResult);
     return $dbResult;
 }
Esempio n. 2
0
 /**
  * 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;
 }