Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| taoItems_models_classes_CrudItemsService | |
0.00% |
0 / 24 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getRootClass | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getClassService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| createFromArray | |
0.00% |
0 / 17 |
|
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 | * |
| 19 | */ |
| 20 | |
| 21 | use oat\tao\model\TaoOntology; |
| 22 | use oat\generis\model\OntologyRdf; |
| 23 | use oat\generis\model\OntologyRdfs; |
| 24 | use oat\oatbox\event\EventManagerAwareTrait; |
| 25 | use oat\taoItems\model\event\ItemCreatedEvent; |
| 26 | |
| 27 | /** |
| 28 | * .Crud services implements basic CRUD services, orginally intended for REST controllers/ HTTP exception handlers |
| 29 | * Consequently the signatures and behaviors is closer to REST and throwing HTTP like exceptions |
| 30 | * |
| 31 | * |
| 32 | * |
| 33 | */ |
| 34 | class taoItems_models_classes_CrudItemsService extends tao_models_classes_CrudService |
| 35 | { |
| 36 | use EventManagerAwareTrait; |
| 37 | |
| 38 | protected $itemClass = null; |
| 39 | |
| 40 | protected $itemsServices = null; |
| 41 | |
| 42 | public function __construct() |
| 43 | { |
| 44 | parent::__construct(); |
| 45 | $this->itemClass = new core_kernel_classes_Class(TaoOntology::ITEM_CLASS_URI); |
| 46 | $this->itemsServices = taoItems_models_classes_ItemsService::singleton(); |
| 47 | } |
| 48 | |
| 49 | public function getRootClass() |
| 50 | { |
| 51 | return $this->itemClass; |
| 52 | } |
| 53 | |
| 54 | protected function getClassService() |
| 55 | { |
| 56 | return $this->itemsServices; |
| 57 | } |
| 58 | |
| 59 | public function delete($resource) |
| 60 | { |
| 61 | taoItems_models_classes_ItemsService::singleton()->deleteItem(new core_kernel_classes_Resource($resource)); |
| 62 | //parent::delete($resource) |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * @param array parameters an array of property uri and values |
| 69 | */ |
| 70 | public function createFromArray(array $propertiesValues) |
| 71 | { |
| 72 | |
| 73 | if (!isset($propertiesValues[OntologyRdfs::RDFS_LABEL])) { |
| 74 | $propertiesValues[OntologyRdfs::RDFS_LABEL] = ""; |
| 75 | } |
| 76 | |
| 77 | $type = isset($propertiesValues[OntologyRdf::RDF_TYPE]) |
| 78 | ? $propertiesValues[OntologyRdf::RDF_TYPE] |
| 79 | : $this->getRootClass(); |
| 80 | $label = $propertiesValues[OntologyRdfs::RDFS_LABEL]; |
| 81 | unset($propertiesValues[OntologyRdfs::RDFS_LABEL]); |
| 82 | unset($propertiesValues[OntologyRdf::RDF_TYPE]); |
| 83 | |
| 84 | $itemContent = null; |
| 85 | if (isset($propertiesValues[taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT])) { |
| 86 | $itemContent = $propertiesValues[taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT]; |
| 87 | unset($propertiesValues[taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT]); |
| 88 | } |
| 89 | $resource = parent::create($label, $type, $propertiesValues); |
| 90 | if (isset($itemContent)) { |
| 91 | $event = new ItemCreatedEvent($resource->getUri(), $itemContent); |
| 92 | $this->getEventManager()->trigger($event); |
| 93 | } |
| 94 | return $resource; |
| 95 | } |
| 96 | } |