* @package taoSubjects */ class CsvImporter extends \tao_models_classes_import_CsvImporter { public function import($class, $form, $userId = null) { $report = parent::import($class, $form); $this->getTestTakerImportEventDispatcher() ->dispatch( $report, function ($resource) { return $this->getProperties($resource); } ); return $report; } public function getValidators() { return [ GenerisRdf::PROPERTY_USER_LOGIN => [\tao_helpers_form_FormFactory::getValidator('Unique')], GenerisRdf::PROPERTY_USER_UILG => [\tao_helpers_form_FormFactory::getValidator('NotEmpty')], ]; } /** * @param core_kernel_classes_Resource $resource * @return array * @throws \core_kernel_persistence_Exception * @throws \common_ext_ExtensionException */ protected function getProperties($resource) { /** @var \common_ext_ExtensionsManager $extManager */ $extManager = ServiceManager::getServiceManager()->get(\common_ext_ExtensionsManager::SERVICE_ID); $taoTestTaker = $extManager->getExtensionById('taoTestTaker'); $config = $taoTestTaker->getConfig('csvImporterCallbacks'); if ((bool)$config['use_properties_for_event']) { return [ 'hashForKey' => UserHashForEncryption::hash(TestTakerSavePasswordInMemory::getPassword()), GenerisRdf::PROPERTY_USER_PASSWORD => $resource->getOnePropertyValue( new \core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_PASSWORD) )->literal ]; } return []; } /** * (non-PHPdoc) * @see tao_models_classes_import_CsvImporter::getExludedProperties() */ protected function getExludedProperties() { return array_merge(parent::getExludedProperties(), [ GenerisRdf::PROPERTY_USER_DEFLG, GenerisRdf::PROPERTY_USER_ROLES, TaoOntology::PROPERTY_USER_LAST_EXTENSION, TaoOntology::PROPERTY_USER_FIRST_TIME, GenerisRdf::PROPERTY_USER_TIMEZONE ]); } /** * (non-PHPdoc) * @see tao_models_classes_import_CsvImporter::getStaticData() */ protected function getStaticData() { $lang = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri(); return [ GenerisRdf::PROPERTY_USER_DEFLG => $lang, GenerisRdf::PROPERTY_USER_TIMEZONE => TIME_ZONE, GenerisRdf::PROPERTY_USER_ROLES => TaoOntology::PROPERTY_INSTANCE_ROLE_DELIVERY, ]; } /** * (non-PHPdoc) * @see tao_models_classes_import_CsvImporter::getAdditionAdapterOptions() * @throws \common_ext_ExtensionException */ protected function getAdditionAdapterOptions() { /** @var \common_ext_ExtensionsManager $extManager */ $extManager = ServiceManager::getServiceManager()->get(\common_ext_ExtensionsManager::SERVICE_ID); $taoTestTaker = $extManager->getExtensionById('taoTestTaker'); $config = $taoTestTaker->getConfig('csvImporterCallbacks'); if (empty($config['callbacks'])) { $returnValue = [ 'callbacks' => [ '*' => ['trim'], GenerisRdf::PROPERTY_USER_PASSWORD => ['oat\taoTestTaker\models\CsvImporter::taoSubjectsPasswordEncode'] ] ]; } else { $returnValue = [ 'callbacks' => $config['callbacks'] ]; } return $returnValue; } /** * Wrapper for password hash * * @param string $value * @return string */ public static function taoSubjectsPasswordEncode($value) { return \core_kernel_users_Service::getPasswordHash()->encrypt($value); } private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher { return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class); } }