| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 0.00% | 0 / 14 |  | 0.00% | 0 / 1 | CRAP |  | 0.00% | 0 / 1 | 
| OntologyLink |  | 0.00% | 0 / 14 |  | 0.00% | 0 / 1 | 12 |  | 0.00% | 0 / 1 | 
| getLinkId |  | 0.00% | 0 / 14 |  | 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 (under the project TAO-PRODUCT); | 
| 19 | * | 
| 20 | * | 
| 21 | */ | 
| 22 | |
| 23 | namespace oat\taoLti\models\classes\ResourceLink; | 
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; | 
| 26 | use oat\generis\model\OntologyAwareTrait; | 
| 27 | |
| 28 | /** | 
| 29 | * Service to generate unique ids for consumers resource links | 
| 30 | * using the generis ontology | 
| 31 | * | 
| 32 | * @author joel bout (joel@taotesting.com) | 
| 33 | */ | 
| 34 | class OntologyLink extends ConfigurableService implements LinkService | 
| 35 | { | 
| 36 | use OntologyAwareTrait; | 
| 37 | |
| 38 | public const CLASS_LTI_INCOMINGLINK = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LtiIncomingLink'; | 
| 39 | |
| 40 | public const PROPERTY_LINK_ID = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LTILinkId'; | 
| 41 | |
| 42 | public const PROPERTY_CONSUMER = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#LTILinkConsumer'; | 
| 43 | |
| 44 | public const PROPERTY_LAUNCH_URL = 'http://www.tao.lu/Ontologies/TAOLTI.rdf#ResourceLinkLaunchUrl'; | 
| 45 | |
| 46 | public function getLinkId($consumerId, $resourceLink): string | 
| 47 | { | 
| 48 | $class = $this->getClass(self::CLASS_LTI_INCOMINGLINK); | 
| 49 | // search for existing resource | 
| 50 | $instances = $class->searchInstances([ | 
| 51 | self::PROPERTY_LINK_ID => $resourceLink, | 
| 52 | self::PROPERTY_CONSUMER => $consumerId | 
| 53 | ], ['like' => false,'recursive' => false]); | 
| 54 | if (count($instances) > 1) { | 
| 55 | throw new \common_exception_Error('Multiple resources for link ' . $resourceLink); | 
| 56 | } | 
| 57 | if (count($instances) == 1) { | 
| 58 | // use existing link | 
| 59 | $ltiLink = current($instances); | 
| 60 | } else { | 
| 61 | // spawn new link | 
| 62 | $ltiLink = $class->createInstanceWithProperties([ | 
| 63 | self::PROPERTY_LINK_ID => $resourceLink, | 
| 64 | self::PROPERTY_CONSUMER => $consumerId | 
| 65 | ]); | 
| 66 | } | 
| 67 | return $ltiLink->getUri(); | 
| 68 | } | 
| 69 | } |