Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| TestTakerUpdate | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| propertyChange | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
30 | |||
| 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) 2016 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoProctoring\model\monitorCache\update; |
| 24 | |
| 25 | use oat\generis\model\GenerisRdf; |
| 26 | use oat\tao\model\event\MetadataModified; |
| 27 | use oat\taoProctoring\helpers\DeliveryHelper; |
| 28 | use oat\taoProctoring\model\monitorCache\DeliveryMonitoringService; |
| 29 | use oat\oatbox\service\ServiceManager; |
| 30 | use oat\tao\helpers\UserHelper; |
| 31 | use oat\taoTestTaker\models\TestTakerService; |
| 32 | |
| 33 | /** |
| 34 | * |
| 35 | * @package oat\taoProctoring |
| 36 | * @author Mikhail Kamarouski <kamarouski@1pt.com> |
| 37 | */ |
| 38 | class TestTakerUpdate |
| 39 | { |
| 40 | public static function propertyChange(MetadataModified $event) |
| 41 | { |
| 42 | $resource = $event->getResource(); |
| 43 | $service = ServiceManager::getServiceManager()->get(DeliveryMonitoringService::SERVICE_ID); |
| 44 | |
| 45 | $tracked = array_merge( |
| 46 | [GenerisRdf::PROPERTY_USER_FIRSTNAME, GenerisRdf::PROPERTY_USER_LASTNAME], |
| 47 | array_map( |
| 48 | function ($field) { |
| 49 | return $field['property']->getUri(); |
| 50 | }, |
| 51 | DeliveryHelper::getExtraFieldsProperties() |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | |
| 56 | if ( |
| 57 | in_array($event->getMetadataUri(), $tracked) |
| 58 | && $resource->hasType(new \core_kernel_classes_Class(TestTakerService::CLASS_URI_SUBJECT)) |
| 59 | ) { |
| 60 | $deliveryExecutionsData = $service->find([ |
| 61 | DeliveryMonitoringService::TEST_TAKER => $resource->getUri(), |
| 62 | ], []); |
| 63 | $user = new \core_kernel_users_GenerisUser($resource); |
| 64 | |
| 65 | foreach ($deliveryExecutionsData as $data) { |
| 66 | $data->update(DeliveryMonitoringService::TEST_TAKER_FIRST_NAME, UserHelper::getUserFirstName($user)); |
| 67 | $data->update(DeliveryMonitoringService::TEST_TAKER_LAST_NAME, UserHelper::getUserLastName($user)); |
| 68 | $success = $service->partialSave($data); |
| 69 | if (!$success) { |
| 70 | \common_Logger::w( |
| 71 | 'monitor cache for delivery ' . $data[DeliveryMonitoringService::DELIVERY_EXECUTION_ID] |
| 72 | . ' could not be updated. TestTaker data has not been changed' |
| 73 | ); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | } |