当前位置: 首页>>代码示例>>PHP>>正文


PHP CustomerMessage::getLastMessageForCustomerThread方法代码示例

本文整理汇总了PHP中CustomerMessage::getLastMessageForCustomerThread方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerMessage::getLastMessageForCustomerThread方法的具体用法?PHP CustomerMessage::getLastMessageForCustomerThread怎么用?PHP CustomerMessage::getLastMessageForCustomerThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CustomerMessage的用法示例。


在下文中一共展示了CustomerMessage::getLastMessageForCustomerThread方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendMessage

 public function sendMessage()
 {
     $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
     $file_attachment = Tools::fileAttachment('fileUpload');
     $message = Tools::getValue('message');
     if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) {
         $this->context->controller->errors[] = $this->l('Invalid email address.');
     } elseif (!$message) {
         $this->context->controller->errors[] = $this->l('The message cannot be blank.');
     } elseif (!Validate::isCleanHtml($message)) {
         $this->context->controller->errors[] = $this->l('Invalid message');
     } elseif (!($id_contact = (int) Tools::getValue('id_contact')) || !Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id))) {
         $this->context->controller->errors[] = $this->l('Please select a subject from the list provided. ');
     } elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) {
         $this->context->controller->errors[] = $this->l('An error occurred during the file-upload process.');
     } elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) && !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) {
         $this->context->controller->errors[] = $this->l('Bad file extension');
     } else {
         $customer = $this->context->customer;
         if (!$customer->id) {
             $customer->getByEmail($from);
         }
         $id_order = (int) Tools::getValue('id_order');
         $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, $id_order);
         if ($contact->customer_service) {
             if ((int) $id_customer_thread) {
                 $ct = new CustomerThread($id_customer_thread);
                 $ct->status = 'open';
                 $ct->id_lang = (int) $this->context->language->id;
                 $ct->id_contact = (int) $id_contact;
                 $ct->id_order = (int) $id_order;
                 if ($id_product = (int) Tools::getValue('id_product')) {
                     $ct->id_product = $id_product;
                 }
                 $ct->update();
             } else {
                 $ct = new CustomerThread();
                 if (isset($customer->id)) {
                     $ct->id_customer = (int) $customer->id;
                 }
                 $ct->id_shop = (int) $this->context->shop->id;
                 $ct->id_order = (int) $id_order;
                 if ($id_product = (int) Tools::getValue('id_product')) {
                     $ct->id_product = $id_product;
                 }
                 $ct->id_contact = (int) $id_contact;
                 $ct->id_lang = (int) $this->context->language->id;
                 $ct->email = $from;
                 $ct->status = 'open';
                 $ct->token = Tools::passwdGen(12);
                 $ct->add();
             }
             if ($ct->id) {
                 $lastMessage = CustomerMessage::getLastMessageForCustomerThread($ct->id);
                 $testFileUpload = isset($file_attachment['rename']) && !empty($file_attachment['rename']);
                 // if last message is the same as new message (and no file upload), do not consider this contact
                 if ($lastMessage != $message || $testFileUpload) {
                     $cm = new CustomerMessage();
                     $cm->id_customer_thread = $ct->id;
                     $cm->message = $message;
                     if ($testFileUpload && rename($file_attachment['tmp_name'], _PS_UPLOAD_DIR_ . basename($file_attachment['rename']))) {
                         $cm->file_name = $file_attachment['rename'];
                         @chmod(_PS_UPLOAD_DIR_ . basename($file_attachment['rename']), 0664);
                     }
                     $cm->ip_address = (int) ip2long(Tools::getRemoteAddr());
                     $cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
                     if (!$cm->add()) {
                         $this->context->controller->errors[] = $this->l('An error occurred while sending the message.');
                     }
                 } else {
                     $mailAlreadySend = true;
                 }
             } else {
                 $this->context->controller->errors[] = $this->l('An error occurred while sending the message.');
             }
         }
         if (!count($this->context->controller->errors) && empty($mailAlreadySend)) {
             $var_list = ['{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{product_name}' => ''];
             if (isset($file_attachment['name'])) {
                 $var_list['{attached_file}'] = $file_attachment['name'];
             }
             $id_product = (int) Tools::getValue('id_product');
             if (isset($ct) && Validate::isLoadedObject($ct) && $ct->id_order) {
                 $order = new Order((int) $ct->id_order);
                 $var_list['{order_name}'] = $order->getUniqReference();
                 $var_list['{id_order}'] = (int) $order->id;
             }
             if ($id_product) {
                 $product = new Product((int) $id_product);
                 if (Validate::isLoadedObject($product) && isset($product->name[Context::getContext()->language->id])) {
                     $var_list['{product_name}'] = $product->name[Context::getContext()->language->id];
                 }
             }
             if (empty($contact->email)) {
                 Mail::Send($this->context->language->id, 'contact_form', isset($ct) && Validate::isLoadedObject($ct) ? $this->trans('Your message has been correctly sent #ct%thread_id% #tc%thread_token%', array('%thread_id%' => $ct->id, '%thread_token%' => $ct->token), 'Emails.Subject') : $this->trans('Your message has been correctly sent', array(), 'Emails.Subject'), $var_list, $from, null, null, null, $file_attachment);
             } else {
                 if (!Mail::Send($this->context->language->id, 'contact', $this->trans('Message from contact form', array(), 'Emails.Subject') . ' [no_sync]', $var_list, $contact->email, $contact->name, null, null, $file_attachment, null, _PS_MAIL_DIR_, false, null, null, $from) || !Mail::Send($this->context->language->id, 'contact_form', isset($ct) && Validate::isLoadedObject($ct) ? $this->trans('Your message has been correctly sent #ct%thread_id% #tc%thread_token%', array('%thread_id%' => $ct->id, '%thread_token%' => $ct->token), 'Emails.Subject') : $this->trans('Your message has been correctly sent', array(), 'Emails.Subject'), $var_list, $from, null, null, null, $file_attachment, null, _PS_MAIL_DIR_, false, null, null, $contact->email)) {
                     $this->context->controller->errors[] = $this->l('An error occurred while sending the message.');
                 }
             }
//.........这里部分代码省略.........
开发者ID:prestashop,项目名称:contactform,代码行数:101,代码来源:contactform.php


注:本文中的CustomerMessage::getLastMessageForCustomerThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。