Course::class, 'foreign_key' => 'course_id' ]; $config['belongs_to']['deployment'] = [ 'class_name' => LtiDeployment::class, 'foreign_key' => 'deployment_id' ]; $config['registered_callbacks']['before_create'] = ['cbCalculatePosition']; parent::configure($config); } /** * Calculates the position for a new LTI resource link in the course. */ public function cbCalculatePosition() : void { $this->position = self::countByCourse_id($this->course_id); } /** * Delete this entity. */ public function delete() { $course_id = $this->course_id; $position = $this->position; if ($result = parent::delete()) { DBManager::get()->execute( "UPDATE `lti_resource_links` SET `position` = position - 1 WHERE `course_id` = :course_id AND `position` > :position", [ 'course_id' => $course_id, 'position' => $position ] ); } return $result; } /** * Find a single entry by course_id and position. * * @return static|null */ public static function findByCourseAndPosition($course_id, $position) { return self::findOneBySQL('course_id = ? AND position = ?', [$course_id, $position]); } //OAT library LtiResourceLinkInterface and ResourceInterface implementation: public function getUrl(): ?string { if ($this->deployment) { return $this->deployment->getLaunchURL(); } return null; } public function getIcon(): ?array { return null; } public function getThumbnail(): ?array { if ($this->course) { return [$this->course->getItemAvatarURL()]; } return null; } public function getIframe(): ?array { //Not supported. return null; } public function getCustom(): ?array { //Not supported. return null; } public function getLineItem(): ?array { // TODO: Implement getLineItem() method. return null; } public function getAvailability(): ?array { // TODO: Implement getAvailability() method. return null; } public function getSubmission(): ?array { // TODO: Implement getSubmission() method. return null; } public function getIdentifier(): string { return strval($this->id); } public function getType(): string { return 'ltiResourceLink'; } public function getTitle(): ?string { if ($this->deployment) { return $this->deployment->title; } return null; } public function getText(): ?string { return null; } public function getProperties(): CollectionInterface { $collection = new Collection(); $collection->add([ 'url' => $this->getUrl(), 'title' => $this->getTitle() ]); return $collection; } public function normalize(): array { return array_filter( array_merge( $this->getProperties()->all(), ['type' => $this->getType()] ) ); } }