예제 #1
0
 public function deleteDocumentAction()
 {
     if ($this->_request->isXmlHttpRequest()) {
         $this->view->layout()->disableLayout();
     } else {
         $this->_helper->pageTitle('workshop-index-deleteDocument:title');
     }
     $get = Zend_Registry::get('getFilter');
     if (!isset($get->workshopDocumentId)) {
         throw new Ot_Exception_Input('msg-error-workshopDocIdNotSet');
     }
     $workshop = new Workshop();
     $document = new Workshop_Document();
     $thisDocument = $document->find($get->workshopDocumentId);
     if (is_null($thisDocument)) {
         throw new Ot_Exception_Data('msg-error-noDocument');
     }
     $thisWorkshop = $workshop->find($thisDocument->workshopId);
     if (is_null($thisWorkshop)) {
         throw new Ot_Exception_Data('msg-error-noWorkshop');
     }
     $we = new Workshop_Editor();
     if (!$this->_helper->hasAccess('edit-all-workshops') && !$we->isEditor($thisWorkshop->workshopId, Zend_Auth::getInstance()->getIdentity()->accountId)) {
         throw new Ot_Exception_Access('msg-error-noAccess');
     }
     $config = Zend_Registry::get('config');
     if (!is_writable($config->user->fileUploadPathWorkshop->val)) {
         throw new Ot_Exception_Access($this->view->translate('msg-error-targetDirNotWritable', $config->user->fileUploadPathWorkshop->val));
     }
     $form = Ot_Form_Template::delete('deleteDocument');
     $form->setAction($this->view->baseUrl() . '/workshop/index/delete-document/?workshopDocumentId=' . $thisDocument->workshopDocumentId);
     if ($this->_request->isPost() && $form->isValid($_POST)) {
         $target = $config->user->fileUploadPathWorkshop->val . '/' . $thisWorkshop->workshopId . '/' . $thisDocument->name;
         if (is_file($target)) {
             unlink($target);
         }
         $document->delete($document->getAdapter()->quoteInto('workshopDocumentId = ?', $thisDocument->workshopDocumentId));
         $document->rebuildZipFile($thisWorkshop->workshopId);
         $logOptions = array('attributeName' => 'workshopId', 'attributeId' => $thisWorkshop->workshopId);
         $this->_helper->log(Zend_Log::INFO, 'Document was deleted', $logOptions);
         $this->_helper->flashMessenger->addMessage('msg-info-documentDeleted');
         $this->_helper->redirector->gotoUrl('/workshop/index/details/?workshopId=' . $thisWorkshop->workshopId);
     }
     $this->view->form = $form;
 }