The DocumentManager class provides the core API and management functions for uploading documents and managing document libraries.
More...
The DocumentManager class provides the core API and management functions for uploading documents and managing document libraries.
- Author
- Andy Green
Definition at line 70 of file document_manager.inc.
◆ buildDocumentLibraryForm()
static DocumentManager::buildDocumentLibraryForm |
( |
|
$library | ) |
|
|
static |
Definition at line 691 of file document_manager.inc.
694 $form->hide(
"owner_id",
"allow_access",
"manage_folders",
"upload_files",
"delete_files",
"create_date");
695 $form->required(
"name",
"identifier");
696 $form->annotate(
"allow_comments",
"Allow users to comment on documents from the document details page (if commenting is enabled).");
698 $form->allowDelete =
true;
◆ createLibrary()
static DocumentManager::createLibrary |
( |
|
$form | ) |
|
|
static |
Definition at line 632 of file document_manager.inc.
634 $d =
$form->data->getLibraryDirectory();
if(!checkRole($library->allow_access) &&! $library->allowAccess()) if(!checkRole($document->allow_access)) $d
◆ createLibraryObj()
static DocumentManager::createLibraryObj |
( |
| ) |
|
|
static |
Definition at line 608 of file document_manager.inc.
618 $library->allow_access = $defaultRole;
619 $library->manage_folders = $defaultRole;
620 $library->upload_files = $defaultRole;
621 $library->delete_files = $defaultRole;
625 $library->filter =
new InclusionFilter(
"document_library_id",
"name",
626 "identifier",
"description",
"owner_id",
"last_modified",
627 "allow_access",
"manage_folders",
"upload_files",
"delete_files",
"create_date");
static getDefaultRole($fileshare=false)
◆ deleteDocument()
DocumentManager::deleteDocument |
( |
|
$document | ) |
|
Delete the specified document (assuming the user has permission).
- Parameters
-
Document | $document | the document object to be deleted |
- Returns
- boolean true if the document was successfully deleted, false otherwise
Definition at line 485 of file document_manager.inc.
487 $fullPath = $this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR .
$document->file;
488 if (file_exists($fullPath))
if(! $document_id) $document
◆ deleteDocumentLibrary()
DocumentManager::deleteDocumentLibrary |
( |
| ) |
|
Definition at line 637 of file document_manager.inc.
646 $folders = $this->library->Folders();
647 if(count($folders) > 0)
655 $fileshareUsers = $this->library->FileshareUsers();
656 if(count($fileshareUsers) > 0)
658 foreach($fileshareUsers as $f_user)
662 $this->library->delete();
deleteDocument($document)
Delete the specified document (assuming the user has permission).
◆ deleteFolder()
DocumentManager::deleteFolder |
( |
|
$folder | ) |
|
◆ deleteRole()
static DocumentManager::deleteRole |
( |
|
$del_role | ) |
|
|
static |
Definition at line 666 of file document_manager.inc.
670 $roleFields = array(
"upload_files",
"delete_files",
"manage_folders",
"allow_access");
671 foreach($roleFields as
$field)
static deleteRoleFromString(&$items, $del_role, $field="")
◆ deleteUser()
static DocumentManager::deleteUser |
( |
|
$user | ) |
|
|
static |
Respond to fired event DeleteUser.
Delete any records in this component that have dependencies on user object.
- Parameters
-
obj | $user | - class SiteUser or custom user class |
Definition at line 382 of file document_manager.inc.
387 trace(
"Component document is deleting objects dependent on user_id {$user_id}", 3);
389 $tx =
new DataTransaction();
403 $mgr->deleteDocumentLibrary();
409 $document->delete(
"WHERE owner_id={$user_id}");
412 $download->joinTransaction(
$tx);
413 $download->delete(
"WHERE user_id={$user_id}");
This class maps the publication table.
DocumentManager($library)
Creates a new DocumentManager for the specified library.
◆ displayLibrary()
static DocumentManager::displayLibrary |
( |
|
$identifier, |
|
|
& |
$continue |
|
) |
| |
|
static |
Definition at line 576 of file document_manager.inc.
589 if (!checkRole(
$page->role))
595 echo $pageView->drawView();
599 catch(DataNotFoundException $e)
static findByIdentifier($identifier, $constraint="")
ComponentPageView generates the page content for a component page, substituting page fields,...
static findByIdentifier($identifier)
static storeRedirectPage()
Store the page from which a user has been redirected when prompted to login or create an account.
◆ documentLibraryTabs()
static DocumentManager::documentLibraryTabs |
( |
|
$key | ) |
|
|
static |
Definition at line 680 of file document_manager.inc.
683 "Details" =>
"document_library_form",
684 "Files" =>
"document_library_files"
687 $qs = ($key) ?
"document_library_id=$key" :
"";
688 return new TabBar(
"tabs",
$tabs,
$qs);
◆ DocumentManager()
DocumentManager::DocumentManager |
( |
|
$library | ) |
|
Creates a new DocumentManager for the specified library.
- Parameters
-
Definition at line 82 of file document_manager.inc.
85 if ($this->library->document_library_id)
87 $this->documents =
$library->Documents(
"ORDER BY title");
91 $this->documents = array();
◆ drawButtons()
DocumentManager::drawButtons |
( |
| ) |
|
Definition at line 338 of file document_manager.inc.
342 <button
id=
"download" class=
"button" disabled=
"disabled" onclick=
"downloadFile()"> Download File </button>&
nbsp;&
nbsp;
344 if (checkRole($this->library->upload_files))
347 <button
id=
"edit" class=
"button" disabled=
"disabled" onclick=
"editFile()">Edit Details...</button>&
nbsp;&
nbsp;
348 <button
id=
"upload" class=
"button" onclick=
"uploadFile()">Upload a File...</button>
352 if (checkRole($this->library->delete_files))
355 <button
id=
"deleteButton" class=
"button" disabled=
"disabled" onclick=
"deleteFile()">Delete File</button>&
nbsp;&
nbsp;
359 if (checkRole($this->library->manage_folders))
362 &
nbsp;&
nbsp;<button
id=
"createFolder" class=
"button" onclick=
"createFolder()">Create Folder...</button>&
nbsp;&
nbsp;
363 <button
id=
"deleteFolder" class=
"button" onclick=
"deleteFolder()">Delete Folder</button>&
nbsp;&
nbsp;
367 if (checkRole(
"admin"))
370 <button
id=
"rescan" class=
"button" onclick=
"rescanLibrary()">Rescan</button>
◆ drawSelectView()
DocumentManager::drawSelectView |
( |
|
$selectionChanged = "" , |
|
|
|
$doubleClick = "" , |
|
|
|
$width = 700 , |
|
|
|
$height = 400 |
|
) |
| |
Definition at line 510 of file document_manager.inc.
514 $tree =
new DirectoryTreeControl(
"files");
517 $tree->onSelectionChanged = $selectionChanged;
518 $tree->onDoubleClick = $doubleClick;
520 $tree->selectMode =
"file";
523 if ($this->documents)
525 $root = $this->library->getLibraryDirectory();
529 foreach($this->documents as $doc)
531 $file = str_replace(
"/", DIRECTORY_SEPARATOR, $doc->file);
532 $file = str_replace(
"\\", DIRECTORY_SEPARATOR,
$file);
535 $folderNode =
$tree->findFolder(dirname(
$file));
537 if ($folderNode !=
null)
539 trace(
"Found Folder {$folderNode->id} for document {$doc->document_id}", 4);
540 $id = str_replace(DIRECTORY_SEPARATOR,
"_",
$file);
541 $fileNode =
new FileNode(
$id, basename(
$file), $doc->document_id);
543 $folderNode->add($fileNode);
547 trace(
"*** NODE NOT FOUND - $file", 3);
551 $tree->children[
"documents"]->open =
true;
557 <div
style=
"width: <?echo $width?>px;height:<?echo $height?>px;border: solid 1px #000;">&
nbsp;</div>
folderPermission($folder)
◆ drawView()
DocumentManager::drawView |
( |
| ) |
|
Definition at line 288 of file document_manager.inc.
292 $tree =
new DirectoryTreeControl(
"files");
295 $tree->onSelectionChanged =
"selectionChanged";
296 $tree->onDoubleClick =
"downloadFile";
298 $tree->selectMode =
"file";
301 $root = $this->library->getLibraryDirectory();
305 foreach($this->documents as $doc)
308 if (!checkRole($doc->allow_access))
continue;
310 $file = str_replace(
"/", DIRECTORY_SEPARATOR, $doc->file);
311 $file = str_replace(
"\\", DIRECTORY_SEPARATOR,
$file);
314 $folderNode =
$tree->findFolder(dirname(
$file));
316 if ($folderNode !=
null)
318 trace(
"Found Folder {$folderNode->id}", 4);
319 $id = str_replace(DIRECTORY_SEPARATOR,
"_",
$file);
321 $folderNode->add(
new FileNode(
$id, basename(
$file), $doc->document_id));
325 trace(
"*** NODE NOT FOUND - $file", 3);
329 $tree->children[
"documents"]->open =
true;
331 $page->page_title =
"Documents";
◆ enumerateItems()
static DocumentManager::enumerateItems |
( |
|
$items | ) |
|
|
static |
◆ folderPermission()
DocumentManager::folderPermission |
( |
|
$folder | ) |
|
Definition at line 95 of file document_manager.inc.
101 if (strpos(
$folder,
"Board Members Only") !== FALSE && (!checkRole(
"board,admin,super") && !$this->library->allowManageFiles()))
106 trace(
"folderPermission: $folder ($permission)", 3);
◆ formatDocumentLink()
static DocumentManager::formatDocumentLink |
( |
|
$document | ) |
|
|
static |
Definition at line 721 of file document_manager.inc.
725 $img = DocumentHandler::getDocIcon(
$document->file);
727 return "<img src='$img' alt='' style='display: inline-block; vertical-align: middle'> ".
728 "<a href='/action/document/download?document_id={$document->document_id}'>{$document->title}</a> $size";
◆ formatLinkPickerTitle()
DocumentManager::formatLinkPickerTitle |
( |
|
$document | ) |
|
Definition at line 704 of file document_manager.inc.
715 $size =
"($file_size)";
718 return $document->format(
"<a style='display: inline' id='document_id_{document_id}' href='#' ondblclick=\"new LinkPicker().documentPickerInsertLink({document_id})\" onclick=\"new LinkPicker().toggleDocumentSelected(this, {document_id}); return false;\">{title}</a> <img style='display:inline; vertical-align: middle' src='$icon' alt='$type'/> $size");
◆ getMaxUploadBytes()
static DocumentManager::getMaxUploadBytes |
( |
| ) |
|
|
static |
Calculate the maximum allowed file upload size in bytes.
Definition at line 923 of file document_manager.inc.
925 $max = ini_get(
"upload_max_filesize");
927 if (endsWith(
$max,
"M"))
931 else if (endsWith(
$max,
"K"))
935 else if (endsWidth(
$max,
"G"))
937 $max *= 1024 * 1024 * 1024;
940 $postMax = ini_get(
"post_max_size");
942 if (endsWith($postMax,
"M"))
944 $postMax *= 1024 * 1024;
946 else if (endsWith($postMax,
"K"))
950 else if (endsWidth($postMax,
"G"))
952 $postMax *= 1024 * 1024 * 1024;
955 return min(
$max, $postMax);
◆ getMaxUploadSize()
static DocumentManager::getMaxUploadSize |
( |
| ) |
|
|
static |
Returns the maximum allowed file upload size in human-readable format.
Definition at line 961 of file document_manager.inc.
static getMaxUploadBytes()
Calculate the maximum allowed file upload size in bytes.
◆ getRoleList()
static DocumentManager::getRoleList |
( |
| ) |
|
|
static |
◆ getRoleOptions()
static DocumentManager::getRoleOptions |
( |
| ) |
|
|
static |
Definition at line 907 of file document_manager.inc.
910 $roles[
"visitor"] =
"Visitor";
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
◆ getStyles()
static DocumentManager::getStyles |
( |
| ) |
|
|
static |
◆ importMetaData()
DocumentManager::importMetaData |
( |
|
$file | ) |
|
Definition at line 782 of file document_manager.inc.
784 $this->indexedDocuments = reindexList($this->documents,
"file");
786 $fp = fopen(
$file,
"r");
788 $fields = fgetcsv($fp);
792 foreach($fields as
$field)
808 while($values = fgetcsv($fp))
810 $files = explode(
";", $values[$fileIdx]);
811 foreach($files as
$f)
817 foreach($this->indexedDocuments as
$path => $doc)
823 foreach($fields as
$field)
831 $doc->set(
$field, $values[$i]);
FakoliException is the base exception class for all Fakoli errors.
◆ registerCommentAdapter()
static DocumentManager::registerCommentAdapter |
( |
| ) |
|
|
static |
◆ registerSearchables()
static DocumentManager::registerSearchables |
( |
|
$searchables | ) |
|
|
static |
Definition at line 966 of file document_manager.inc.
968 trace(
"DocumentManager registerSearchables", 3);
971 $searchables[
"document"] = array(
Document);
static getValue($component, $name)
Retrieve the value of the specified Setting.
◆ registerSerializationHandler()
static DocumentManager::registerSerializationHandler |
( |
| ) |
|
|
static |
Definition at line 998 of file document_manager.inc.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
◆ registerSolrAdapter()
static DocumentManager::registerSolrAdapter |
( |
| ) |
|
|
static |
◆ registerTaxonomyClasses()
static DocumentManager::registerTaxonomyClasses |
( |
|
$classes | ) |
|
|
static |
◆ rescan()
DocumentManager::rescan |
( |
| ) |
|
Definition at line 738 of file document_manager.inc.
740 $this->indexedDocuments = reindexList($this->documents,
"file");
741 $this->indexedFolders = IndexedQuery::create(
DocumentFolder,
"WHERE document_library_id=:id",
"path")
742 ->bind(
":id", $this->library->document_library_id)
◆ scanFiles()
DocumentManager::scanFiles |
( |
|
$path | ) |
|
Definition at line 748 of file document_manager.inc.
752 $base = sanitizePath($this->library->getLibraryDirectory() . DIRECTORY_SEPARATOR .
$path);
754 $files = scandir(
$base);
755 foreach($files as
$file)
761 if (is_dir(
$base . DIRECTORY_SEPARATOR .
$file))
767 if ($this->indexedDocuments[
$f])
continue;
775 $doc->document_library_id = $this->library->document_library_id;
776 $doc->owner_id =
$user->get(
$user->getPrimaryKey());
◆ setDefaults()
static DocumentManager::setDefaults |
( |
| ) |
|
|
static |
Definition at line 1004 of file document_manager.inc.
1006 Settings::setDefaultValue(
"document",
"show_upload_details",
true, Boolean,
"Include upload details on the document library view");
1007 Settings::setDefaultValue(
"document",
"link_to_details",
false, Boolean,
"Link to the document details page for each document from the library view");
1008 Settings::setDefaultValue(
"document",
"show_table_filter",
false, Boolean,
"Show the generic column filter controls for the document table view");
1009 Settings::setDefaultValue(
"document",
"always_display_PDFs_in_browser",
false, Boolean,
"When downloading PDF documents, have them display in the browser in a new tab, rather than as a file download");
static setDefaultValue($component, $name, $value, $field_type="String", $annotation="", $category="", $options="", $weight=0)
Sets the default value of the given component setting.
◆ upgradeComponent()
static DocumentManager::upgradeComponent |
( |
|
$version | ) |
|
|
static |
◆ uploadFile()
DocumentManager::uploadFile |
( |
|
$field, |
|
|
|
$folder |
|
) |
| |
Upload a file from the specified form field to the specified folder within the current document library.
- Parameters
-
string | $field | the form field containing the record for uploaded file |
string | $folder | the folder within the document library to which the file is to be uploaded |
- Returns
- string the path of the uploaded file within the document library.
Definition at line 432 of file document_manager.inc.
440 if ($_FILES[
$field][
"name"]==
"")
454 $base = $this->library->getLibraryDirectory();
456 $fullpath =
$dir . DIRECTORY_SEPARATOR .
$name;
458 trace(
"Upload Directory: {$dir}", 3);
460 trace(
"Uploading file to $fullpath", 3);
462 if (!file_exists(
$dir))
468 if (file_exists($fullpath))
474 move_uploaded_file($_FILES[
$field][
"tmp_name"], $fullpath);
475 chmod($fullpath, 0755);
477 return str_replace(DIRECTORY_SEPARATOR,
"/",
$filepath);
◆ writeScript()
DocumentManager::writeScript |
( |
| ) |
|
Definition at line 111 of file document_manager.inc.
117 <div
class=
"dialog" id=
"documentManagerDlg" style=
"width: 760px">
118 <div
class=
"dialog_header" id=
"documentManagerDlgHeader">
119 <div
style=
"padding: 4px;">
120 <div
style=
"float: right">&
nbsp;<a
id=
'closeDocumentManagerDlg' href=
"javascript:docManagerDlg.hide();">Close ×</a></div>
121 <span
style=
"font-weight: bold" id=
"documentManagerTitle">
Document Manager</span>
124 <div
id=
"documentManagerDlgBody" class=
"dialog_body">
128 $dialogs .= ob_get_contents();
133 <script type=
"text/javascript">
135 window.addEvent(
'domready',
function()
137 docManagerDlg =
new ModalDialog(document.id(
'documentManagerDlg'), {handle: document.id(
'documentManagerDlgHeader'), draggable: true, body: document.id(
'documentManagerDlgBody')});
140 function downloadFile()
142 id = document.id(
'files_value').value;
143 go(
"/action/document/download?document_id=" +
id);
148 id = document.id(
'files_value').value;
149 docManagerDlg.show(
function() {},
"/action/document/edit?document_id=" +
id);
152 function editResult(result)
156 docManagerDlg.hide();
160 document.id(
'Document_form__error').set({
'text': result,
'display':
'table-cell'});
167 id = document.id(
'files_value').value;
168 docManagerDlg.show(
function() {},
"/action/document/upload?document_library_id=<?echo $this->library->document_library_id?>");
171 function uploadResult(responseText)
173 if (responseText ==
"1")
175 window.location.reload();
183 function deleteFile()
185 if (confirm(
"Are you sure you want to delete this file?"))
187 id = document.id(
'files_value').value;
189 var request =
new Request({
'url':
'/action/document/delete?document_id=' +
id,
191 'onSuccess':
function(responseText)
193 if (responseText ==
"1")
195 window.location.reload();
202 'onFailure':
function() { alert(
"Failed to communicate with server");}});
208 function selectionChanged()
210 var
id = document.id(
'files_value').value;
214 document.id(
'download').removeProperty(
"disabled");
215 if(document.id(
'edit')) document.id(
'edit').removeProperty(
"disabled");
216 document.id(
'deleteButton').removeProperty(
"disabled");
221 document.id(
'download').addProperty(
"disabled",
"disabled");
222 if(document.id(
'edit')) document.id(
'edit').addProperty(
"disabled",
"disabled");
223 document.id(
'deleteButton').addProperty(
"disabled",
"disabled");
227 function rescanLibrary()
229 result = httpRequest(
"/action/document/rescan?document_library_id=<?echo $this->library->document_library_id?>");
232 window.location.reload();
241 if (checkRole($this->library->manage_folders) || $this->library->allowManageFiles())
244 function createFolder()
246 docManagerDlg.show(
function() {},
"/action/document/create_folder?document_library_id=<?echo $this->library->document_library_id?>");
249 function createFolderResult(result)
253 window.location.reload();
263 docManagerDlg.show(
function() {},
"/action/document/delete_folder?document_library_id=<?echo $this->library->document_library_id?>");
266 function deleteFolderResult(result)
270 window.location.reload();
uploadFile($field, $folder)
Upload a file from the specified form field to the specified folder within the current document libra...
◆ zipLibrary()
static DocumentManager::zipLibrary |
( |
|
$library_id, |
|
|
|
$process = null |
|
) |
| |
|
static |
Generate a ZIP archive of all the documents in the specified library.
- Parameters
-
integer | $library_id | the ID of the library to be zipped |
Definition at line 846 of file document_manager.inc.
855 $process->setProgress(
"Running",
"Scanning files", 0);
858 $files =
$library->Documents(
"ORDER BY file");
860 $libraryFileName =
$library->format(
"library_{document_library_id}.zip");
861 $libraryDir =
$library->getLibraryDirectory();
862 $libraryZipFile =
$config[
'uploadbase'] . DIRECTORY_SEPARATOR . $libraryFileName;
863 if (file_exists($libraryZipFile))
865 unlink($libraryZipFile);
869 $zip =
new ZipArchive();
872 if ($zip->open($libraryZipFile, ZIPARCHIVE::CREATE) !== TRUE)
876 $process->setProgress(
"Error",
"Could not create ZIP archive");
881 $max = count($files);
884 foreach($files as
$file)
886 $fullPath = $libraryDir . DIRECTORY_SEPARATOR .
$file->file;
887 $zip->addFile($fullPath,
$file->file);
891 $process->setProgress(
"Running",
"Added $c of $max ".pluralize(
"file",
$max), number_format(100 *
$c /
$max, 0));
899 $process->setProgress(
"Completed",
"Zip archive created", 100);
static assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
if(!checkRole("admin")) $c
◆ $docs
◆ $documents
DocumentManager::$documents |
◆ $height
DocumentManager::$height = 400 |
◆ $library
DocumentManager::$library |
◆ $width
DocumentManager::$width = 700 |
The documentation for this class was generated from the following file: