/**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  */
 public function clearDraft($ticket)
 {
     $ticketId = $ticket->getId();
     $collection = Mage::getModel('helpdesk/draft')->getCollection();
     $collection->addFieldToFilter('ticket_id', $ticketId);
     foreach ($collection as $item) {
         $item->delete();
     }
     return;
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $object
  * @param string                         $subject
  *
  * @return string
  */
 public function getEmailSubject($object, $subject = '')
 {
     $result = '';
     if (Mage::getSingleton('helpdesk/config')->getNotificationIsShowCode()) {
         $result = "[#{$object->getCode()}] ";
     }
     if ($subject) {
         $result .= "{$subject} - ";
     }
     $result .= $object->getName();
     return $result;
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  *
  * @return string
  */
 public function getParsedTemplate($ticket)
 {
     $storeId = $ticket->getStoreId();
     $storeOb = Mage::getModel('core/store')->load($storeId);
     if (!($name = Mage::getStoreConfig('general/store_information/name', $storeId))) {
         $name = $storeOb->getName();
     }
     $store = new Varien_Object(array('name' => $name, 'phone' => Mage::getStoreConfig('general/store_information/phone', $storeId), 'address' => Mage::getStoreConfig('general/store_information/address', $storeId)));
     /** @var Mage_Admin_Model_User $user */
     $user = Mage::getSingleton('admin/session')->getUser();
     $result = Mage::helper('mstcore/parsevariables')->parse($this->getTemplate(), array('ticket' => $ticket, 'store' => $store, 'user' => $user), array(), $store->getId());
     return $result;
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  */
 public function checkReadTicketRestrictions($ticket)
 {
     $allow = false;
     if ($permission = $this->getPermission()) {
         $departmentIds = $permission->getDepartmentIds();
         if (in_array(0, $departmentIds)) {
             $allow = true;
         } else {
             if (in_array($ticket->getDepartmentId(), $departmentIds)) {
                 $allow = true;
             }
         }
     }
     if (!$allow) {
         echo $this->__('You don\'t have permissions to read this ticket. Please, contact your administrator.');
         die;
     }
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  */
 public function sendNotificationReminder($ticket)
 {
     $templateName = $this->getConfig()->getNotificationReminderTemplate();
     $recipientEmail = $ticket->getFpRemindEmail();
     $recipientName = '';
     $config = Mage::getSingleton('helpdesk/config');
     if ($config->getDeveloperIsActive()) {
         if ($sandboxEmail = $config->getDeveloperSandboxEmail()) {
             $recipientEmail = $sandboxEmail;
         }
     }
     $ticket = Mage::getModel('helpdesk/ticket')->getCollection()->joinFields()->addFieldToFilter('ticket_id', $ticket->getId())->getFirstItem();
     $department = Mage::getModel('helpdesk/department')->load($ticket->getDepartmentId());
     $customer = $ticket->getCustomer();
     $user = Mage::getModel('admin/user')->load($ticket->getUserId());
     $store = Mage::getModel('core/store')->load($ticket->getStoreId());
     $variables = array('ticket' => $ticket, 'customer' => $customer, 'user' => $user, 'department' => $department, 'store' => $store);
     $senderName = Mage::getStoreConfig("trans_email/ident_{$this->getSender()}/name");
     $senderEmail = Mage::getStoreConfig("trans_email/ident_{$this->getSender()}/email");
     $this->send($templateName, $senderName, $senderEmail, $recipientEmail, $recipientName, $variables, $ticket->getStoreId());
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  * @param $triggeredBy
  * @param $by
  *
  * @return mixed
  */
 public static function getHistoryRecord($ticket, $triggeredBy, $by)
 {
     if (!isset(self::$history[$ticket->getId()])) {
         $history = Mage::getModel('helpdesk/history');
         $history->setTicketId($ticket->getId());
         $history->setTriggeredBy($triggeredBy);
         switch ($triggeredBy) {
             case Mirasvit_Helpdesk_Model_Config::CUSTOMER:
                 $history->setName($by['customer']->getName());
                 break;
             case Mirasvit_Helpdesk_Model_Config::USER:
                 $history->setName($by['user']->getName());
                 break;
             case Mirasvit_Helpdesk_Model_Config::THIRD:
                 $history->setName($by['email']->getSenderNameOrEmail());
                 break;
             case Mirasvit_Helpdesk_Model_Config::RULE:
                 $history->setName($by['rule']->getName());
                 break;
         }
         self::$history[$ticket->getId()] = $history;
     }
     return self::$history[$ticket->getId()];
 }
Exemple #7
0
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  *
  * @return string
  */
 public function getTagsAsString($ticket)
 {
     $ticket->loadTagIds();
     if (count($ticket->getTagIds()) == 0) {
         return '';
     }
     $collection = Mage::getModel('helpdesk/tag')->getCollection()->addFieldToFilter('tag_id', $ticket->getTagIds());
     $arr = array();
     foreach ($collection as $tag) {
         $arr[] = $tag->getName();
     }
     return implode(', ', $arr);
 }
 /**
  * @test
  * @loadFixture data2
  *
  * @doNotIndex catalog_product_price
  */
 public function getLastMessageTest()
 {
     $this->assertEquals('Test message body', $this->_model->getLastMessage()->getBodyPlain());
     $this->assertEquals('Test message body', $this->_model->getLastMessageHtmlText());
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  */
 public function process($ticket)
 {
     if ($ticket->getFpPriorityId()) {
         $ticket->setPriorityId($ticket->getFpPriorityId());
     }
     if ($ticket->getFpStatusId()) {
         $ticket->setStatusId($ticket->getFpStatusId());
     }
     if ($ticket->getFpDepartmentId()) {
         $ticket->setDepartmentId($ticket->getFpDepartmentId());
     }
     if ($ticket->getFpUserId()) {
         $ticket->setUserId($ticket->getFpUserId());
     }
     if ($ticket->getFpIsRemind()) {
         Mage::helper('helpdesk/mail')->sendNotificationReminder($ticket);
     }
     $ticket->setData('fp_execute_at', null)->setData('fp_period_value', null)->setData('fp_period_unit', null)->setData('fp_is_remind', false);
     $ticket->save();
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket       $ticket
  * @param Mage_Customer_Model_Customer|false   $customer
  * @param Mage_Admin_Model_User|false          $user
  * @param $recipientEmail
  * @param $recipientName
  * @param $templateName
  * @param Mirasvit_Helpdesk_Model_Attachment[] $attachments
  * @param array                                $variables
  * @param bool                                 $emailFlag
  *
  * @return bool
  *
  * @throws Exception
  * @throws Zend_Mail_Exception
  */
 public function mail($ticket, $customer, $user, $recipientEmail, $recipientName, $templateName, $attachments = array(), $variables = array(), $emailFlag = false)
 {
     if ($templateName == 'none') {
         return false;
     }
     $storeId = $ticket->getStoreId();
     $config = Mage::getSingleton('helpdesk/config');
     if ($config->getDeveloperIsActive($storeId)) {
         if ($sandboxEmail = $config->getDeveloperSandboxEmail($storeId)) {
             $recipientEmail = $sandboxEmail;
         }
     }
     $department = $ticket->getDepartment();
     $store = $ticket->getStore();
     if (!$customer) {
         $customer = $ticket->getCustomer();
     }
     if (!$user) {
         $user = $ticket->getUser();
     }
     // save current design settings
     $currentDesignConfig = clone $this->_getDesignConfig();
     $this->_setDesignConfig(array('area' => 'frontend', 'store' => $store->getId()));
     $this->_applyDesignConfig();
     $variables = array_merge($variables, array('ticket' => $ticket, 'customer' => $customer, 'user' => $user, 'department' => $department, 'store' => $store, 'hidden_separator' => Mage::helper('helpdesk/email')->getHiddenSeparator(), 'logo_url' => $this->_getLogoUrl($store), 'logo_alt' => $this->_getLogoAlt($store)));
     if (isset($variables['email_subject'])) {
         $variables['email_subject'] = $this->processVariable($variables['email_subject'], $variables);
     }
     if (isset($variables['email_body'])) {
         $variables['email_body'] = $this->processVariable($variables['email_body'], $variables);
     }
     $senderName = Mage::getStoreConfig("trans_email/ident_{$department->getSenderEmail()}/name", $storeId);
     $senderEmail = Mage::getStoreConfig("trans_email/ident_{$department->getSenderEmail()}/email", $storeId);
     if (!$senderEmail) {
         return;
     }
     if (!$recipientEmail) {
         return;
     }
     $template = Mage::getModel('core/email_template');
     foreach ($attachments as $attachment) {
         /* @noinspection PhpUndefinedClassInspection */
         $template->getMail()->createAttachment($attachment->getBody(), $attachment->getType(), Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $attachment->getName());
     }
     $translate = Mage::getSingleton('core/translate');
     $translate->setTranslateInline(false);
     if ($emailFlag) {
         $template->getMail()->addHeader('Auto-Submitted', $emailFlag);
     }
     // Mandrill NOT ABLE to send CC - so we need an overwork
     if (method_exists($template->getMail(), 'addCc')) {
         if (count($ticket->getCc())) {
             $template->getMail()->addCc($ticket->getCc());
         }
     } else {
         $recipientEmail = array_unique(array_merge((array) $recipientEmail, $ticket->getCc()));
     }
     $bcc = array_unique(array_merge($this->getConfig()->getGeneralBccEmail($storeId), $ticket->getBcc()));
     if (count($bcc)) {
         $template->getMail()->addBcc($bcc);
     }
     $template->setDesignConfig(array('area' => 'frontend', 'store' => $storeId));
     $template->sendTransactional($templateName, array('name' => $senderName, 'email' => $senderEmail), $recipientEmail, $recipientName, $variables, $storeId);
     $text = $template->getProcessedTemplate($variables, true);
     $this->emails[] = $text;
     $translate->setTranslateInline(true);
     // restore previous design settings
     $this->_setDesignConfig($currentDesignConfig->getData());
     $this->_applyDesignConfig();
 }
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  * @param Mirasvit_Helpdesk_Model_Field  $field
  *
  * @return bool|string
  */
 public function getValue($ticket, $field)
 {
     $value = $ticket->getData($field->getCode());
     if (!$value) {
         return false;
     }
     if ($field->getType() == 'checkbox') {
         $value = $value ? Mage::helper('helpdesk')->__('Yes') : Mage::helper('helpdesk')->__('No');
     } elseif ($field->getType() == 'date') {
         $value = Mage::helper('core')->formatDate($value, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
     } elseif ($field->getType() == 'select') {
         $values = $field->getValues();
         $value = $values[$value];
     }
     return $value;
 }