/** * * @author Patrick Plichart, patrick@taotesting.com * @param array $propertiesValues * @throws \common_exception_MissingParameter * @throws \common_exception_PreConditionFailure * @return \core_kernel_classes_Resource */ public function createFromArray($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"); } // 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] = ""; } // 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"); } $propertiesValues[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[PROPERTY_USER_PASSWORD]); $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; }
/** * Allows the remote system to change the data language * * @return string The json response * @throws common_Exception */ public function setDataLanguage() { $success = false; if (!$this->hasRequestParameter('lang')) { throw new common_Exception('Missing parameters'); } $user = $this->getCurrentUser(); $dataLangResource = tao_helpers_I18n::getLangResourceByCode($this->getRequestParameter('lang')); if (!is_null($dataLangResource)) { $success = $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_DEFLG), $dataLangResource); common_Logger::w('Data language changed to "' . $this->getRequestParameter('lang') . '"'); } else { common_Logger::w('language ' . $this->getRequestParameter('lang') . ' not found'); return $this->returnFailure(__('Language not supported')); } $this->returnSuccess(); }
/** * (non-PHPdoc) * @see tao_models_classes_import_CsvImporter::getStaticData() */ protected function getStaticData() { $lang = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri(); return array(PROPERTY_USER_DEFLG => $lang, PROPERTY_USER_TIMEZONE => TIME_ZONE, PROPERTY_USER_ROLES => INSTANCE_ROLE_DELIVERY); }