Import::using('yii\helpers\*'); | Import::using('yii\helpers\*'); | ||||
Import::using('yii\web\NotFoundHttpException'); | Import::using('yii\web\NotFoundHttpException'); | ||||
// models | // models | ||||
Import::using('common\models\*'); | Import::using('common\models\*'); | ||||
Import::using('frontend\models\*'); | Import::using('frontend\models\*'); |
<?php | <?php | ||||
namespace frontend\models; | |||||
namespace common\models; | |||||
use Yii; | use Yii; | ||||
use yii\base\Model; | use yii\base\Model; |
public function getUser() { | public function getUser() { | ||||
return $this->hasMany(User::className(), ['id_etablissement' => 'id']); | return $this->hasMany(User::className(), ['id_etablissement' => 'id']); | ||||
} | } | ||||
public function getContact() { | |||||
return $this->hasMany(User::className(), ['id_etablissement' => 'id'])->where(['status' => User::STATUS_BOULANGER]); | |||||
} | |||||
public static function getEtablissementsPopulateDropdown() { | public static function getEtablissementsPopulateDropdown() { | ||||
use frontend\models\PasswordResetRequestForm; | use frontend\models\PasswordResetRequestForm; | ||||
use frontend\models\ResetPasswordForm; | use frontend\models\ResetPasswordForm; | ||||
use frontend\models\SignupForm; | use frontend\models\SignupForm; | ||||
use frontend\models\ContactForm; | |||||
use common\models\ContactForm; | |||||
use yii\base\InvalidParamException; | use yii\base\InvalidParamException; | ||||
use yii\web\BadRequestHttpException; | use yii\web\BadRequestHttpException; | ||||
use yii\web\Controller; | use yii\web\Controller; |
/* @var $this yii\web\View */ | /* @var $this yii\web\View */ | ||||
/* @var $form yii\bootstrap\ActiveForm */ | /* @var $form yii\bootstrap\ActiveForm */ | ||||
/* @var $model \frontend\models\ContactForm */ | |||||
$this->title = 'Contact'; | $this->title = 'Contact'; | ||||
$this->params['breadcrumbs'][] = $this->title; | $this->params['breadcrumbs'][] = $this->title; |
return $this->producer ; | return $this->producer ; | ||||
} | } | ||||
else { | else { | ||||
$producer = Etablissement::findOne(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) ; | |||||
$producer = Etablissement::find() | |||||
->with('contact') | |||||
->where(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) | |||||
->one() ; | |||||
if($producer) { | if($producer) { | ||||
$this->producer = $producer ; | $this->producer = $producer ; | ||||
return $this->producer ; | return $this->producer ; |
<?php | |||||
namespace producer\controllers; | |||||
class ProducerController extends ProducerBaseController { | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function behaviors() { | |||||
return []; | |||||
} | |||||
public function actions() { | |||||
return [ | |||||
'error' => [ | |||||
'class' => 'yii\web\ErrorAction', | |||||
], | |||||
]; | |||||
} | |||||
public function actionIndex() { | |||||
$etablissement = Etablissement::findOne(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) ; | |||||
$points_vente = [] ; | |||||
if($etablissement) { | |||||
$points_vente = PointVente::find() | |||||
->where([ | |||||
'id_etablissement' => $etablissement->id, | |||||
]) | |||||
->all() ; | |||||
} | |||||
return $this->render('index',[ | |||||
'points_vente' => $points_vente | |||||
]) ; | |||||
} | |||||
} | |||||
?> |
<?php | |||||
namespace producer\controllers; | |||||
class SiteController extends ProducerBaseController { | |||||
/** | |||||
* @inheritdoc | |||||
*/ | |||||
public function behaviors() { | |||||
return []; | |||||
} | |||||
public function actions() { | |||||
return [ | |||||
'error' => [ | |||||
'class' => 'yii\web\ErrorAction', | |||||
], | |||||
'captcha' => [ | |||||
'class' => 'yii\captcha\CaptchaAction', | |||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, | |||||
], | |||||
]; | |||||
} | |||||
/** | |||||
* | |||||
* Affiche la page d'accueil des producteurs comprenant une image, une | |||||
* description et la liste des points de vente. | |||||
* | |||||
* @return ProducerView | |||||
*/ | |||||
public function actionIndex() { | |||||
$etablissement = Etablissement::findOne([ | |||||
'slug' => Yii::$app->getRequest()->getQueryParam('slug_producer') | |||||
]) ; | |||||
$points_vente = [] ; | |||||
if($etablissement) { | |||||
$points_vente = PointVente::find() | |||||
->where([ | |||||
'id_etablissement' => $etablissement->id, | |||||
]) | |||||
->all() ; | |||||
} | |||||
return $this->render('index',[ | |||||
'points_vente' => $points_vente | |||||
]) ; | |||||
} | |||||
/** | |||||
* | |||||
* Affiche et traite le formulaire de contact dédié aux producteurs | |||||
* | |||||
* @return ProducerView | |||||
*/ | |||||
public function actionContact() { | |||||
$model = new ContactForm(); | |||||
$producer = $this->getProducer() ; | |||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) { | |||||
if (is_array($producer->contact) && $model->sendEmail($producer->contact[0]->email)) { | |||||
Yii::$app->session->setFlash('success', 'Votre message a bien été envoyé.'); | |||||
} | |||||
else { | |||||
Yii::$app->session->setFlash('error', 'Il y a eu une erreur lors de l\'envoi de votre message.'); | |||||
} | |||||
return $this->refresh(); | |||||
} | |||||
else { | |||||
return $this->render('contact', [ | |||||
'model' => $model, | |||||
]); | |||||
} | |||||
} | |||||
} | |||||
?> |
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion', | 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion', | ||||
'url' => Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/login','return_url' => Yii::$app->urlManager->createAbsoluteUrl(['producer/index'])]), | |||||
'url' => Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/login','return_url' => Yii::$app->urlManager->createAbsoluteUrl(['site/index'])]), | |||||
'visible' => Yii::$app->user->isGuest | 'visible' => Yii::$app->user->isGuest | ||||
], | ], | ||||
[ | [ | ||||
'items' => [ | 'items' => [ | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-th-large"></span> Accueil', | 'label' => '<span class="glyphicon glyphicon-th-large"></span> Accueil', | ||||
'url' => Yii::$app->urlManager->createUrl(['producer/index']), | |||||
'active' => $this->getControllerAction() == 'producer/index', | |||||
'url' => Yii::$app->urlManager->createUrl(['site/index']), | |||||
'active' => $this->getControllerAction() == 'site/index', | |||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander', | ||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact', | 'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact', | ||||
'url' => Yii::$app->urlManager->createUrl(['producer/contact']), | |||||
'active' => $this->getControllerAction() == 'producer/contact', | |||||
'url' => Yii::$app->urlManager->createUrl(['site/contact']), | |||||
'active' => $this->getControllerAction() == 'site/contact', | |||||
], | ], | ||||
[ | [ | ||||
'label' => '<span class="glyphicon glyphicon-cog"></span> Administration', | 'label' => '<span class="glyphicon glyphicon-cog"></span> Administration', |
<?php | |||||
use yii\helpers\Html; | |||||
use yii\bootstrap\ActiveForm; | |||||
use yii\captcha\Captcha; | |||||
$this->setTitle('Contact'); | |||||
?> | |||||
<div class="site-contact"> | |||||
<div class="row"> | |||||
<div class="col-lg-5"> | |||||
<?php $form = yii\bootstrap\ActiveForm::begin(['id' => 'contact-form', 'enableClientValidation' => false,]); ?> | |||||
<?= $form->field($model, 'name') ?> | |||||
<?= $form->field($model, 'email') ?> | |||||
<?= $form->field($model, 'subject') ?> | |||||
<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?> | |||||
<?php echo $form->field($model, 'verifyCode')->widget(yii\captcha\Captcha::className(), [ | |||||
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>', | |||||
]); ?> | |||||
<div class="form-group"> | |||||
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?> | |||||
</div> | |||||
<?php ActiveForm::end(); ?> | |||||
</div> | |||||
</div> | |||||
</div> |
margin-right: 10px; | margin-right: 10px; | ||||
} | } | ||||
/* line 4, ../sass/producer/_index.scss */ | |||||
.producer-index #presentation .photo { | |||||
/* line 4, ../sass/site/_index.scss */ | |||||
.site-index #presentation .photo { | |||||
text-align: center; | text-align: center; | ||||
} | } | ||||
/* line 6, ../sass/producer/_index.scss */ | |||||
.producer-index #presentation .photo .img-photo { | |||||
/* line 6, ../sass/site/_index.scss */ | |||||
.site-index #presentation .photo .img-photo { | |||||
width: 100%; | width: 100%; | ||||
max-width: 500px; | max-width: 500px; | ||||
} | } |
@import "compass"; | @import "compass"; | ||||
@import "compass/reset"; | @import "compass/reset"; | ||||
@import "_layout.scss"; | @import "_layout.scss"; | ||||
@import "producer/_index.scss"; | |||||
@import "site/_index.scss"; | |||||
@import "commande/_form.scss"; | @import "commande/_form.scss"; | ||||
@import "commande/_historique.scss"; | @import "commande/_historique.scss"; |
.producer-index { | |||||
.site-index { | |||||
#presentation { | #presentation { | ||||
.photo { | .photo { | ||||
text-align: center ; | text-align: center ; | ||||
width: 100% ; | width: 100% ; | ||||
max-width: 500px ; | max-width: 500px ; | ||||
} | } | ||||
} | |||||
} | |||||
} | } | ||||
} | } |