/** * 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; }