src/snac/server/database/DBUtil.php
/**
     * Read Resource By Data
     *
     * Read a resource by title, href and type if it exists in database
     *
     * @param  \snac\data\Resource $resource Resource object to read
     * @return \snac\data\Resource|boolean The resource object or false if not in database
     */
Read Resource By Data
Read a resource by title, href and type if it exists in database


Read Resource By Data Read a resource by title href and type if it exists in database
public function readResourceByData(Resource $resource) {
        if ($resource === null)
            return false;
        $documentType = null;
        if ($resource->getDocumentType() != null)
            $documentType = $resource->getDocumentType()->getID();
        $result = $this->sql->selectResourceByData($resource->getTitle(), $resource->getLink(), $documentType);
        if ($result === false)
            return false;
        if (count($result) == 1) {
            return $this->populateResource($result[0]['id'], $result[0]['version']);
        } else {
            foreach ($result as $pair) {
                $other = $this->populateResource($pair['id'], $pair['version']);
                if ($resource->equals($other, false)){
                    return $other;
                }
            }
        }
        return false;
    }
public function readResourceByData ( Resource $ resource ) { if ( $ resource === null ) return false ; $ documentType = null ; if ( $ resource -> getDocumentType ( ) != null ) $ documentType = $ resource -> getDocumentType ( ) -> getID ( ) ; $ result = $ this -> sql -> selectResourceByData ( $ resource -> getTitle ( ) , $ resource -> getLink ( ) , $ documentType ) ; if ( $ result === false ) return false ; if ( count ( $ result ) == 1 ) { return $ this -> populateResource ( $ result [ 0 ] [ 'id' ] , $ result [ 0 ] [ 'version' ] ) ; } else { foreach ( $ result as $ pair ) { $ other = $ this -> populateResource ( $ pair [ 'id' ] , $ pair [ 'version' ] ) ; if ( $ resource -> equals ( $ other , false ) ) { return $ other ; } } } return false ; }
Read Resource By Data
 Read a resource by title, href and type if it exists in database
Read Resource By Data Read a resource by title href and type if it exists in database
// check if resource exists in database // check equality(not strict) and see if any other resources match // if so, return that matching resource