/**
  * @param int $resourceId
  * @return BookableResource
  */
 public function LoadById($resourceId)
 {
     if (!$this->_cache->Exists($resourceId)) {
         $resource = $this->LoadResource(new GetResourceByIdCommand($resourceId));
         $this->_cache->Add($resourceId, $resource);
     }
     return $this->_cache->Get($resourceId);
 }
Exemple #2
0
 public function LoadById($groupId)
 {
     if ($this->_cache->Exists($groupId)) {
         return $this->_cache->Get($groupId);
     }
     $group = null;
     $db = ServiceLocator::GetDatabase();
     $reader = $db->Query(new GetGroupByIdCommand($groupId));
     if ($row = $reader->GetRow()) {
         $group = new Group($row[ColumnNames::GROUP_ID], $row[ColumnNames::GROUP_NAME]);
         $group->WithGroupAdmin($row[ColumnNames::GROUP_ADMIN_GROUP_ID]);
     }
     $reader->Free();
     $reader = $db->Query(new GetAllGroupUsersCommand($groupId, AccountStatus::ACTIVE));
     while ($row = $reader->GetRow()) {
         $group->WithUser($row[ColumnNames::USER_ID]);
     }
     $reader->Free();
     $reader = $db->Query(new GetAllGroupPermissionsCommand($groupId));
     while ($row = $reader->GetRow()) {
         $group->WithPermission($row[ColumnNames::RESOURCE_ID]);
     }
     $reader->Free();
     $reader = $db->Query(new GetAllGroupRolesCommand($groupId));
     while ($row = $reader->GetRow()) {
         $group->WithRole($row[ColumnNames::ROLE_ID]);
     }
     $reader->Free();
     $this->_cache->Add($groupId, $group);
     return $group;
 }
 /**
  * @param int|CustomAttributeCategory $category
  * @return array|CustomAttribute[]
  */
 public function GetByCategory($category)
 {
     if (!$this->cache->Exists($category)) {
         $reader = ServiceLocator::GetDatabase()->Query(new GetAttributesByCategoryCommand($category));
         $attributes = array();
         while ($row = $reader->GetRow()) {
             $attributes[] = CustomAttribute::FromRow($row);
         }
         $this->cache->Add($category, $attributes);
     }
     return $this->cache->Get($category);
 }
Exemple #4
0
 /**
  * @param $command SqlCommand
  * @return User
  */
 private function Load($command)
 {
     $reader = ServiceLocator::GetDatabase()->Query($command);
     if ($row = $reader->GetRow()) {
         $userId = $row[ColumnNames::USER_ID];
         $emailPreferences = $this->LoadEmailPreferences($userId);
         $permissions = $this->LoadPermissions($userId);
         $groups = $this->LoadGroups($userId);
         $user = User::FromRow($row);
         $user->WithEmailPreferences($emailPreferences);
         $user->WithPermissions($permissions);
         $user->WithGroups($groups);
         $this->LoadAttributes($userId, $user);
         if ($user->IsGroupAdmin()) {
             $ownedGroups = $this->LoadOwnedGroups($userId);
             $user->WithOwnedGroups($ownedGroups);
         }
         $preferences = $this->LoadPreferences($userId);
         $user->WithPreferences($preferences);
         $user->WithDefaultSchedule($row[ColumnNames::DEFAULT_SCHEDULE_ID]);
         $this->_cache->Add($userId, $user);
         return $user;
     } else {
         return User::Null();
     }
 }