Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ItemCategoriesService | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
72 | |
0.00% |
0 / 1 |
| getCategories | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
72 | |||
| 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 (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoQtiItem\model; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @author Antoine Robin, <antoine@taotesting.com> |
| 30 | * @package taoQtiItem |
| 31 | * |
| 32 | * @deprecated Use oat\taoItems\model\CategoryService instead |
| 33 | */ |
| 34 | class ItemCategoriesService extends ConfigurableService |
| 35 | { |
| 36 | public const SERVICE_ID = 'taoQtiItem/ItemCategories'; |
| 37 | |
| 38 | /** |
| 39 | * Get the categories link to the list of items in parameter. |
| 40 | * Theses categories come from a configurable list of properties. |
| 41 | * The category label is also set in a configurable list |
| 42 | * @param \core_kernel_classes_Resource[] $items |
| 43 | * @return array of categories for specified items |
| 44 | * ['itemUri' => ['CATEGORY1', 'CATEGORY2']] |
| 45 | */ |
| 46 | public function getCategories(array $items) |
| 47 | { |
| 48 | $categories = []; |
| 49 | $lookupProperties = $this->getOption('properties'); |
| 50 | if (!empty($lookupProperties)) { |
| 51 | foreach ($items as $item) { |
| 52 | $itemCategories = []; |
| 53 | if ($item instanceof \core_kernel_classes_Resource) { |
| 54 | $properties = $item->getPropertiesValues(array_keys($lookupProperties)); |
| 55 | foreach ($properties as $property => $propertyValues) { |
| 56 | foreach ($propertyValues as $value) { |
| 57 | $propertyValue = ($value instanceof \core_kernel_classes_Resource) |
| 58 | ? $value->getUri() |
| 59 | : (string)$value; |
| 60 | |
| 61 | if (isset($lookupProperties[$property][$propertyValue])) { |
| 62 | $itemCategories[] = $lookupProperties[$property][$propertyValue]; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | $categories[$item->getUri()] = $itemCategories; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return $categories; |
| 72 | } |
| 73 | } |