Exemplo n.º 1
0
 function check_entity($oEntity)
 {
     if (is_a($oEntity, 'Document')) {
         if (!KTDocumentUtil::canBeDeleted($oEntity, $sError)) {
             if (PEAR::isError($sError)) {
                 return $sError;
             }
             return PEAR::raiseError(_kt('Document cannot be deleted'));
         }
     }
     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 deleted
                     return PEAR::raiseError(_kt('Folder cannot be deleted'));
                 }
             }
         }
         // If all documents at the current level may be deleted, 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 deleted
                     return PEAR::raiseError(_kt('Folder cannot be deleted'));
                 }
             }
         }
     }
     return parent::check_entity($oEntity);
 }