Esempio n. 1
0
 function check_entity($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         if (!KTDocumentUtil::canBeCopied($oEntity, $sError)) {
             if (PEAR::isError($sError)) {
                 return $sError;
             }
             return PEAR::raiseError(_kt('Document cannot be copied'));
         }
     }
     if (is_a($oEntity, 'Folder')) {
         $aDocuments = array();
         $aChildFolders = array();
         $oFolder = $oEntity;
         // Get folder id
         $sFolderId = $oFolder->getID();
         // Get documents in folder
         $sDocuments = $oFolder->getDocumentIDs($sFolderId);
         $aDocuments = !empty($sDocuments) ? explode(',', $sDocuments) : array();
         // Loop through documents and send to this function for checking
         if (!empty($aDocuments)) {
             foreach ($aDocuments as $sDocID) {
                 $oDocument = Document::get($sDocID);
                 $res = $this->check_entity($oDocument);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be copied
                     return PEAR::raiseError(_kt('Folder cannot be copied'));
                 }
             }
         }
         // If all documents at the current level may be copied, we can continue
         // Get any existing subfolders
         $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR\n            parent_folder_ids LIKE '{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId}'";
         $aChildFolders = $this->oFolder->getList($sWhereClause);
         // Loop through subfolders and check each in the same way as the parent
         if (!empty($aChildFolders)) {
             foreach ($aChildFolders as $oChild) {
                 $res = $this->check_entity($oChild);
                 if (PEAR::isError($res)) {
                     // NOTE: we may want to append the document reason to this
                     // in order for the user to have some idea WHY the folder cannot be copied
                     return PEAR::raiseError(_kt('Folder cannot be copied'));
                 }
             }
         }
     }
     return parent::check_entity($oEntity);
 }