/** * Send mail to author(s) of document. */ public function toauthorAction() { $docId = $this->getRequest()->getParam('docId'); if (is_null($docId)) { throw new Application_Exception('missing parameter docId'); } $authorsModel = null; try { $authorsModel = new Frontdoor_Model_Authors($docId); } catch (Frontdoor_Model_Exception $e) { throw new Application_Exception($e->getMessage()); } $authors = $authorsModel->getContactableAuthors(); if (empty($authors)) { throw new Application_Exception('no authors contactable via email'); } $form = new Frontdoor_Form_ToauthorForm(array('authors' => $authors)); $form->setAction($this->view->url(array('module' => 'frontdoor', 'controller' => 'mail', 'action' => 'toauthor'))); $form->setMethod('post'); $this->view->docId = $docId; if (!$this->getRequest()->isPost() || !$form->isValid($this->getRequest()->getPost())) { $this->view->form = $form; $this->view->author = $authors; $this->view->type = $authorsModel->getDocument()->getType(); $this->view->title = $authorsModel->getDocument()->getTitleMain(0)->getValue(); return; } try { $authorsModel->sendMail(new Opus_Mail_SendMail(), $form->getValue('sender_mail'), $form->getValue('sender'), $this->view->translate('mail_toauthor_subject'), $form->getValue('message'), $form->getValue('authors')); $this->view->success = 'frontdoor_mail_ok'; } catch (Exception $e) { $log = Zend_Registry::get('Zend_Log'); $log->err($e->getMessage()); $this->view->success = 'frontdoor_mail_notok'; } $this->render('feedback'); }
/** * * @param Opus_Document $doc */ private function isMailPossible($doc) { $authors = new Frontdoor_Model_Authors($doc); return count($authors->getContactableAuthors()) > 0; }