/** @return $files [urn => OmekaFile] Fetches all files that belong to this Item. Obeys Omeka->$dbUsage. */ public function getFiles() { if ($this->files === null) { if (Config::getOmeka()->getDbUsage()) { $this->files = OmekaFile::getFilesFromDbByItem($this); } else { $this->files = array(); $url = $this->data['files']['url']; foreach (Config::getOmeka()->httpGet($url) as $fData) { $file = new OmekaFile($fData); $this->files[$file->getUrn()] = $file; } } } return $this->files; }
/** @param $scanRectangleMap [scanUrn => [rectangle]] @param $user User, see auth/user.php @param $type int, see AreaOfInterestType @param $typeText String || null, see AreaOfInterestType @return $aoi AreaOfInterest || Exception Tries to create a new AreaOfInterest. Constraints: $scanUrn keys of $scanRectangleMap must be valid URNs for scans table. $scanRectangleMap must pass AreaOfInterestUrn::createUrn(). $type must pass AreaOfInterestType::validType(). $typeText may only be !== null, if AreaOfInterestType::hasText($type). Created urn may only have maximum length of 250. */ public static function createAOI($scanRectangleMap, $user, $type, $typeText = null) { $fail = function ($reason) { //Fail helper return new Exception("Problem in AreaOfInterest::createAOI(…). Reason: {$reason}"); }; //Checking some constraints: if (!is_array($scanRectangleMap)) { return $fail('$scanRectangleMap must be an array.'); } if (!$user instanceof User) { return $fail('$user must be instance of auth/user.php.'); } if (!AreaOfInterestType::validType($type)) { return $fail('$type has invalid/unexpected value.'); } if ($typeText !== null) { if (is_string($typeText)) { if (!AreaOfInterestType::hasText($type)) { return $fail('$typeText given when it was not allowed.'); } else { //Storing empty string in db instead of null: $typeText = ''; } } else { return $fail('Invalid value for $typeText: ' . $typeText); } } //Checking scan URNs: $scanUrns = array_keys($scanRectangleMap); if (!OmekaFile::validateUrns($scanUrns)) { return $fail('At least one urn was invalid. $urns: ' . json_encode($scanUrns)); } //Trying to create URN: $urn = AreaOfInterestUrn::createUrn($scanRectangleMap); if ($urn instanceof Exception) { $msg = $urn->getMessage(); return $fail('Could not create URN. ' . $msg); } if (strlen($urn) > 250) { return $fail("\$urn is longer than 250 chars: '{$urn}'."); } //Input valid, can create AreaOfInterest: $q = 'INSERT INTO areasOfInterest (urn,userId,typeEnum,typeText) VALUES (?,?,?,?)'; $stmt = Config::getDB()->prepare($q); $stmt->bind_param('siis', $urn, $user->getUserId(), $type, $typeText); $stmt->execute(); $stmt->close(); //Creating entries for scanAoiMap: $q = 'INSERT INTO scanAoiMap (aoiUrn, scanUrn) VALUES (?,?)'; foreach ($scanUrns as $scanUrn) { $stmt = Config::getDB()->prepare($q); $stmt->bind_param('ss', $urn, $scanUrn); $stmt->execute(); $stmt->close; } //Return AOI, iff possible: return self::getAOIFromUrn($urn); }
<?php /** This file is concerend with displaying a single OmekaFile. To do so, it expects a urn GET parameter to be given. If the urn parameter is missing, errors/noGet.php will be required. If the urn parameter is invalid, errors/invalidUrn.php will be required. Else the page will be displayed as expected. */ require_once 'config.php'; if (!isset($_GET['urn']) || !$_GET['urn']) { require 'errors/noGet.php'; } else { if (is_null(Config::getUserManager()->verify())) { require 'errors/loginRequired.php'; } else { $file = OmekaFile::getFileFromDb($_GET['urn']); if ($file === null) { require 'errors/invalidUrn.php'; } else { //We need to hand out some file info as JSON: $json = array(); //Function to add an OmekaFile $file to a $field String in the $json array. $addFile = function ($field, $file) use(&$json) { $arr = array('urn' => $file->getUrn(), 'img' => $file->getFullsizeFileUrl(), 'aois' => array()); foreach ($file->getAOIs() as $aoi) { $urn = $aoi->getUrn(); $arr['aois'][$urn] = $aoi->toArray(); } $json[$field] = $arr; }; //Adding {current, prev, main}:
/** @param $comparator '<' || '>' @return $f OmekaFile || null Helper function for get{Next,Prev}(). */ private function getNeighbour($comparator) { //Sanitizing $comparator: if ($comparator !== '>' && $comparator !== '<') { return null; } $order = $comparator === '>' ? 'ASC' : 'DESC'; //Current $urn: $urn = $this->getUrn(); //Discovering $prefix for files that belong to the same item: $parts = explode('_', $urn); array_pop($parts); //Remove last part of urn $prefix = implode('_', $parts) . '%'; //Query to use: $q = "SELECT urn, omekaUrl, scanDataJSON FROM scans " . "WHERE urn LIKE ? AND urn {$comparator} ? " . "ORDER BY (urn) {$order} LIMIT 1"; $stmt = Config::getDB()->prepare($q); $stmt->bind_param('ss', $prefix, $urn); $f = OmekaFile::fileFromDbData($stmt); if (count($f) === 1) { return current($f); } return null; }