getClass(self::CLASS_LTI_INCOMINGLINK); // search for existing resource $instances = $class->searchInstances([ self::PROPERTY_LINK_ID => $resourceLink, self::PROPERTY_CONSUMER => $consumerId ], ['like' => false,'recursive' => false]); if (count($instances) > 1) { throw new \common_exception_Error('Multiple resources for link ' . $resourceLink); } if (count($instances) == 1) { // use existing link $ltiLink = current($instances); } else { // spawn new link $ltiLink = $class->createInstanceWithProperties([ self::PROPERTY_LINK_ID => $resourceLink, self::PROPERTY_CONSUMER => $consumerId ]); } return $ltiLink->getUri(); } }