@@ -30,7 +30,6 @@ Import::using('yii\behaviors\*'); | |||
Import::using('yii\helpers\*'); | |||
Import::using('yii\web\NotFoundHttpException'); | |||
// models | |||
Import::using('common\models\*'); | |||
Import::using('frontend\models\*'); |
@@ -1,6 +1,6 @@ | |||
<?php | |||
namespace frontend\models; | |||
namespace common\models; | |||
use Yii; | |||
use yii\base\Model; |
@@ -91,6 +91,10 @@ class Etablissement extends \yii\db\ActiveRecord { | |||
public function getUser() { | |||
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() { | |||
@@ -9,7 +9,7 @@ use common\models\Etablissement; | |||
use frontend\models\PasswordResetRequestForm; | |||
use frontend\models\ResetPasswordForm; | |||
use frontend\models\SignupForm; | |||
use frontend\models\ContactForm; | |||
use common\models\ContactForm; | |||
use yii\base\InvalidParamException; | |||
use yii\web\BadRequestHttpException; | |||
use yii\web\Controller; |
@@ -5,7 +5,6 @@ use yii\captcha\Captcha; | |||
/* @var $this yii\web\View */ | |||
/* @var $form yii\bootstrap\ActiveForm */ | |||
/* @var $model \frontend\models\ContactForm */ | |||
$this->title = 'Contact'; | |||
$this->params['breadcrumbs'][] = $this->title; |
@@ -27,7 +27,11 @@ class ProducerBaseController extends CommonController { | |||
return $this->producer ; | |||
} | |||
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) { | |||
$this->producer = $producer ; | |||
return $this->producer ; |
@@ -1,41 +0,0 @@ | |||
<?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 | |||
]) ; | |||
} | |||
} | |||
?> |
@@ -0,0 +1,81 @@ | |||
<?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, | |||
]); | |||
} | |||
} | |||
} | |||
?> |
@@ -43,7 +43,7 @@ $producer = $this->context->getProducer() ; | |||
], | |||
[ | |||
'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 | |||
], | |||
[ | |||
@@ -94,8 +94,8 @@ $producer = $this->context->getProducer() ; | |||
'items' => [ | |||
[ | |||
'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', | |||
@@ -111,8 +111,8 @@ $producer = $this->context->getProducer() ; | |||
], | |||
[ | |||
'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', |
@@ -0,0 +1,29 @@ | |||
<?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> |
@@ -358,12 +358,12 @@ body { | |||
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; | |||
} | |||
/* 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%; | |||
max-width: 500px; | |||
} |
@@ -3,6 +3,6 @@ | |||
@import "compass"; | |||
@import "compass/reset"; | |||
@import "_layout.scss"; | |||
@import "producer/_index.scss"; | |||
@import "site/_index.scss"; | |||
@import "commande/_form.scss"; | |||
@import "commande/_historique.scss"; |
@@ -1,5 +1,5 @@ | |||
.producer-index { | |||
.site-index { | |||
#presentation { | |||
.photo { | |||
text-align: center ; | |||
@@ -7,7 +7,7 @@ | |||
width: 100% ; | |||
max-width: 500px ; | |||
} | |||
} | |||
} | |||
} | |||
} |