本文整理匯總了PHP中Folder::getAll方法的典型用法代碼示例。如果您正苦於以下問題:PHP Folder::getAll方法的具體用法?PHP Folder::getAll怎麽用?PHP Folder::getAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Folder
的用法示例。
在下文中一共展示了Folder::getAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addFolder
public function addFolder()
{
$form = new Form('form-addfolder', Router::getInstance()->build('BrowserController', 'addFolder'));
$fieldset = new Fieldset(System::getLanguage()->_('AddFolder'));
$name = new Text('name', System::getLanguage()->_('FolderName'), true);
$parent = new Select('parent', System::getLanguage()->_('ParentFolder'), Folder::getAll());
$parent->selected_value = Utils::getGET('parent', 0);
$fieldset->addElements($name, $parent);
$form->addElements($fieldset);
if (Utils::getPOST('submit', false) !== false) {
if ($form->validate()) {
try {
$folder = new Folder($parent->selected_value);
$folder->addFolder($name->value);
if ($folder->id == 0) {
System::forwardToRoute(Router::getInstance()->build('BrowserController', 'index'));
} else {
System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder->id));
}
exit;
} catch (InvalidFolderNameException $e) {
$name->error = System::getLanguage()->_('ErrorInvalidFolderName');
} catch (FolderAlreadyExistsException $e) {
$name->error = System::getLanguage()->_('ErrorFolderAlreadyExists');
} catch (Exception $e) {
$name->error = System::getLanguage()->_('ErrorInvalidParameter');
}
}
}
$form->setSubmit(new Button(System::getLanguage()->_('Create'), 'icon icon-new-folder'));
$smarty = new Template();
$smarty->assign('title', System::getLanguage()->_('AddFolder'));
$smarty->assign('form', $form->__toString());
$smarty->display('form.tpl');
}
示例2: getAll
/**
* Gets a list of folders incl. subfolders
* @return object[]
*/
public static function getAll($parent = NULL, $keys = true, $exclude = array(), $prefix = ' / ')
{
$list = array();
// Add root folder if necessary
if ($parent == NULL) {
$list[] = $prefix;
}
$folders = Folder::find('parent', $parent);
if ($folders != NULL) {
if (!is_array($folders)) {
$folders = array($folders);
}
if (count($folders) > 0) {
foreach ($folders as $folder) {
if (!in_array($folder->id, $exclude)) {
if ($keys == true) {
$list[$folder->id] = $prefix . $folder->name;
} else {
$list[] = $prefix . $folder->name;
}
$list += Folder::getAll($folder->id, $keys, $exclude, $prefix . $folder->name . ' / ');
}
}
}
}
return $list;
}
示例3: upload
public function upload()
{
$form = new Form('form-upload', Router::getInstance()->build('UploadController', 'upload'));
$form->setAttribute('data-noajax', 'true');
$form->setEnctype();
$fieldset = new Fieldset(System::getLanguage()->_('General'));
$folderInput = new Select('folder', System::getLanguage()->_('ChooseFolder'), Folder::getAll());
$folderInput->selected_value = Utils::getGET('parent', NULL);
$fieldset->addElements($folderInput);
$form->addElements($fieldset);
$fieldset = new Fieldset(System::getLanguage()->_('FileUpload'));
$fileInput = new FileUpload('file', System::getLanguage()->_('ChooseFile'), false);
$fieldset->addElements($fileInput);
$form->addElements($fieldset);
if (DOWNLOAD_VIA_SERVER) {
$fieldset = new Fieldset(System::getLanguage()->_('UploadFromURL'));
$url = new Text('url', System::getLanguage()->_('EnterURL'), false);
$name = new Text('name', System::getLanguage()->_('Name'), false);
$name->setValue(System::getLanguage()->_('DownloadedFile'));
$fieldset->addElements($url, $name);
$form->addElements($fieldset);
}
$fieldset = new Fieldset(System::getLanguage()->_('PermissionSetting'));
$permissionInput = new Select('permissions', System::getLanguage()->_('Permission'), FilePermissions::getAll());
$permissionInput->selected_value = DEFAULT_FILE_PERMISSION;
$password = new Password('password', System::getLanguage()->_('Password'), false);
$fieldset->addElements($permissionInput, $password);
$form->addElements($fieldset);
if (Utils::getPOST('submit', false) != false) {
if ($permissionInput->selected_value == 2 && empty($password->value)) {
$password->error = System::getLanguage()->_('ErrorEmptyTextfield');
} else {
if ($form->validate() && (!empty($url->value) || !empty($fileInput->uploaded_file))) {
// Specify input control for error display
$err = empty($url->value) ? $fileInput : $url;
try {
$folder = Folder::find('_id', $folderInput->selected_value);
$file = new File();
$file->folder = $folder;
$file->permission = $permissionInput->selected_value;
$file->password = $password->value;
if (empty($url->value)) {
$file->filename = $fileInput->filename;
$file->upload($fileInput->uploaded_file);
} else {
$file->filename = $name->value;
$file->remote($url->value);
}
$file->save();
System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder));
exit;
} catch (UploadException $e) {
$fileInput->filename = '';
$fileInput->uploaded_file = '';
$err->error = $e->getMessage();
if ($e->getCode() != 0) {
$err->error .= ' Code: ' . $e->getCode();
}
} catch (QuotaExceededException $e) {
$err->error = System::getLanguage()->_('ErrorQuotaExceeded');
} catch (Exception $e) {
$fileInput->filename = '';
$fileInput->uploaded_file = '';
$err->error = System::getLanguage()->_('ErrorWhileUpload') . ' ' . $e->getMessage();
}
}
}
}
$form->setSubmit(new Button(System::getLanguage()->_('Upload'), 'open'));
if ($folderInput->selected_value == 0) {
$form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'index')));
} else {
$form->addButton(new Button(System::getLanguage()->_('Cancel'), '', Router::getInstance()->build('BrowserController', 'show', new Folder($folderInput->selected_value))));
}
$smarty = new Template();
$smarty->assign('title', System::getLanguage()->_('Upload'));
$smarty->assign('heading', System::getLanguage()->_('FileUpload'));
$smarty->assign('form', $form->__toString());
$smarty->assign('BODY_CLASS', 'preventreload');
$smarty->requireResource('upload');
$smarty->display('form.tpl');
}