Load resource link object.

@param ResourceLink $resourceLink Resource_Link object

@return boolean True if the resource link object was successfully loaded
190784
public function loadResourceLink($resourceLink)
    {

        $ok = false;
        if (!empty($resourceLink->getRecordId())) {
            $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
                           "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
                           'WHERE (resource_link_pk = %d)',
                           $resourceLink->getRecordId());
        } else if (!empty($resourceLink->getContext())) {
            $sql = sprintf('SELECT resource_link_pk, context_pk, consumer_pk, lti_resource_link_id, settings, primary_resource_link_pk, share_approved, created, updated ' .
                           "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' ' .
                           'WHERE (context_pk = %d) AND (lti_resource_link_id = %s)',
                           $resourceLink->getContext()->getRecordId(), DataConnector::quoted($resourceLink->getId()));
        } else {
            $sql = sprintf('SELECT r.resource_link_pk, r.context_pk, r.consumer_pk, r.lti_resource_link_id, r.settings, r.primary_resource_link_pk, r.share_approved, r.created, r.updated ' .
                           "FROM {$this->dbTableNamePrefix}" . DataConnector::RESOURCE_LINK_TABLE_NAME . ' r LEFT OUTER JOIN ' .
                           $this->dbTableNamePrefix . DataConnector::CONTEXT_TABLE_NAME . ' c ON r.context_pk = c.context_pk ' .
                           ' WHERE ((r.consumer_pk = %d) OR (c.consumer_pk = %d)) AND (lti_resource_link_id = %s)',
                           $resourceLink->getConsumer()->getRecordId(), $resourceLink->getConsumer()->getRecordId(), DataConnector::quoted($resourceLink->getId()));
        }
        $rsContext = mysql_query($sql);
        if ($rsContext) {
            $row = mysql_fetch_object($rsContext);
            if ($row) {
                $resourceLink->setRecordId(intval($row->resource_link_pk));
                if (!is_null($row->context_pk)) {
                    $resourceLink->setContextId(intval($row->context_pk));
                } else {
                    $resourceLink->setContextId(null);
                }
                if (!is_null($row->consumer_pk)) {
                    $resourceLink->setConsumerId(intval($row->consumer_pk));
                } else {
                    $resourceLink->setConsumerId(null);
                }
                $resourceLink->ltiResourceLinkId = $row->lti_resource_link_id;
                $settings = unserialize($row->settings);
                if (!is_array($settings)) {
                    $settings = array();
                }
                $resourceLink->setSettings($settings);
                if (!is_null($row->primary_resource_link_pk)) {
                    $resourceLink->primaryResourceLinkId = intval($row->primary_resource_link_pk);
                } else {
                    $resourceLink->primaryResourceLinkId = null;
                }
                $resourceLink->shareApproved = (is_null($row->share_approved)) ? null : (intval($row->share_approved) === 1);
                $resourceLink->created = strtotime($row->created);
                $resourceLink->updated = strtotime($row->updated);
                $ok = true;
            }
        }

        return $ok;

    }
69197
public function hasResource(ResourceInterface $otherResource) {
		if ($this->isEmpty()) {
			return false;
		}
		if ($this->type === RelationshipObject::TO_ONE) {
			return $this->resource->getResource()->equals($otherResource->getResource());
		}
		if ($this->type === RelationshipObject::TO_MANY) {
			foreach ($this->resources as $ownResource) {
				if ($ownResource->getResource()->equals($otherResource->getResource())) {
					return true;
				}
			}
		}
		
		return false;
	}
52200
public function load(LoadResourceEvent $event)
    {
        /** @var Shortcut $shortcut */
        $shortcut = $event->getResource();

        $this->resourceLifecycle->load($shortcut->getTarget());
    }
1086592
public function hasLink(Link $compared)
    {
        foreach ($this->links as $link) {
            if ($this->linksMatch($link, $compared)) {
                return true;
            }
        }

        return false;
    }
522516
private function isLinkDecorable($link)
    {
        if (!is_object($link) || !property_exists($link, 'type')) {
            return false;
        }

        return $link->type == 'notes' || $link->type == 'exceptions';
    }
281652
function load( $uri, $extraParameters = false, $returnResourceData = false )
    {
        $resourceData = $this->loadURIRoot( $uri, true, $extraParameters );
        if ( !$resourceData or
             $resourceData['root-node'] === null )
        {
            $retValue = null;
            return $retValue;
        }
        else
            return $resourceData['root-node'];
    }
252314
protected function LinkWithSearch($link) {
        // Whitelist to avoid side effects
        $params=array(
                    'q'=>(array)$this->request->getVar('q'),
                    'tag'=>$this->request->getVar('tag'),
                    'creator'=>$this->request->getVar('creator'),
                    'ParentID'=>$this->request->getVar('ParentID')
                );
        
        $link=Controller::join_links(
                                    $link,
                                    (array_filter(array_values($params)) ? '?'.http_build_query($params):null)
                                );
        
        $this->extend('updateLinkWithSearch', $link);
        return $link;
    }
