/**
  * Load an existing Mongo object.
  * @param MongoId $id
  * @return MongoFile
  */
 public static function loadFromMongoId(MongoId $id)
 {
     $query = array("_id" => $id);
     $gridFs = ConnectionHandler::getInstance()->getConnection();
     /* @var $mongoDoc MongoGridFSFile */
     $mongoDoc = $gridFs->findOne($query);
     $mongoFile = MongoFolder::loadFromMongoDoc($mongoDoc);
     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;
 }
 /**
  * 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;
 }