Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| taoItems_actions_Category | |
0.00% |
0 / 30 |
|
0.00% |
0 / 4 |
182 | |
0.00% |
0 / 1 |
| getExposedsByClass | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| setExposed | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
56 | |||
| returnBadParameter | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| returnSuccess | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 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-2018 (original work) Open Assessment Technologies SA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | use oat\taoItems\model\CategoryService; |
| 23 | use oat\generis\model\OntologyAwareTrait; |
| 24 | |
| 25 | /** |
| 26 | * Category controller |
| 27 | * How to expose RDF properties to categorize them. |
| 28 | * |
| 29 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 30 | */ |
| 31 | class taoItems_actions_Category extends tao_actions_CommonModule |
| 32 | { |
| 33 | use OntologyAwareTrait; |
| 34 | |
| 35 | /** |
| 36 | * Request |
| 37 | * taoItems/Category/getExposedsByClass?id=${classUri} |
| 38 | * Response |
| 39 | * { success : bool, data : { propUri : exposed } } |
| 40 | */ |
| 41 | public function getExposedsByClass() |
| 42 | { |
| 43 | $id = $this->getRequestParameter('id'); |
| 44 | |
| 45 | if (is_null($id) || empty($id)) { |
| 46 | return $this->returnBadParameter('The class URI is required'); |
| 47 | } |
| 48 | |
| 49 | $class = $this->getClass($id); |
| 50 | |
| 51 | $service = $this->getServiceLocator()->get(CategoryService::SERVICE_ID); |
| 52 | |
| 53 | $data = []; |
| 54 | $properties = $service->getElligibleProperties($class); |
| 55 | foreach ($properties as $property) { |
| 56 | $data[$property->getUri()] = $service->doesExposeCategory($property); |
| 57 | } |
| 58 | |
| 59 | return $this->returnSuccess($data); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Request |
| 64 | * taoItems/Category/setExposed?id=${propUri}&expose=(true|false) |
| 65 | * Response |
| 66 | * { success : bool, data : bool} |
| 67 | */ |
| 68 | public function setExposed() |
| 69 | { |
| 70 | $id = $this->getRequestParameter('id'); |
| 71 | |
| 72 | if (is_null($id) || empty($id)) { |
| 73 | return $this->returnBadParameter('The property URI is required'); |
| 74 | } |
| 75 | |
| 76 | $exposed = $this->getRequestParameter('exposed'); |
| 77 | if (is_null($exposed) || empty($exposed) || ($exposed != 'true' && $exposed != 'false')) { |
| 78 | return $this->returnBadParameter('The exposed value is missing or incorrect'); |
| 79 | } |
| 80 | |
| 81 | $service = $this->getServiceLocator()->get(CategoryService::SERVICE_ID); |
| 82 | $service->exposeCategory(new \core_kernel_classes_Property($id), $exposed == 'true'); |
| 83 | |
| 84 | return $this->returnSuccess(true); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Format response when a wrong/missing parameter is sent |
| 89 | * |
| 90 | * @param string $message the error message |
| 91 | * |
| 92 | * @return void |
| 93 | */ |
| 94 | private function returnBadParameter($message) |
| 95 | { |
| 96 | return $this->returnJson([ |
| 97 | 'success' => false, |
| 98 | 'errorCode' => 412, |
| 99 | 'errorMsg' => $message, |
| 100 | 'version' => TAO_VERSION |
| 101 | ], 412); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Format successful response |
| 106 | * |
| 107 | * @param mixed $data the response data |
| 108 | * |
| 109 | * @return void |
| 110 | */ |
| 111 | private function returnSuccess($data) |
| 112 | { |
| 113 | return $this->returnJson([ |
| 114 | 'success' => true, |
| 115 | 'data' => $data, |
| 116 | 'version' => TAO_VERSION |
| 117 | ]); |
| 118 | } |
| 119 | } |