Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Gets a folder from QBank.
  * @param int $id The folders id.
  * @param bool $simple If true, gets {@link SimpleFolder}s, otherwise a {@link Folder}.
  * @param bool $recursive If the folders subfolders also should be returned.
  * @throws CommunicationException Thrown if something went wrong while getting the folder.
  * @throws ConnectionException Thrown if something went wrong with the connection.
  * @author Björn Hjortsten
  * @return mixed If $simple is TRUE and it may return an array of {@link SimpleFolder}s or a {@link SimpleFolder} depending on $recursive. If $simple is FALSE it will return a {@link Folder}.
  */
 public function getFolder($id, $simple = true, $recursive = false)
 {
     if ($recursive === true) {
         $calls[] = array('name' => 'subfolders', 'function' => 'getfolderstructure', 'arguments' => array('folderId' => $id, 'depth' => 23, 'fetchProperties' => !$simple));
     }
     $calls[] = array('name' => 'folder', 'function' => 'getfolderinformation', 'arguments' => array('folderId' => $id));
     $result = $this->call('batch', array('calls' => $calls));
     if ($result->results->folder->success !== true) {
         $this->wrapperLog->error('Error while getting folder: ' . $result->results->folder->error->message, array('code' => $result->results->folder->error->code, 'type' => $result->results->folder->error->type));
         throw new CommunicationException($result->results->folder->error->message, $result->results->folder->error->code, $result->results->folder->error->type);
     }
     $folder = $result->results->folder->folder;
     if ($simple === true) {
         $folder = new SimpleFolder($folder->name, $folder->tree, $folder->owner, strtotime($folder->created), strtotime($folder->updated));
     } else {
         $properties = array();
         foreach ($folder->properties as $property) {
             $properties[] = Property::createFromRawObject($property);
         }
         $folder = new Folder($folder->name, $folder->tree, $folder->owner, strtotime($folder->created), strtotime($folder->updated), $properties);
     }
     if ($recursive === true) {
         if ($result->results->subfolders->success !== true) {
             $this->wrapperLog->error('Error while getting folder: ' . $result->results->subfolders->error->message, array('code' => $result->results->subfolders->error->code, 'type' => $result->results->subfolders->error->type));
             throw new CommunicationException($result->results->subfolders->error->message, $result->results->subfolders->error->code, $result->results->subfolders->error->type);
         }
         if (is_array($result->results->subfolders->data)) {
             foreach ($result->results->subfolders->data as $subfolder) {
                 if ($simple === true) {
                     $folders[$subfolder->folderId] = new SimpleFolder($subfolder->name, $subfolder->tree, $subfolder->owner, strtotime($subfolder->created), strtotime($subfolder->updated));
                 } else {
                     $properties = array();
                     foreach ($subfolder->properties as $property) {
                         $properties[] = Property::createFromRawObject($property);
                     }
                     $folders[$subfolder->folderId] = new Folder($subfolder->name, $subfolder->tree, $subfolder->owner, strtotime($subfolder->created), strtotime($subfolder->updated), $properties);
                 }
             }
         }
         $folders[$folder->getId()] = $folder;
         if ($simple === false) {
             $folders = Folder::createTree($folders);
             return $folders[$folder->getId()];
         }
         $folder = $folders;
     }
     return $folder;
 }