Skip to content

Commit

Permalink
Merge branch 'release-7.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ionut-mihai-sandu-tao committed Jul 3, 2020
2 parents e213a9d + 3b237d3 commit e9f5335
Show file tree
Hide file tree
Showing 11 changed files with 343 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

composer.lock
vendor/
.idea/
34 changes: 20 additions & 14 deletions actions/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,44 @@
*
*/

declare(strict_types=1);

namespace oat\taoTestTaker\actions;

use common_report_Report;
use core_kernel_classes_Resource;
use oat\generis\Helper\UserHashForEncryption;
use oat\generis\model\GenerisRdf;
use oat\taoTestTaker\models\CsvImporter;
use oat\taoTestTaker\models\events\TestTakerImportedEvent;
use oat\taoTestTaker\models\TestTakerSavePasswordInMemory;
use tao_helpers_form_FormFactory;
use oat\taoTestTaker\models\RdfImporter;
use tao_actions_Import;
use tao_models_classes_import_CsvImporter;
use tao_models_classes_import_RdfImporter;

/**
* Extends the common Import class to exchange the generic
* CsvImporter with a subject specific one
*
* @author Bertrand Chevrier, <[email protected]>
*/
class Import extends \tao_actions_Import
class Import extends tao_actions_Import
{
/**
* (non-PHPdoc)
* @see tao_actions_Import::getAvailableImportHandlers()
* @inheritDoc
*/
public function getAvailableImportHandlers()
{
$returnValue = parent::getAvailableImportHandlers();

foreach (array_keys($returnValue) as $key) {
if ($returnValue[$key] instanceof \tao_models_classes_import_CsvImporter) {
$importer = new CsvImporter();
$importer->setValidators($this->getValidators());
$returnValue[$key] = $importer;
switch (get_class($returnValue[$key])) {
case tao_models_classes_import_CsvImporter::class:
$importer = new CsvImporter();
$importer->setValidators($this->getValidators());
$returnValue[$key] = $importer;

break;
case tao_models_classes_import_RdfImporter::class:
$importer = new RdfImporter();
$returnValue[$key] = $importer;

break;
}
}

Expand Down
16 changes: 11 additions & 5 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
* @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php
*
*/

use oat\taoTestTaker\models\routing\ApiRoute;
use oat\taoTestTaker\models\TestTakerService;
use oat\taoTestTaker\scripts\install\SetupConfig;
use oat\taoTestTaker\scripts\install\SetupTesttakerCsvImporter;

$extpath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$taopath = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'tao' . DIRECTORY_SEPARATOR;

Expand All @@ -34,7 +40,7 @@
'label' => 'Test-taker core extension',
'description' => 'TAO TestTaker extension',
'license' => 'GPL-2.0',
'version' => '7.5.1',
'version' => '7.7.1',
'author' => 'Open Assessment Technologies, CRP Henri Tudor',
'requires' => [
'generis' => '>=12.15.0',
Expand All @@ -49,17 +55,17 @@
dirname(__FILE__) . '/models/ontology/taosubject.rdf'
],
'php' => [
\oat\taoTestTaker\scripts\install\SetupConfig::class,
\oat\taoTestTaker\scripts\install\SetupTesttakerCsvImporter::class,
SetupConfig::class,
SetupTesttakerCsvImporter::class,
]
],
'update' => "oat\\taoTestTaker\\scripts\\update\\Updater",
'managementRole' => 'http://www.tao.lu/Ontologies/TAOSubject.rdf#SubjectsManagerRole',
'acl' => [
['grant', \oat\taoTestTaker\models\TestTakerService::ROLE_SUBJECT_MANAGER, ['ext' => 'taoTestTaker']]
['grant', TestTakerService::ROLE_SUBJECT_MANAGER, ['ext' => 'taoTestTaker']]
],
'routes' => [
'/taoTestTaker/api' => ['class' => \oat\taoTestTaker\models\routing\ApiRoute::class],
'/taoTestTaker/api' => ['class' => ApiRoute::class],
'/taoTestTaker' => 'oat\\taoTestTaker\\actions'
],
'constants' => [
Expand Down
35 changes: 17 additions & 18 deletions models/CsvImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*
* Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/

declare(strict_types=1);

namespace oat\taoTestTaker\models;

use common_Logger;
use common_report_Report;
use core_kernel_classes_Resource;
use oat\generis\Helper\UserHashForEncryption;
use oat\oatbox\service\ServiceManager;
use oat\oatbox\user\UserLanguageService;
use oat\tao\model\TaoOntology;
use oat\generis\model\GenerisRdf;
use oat\taoTestTaker\models\events\TestTakerImportedEvent;
use oat\taoTestTaker\models\events\dispatcher\TestTakerImportEventDispatcher;

/**
* A custom subject CSV importer
Expand All @@ -46,17 +43,14 @@ public function import($class, $form, $userId = null)
{
$report = parent::import($class, $form);

/** @var common_report_Report $success */
foreach ($report->getSuccesses() as $success) {
$resource = $success->getData();
try {
$this->getEventManager()->trigger(
new TestTakerImportedEvent($resource->getUri(), $this->getProperties($resource))
);
} catch (\Exception $e) {
common_Logger::e($e->getMessage());
}
}
$this->getTestTakerImportEventDispatcher()
->dispatch(
$report,
function ($resource)
{
return $this->getProperties($resource);
}
);

return $report;
}
Expand Down Expand Up @@ -164,4 +158,9 @@ public static function taoSubjectsPasswordEncode($value)
{
return \core_kernel_users_Service::getPasswordHash()->encrypt($value);
}

private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher
{
return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class);
}
}
56 changes: 56 additions & 0 deletions models/RdfImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/

