Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TestTakerImporter | |
0.00% |
0 / 20 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| import | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getUserClass | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| triggerUserUpdated | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoTestTaker\models; |
| 22 | |
| 23 | use oat\generis\Helper\UserHashForEncryption; |
| 24 | use oat\generis\model\OntologyRdf; |
| 25 | use oat\generis\model\user\UserRdf; |
| 26 | use oat\oatbox\event\EventManager; |
| 27 | use oat\tao\model\TaoOntology; |
| 28 | use oat\tao\model\user\import\RdsUserImportService; |
| 29 | use oat\tao\model\user\TaoRoles; |
| 30 | use oat\taoTestTaker\models\events\TestTakerUpdatedEvent; |
| 31 | |
| 32 | /** |
| 33 | * Class TestTakerImporter |
| 34 | * |
| 35 | * Implementation of RdsUserImportService to import test-taker resource from a CSV |
| 36 | * |
| 37 | * ` |
| 38 | * $userImporter = $this->getServiceLocator()->get(UserCsvImporterFactory::SERVICE_ID); |
| 39 | * $importer = $userImporter->getImporter(TestTakerImporter::USER_IMPORTER_TYPE); |
| 40 | * $report = $importer->import($filePath); |
| 41 | * ` |
| 42 | * |
| 43 | * or by command line: |
| 44 | * ` |
| 45 | * sudo -u www-data php index.php 'oat\tao\scripts\tools\import\ImportUsersCsv' -t test-taker |
| 46 | * -f tao/test/user/import/example.csv |
| 47 | * ` |
| 48 | * @package oat\taoTestTaker\models |
| 49 | */ |
| 50 | class TestTakerImporter extends RdsUserImportService |
| 51 | { |
| 52 | public const USER_IMPORTER_TYPE = 'test-taker'; |
| 53 | |
| 54 | /** |
| 55 | * Add test taker role to user to import |
| 56 | * |
| 57 | * @param $filePath |
| 58 | * @param array $extraProperties |
| 59 | * @param array $options |
| 60 | * @return \common_report_Report |
| 61 | * @throws \Exception |
| 62 | * @throws \common_exception_Error |
| 63 | */ |
| 64 | public function import($filePath, $extraProperties = [], $options = []) |
| 65 | { |
| 66 | $extraProperties[UserRdf::PROPERTY_ROLES] = TaoRoles::DELIVERY; |
| 67 | $extraProperties['roles'] = TaoRoles::DELIVERY; |
| 68 | return parent::import($filePath, $extraProperties, $options); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Add rds class to test-taker resource |
| 73 | * |
| 74 | * If type $properties exists, use it |
| 75 | * If there is not then use subject root class |
| 76 | * |
| 77 | * @param array $properties |
| 78 | * @return \core_kernel_classes_Class |
| 79 | */ |
| 80 | protected function getUserClass(array $properties) |
| 81 | { |
| 82 | $testtakerRootClass = $this->getClass(TaoOntology::CLASS_URI_SUBJECT); |
| 83 | if (isset($properties[OntologyRdf::RDF_TYPE])) { |
| 84 | $class = $this->getClass($properties[OntologyRdf::RDF_TYPE]); |
| 85 | if ($class->isSubClassOf($testtakerRootClass)) { |
| 86 | return $class; |
| 87 | } |
| 88 | } |
| 89 | return $testtakerRootClass; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Trigger a TestTakerUpdatedEvent at user import |
| 94 | * |
| 95 | * @param \core_kernel_classes_Resource $resource |
| 96 | * @param array $properties |
| 97 | * @param string $plainPassword |
| 98 | */ |
| 99 | protected function triggerUserUpdated(\core_kernel_classes_Resource $resource, array $properties, $plainPassword) |
| 100 | { |
| 101 | /** @var EventManager $eventManager */ |
| 102 | $eventManager = $this->getServiceLocator()->get(EventManager::SERVICE_ID); |
| 103 | $eventManager->trigger(new TestTakerUpdatedEvent( |
| 104 | $resource->getUri(), |
| 105 | array_merge( |
| 106 | $properties, |
| 107 | [ |
| 108 | 'hashForKey' => UserHashForEncryption::hash($plainPassword) |
| 109 | ] |
| 110 | ) |
| 111 | )); |
| 112 | } |
| 113 | } |