浏览代码

Merge branch 'develop'

master
Guillaume Bourgeois 1年前
父节点
当前提交
eb1966ad71
共有 4 个文件被更改,包括 30 次插入22 次删除
  1. +13
    -3
      common/components/MailerService.php
  2. +11
    -9
      common/forms/ContactForm.php
  3. +4
    -7
      producer/controllers/SiteController.php
  4. +2
    -3
      producer/views/site/contact.php

+ 13
- 3
common/components/MailerService.php 查看文件

@@ -11,14 +11,24 @@ class MailerService
{
$message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromProducer($message, $subject, $producer);
$message->send();
return $message->send();
}

public function sendFromSite(string $subject, string $view, array $params, string $toEmail)
{
$message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromSite($message, $subject);
$message->send();
return $message->send();
}

public function sendProducer(Producer $producer, string $subject, string $view, array $params = [], string $replyTo = null)
{
$message = $this->composeBase($producer->contact_email, $view, $params);
if($replyTo) {
$message->setReplyTo($replyTo);
}
$this->initMessageFromSite($message, $subject);
return $message->send();
}

public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null)
@@ -28,7 +38,7 @@ class MailerService
$message->setReplyTo($replyTo);
}
$this->initMessageFromSite($message, $subject);
$message->send();
return $message->send();
}

private function composeBase(string $toEmail, string $view, array $params = [])

+ 11
- 9
common/forms/ContactForm.php 查看文件

@@ -38,6 +38,7 @@ termes.

namespace common\forms;

use common\logic\Producer\Producer\Model\Producer;
use Yii;
use yii\base\Model;

@@ -89,17 +90,18 @@ class ContactForm extends Model
* @param string $email the target email address
* @return boolean whether the email was sent
*/
public function sendEmail($email)
public function sendEmail(Producer $producer)
{
return Yii::$app->mailer->compose([
'html' => 'contact-html',
'text' => 'contact-text'], [ 'content' => $this->body,
return Yii::$app->mailerService->sendProducer(
$producer,
'Contact : ' . $this->subject,
'contact',
[
'content' => $this->body,
'name' => $this->name
])
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('[Opendistrib] Contact : ' . $this->subject)
->send();
],
$this->email
);
}

}

+ 4
- 7
producer/controllers/SiteController.php 查看文件

@@ -181,13 +181,10 @@ class SiteController extends ProducerBaseController
$model = new ContactForm();
$producer = $this->getProducerCurrent();

/*if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false;
if (is_array($producer->contact)) {
$email = $this->getProducerModule()->getMainContactEmail($producer);
if (strlen($email) && $model->sendEmail($email)) {
$isSent = true;
}
if ($producer->contact_email && strlen($producer->contact_email) > 0 && $model->sendEmail($producer)) {
$isSent = true;
}

if ($isSent) {
@@ -197,7 +194,7 @@ class SiteController extends ProducerBaseController
}

$model = new ContactForm();
}*/
}

return $this->render('contact', [
'model' => $model,

+ 2
- 3
producer/views/site/contact.php 查看文件

@@ -44,8 +44,7 @@ $this->setTitle('Contact');

?>
<div class="site-contact">
<div class="alert alert-warning">Page en maintenance</div>
<!--<div class="row">
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?>
<?= $form->field($model, 'name') ?>
@@ -62,5 +61,5 @@ $this->setTitle('Contact');
</div>
<?php ActiveForm::end(); ?>
</div>
</div>-->
</div>
</div>

正在加载...
取消
保存