* @package generis */ class core_kernel_users_GenerisUser extends common_user_User implements UserInternalInterface { /** * @var string identifier of user */ private $identifier; private $cache; private $cachedProperties = [ GenerisRdf::PROPERTY_USER_DEFLG, GenerisRdf::PROPERTY_USER_ROLES, GenerisRdf::PROPERTY_USER_UILG, GenerisRdf::PROPERTY_USER_FIRSTNAME, GenerisRdf::PROPERTY_USER_LASTNAME, GenerisRdf::PROPERTY_USER_LOGIN, GenerisRdf::PROPERTY_USER_TIMEZONE, ]; public function __construct(core_kernel_classes_Resource $user) { $this->identifier = $user->getUri(); // load datalanguage to prevent cycle later on $this->getPropertyValues(GenerisRdf::PROPERTY_USER_DEFLG); } public function getIdentifier() { return $this->identifier; } private function getUserResource() { return new core_kernel_classes_Resource($this->getIdentifier()); } public function getPropertyValues($property) { if (!in_array($property, $this->cachedProperties)) { return $this->getUncached($property); } elseif (!isset($this->cache[$property])) { $this->cache[$property] = $this->getUncached($property); } return $this->cache[$property]; } private function getUncached($property) { $value = []; switch ($property) { case GenerisRdf::PROPERTY_USER_DEFLG: case GenerisRdf::PROPERTY_USER_UILG: $resource = $this->getUserResource()->getOnePropertyValue(new core_kernel_classes_Property($property)); if (!is_null($resource)) { if ($resource instanceof core_kernel_classes_Resource) { $value = (string)$resource->getUniquePropertyValue(new core_kernel_classes_Property(OntologyRdf::RDF_VALUE)); return [$value]; } else { common_Logger::w('Language ' . $resource . ' is not a resource'); return [DEFAULT_LANG]; } } else { return [DEFAULT_LANG]; } break; default: return $this->getUserResource()->getPropertyValues(new core_kernel_classes_Property($property)); } } public function refresh() { $this->roles = false; $this->cache = [ GenerisRdf::PROPERTY_USER_DEFLG => $this->getUncached(GenerisRdf::PROPERTY_USER_DEFLG) ]; return true; } }