Example #1
0
 /**
  * Load this object from the provided document within the gridfs system.
  * @param MongoGridFSFile $doc - the doc that represents a file.
  * @return \MongoFile
  */
 public static function loadFromMongoDoc(MongoGridFSFile $doc)
 {
     $name = $doc->file['name'];
     $modificationTime = $doc->file['modification_time'];
     $creationTime = $doc->file['creation_time'];
     $parentFolder = MongoFolder::loadFromMongoId($doc->file['parent']);
     $mongoFile = new MongoFile($name, $parentFolder, $creationTime, $modificationTime, $doc);
     $mongoFile->mMongoId = $id;
     return $mongoFile;
 }
 /**
  * Load the root folder from which everything else is under.
  * @return MongoFolder
  */
 public static function loadRoot()
 {
     $gridfs = ConnectionHandler::getInstance()->getConnection();
     $conditions = array();
     $conditions[] = array("type" => "folder");
     $conditions[] = array("parent" => array('$exists' => false));
     $document = $gridfs->findOne(array('$and' => $conditions));
     $rootFolder = MongoFolder::loadFromMongoDoc($document);
     return $rootFolder;
 }
Example #3
0
 /**
  * Move this object to within the provided parent folder.
  * @param FolderInterface $parent - the folder we wish to move this file/folder to within.
  *
  * @return $this - this modified item.
  */
 public function setParentFolder(FolderInterface $parent)
 {
     $parentMongoFolder = MongoFolder::loadFromFolderInterface($parent);
     $this->updateField("parent", $parentMongoFolder->getMongoId());
     return $this;
 }
Example #4
0
 /**
  * Fetch an array of folders that are directly within this folder.
  * @return MongoFolder[]
  */
 public function getSubFolders()
 {
     $subfolders = array();
     $gridFs = ConnectionHandler::getInstance()->getConnection();
     $conditions = array();
     $conditions[] = array('parent' => $this->mGridFsFile->file['_id']);
     $conditions[] = array('type' => $this->mGridFsFile->file['folder']);
     $query = array('$and' => $conditions);
     $cursor = $gridFs->find($query);
     while (($folder = $cursor->getNext()) != null) {
         /* @var $folder MongoGridFsFile */
         $subfolders[] = MongoFolder::loadFromMongoDoc($folder);
     }
     return $subfolders;
 }