/** * Creates a {@link SimpleObject} 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 SimpleObject */ public static function createFromRawObject(stdClass $rawObject) { $object = new SimpleObject(intval($rawObject->objectId), intval($rawObject->mediaId), $rawObject->objectName, strtotime($rawObject->createdTime), strtotime($rawObject->updatedTime), intval($rawObject->objectType), $rawObject->objectTypeName, intval($rawObject->owner), $rawObject->filename, $rawObject->filetype, $rawObject->extension, $rawObject->filenameHashedThumb, intval($rawObject->filesize)); @(list($width, $height) = explode('x', $rawObject->imageWidthHeight)); $object->width = intval($width); $object->height = intval($height); @(list($width, $height) = explode('x', $rawObject->thumbWidthHeight)); $object->thumbnailWidth = intval($width); $object->thumbnailHeigth = intval($height); if (isset($rawObject->publishedTo)) { if ($rawObject->publishedTo instanceof stdClass) { $rawObject->publishedTo = (array) $rawObject->publishedTo; } if (is_array($rawObject->publishedTo)) { foreach ($rawObject->publishedTo as $publishedTo) { if (is_numeric($publishedTo)) { $object->publishedTo[] = (int) $publishedTo; } } } } if (isset($rawObject->properties) && (is_array($rawObject->properties) || is_object($rawObject->properties))) { $properties = array(); foreach ($rawObject->properties as $rawProperty) { $properties[] = Property::createFromRawObject($rawProperty); } $object->setProperties($properties); } return $object; }
/** * 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; }
/** * 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; }
/** * Gets all the folders an object exists in. * @param SimpleObject $object The object to get the folders for. * @author Björn Hjortsten * @throws CommunicationException Thrown if something went went wrong getting the folders. * @throws ConnectionException Thrown if something went wrong with the connection. * @return array An array of {@link SimpleFolder}s. */ public function getFoldersByObject(SimpleObject $object) { $result = $this->call('getfoldersbyobjectid', array('objectId' => $object->getId())); if (is_array($result->folders)) { $folders = array(); foreach ($result->folders as $rawFolder) { $folders[] = new SimpleFolder($rawFolder->name, $rawFolder->tree, $rawFolder->owner, strtotime($rawFolder->created), strtotime($rawFolder->updated)); } return $folders; } else { return array(); } }