Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| IrregularityReport | |
0.00% |
0 / 34 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
| getIrregularitiesTable | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
72 | |||
| getUserName | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2017 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoProctoring\model\service; |
| 23 | |
| 24 | use oat\oatbox\service\ServiceManager; |
| 25 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 26 | use oat\taoOutcomeUi\model\ResultsService; |
| 27 | use oat\taoProctoring\model\deliveryLog\DeliveryLog; |
| 28 | use oat\tao\helpers\UserHelper; |
| 29 | use oat\oatbox\user\User; |
| 30 | use oat\taoProctoring\model\deliveryLog\event\DeliveryLogEvent; |
| 31 | |
| 32 | class IrregularityReport extends AbstractIrregularityReport |
| 33 | { |
| 34 | private $userNames = []; |
| 35 | |
| 36 | /** |
| 37 | * @param \core_kernel_classes_Resource $delivery |
| 38 | * @param string $from |
| 39 | * @param string $to |
| 40 | * @return array |
| 41 | */ |
| 42 | public function getIrregularitiesTable(\core_kernel_classes_Resource $delivery, $from = '', $to = '') |
| 43 | { |
| 44 | $export = [ |
| 45 | [__('date'), __('author'), __('test taker'), __('category'), __('subcategory'), __('comment')], |
| 46 | ]; |
| 47 | $deliveryLog = ServiceManager::getServiceManager()->get(DeliveryLog::SERVICE_ID); |
| 48 | $service = ResultsService::singleton(); |
| 49 | $implementation = $service->getReadableImplementation($delivery); |
| 50 | |
| 51 | $service->setImplementation($implementation); |
| 52 | |
| 53 | $results = $service->getImplementation()->getResultByDelivery([$delivery->getUri()]); |
| 54 | |
| 55 | foreach ($results as $res) { |
| 56 | $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($res['deliveryResultIdentifier']); |
| 57 | $logs = $deliveryLog->get( |
| 58 | $deliveryExecution->getIdentifier(), |
| 59 | DeliveryLogEvent::EVENT_ID_TEST_IRREGULARITY |
| 60 | ); |
| 61 | foreach ($logs as $data) { |
| 62 | $exportable = []; |
| 63 | if ((empty($from) || $data['created_at'] > $from) && (empty($to) || $data['created_at'] < $to)) { |
| 64 | $exportable[] = \tao_helpers_Date::displayeDate($data['created_at']); |
| 65 | $exportable[] = $this->getUserName($data['created_by']); |
| 66 | $exportable[] = $this->getUserName($res['testTakerIdentifier']); |
| 67 | $exportable[] = $data['data']['reason']['reasons']['category']; |
| 68 | $exportable[] = (isset($data['data']['reason']['reasons']['subCategory'])) |
| 69 | ? $data['data']['reason']['reasons']['subCategory'] |
| 70 | : ''; |
| 71 | $exportable[] = $data['data']['reason']['comment']; |
| 72 | $export[] = $exportable; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return $export; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @param string $userId |
| 82 | * @return string |
| 83 | */ |
| 84 | private function getUserName($userId) |
| 85 | { |
| 86 | if (!isset($this->userNames[$userId])) { |
| 87 | $user = UserHelper::getUser($userId); |
| 88 | $userName = UserHelper::getUserName($user, true); |
| 89 | if (empty($userName)) { |
| 90 | $userName = $userId; |
| 91 | } |
| 92 | $this->userNames[$userId] = $userName; |
| 93 | } |
| 94 | |
| 95 | return $this->userNames[$userId]; |
| 96 | } |
| 97 | } |