function _cloneDocman($srcGroupId, $dstGroupId, $ugroupsMapping) { $user = $this->getUser(); // Clone Docman permissions $dPm = $this->_getPermissionsManager(); if ($ugroupsMapping === false) { $dPm->setDefaultDocmanPermissions($dstGroupId); } else { $dPm->cloneDocmanPermissions($srcGroupId, $dstGroupId); } // Clone Metadata definitions $metadataMapping = array(); $mdFactory = new Docman_MetadataFactory($srcGroupId); $mdFactory->cloneMetadata($dstGroupId, $metadataMapping); // Clone Items, Item's permissions and metadata values $itemFactory = $this->_getItemFactory(); $dataRoot = $this->getProperty('docman_root'); $itemMapping = $itemFactory->cloneItems($srcGroupId, $dstGroupId, $user, $metadataMapping, $ugroupsMapping, $dataRoot); // Clone reports $reportFactory = new Docman_ReportFactory($srcGroupId); $reportFactory->copy($dstGroupId, $metadataMapping, $user, false, $itemMapping); //@todo: verify that key for title for root is copied instead of // string }
function report_import() { $groupId = $this->_controler->_actionParams['sGroupId']; $importReportId = $this->_controler->_actionParams['sImportReportId']; $importGroupId = $this->_controler->_actionParams['sImportGroupId']; $user =& $this->_controler->getUser(); // Any user can importreports from any public projects and from // Private projects he is member of. $pm = ProjectManager::instance(); $go = $pm->getProject($importGroupId); if ($go != false && ($go->isPublic() || !$go->isPublic() && $go->userIsMember())) { $srcReportFactory = new Docman_ReportFactory($importGroupId); // Get the mapping between src and current project metadata definition. $mdMap = array(); $srcMdFactory = new Docman_MetadataFactory($importGroupId); $srcMdFactory->getMetadataMapping($groupId, $mdMap); // Get the mapping between src and current project items definition for the item involved // in the reports. $itemMapping = array(); // Get involved items $srcReportItems = $srcReportFactory->getReportsItems($importReportId); if (count($srcReportItems) > 0) { // Get the subtree from the original docman on which reports applies $srcItemFactory = new Docman_ItemFactory($importGroupId); $srcItemTree = $srcItemFactory->getItemTreeFromLeaves($srcReportItems, $user); if ($srcItemTree !== null) { // Final step: find in the current ($groupId) docman $dstItemFactory = new Docman_ItemFactory($groupId); $itemMapping = $dstItemFactory->getItemMapping($srcItemTree); } } // If user is admin he can create 'P' report otherwise everything is 'I' $forceScope = true; if ($this->_controler->userCanAdmin()) { $forceScope = false; } if ($importReportId !== null) { // Import only one report $report = $srcReportFactory->getReportById($importReportId); if ($report !== null) { // User can import Project wide reports or his own Individual reports. if ($report->getScope() == 'P' || $report->getScope() == 'I' && $report->getUserId() == $user->getId()) { $srcReportFactory->cloneReport($report, $groupId, $mdMap, $user, $forceScope, $itemMapping); $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'report_clone_success')); } else { $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'report_err_clone_iorp')); } } else { $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'report_err_notfound', array($importReportId))); } } else { // Import all personal and project reports from the given project. $srcReportFactory->copy($groupId, $mdMap, $user, $forceScope, $itemMapping); $this->_controler->feedback->log('info', $GLOBALS['Language']->getText('plugin_docman', 'report_clone_success')); } } else { $this->_controler->feedback->log('error', $GLOBALS['Language']->getText('plugin_docman', 'error_perms_generic')); } }