564278
private function getLinkObject(string $resourceClass, string $operationId, string $path): array
    {
        $linkObject = $identifiers = [];
        foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $propertyName) {
            $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
            if (!$propertyMetadata->isIdentifier()) {
                continue;
            }

            $linkObject['parameters'][$propertyName] = sprintf('$response.body#/%s', $propertyName);
            $identifiers[] = $propertyName;
        }

        if (!$linkObject) {
            return [];
        }
        $linkObject['operationId'] = $operationId;
        $linkObject['description'] = 1 === \count($identifiers) ? sprintf('The `%1$s` value returned in the response can be used as the `%1$s` parameter in `GET %2$s`.', $identifiers[0], $path) : sprintf('The values returned in the response can be used in `GET %s`.', $path);

        return $linkObject;
    }
1105303
public function loadResourceLink($resourcelink) {
        global $DB;

        $resourceid = $resourcelink->getRecordId();
        if (!empty($resourceid)) {
            $params = ['id' => $resourceid];
            $row = $DB->get_record($this->resourcelinktable, $params);
        } else if (!empty($resourcelink->getContext())) {
            $params = [
                'contextid' => $resourcelink->getContext()->getRecordId(),
                'ltiresourcelinkkey' => $resourcelink->getId()
            ];
            $row = $DB->get_record($this->resourcelinktable, $params);
        } else {
            $sql = "SELECT r.*
                      FROM {{$this->resourcelinktable}} r
           LEFT OUTER JOIN {{$this->contexttable}} c
                        ON r.contextid = c.id
                     WHERE (r.consumerid = ? OR c.consumerid = ?)
                           AND ltiresourcelinkkey = ?";
            $params = [
                $resourcelink->getConsumer()->getRecordId(),
                $resourcelink->getConsumer()->getRecordId(),
                $resourcelink->getId()
            ];
            $row = $DB->get_record_sql($sql, $params);
        }
        if ($row) {
            $resourcelink->setRecordId($row->id);
            if (!is_null($row->contextid)) {
                $resourcelink->setContextId($row->contextid);
            } else {
                $resourcelink->setContextId(null);
            }
            if (!is_null($row->consumerid)) {
                $resourcelink->setConsumerId($row->consumerid);
            } else {
                $resourcelink->setConsumerId(null);
            }
            $resourcelink->ltiResourceLinkId = $row->ltiresourcelinkkey;
            $settings = unserialize($row->settings);
            if (!is_array($settings)) {
                $settings = array();
            }
            $resourcelink->setSettings($settings);
            if (!is_null($row->primaryresourcelinkid)) {
                $resourcelink->primaryResourceLinkId = $row->primaryresourcelinkid;
            } else {
                $resourcelink->primaryResourceLinkId = null;
            }
            $resourcelink->shareApproved = (is_null($row->shareapproved)) ? null : ($row->shareapproved == 1);
            $resourcelink->created = $row->created;
            $resourcelink->updated = $row->updated;
            return true;
        }

        return false;
    }
34709
protected function load()
    {
        if ($this->resources !== null) {
            return $this->count() > 0;
        }

        $this->resources = null;
        $this->index = 0;
        $this->loadResources();

        return $this->count() > 0;
    }
207613
public function hasLink( $link, &$linkDetail = null )
    {

        $links = $this->__get('links');

        if( isset($links[$link])) {
            $linkDetail = $links[$link];
            return $link;
        }

        foreach( $links as $via => $linkDetail ){
            if( in_array( $link, $linkDetail->foreignEntities ) ) {
                return $via;
            }
        }

        return false;

    }
16970
public function remove(ResourceRecord $resourceRecord): bool
    {
        foreach ($this->resourceRecords as $key => $_item) {
            if ($_item === $resourceRecord) {
                unset($this->resourceRecords[$key]);

                return true;
            }
        }

        return false;
    }
406996
private function annotationRel(array $annotations, LinkType $link, ResourceObject $current) : ResourceObject
    {
        /* @noinspection LoopWhichDoesNotLoopInspection */
        foreach ($annotations as $annotation) {
            if ($annotation->rel !== $link->key) {
                continue;
            }
            $uri = uri_template($annotation->href, $current->body);
            $rel = $this->factory->newInstance($uri);
            /* @noinspection UnnecessaryParenthesesInspection */
            $request = new Request($this->invoker, $rel, Request::GET, (new Uri($uri))->query);

            return $this->invoker->invoke($request);
        }

        throw new LinkRelException("rel:{$link->key} class:" . get_class($current), 500);
    }
583053
protected function loadResource(ResourceInterface $resource)
    {
        $res = $this->doLoad($resource);
        $this->notify($resource);

        return $res;
    }
919763
public function getSharesResourceLink($resourcelink) {
        global $DB;

        $shares = [];

        $params = ['primaryresourcelinkid' => $resourcelink->getRecordId()];
        $fields = 'id, shareapproved, consumerid';
        $records = $DB->get_records($this->resourcelinktable, $params, 'consumerid', $fields);
        foreach ($records as $record) {
            $share = new ResourceLinkShare();
            $share->resourceLinkId = $record->id;
            $share->approved = $record->shareapproved == 1;
            $shares[] = $share;
        }

        return $shares;
    }
1213039
public function setLink($link)
    {
        $relation = new RelationLink();
        $relation
            ->setRelationType('alternate')
            ->setUrl($link);
        return $this->setRelation($relation);
    }
1186950
public function isSitesResourceId($resourceId)
    {
        $needle = ResourceProvider::RESOURCE_SITES . '.';
        $length = strlen($needle);

        return (substr($resourceId, 0, $length) === $needle);
    }