declare(strict_types=1);

namespace oat\taoTestTaker\models;

use core_kernel_classes_Resource;
use oat\taoTestTaker\models\events\dispatcher\TestTakerImportEventDispatcher;
use tao_models_classes_import_RdfImporter;

class RdfImporter extends tao_models_classes_import_RdfImporter
{
public function import($class, $form, $userId = null)
{
$report = parent::import($class, $form);

$this->getTestTakerImportEventDispatcher()
->dispatch(
$report,
function ($resource)
{
return $this->getProperties($resource);
}
);

return $report;
}

protected function getProperties(core_kernel_classes_Resource $resource): array
{
return [];
}

private function getTestTakerImportEventDispatcher(): TestTakerImportEventDispatcher
{
return $this->getServiceLocator()->get(TestTakerImportEventDispatcher::class);
}
}
27 changes: 25 additions & 2 deletions models/events/TestTakerCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,41 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016 (original work) Open Assessment Technologies SA;
* Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA;
*
* @author Ivan klimchuk <[email protected]>
*/

declare(strict_types=1);

namespace oat\taoTestTaker\models\events;

use oat\tao\model\webhooks\WebhookSerializableEventInterface;

/**
* Class TestTakerCreatedEvent
* @package oat\taoTestTaker\models\events
*/
class TestTakerCreatedEvent extends AbstractTestTakerEvent
class TestTakerCreatedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface
{
private const WEBHOOK_EVENT_NAME = 'test-taker-created';

/**
* @inheritDoc
*/
public function getWebhookEventName()
{
return self::WEBHOOK_EVENT_NAME;
}

/**
* @inheritDoc
*/
public function serializeForWebhook()
{
return [
'testTakerUri' => $this->testTakerUri,
'unit' => 1
];
}
}
27 changes: 25 additions & 2 deletions models/events/TestTakerImportedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,41 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016 (original work) Open Assessment Technologies SA;
* Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA;
*
* @author Ivan klimchuk <[email protected]>
*/

declare(strict_types=1);

namespace oat\taoTestTaker\models\events;

use oat\tao\model\webhooks\WebhookSerializableEventInterface;

/**
* Class TestTakerImportedEvent
* @package oat\taoTestTaker\models\events
*/
class TestTakerImportedEvent extends AbstractTestTakerEvent
class TestTakerImportedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface
{
private const WEBHOOK_EVENT_NAME = 'test-taker-imported';

/**
* @inheritDoc
*/
public function getWebhookEventName()
{
return self::WEBHOOK_EVENT_NAME;
}

/**
* @inheritDoc
*/
public function serializeForWebhook()
{
return [
'testTakerUri' => $this->testTakerUri,
'unit' => 1
];
}
}
30 changes: 27 additions & 3 deletions models/events/TestTakerRemovedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,42 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016 (original work) Open Assessment Technologies SA;
* Copyright (c) 2016-2020 (original work) Open Assessment Technologies SA;
*
* @author Ivan klimchuk <[email protected]>
*/

declare(strict_types=1);

namespace oat\taoTestTaker\models\events;

use oat\tao\model\webhooks\WebhookSerializableEventInterface;

/**
* Class TestTakerRemovedEvent
* @package oat\taoTestTaker\models\events
*/
class TestTakerRemovedEvent extends AbstractTestTakerEvent
class TestTakerRemovedEvent extends AbstractTestTakerEvent implements WebhookSerializableEventInterface
{
const EVENT_NAME = __CLASS__;
private const WEBHOOK_EVENT_NAME = 'test-taker-removed';
public const EVENT_NAME = __CLASS__;

/**
* @inheritDoc
*/
public function getWebhookEventName()
{
return self::WEBHOOK_EVENT_NAME;
}

/**
* @inheritDoc
*/
public function serializeForWebhook()
{
return [
'testTakerUri' => $this->testTakerUri,
'unit' => 1
];
}
}
Loading

0 comments on commit e9f5335

Please sign in to comment.