getClassService()->deleteSubject(new \core_kernel_classes_Resource($resource)); return true; } /** * * @author Patrick Plichart, patrick@taotesting.com * @param array $propertiesValues * @return \core_kernel_classes_Resource * @throws \common_exception_Error * @throws \common_exception_MissingParameter * @throws \common_exception_PreConditionFailure * @throws \common_exception_ValidationFailed * @throws \oat\generis\model\user\PasswordConstraintsException */ public function createFromArray($propertiesValues = []) { // mandatory parameters if (! isset($propertiesValues[GenerisRdf::PROPERTY_USER_LOGIN])) { throw new \common_exception_MissingParameter("login"); } if (! isset($propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD])) { throw new \common_exception_MissingParameter("password"); } // validate parameters if (empty($propertiesValues[GenerisRdf::PROPERTY_USER_LOGIN])) { throw new \common_exception_ValidationFailed(GenerisRdf::PROPERTY_USER_LOGIN); } // default values and validation $propertiesValues[GenerisRdf::PROPERTY_USER_UILG] = self::readLangProperty($propertiesValues, GenerisRdf::PROPERTY_USER_UILG); $propertiesValues[GenerisRdf::PROPERTY_USER_DEFLG] = self::readLangProperty($propertiesValues, GenerisRdf::PROPERTY_USER_DEFLG); if (! isset($propertiesValues[OntologyRdfs::RDFS_LABEL])) { $propertiesValues[OntologyRdfs::RDFS_LABEL] = ""; } // check if login already exists $userService = \tao_models_classes_UserService::singleton(); if ($userService->loginExists($propertiesValues[GenerisRdf::PROPERTY_USER_LOGIN])) { throw new \common_exception_PreConditionFailure("login already exists"); } $propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD]); $type = isset($propertiesValues[OntologyRdf::RDF_TYPE]) ? $propertiesValues[OntologyRdf::RDF_TYPE] : $this->getRootClass(); $label = $propertiesValues[OntologyRdfs::RDFS_LABEL]; // hmmm unset($propertiesValues[OntologyRdfs::RDFS_LABEL]); unset($propertiesValues[OntologyRdf::RDF_TYPE]); $resource = parent::create($label, $type, $propertiesValues); $this->getClassService()->setTestTakerRole($resource); return $resource; } public function createFromLdapData($propertiesValues = array()) { $this->checkIfMandatoryParametersExist($propertiesValues); $this->checkIfLoginAlreadyExists($propertiesValues); $propertiesValues = $this->setDefaultPropertiesValues($propertiesValues); $propertiesValues[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encryptWithoutValidation($propertiesValues[PROPERTY_USER_PASSWORD]); return $this->createTestTakerResource($propertiesValues); } private function checkIfMandatoryParametersExist($propertiesValues = array()) { // mandatory parameters if (! isset($propertiesValues[PROPERTY_USER_LOGIN])) { throw new \common_exception_MissingParameter("login"); } if (! isset($propertiesValues[PROPERTY_USER_PASSWORD])) { throw new \common_exception_MissingParameter("password"); } } private function checkIfLoginAlreadyExists($propertiesValues = array()) { // check if login already exists $userService = \tao_models_classes_UserService::singleton(); if ($userService->loginExists($propertiesValues[PROPERTY_USER_LOGIN])) { throw new \common_exception_PreConditionFailure("login already exists"); } } private function setDefaultPropertiesValues($propertiesValues = array()) { // default values if (! isset($propertiesValues[PROPERTY_USER_UILG])) { $propertiesValues[PROPERTY_USER_UILG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG); } if (! isset($propertiesValues[PROPERTY_USER_DEFLG])) { $propertiesValues[PROPERTY_USER_DEFLG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG); } if (! isset($propertiesValues[RDFS_LABEL])) { $propertiesValues[RDFS_LABEL] = ""; } return $propertiesValues; } private function createTestTakerResource($propertiesValues = array()) { $type = isset($propertiesValues[RDF_TYPE]) ? $propertiesValues[RDF_TYPE] : $this->getRootClass(); $label = $propertiesValues[RDFS_LABEL]; // hmmm unset($propertiesValues[RDFS_LABEL]); unset($propertiesValues[RDF_TYPE]); $resource = parent::create($label, $type, $propertiesValues); $this->getClassService()->setTestTakerRole($resource); return $resource; } /** * (non-PHPdoc) * @see tao_models_classes_CrudService::update() */ public function update($uri = null, $propertiesValues = []) { if (is_null($uri)) { throw new \common_exception_MissingParameter("uri"); } if (isset($propertiesValues[GenerisRdf::PROPERTY_USER_LOGIN])) { throw new \common_exception_PreConditionFailure("login update not allowed"); } if (isset($propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD])) { $propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[GenerisRdf::PROPERTY_USER_PASSWORD]); } parent::update($uri, $propertiesValues); // throw new common_exception_NotImplemented(); } /** * @param array $properties * @param string $propKey * @return string * @throws \common_exception_Error * @throws \common_exception_ValidationFailed */ protected static function readLangProperty(array &$properties, $propKey) { if (!isset($properties[$propKey])) { return \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri(); } $existingUri = \tao_models_classes_LanguageService::getExistingLanguageUri($properties[$propKey]); if ($existingUri === null) { throw new \common_exception_ValidationFailed($propKey); } return $existingUri; } }