Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
ItemUpdater
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 1
 catchItemRdfUpdatedEvent
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
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) 2016 (original work) Open Assessment Technologies SA
19 *
20 */
21
22namespace oat\taoQtiItem\model\Listener;
23
24use core_kernel_classes_Resource;
25use oat\oatbox\filesystem\File;
26use oat\taoItems\model\event\ItemRdfUpdatedEvent;
27use oat\taoQtiItem\model\qti\Parser;
28use oat\taoQtiItem\model\qti\Service;
29use taoItems_models_classes_itemModel;
30use taoItems_models_classes_ItemsService;
31
32/**
33 * synchronise item between database and QTI XMl
34 * @author Christophe GARCIA <christopheg@taotesting.com>
35 */
36class ItemUpdater
37{
38    /**
39     * synchronise item label
40     * @param ItemRdfUpdatedEvent $event
41     */
42    public static function catchItemRdfUpdatedEvent(ItemRdfUpdatedEvent $event)
43    {
44        $rdfItem = new core_kernel_classes_Resource($event->getItemUri());
45        $type = $rdfItem->getProperty(taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL);
46        /*@var $directory \oat\oatbox\filesystem\Directory */
47        $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem);
48        $itemModel = $rdfItem->getPropertyValues($type);
49        if ($directory->exists() && in_array(taoItems_models_classes_itemModel::CLASS_URI_QTI, $itemModel)) {
50            /* @var $file File */
51            $file = $directory->getFile(Service::QTI_ITEM_FILE);
52
53            $qtiParser = new Parser($file->read());
54            $qtiItem = $qtiParser->load();
55            $label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8');
56            $qtiItem->setAttribute('label', $label);
57            $file->put($qtiItem->toXML());
58        }
59    }
60}