Example #1
0
 /**
  * Adds a new File folder to the specified parent File folder
  *
  * @param int $parentFileId Parent File folder Id
  * @param string $name (optional) File folder name
  * @return int New File folder Id
  * @throws Exception
  */
 function addFolder($parentFileId, $name = 'New Folder')
 {
     $parentFileId = (int) $parentFileId;
     $name = sYDB()->escape_string($name);
     if ($this->permissions->checkInternal($this->_uid, $parentFileId, "RSUB")) {
         // Create node in File Tree
         $fileId = $this->tree->add($parentFileId);
         $this->filetypes = new Filetypes();
         $type = $this->filetypes->getByCode('FLD');
         $ts = time();
         $sql = "INSERT INTO\n\t\t\t\t`yg_files_properties`\n\t\t\t\t\t(`OBJECTID`, `FOLDER`, `APPROVED`, `CREATEDTS`, `CHANGEDTS`, `FILENAME`, `FILETYPE`, `VERSION`)\n\t\t\t\tVALUES\n\t\t\t\t\t(?, '1', '1', ?, ?, '', ?, 1);";
         $result = sYDB()->Execute($sql, $fileId, $ts, $ts, $type[0]['OBJECTID']);
         if ($result === false) {
             throw new Exception(sYDB()->ErrorMsg());
         }
         $this->_db->Insert_ID();
         $this->permissions->copyTo($parentFileId, $fileId);
         $TargetFile = new File($fileId);
         $TargetFile->properties->setValue("NAME", $name);
         $sourceFile = new File($parentFileId);
         $TargetFile->views->copyTo($parentFileId, $sourceFile->getLatestVersion(), $fileId, $TargetFile->getLatestVersion());
         return $fileId;
     } else {
         return false;
     }
 }