Example #1
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Update a metadata field. Taken from https://secure.php.net/manual/en/class.mongogridfs.php
  * @param string $name - the name of the metadata field to update/insert
  * @param mixed $value - the value to put in.
  */
 protected function updateField($name, $value)
 {
     $gridFs = ConnectionHandler::getInstance()->getConnection();
     $this->mGridFsFile->file[$name] = $value;
     $gridFs->save($this->mGridFsFile->file);
 }
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;
 }