public function testToAPI() { $folder = new Folder(); $folder->setId(3); $folder->setName('name'); $this->assertEquals(array('id' => 3, 'name' => 'name'), $folder->toAPI()); }
public function testSerialize() { $folder = new Folder(); $folder->setId(3); $folder->setName('john'); $folder->setParentId(4); $folder->setUserId('abc'); $folder->setOpened(true); $folder->setDeletedAt(9); $this->assertEquals(['id' => 3, 'parentId' => 4, 'name' => 'john', 'userId' => 'abc', 'opened' => true, 'deletedAt' => 9], $folder->jsonSerialize()); }
public function testDelete() { $folder = new Folder(); $folder->setId(3); $sql = 'DELETE FROM `*PREFIX*news_folders` WHERE `id` = ?'; $arguments = array($folder->getId()); $sql2 = 'DELETE FROM `*PREFIX*news_feeds` WHERE `folder_id` = ?'; $sql3 = 'DELETE FROM `*PREFIX*news_items` WHERE `feed_id` NOT IN ' . '(SELECT `feeds`.`id` FROM `*PREFIX*news_feeds` `feeds`)'; $arguments2 = array($folder->getId()); $this->setMapperResult($sql, $arguments); $this->setMapperResult($sql2, $arguments2); $this->setMapperResult($sql3); $this->folderMapper->delete($folder); }
/** * @brief Store the folder and all its feeds into the database * @param folder the folder to be saved * @returns The id of the folder in the database table. */ public function save(Folder $folder) { $query = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(name, parent_id, user_id, opened) VALUES (?, ?, ?, ?) '); $name = $folder->getName(); if (empty($name)) { $l = \OC_L10N::get('news'); $name = $l->t('no name'); } $parentid = $folder->getParentId(); $params = array($name, $parentid, $this->userid, $folder->getOpened()); $query->execute($params); $folderid = \OCP\DB::insertid(self::tableName); $folder->setId($folderid); return $folderid; }
/** * Get Folder Info * * @param folderId - required - * The id of the folder. * @param includeFiles - optional - * Default = true. If true, the API returns * info about all the files in the specified folder, at this folder level only. * @param includeFolders - optional - * Default = true. If true, the API returns info about all * the sub folders, at this folder level only * @return The Folder object. If the operation was successful, the object contains the folder info, if not, the object * contains the error code and message. */ public function getFolderInfo($folderId, $includeFiles = '', $includeFolders = '') { $parameters = array(); if ($includeFiles !== '') { $parameters['includeFiles'] = $includeFiles; } if ($includeFolders !== '') { $parameters['includeFolders'] = $includeFolders; } $urld = 'dpi/v1/folder/' . $folderId; $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_GET, $this->authToken); $responseBody = simplexml_load_string($this->response); $returnObject = new Folder(); if ($responseBody === false) { $errorCode = 'N/A'; $errorMessage = 'The server has encountered an error, please try again.'; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } else { $errorStatus = $responseBody->errorStatus; if (empty($errorStatus)) { $returnObject->setRevision((string) $responseBody->attributes()->revision); $returnObject->setId((string) $responseBody->attributes()->id); $returnObject->setCreatedOn((string) $responseBody->createdOn); $returnObject->setName((string) $responseBody->name); $returnObject->setParentId((string) $responseBody->parentid); $returnObject->setReadable((string) $responseBody->readable); $returnObject->setSize((string) $responseBody->size); $returnObject->setType((string) $responseBody->type); $returnObject->setUpdatedOn((string) $responseBody->updatedOn); $returnObject->setWritable((string) $responseBody->writeable); $returnObject->setCurrentUsage((string) $responseBody->currentUsage); $returnObject->setStorageQuota((string) $responseBody->storageQuota); $fileCount = (string) $responseBody->fileCount; $returnObject->setFileCount($fileCount); $folderCount = (string) $responseBody->folderCount; $returnObject->setFolderCount($folderCount); if ($includeFiles) { $filesTag = $responseBody->files; if (!empty($filesTag)) { $allFiles = $responseBody->files->children(); $files = array(); if (!empty($allFiles)) { foreach ($allFiles as $currentFile) { $file = new File(); $file->setRevision((string) $currentFile->attributes()->revision); $file->setId((string) $currentFile->attributes()->id); $file->setCreatedOn((string) $currentFile->createdOn); $file->setName((string) $currentFile->name); $file->setParentId((string) $currentFile->parentid); $file->setSize((string) $currentFile->size); array_push($files, $file); } $returnObject->setFiles($files); } } } if ($includeFolders) { $foldersTag = $responseBody->folders; if (!empty($foldersTag)) { $allFolders = $responseBody->folders->children(); $folders = array(); if (!empty($allFolders)) { foreach ($allFolders as $currentFolder) { $folder = new Folder(); $folder->setRevision((string) $currentFolder->attributes()->revision); $folder->setId((string) $currentFolder->attributes()->id); $folder->setCreatedOn((string) $currentFolder->createdOn); $folder->setCurrentUsage((string) $currentFolder->currentUsage); $folder->setFileCount((string) $currentFolder->fileCount); $folder->setFolderCount((string) $currentFolder->folderCount); $folder->setName((string) $currentFolder->name); $folder->setParentId((string) $currentFolder->parentid); $folder->setReadable((string) $currentFolder->readable); $folder->setSize((string) $currentFolder->size); $folder->setType((string) $currentFolder->type); $folder->setUpdatedOn((string) $currentFolder->updatedOn); $folder->setWritable((string) $currentFolder->writeable); $folder->setOwnedByUser((string) $currentFolder->ownedByUser); array_push($folders, $folder); } $returnObject->setFolders($folders); } } } } else { $errorCode = (string) $responseBody->errorStatus->code; $errorMessage = (string) $responseBody->errorStatus->message; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } } return $returnObject; }
/** * Maps a Folder object contained in a recordset to an object representation * * @param $rs Recordset filled with the object data * @return objeto Mapped Folder object */ function &mapOne($rs) { if ($rs == null) { return null; } $object = new Folder(); $object->setId($rs->fields["ID"]); $object->setLongDescription($rs->fields["longDescription"]); $object->setParentId($rs->fields["parentID"]); $object->setPosition($rs->fields["position"]); $object->setShortDescription($rs->fields["shortDescription"]); $object->setTitle($rs->fields["title"]); return $object; }
/** * Updates a new folder */ function updateFolder() { $controllerData =& $this->collectControlerData(); $folderId = $controllerData["folderIdHidden"]; $title = $controllerData["titleText"]; $parentId = $controllerData["parentIdHidden"]; $position = $controllerData["positionText"]; $shortDescription = $controllerData["shortDescriptionText"]; $longDescription = $controllerData["longDescriptionTextarea"]; $classesIdArray = $controllerData["classesIdSelect"]; if ($title == null || $title == "") { $this->addErrorMessage("title"); } if ($shortDescription == null || $shortDescription == "") { $this->addErrorMessage("shortdescription"); } if ($longDescription == null || $longDescription == "") { $this->addErrorMessage("longdescription"); } if (count($classesIdArray) <= 0) { $this->addErrorMessage("classes"); } if (count($this->controllerMessageArray) > 0) { $this->displayUpdateFolderView("addFolder.tpl.php"); return; } $folder = new Folder(); $folder->setId($folderId); $folder->setTitle($title); $folder->setParentId($parentId); $folder->setPosition($position); $folder->setShortDescription($shortDescription); $folder->setLongDescription($longDescription); $folderClassesArray = array(); foreach ($classesIdArray as $classId) { $folderClass = new FolderClass(); $folderClass->setClassID($classId); $folderClass->setPosition(1); $folderClass->setIsDefault(0); array_push($folderClassesArray, $folderClass); } $folder->setFolderClasses($folderClassesArray); $folderService = new FolderService(); $folderService->update($folder); $this->redirectToReferer(); }