Commit 51c1b9fda04c3822fe282d43570b820e927455d3
1 parent
60782450
Modernise bulk import to use dispatcher validation and implement
document type choice. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3785 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
39 additions
and
23 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/bulkImport.php
| ... | ... | @@ -12,26 +12,40 @@ require_once(KT_LIB_DIR . "/visualpatterns/PatternMetaData.inc"); |
| 12 | 12 | require_once(KT_LIB_DIR . "/import/fsimportstorage.inc.php"); |
| 13 | 13 | require_once(KT_LIB_DIR . "/import/bulkimport.inc.php"); |
| 14 | 14 | |
| 15 | +require_once(KT_LIB_DIR . "/validation/dispatchervalidation.inc.php"); | |
| 16 | + | |
| 15 | 17 | class KTBulkImportDispatcher extends KTStandardDispatcher { |
| 18 | + function check() { | |
| 19 | + if ($_REQUEST['fFolderID']) { | |
| 20 | + $_REQUEST['fFolderId'] = $_REQUEST['fFolderID']; | |
| 21 | + unset($_REQUEST['fFolderID']); | |
| 22 | + } | |
| 23 | + $this->oFolder =& $this->oValidator->validateFolder($_REQUEST['fFolderId']); | |
| 24 | + $this->oPermission =& $this->oValidator->validatePermissionByName('ktcore.permissions.write'); | |
| 25 | + $this->oValidator->userHasPermissionOnItem($this->oUser, $this->oPermission, $this->oFolder); | |
| 26 | + return true; | |
| 27 | + } | |
| 28 | + | |
| 16 | 29 | function do_main() { |
| 17 | 30 | $oTemplating =& KTTemplating::getSingleton(); |
| 18 | 31 | $oTemplate = $oTemplating->loadTemplate('ktcore/import/fs_import'); |
| 19 | - $oFolder = Folder::get($_REQUEST['fFolderID']); | |
| 32 | + $aTypes = $this->getDocumentTypes(); | |
| 33 | + $iDefaultType = $aTypes[0]->getId(); | |
| 20 | 34 | $aFields = array( |
| 21 | - 'folder_id' => $oFolder->getID(), | |
| 22 | - 'folder_path_array' => $oFolder->getPathArray(), | |
| 23 | - 'document_type_choice' => $this->getDocumentTypeChoice('getMetadataForType(this.value);'), | |
| 35 | + 'folder_id' => $this->oFolder->getID(), | |
| 36 | + 'folder_path_array' => $this->oFolder->getPathArray(), | |
| 37 | + 'document_type_choice' => $this->getDocumentTypeChoice($aTypes, 'getMetadataForType(this.value);'), | |
| 24 | 38 | 'generic_metadata_fields' => $this->getGenericMetadataFields(), |
| 25 | - 'type_metadata_fields' => $this->getTypeMetadataFields(1), | |
| 39 | + 'type_metadata_fields' => $this->getTypeMetadataFields($iDefaultType), | |
| 26 | 40 | ); |
| 27 | 41 | return $oTemplate->render($aFields); |
| 28 | 42 | } |
| 29 | 43 | |
| 30 | - function getDocumentTypeChoice($onchange = "") { | |
| 44 | + function getDocumentTypeChoice($aTypes, $onchange = "") { | |
| 31 | 45 | $oTemplating =& KTTemplating::getSingleton(); |
| 32 | 46 | $oTemplate = $oTemplating->loadTemplate('ktcore/document/document_type_choice'); |
| 33 | 47 | $aFields = array( |
| 34 | - 'document_types' => DocumentType::getList(), | |
| 48 | + 'document_types' => $aTypes, | |
| 35 | 49 | 'onchange' => $onchange, |
| 36 | 50 | ); |
| 37 | 51 | return $oTemplate->render($aFields); |
| ... | ... | @@ -39,7 +53,7 @@ class KTBulkImportDispatcher extends KTStandardDispatcher { |
| 39 | 53 | |
| 40 | 54 | function getGenericMetadataFields() { |
| 41 | 55 | $oTemplating = KTTemplating::getSingleton(); |
| 42 | - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); | |
| 56 | + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/editable_metadata_fields"); | |
| 43 | 57 | $aTemplateData = array( |
| 44 | 58 | 'caption' => _('Generic meta data'), |
| 45 | 59 | 'empty_message' => _("No Generic Meta Data"), |
| ... | ... | @@ -67,12 +81,25 @@ class KTBulkImportDispatcher extends KTStandardDispatcher { |
| 67 | 81 | 'fields' => $aFields, |
| 68 | 82 | ); |
| 69 | 83 | $oTemplating = KTTemplating::getSingleton(); |
| 70 | - $oTemplate = $oTemplating->loadTemplate("ktcore/metadata_fields/editable_metadata_fields"); | |
| 84 | + $oTemplate = $oTemplating->loadTemplate("ktcore/metadata/editable_metadata_fields"); | |
| 71 | 85 | return $oTemplate->render($aTemplateData); |
| 72 | 86 | } |
| 73 | 87 | |
| 88 | + function getDocumentTypes() { | |
| 89 | + $sTable = KTUtil::getTableName('folder_doctypes'); | |
| 90 | + $aQuery = array( | |
| 91 | + "SELECT document_type_id FROM $sTable WHERE folder_id = ?", | |
| 92 | + array($this->oFolder->getId()), | |
| 93 | + ); | |
| 94 | + $aIds = DBUtil::getResultArrayKey($aQuery, 'document_type_id'); | |
| 95 | + $aRet = array(); | |
| 96 | + foreach ($aIds as $iId) { | |
| 97 | + $aRet[] = DocumentType::get($iId); | |
| 98 | + } | |
| 99 | + return $aRet; | |
| 100 | + } | |
| 101 | + | |
| 74 | 102 | function do_import() { |
| 75 | - $oFolder =& Folder::get($_REQUEST['fFolderID']); | |
| 76 | 103 | $matches = array(); |
| 77 | 104 | $aFields = array(); |
| 78 | 105 | foreach ($_REQUEST as $k => $v) { |
| ... | ... | @@ -87,8 +114,7 @@ class KTBulkImportDispatcher extends KTStandardDispatcher { |
| 87 | 114 | ); |
| 88 | 115 | |
| 89 | 116 | $fs =& new KTFSImportStorage($_REQUEST['fPath']); |
| 90 | - $oUser =& User::get($_SESSION['userID']); | |
| 91 | - $bm =& new KTBulkImportManager($oFolder, $fs, $oUser, $aOptions); | |
| 117 | + $bm =& new KTBulkImportManager($this->oFolder, $fs, $this->oUser, $aOptions); | |
| 92 | 118 | DBUtil::startTransaction(); |
| 93 | 119 | $res = $bm->import(); |
| 94 | 120 | if (PEAR::isError($res)) { |
| ... | ... | @@ -98,19 +124,9 @@ class KTBulkImportDispatcher extends KTStandardDispatcher { |
| 98 | 124 | DBUtil::commit(); |
| 99 | 125 | } |
| 100 | 126 | |
| 101 | - controllerRedirect("browse", 'fFolderID=' . $oFolder->getID()); | |
| 127 | + controllerRedirect("browse", 'fFolderID=' . $this->oFolder->getID()); | |
| 102 | 128 | exit(0); |
| 103 | 129 | } |
| 104 | - | |
| 105 | - function handleOutput($data) { | |
| 106 | - global $main; | |
| 107 | - if (empty($data)) { | |
| 108 | - $data = ""; | |
| 109 | - } | |
| 110 | - $main->bFormDisabled = true; | |
| 111 | - $main->setCentralPayload($data); | |
| 112 | - $main->render(); | |
| 113 | - } | |
| 114 | 130 | } |
| 115 | 131 | |
| 116 | 132 | $d =& new KTBulkImportDispatcher; | ... | ... |