Skip to content

Commit

Permalink
Merge branch 'release-8.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 17, 2024
2 parents 76728f5 + 13dfebe commit e908d12
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions models/CsvImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@

namespace oat\taoTestTaker\models;

use common_ext_ExtensionException;
use common_ext_ExtensionsManager;
use core_kernel_classes_Property;
use core_kernel_classes_Resource;
use core_kernel_persistence_Exception;
use core_kernel_users_Service;
use oat\generis\Helper\UserHashForEncryption;
use oat\generis\model\user\UserRdf;
use oat\oatbox\service\ServiceManager;
use oat\tao\model\TaoOntology;
use oat\generis\model\GenerisRdf;
use oat\taoTestTaker\models\events\dispatcher\TestTakerImportEventDispatcher;
use tao_helpers_form_FormFactory;
use tao_helpers_I18n;
use tao_models_classes_import_CsvImporter;

/**
* A custom subject CSV importer
Expand All @@ -37,7 +46,7 @@
* @package taoSubjects
*/
class CsvImporter extends \tao_models_classes_import_CsvImporter
class CsvImporter extends tao_models_classes_import_CsvImporter
{
public function import($class, $form, $userId = null)
{
Expand All @@ -57,29 +66,29 @@ function ($resource) {
public function getValidators()
{
return [
GenerisRdf::PROPERTY_USER_LOGIN => [\tao_helpers_form_FormFactory::getValidator('Unique')],
GenerisRdf::PROPERTY_USER_UILG => [\tao_helpers_form_FormFactory::getValidator('NotEmpty')],
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
* @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);
/** @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)
new core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_PASSWORD)
)->literal
];
}
Expand Down Expand Up @@ -110,7 +119,7 @@ protected function getExludedProperties()
*/
protected function getStaticData()
{
$lang = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri();
$lang = tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG)->getUri();

return [
GenerisRdf::PROPERTY_USER_DEFLG => $lang,
Expand All @@ -122,12 +131,12 @@ protected function getStaticData()
/**
* (non-PHPdoc)
* @see tao_models_classes_import_CsvImporter::getAdditionAdapterOptions()
* @throws \common_ext_ExtensionException
* @throws common_ext_ExtensionException
*/
protected function getAdditionAdapterOptions()
{
/** @var \common_ext_ExtensionsManager $extManager */
$extManager = ServiceManager::getServiceManager()->get(\common_ext_ExtensionsManager::SERVICE_ID);
/** @var common_ext_ExtensionsManager $extManager */
$extManager = ServiceManager::getServiceManager()->get(common_ext_ExtensionsManager::SERVICE_ID);
$taoTestTaker = $extManager->getExtensionById('taoTestTaker');
$config = $taoTestTaker->getConfig('csvImporterCallbacks');

Expand All @@ -146,6 +155,10 @@ protected function getAdditionAdapterOptions()
];
}

$returnValue['onResourceImported'] = [
$this->getResourceImportedCallback(),
];

return $returnValue;
}

Expand All @@ -157,7 +170,17 @@ protected function getAdditionAdapterOptions()
*/
public static function taoSubjectsPasswordEncode($value)
{
return \core_kernel_users_Service::getPasswordHash()->encrypt($value);
return core_kernel_users_Service::getPasswordHash()->encrypt($value);
}

private function getResourceImportedCallback(): callable
{
return function (core_kernel_classes_Resource $resource): void {
$resource->editPropertyValues(
new core_kernel_classes_Property(UserRdf::PROPERTY_DEFLG),
$resource->getOnePropertyValue(new core_kernel_classes_Property(UserRdf::PROPERTY_UILG))->getUri()
);
};
}

private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher
Expand Down

0 comments on commit e908d12

Please sign in to comment.