Parcourir la source

Merge branch 'develop'

master
Guillaume Bourgeois il y a 1 an
Parent
révision
eb1966ad71
4 fichiers modifiés avec 30 ajouts et 22 suppressions
  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 Voir le fichier

{ {
$message = $this->composeBase($toEmail, $view, $params); $message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromProducer($message, $subject, $producer); $this->initMessageFromProducer($message, $subject, $producer);
$message->send();
return $message->send();
} }


public function sendFromSite(string $subject, string $view, array $params, string $toEmail) public function sendFromSite(string $subject, string $view, array $params, string $toEmail)
{ {
$message = $this->composeBase($toEmail, $view, $params); $message = $this->composeBase($toEmail, $view, $params);
$this->initMessageFromSite($message, $subject); $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) public function sendAdmin(string $subject, string $view, array $params = [], string $replyTo = null)
$message->setReplyTo($replyTo); $message->setReplyTo($replyTo);
} }
$this->initMessageFromSite($message, $subject); $this->initMessageFromSite($message, $subject);
$message->send();
return $message->send();
} }


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

+ 11
- 9
common/forms/ContactForm.php Voir le fichier



namespace common\forms; namespace common\forms;


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


* @param string $email the target email address * @param string $email the target email address
* @return boolean whether the email was sent * @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 'name' => $this->name
])
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject('[Opendistrib] Contact : ' . $this->subject)
->send();
],
$this->email
);
} }


} }

+ 4
- 7
producer/controllers/SiteController.php Voir le fichier

$model = new ContactForm(); $model = new ContactForm();
$producer = $this->getProducerCurrent(); $producer = $this->getProducerCurrent();


/*if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
$isSent = false; $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) { if ($isSent) {
} }


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


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

+ 2
- 3
producer/views/site/contact.php Voir le fichier



?> ?>
<div class="site-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"> <div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?> <?php $form = ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?>
<?= $form->field($model, 'name') ?> <?= $form->field($model, 'name') ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
</div>-->
</div>
</div> </div>

Chargement…
Annuler
Enregistrer