public function fetchAll()
 {
     $resultSet = $this->getDbTable()->fetchAll();
     $entries = array();
     foreach ($resultSet as $row) {
         $entry = new Default_Model_TicketReply();
         $entry->setId($row->id)->setTicketId($row->ticketId)->setSubject($row->subject)->setMessage($row->message)->setFromEmail($row->fromEmail)->setReceiveDate($row->receiveDate);
         $entries[] = $entry;
     }
     return $entries;
 }
 public function indexAction()
 {
     $bootstrap = $this->getInvokeArg('bootstrap');
     $options = $bootstrap->getOptions();
     $smtp_config = $options['smtp'];
     $pop3_config = $options['pop3'];
     $mail = new Zend_Mail_Storage_Pop3($pop3_config['config']);
     echo $mail->countMessages() . " messages found\n";
     foreach ($mail as $i => $message) {
         $message = $this->parseMessage($mail, $message, $i);
         $mail->removeMessage($i);
         if (!stristr($message['message']['subject'], 'ticket #')) {
             // Add email as a ticket
             $ticketModel = new Default_Model_Ticket($message['message']);
             $ticketModel->save();
             $ticketId = $ticketModel->getMapper()->getDbTable()->getAdapter()->lastInsertId();
             $replyId = 0;
             $transport = new Zend_Mail_Transport_Smtp($smtp_config['host'], $smtp_config['config']);
             // Send a plain text email
             $sendmail = new Zend_Mail();
             $sendmail->setBodyText('Thank you for your submission. We will process you ticket shortly.');
             $sendmail->setFrom($smtp_config['email']['address'], $smtp_config['email']['name']);
             $sendmail->addTo($message['message']['fromEmail']);
             $sendmail->setSubject('Ticket #' . $ticketId);
             $sendmail->send($transport);
         } else {
             // Get ticket it from subject
             $ticketId = explode('ticket #', strtolower($message['message']['subject']));
             $ticketId = explode(' ', $ticketId[1]);
             $ticketId = array_shift($ticketId);
             $message['message']['ticketId'] = $ticketId;
             // Add email as a reply
             $replyModel = new Default_Model_TicketReply($message['message']);
             $replyModel->save();
             $replyId = $replyModel->getMapper()->getDbTable()->getAdapter()->lastInsertId();
         }
         foreach ($message['attachments'] as &$attachment) {
             if (empty($attachment['filename'])) {
                 // This is probably a text or html alternative.
                 $attachment['filename'] = stristr($attachment['contentType'], 'html') ? 'html-version.html' : 'text-version.txt';
             }
             $attachment['ticketId'] = $ticketId;
             // TODO: reply not being set?
             $attachment['replyId'] = $replyId;
             $ticketAttachmentModel = new Default_Model_TicketAttachment($attachment);
             $ticketAttachmentModel->save();
             unset($attachment);
         }
     }
 }
Ejemplo n.º 3
0
 public function getReplies()
 {
     if (!isset($this->_replies)) {
         $replyModel = new Default_Model_TicketReply();
         $this->_replies = $replyModel->fetchByTicket($this->getId());
     }
     return $this->_replies;
 }