Skip to content

Commit

Permalink
chore: cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
siwane authored and siwane committed Jan 17, 2024
1 parent 668d93e commit 1e48c52
Showing 1 changed file with 13 additions and 31 deletions.
44 changes: 13 additions & 31 deletions models/CsvImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,8 @@
*/
class CsvImporter extends tao_models_classes_import_CsvImporter
{
private function addResourceImportedCallback($form)
{
$callback = function (core_kernel_classes_Resource $resource) {
\common_Logger::i(__METHOD__);

$resource->editPropertyValues(
new core_kernel_classes_Property(UserRdf::PROPERTY_DEFLG),
$resource->getOnePropertyValue(new core_kernel_classes_Property(UserRdf::PROPERTY_UILG))->getUri()
);
};

if ($form instanceof tao_helpers_form_Form) {
$values = $form->getValues();
$values['onResourceImported'][] = $callback;
$form->setValues($values);
} else {
$form['onResourceImported'][] = $callback;
}

return $form;
}

public function import($class, $form, $userId = null)
{
$form = $this->addResourceImportedCallback($form);

$report = parent::import($class, $form);

$this->getTestTakerImportEventDispatcher()
Expand Down Expand Up @@ -180,13 +156,9 @@ protected function getAdditionAdapterOptions()
];
}

$returnValue['onResourceImported'] = [];
$returnValue['onResourceImported'][] = function (core_kernel_classes_Resource $resource) {
$resource->editPropertyValues(
new core_kernel_classes_Property(UserRdf::PROPERTY_DEFLG),
$resource->getOnePropertyValue(new core_kernel_classes_Property(UserRdf::PROPERTY_UILG))->getUri()
);
};
$returnValue['onResourceImported'] = [
$this->getResourceImportedCallback(),
];

return $returnValue;
}
Expand All @@ -202,6 +174,16 @@ public static function taoSubjectsPasswordEncode($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
{
return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class);
Expand Down

0 comments on commit 1e48c52

Please sign in to comment.