/** * Gets an object from QBank * @param int $id The id of the object. * @throws CommunicationException Thrown if something went wrong while getting the object. * @throws ConnectionException Thrown if something went wrong with the connection. * @author Björn Hjortsten * @return Object */ public function getObject($id) { $result = $this->call('getobjectinformation', array('objectId' => $id)); return Object::createFromRawObject($result->data); }
/** * Processes the raw results from a QBank search and creates a {@link SearchResult}. * @param stdClass $result * @param bool $advanced Whether to populate the SearchResult with Advanced objects. * @author Björn Hjortsten * @return SearchResult */ protected function processResult($result, $advanced = false) { if (is_array($result->data->searchResults) && !empty($result->data->searchResults)) { foreach ($result->data->searchResults as $rawObject) { $objects[] = SimpleObject::createFromRawObject($rawObject); } if ($advanced === true) { foreach ($objects as $key => $object) { $calls[] = array('name' => $key, 'function' => 'getobjectinformation', 'arguments' => array('objectId' => $object->getId())); } $result2 = $this->call('batch', array('calls' => $calls), true); $objects = array(); foreach ($result2->results as $res) { $objects[] = Object::createFromRawObject($res->data); } } } else { $objects = array(); } $searchResult = new SearchResult($objects, intval($result->data->counter), $result->data->timeSearching, $result->data->step, $result->data->timeStamp, $result->data->end); return $searchResult; }
/** * Creates an {@link Object} from an object directly from the API. * WARNING: If this is called with the wrong raw object, you may get warnings or even errors! * @param stdClass $rawObject The raw object from the API-call. * @author Björn Hjortsten * @return Object */ public static function createFromRawObject(stdClass $rawObject) { $object = new Object(intval($rawObject->information->id), intval($rawObject->information->mediaId), $rawObject->information->name, strtotime($rawObject->information->createdTime), strtotime($rawObject->information->updatedTime), strtotime($rawObject->information->uploadTime), intval($rawObject->information->objectType), $rawObject->information->objectTypeName, $rawObject->information->version, intval($rawObject->information->owner), $rawObject->information->filename, $rawObject->information->contentType, $rawObject->information->extension, $rawObject->information->filenameHashedThumb, intval($rawObject->information->filesize), (bool) $rawObject->information->deleted); @(list($width, $height) = explode('x', $rawObject->information->imageWidthHeight)); $object->width = intval($width); $object->height = intval($height); @(list($width, $height) = explode('x', $rawObject->information->previewWidthHeight)); $object->previewWidth = intval($width); $object->previewHeight = intval($height); @(list($width, $height) = explode('x', $rawObject->information->thumbWidthHeight)); $object->thumbnailWidth = intval($width); $object->thumbnailHeigth = intval($height); $object->colorspace = $rawObject->information->colorspace; $object->icc = $rawObject->information->iccprofile; @(list($width, $height) = explode('x', $rawObject->information->resolution)); $object->resolutionWidth = intval($width); $object->resolutionHeight = intval($height); $object->length = $rawObject->information->length; $object->bitsPerSecond = $rawObject->information->bps; foreach ($rawObject->properties as $rawProperty) { $properties[] = Property::createFromRawObject($rawProperty); } if (@is_array($properties)) { $object->setProperties($properties); } foreach ($rawObject->children as $child) { $children[] = SimpleObject::createFromRawObject($child); } if (@is_array($children)) { $object->setChildren($children); } return $object; }