Exemplo n.º 1
0
 /**
  * Adds a property to the folder.
  * @param Property $property The property to add.
  * @author Björn Hjortsten
  * @return void
  */
 protected function addProperty(Property $property)
 {
     $this->properties[$property->getSystemName()] = $property;
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * Creates a {@link PropertyType} from an object directly from a call to the API.
  * WARNING: If this is called with the wrong raw object, you may get warnings or even errors!
  * @param stdClass $rawProperty The raw object from the API-call.
  * @author Björn Hjortsten
  * @return Property
  */
 public static function createFromRawObject(stdClass $rawProperty)
 {
     $propertyValueType = Property::getPropertyValueTypeFromString($rawProperty->propertyType);
     switch ($propertyValueType) {
         case PropertyValueType::QB_Array:
             if ($rawProperty->multiplechoice == true) {
                 $value = explode('|', $rawProperty->value);
                 $value = array_filter($value);
             } else {
                 $value = strval($rawProperty->value);
             }
             $defaultValue = explode('|', $rawProperty->defaultValue);
             $defaultValue = array_filter($defaultValue);
             break;
         case PropertyValueType::QB_Bool:
             $value = (bool) $rawProperty->value;
             $defaultValue = (bool) $rawProperty->defaultValue;
             break;
         case PropertyValueType::QB_Date:
             $value = strtotime($rawProperty->value);
             $defaultValue = strtotime($rawProperty->defaultValue);
             break;
         case PropertyValueType::QB_Float:
             $value = floatval($rawProperty->value);
             $defaultValue = floatval($rawProperty->defaultValue);
             break;
         case PropertyValueType::QB_Int:
             $value = intval($rawProperty->value);
             $defaultValue = intval($rawProperty->defaultValue);
             break;
         default:
             if (isset($rawProperty->keywords) && (bool) $rawProperty->keywords === true) {
                 $value = explode('|', $rawProperty->value);
                 $defaultValue = explode('|', $rawProperty->defaultValue);
                 $value = array_filter($value);
                 $defaultValue = array_filter($defaultValue);
             } else {
                 $value = $rawProperty->value;
                 $defaultValue = $rawProperty->defaultValue;
             }
             break;
     }
     if (empty($value)) {
         $value = null;
     }
     if (empty($defaultValue)) {
         $defaultValue = null;
     }
     $property = new PropertyType(intval($rawProperty->id), $rawProperty->propertyName, $rawProperty->title, $value, $defaultValue, $propertyValueType, (bool) $rawProperty->multiplechoice, (bool) $rawProperty->editable);
     $property->qbankValueType = $rawProperty->propertyType;
     if (isset($rawProperty->editable)) {
         $property->editable = (bool) $rawProperty->editable;
     } else {
         $property->editable = null;
     }
     if (isset($rawProperty->mandatory)) {
         $property->mandatory = (bool) $rawProperty->mandatory;
     } else {
         $property->mandatory = null;
     }
     if (isset($rawProperty->keywords)) {
         $property->keywords = (bool) $rawProperty->keywords;
     } else {
         $property->keywords = null;
     }
     if (isset($rawProperty->link)) {
         $property->link = (bool) $rawProperty->link;
     } else {
         $property->link = null;
     }
     if (isset($rawProperty->info)) {
         $property->info = $rawProperty->info;
         if (empty($property->info)) {
             $property->info = null;
         }
     } else {
         $property->info = null;
     }
     return $property;
 }
Exemplo n.º 5
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;
 }