Browse Source

Ajout commentaires + indentation controllers producer

refactoring
Guillaume Bourgeois 6 years ago
parent
commit
255db81453
3 changed files with 112 additions and 33 deletions
  1. +79
    -16
      producer/controllers/CommandeController.php
  2. +16
    -5
      producer/controllers/ProducerBaseController.php
  3. +17
    -12
      producer/controllers/SiteController.php

+ 79
- 16
producer/controllers/CommandeController.php View File



namespace producer\controllers; namespace producer\controllers;


class CommandeController extends ProducerBaseController {
class CommandeController extends ProducerBaseController
{


public function behaviors() {
public function behaviors()
{
return [ return [
'access' => [ 'access' => [
'class' => AccessControl::className(), 'class' => AccessControl::className(),
]; ];
} }


public function actionInfosProduction($id_production) {

/**
* Retourne au format JSON toutes les informations relatives à une
* production donnée.
*
* @param integer $id_production
* @return mixed
*/
public function actionInfosProduction($id_production)
{
$production = Production::findOne($id_production); $production = Production::findOne($id_production);


if ($production) { if ($production) {
return json_encode([]); return json_encode([]);
} }


/**
* Initialise le formulaire de création/modification de commande.
*
* @param Commande $commande
* @return array
*/
public function initForm($commande = null) { public function initForm($commande = null) {


// etablissements // etablissements
* *
* @return ProducerView * @return ProducerView
*/ */
public function actionHistorique() {
public function actionHistorique()
{
$data_provider_commandes = new ActiveDataProvider([ $data_provider_commandes = new ActiveDataProvider([
'query' => Commande::find() 'query' => Commande::find()
]); ]);
} }


public function actionRemoveEtablissement($id = 0) {
/**
* Supprime un producteur.
*
* @param integer $id
*/
public function actionRemoveEtablissement($id = 0)
{
$user_etablissement = UserEtablissement::find() $user_etablissement = UserEtablissement::find()
->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id]) ->where(['id_etablissement' => $id, 'id_user' => Yii::$app->user->identity->id])
->one(); ->one();
$this->redirect(['commande/index']); $this->redirect(['commande/index']);
} }


public function actionCreate() {
/**
* Crée une commande.
*
* @return mixed
*/
public function actionCreate()
{


$id_etablissement = $this->getProducer()->id ; $id_etablissement = $this->getProducer()->id ;
$commande = new Commande; $commande = new Commande;
])); ]));
} }


public function actionUpdate($id) {
/**
* Modifie une commande.
*
* @param integer $id
* @return mixed
* @throws UserException
*/
public function actionUpdate($id)
{


$commande = Commande::find() $commande = Commande::find()
->with('production') ->with('production')




return $this->render('update', array_merge($this->initForm($commande), [ return $this->render('update', array_merge($this->initForm($commande), [
'model' => $commande,
'commande_introuvable' => !$commande,
'model' => $commande,
'commande_introuvable' => !$commande,
])); ]));
} }


public function _verifEtablissementActif($id_etablissement) {
/**
* Vérifie si un producteur est actif.
*
* @param integer $id_etablissement
* @throws NotFoundHttpException
*/
public function _verifEtablissementActif($id_etablissement)
{
$etablissement = Etablissement::findOne($id_etablissement); $etablissement = Etablissement::findOne($id_etablissement);
if ($etablissement && !$etablissement->actif) { if ($etablissement && !$etablissement->actif) {
throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.'); throw new NotFoundHttpException('Cet établissement est actuellement hors ligne.');
} }
} }


public function gestionForm($commande) {
/**
* Traite le formulaire de création/modification de commande.
*
* @param Commande $commande
*/
public function gestionForm($commande)
{
$posts = Yii::$app->request->post(); $posts = Yii::$app->request->post();
$produits = array(); $produits = array();


} }
} }


public function actionAnnuler($id) {

/**
* Annule une commande.
*
* @param integer $id
* @throws \yii\web\NotFoundHttpException
* @throws UserException
*/
public function actionAnnuler($id)
{
$commande = Commande::find() $commande = Commande::find()
->with('production', 'creditHistorique', 'commandeProduits') ->with('production', 'creditHistorique', 'commandeProduits')
->where(['id' => $id]) ->where(['id' => $id])
$this->redirect(Yii::$app->urlManager->createUrl(['commande/historique'])); $this->redirect(Yii::$app->urlManager->createUrl(['commande/historique']));
} }


public function actionVerifCodePointVente($id_point_vente, $code) {
/**
* Vérifie le code saisi pour un point de vente.
*
* @param integer $id_point_vente
* @param string $code
* @return boolean
*/
public function actionVerifCodePointVente($id_point_vente, $code)
{
$point_vente = PointVente::findOne($id_point_vente); $point_vente = PointVente::findOne($id_point_vente);
if ($point_vente) { if ($point_vente) {
if ($point_vente->verifCode($code)) { if ($point_vente->verifCode($code)) {

+ 16
- 5
producer/controllers/ProducerBaseController.php View File



namespace producer\controllers; namespace producer\controllers;


class ProducerBaseController extends CommonController {
class ProducerBaseController extends CommonController
{


var $producer ; var $producer ;
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function behaviors() {
public function behaviors()
{
return []; return [];
} }
public function actions() {
public function actions()
{
return []; return [];
} }
public function beforeAction($event) {
public function beforeAction($event)
{
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
return parent::beforeAction($event); return parent::beforeAction($event);
} }
public function getProducer() {
/**
* Retourne le producteur courant.
*
* @return Etablissement
* @throws \yii\web\HttpException
*/
public function getProducer()
{
if($this->producer) { if($this->producer) {
return $this->producer ; return $this->producer ;
} }

+ 17
- 12
producer/controllers/SiteController.php View File



namespace producer\controllers; namespace producer\controllers;


class SiteController extends ProducerBaseController {
class SiteController extends ProducerBaseController
{
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function behaviors() {
public function behaviors()
{
return []; return [];
} }
public function actions() {
public function actions()
{
return [ return [
'captcha' => [ 'captcha' => [
'class' => 'yii\captcha\CaptchaAction', 'class' => 'yii\captcha\CaptchaAction',
]; ];
} }
/**
* Affiche et gère les erreurs.
*
* @return mixed
*/
public function actionError() public function actionError()
{ {
$exception = Yii::$app->errorHandler->exception; $exception = Yii::$app->errorHandler->exception;
} }
/** /**
*
* Affiche la page d'accueil des producteurs comprenant une image, une * Affiche la page d'accueil des producteurs comprenant une image, une
* description, la liste des points de vente et les produits * description, la liste des points de vente et les produits
* *
* @return ProducerView * @return ProducerView
*/ */
public function actionIndex() {
public function actionIndex()
{
// points de vente // points de vente
$data_provider_points_vente = new ActiveDataProvider([ $data_provider_points_vente = new ActiveDataProvider([
'query' => PointVente::find() 'query' => PointVente::find()
} }
/** /**
*
* Affiche et traite le formulaire de contact dédié aux producteurs * Affiche et traite le formulaire de contact dédié aux producteurs
* *
* @return ProducerView * @return ProducerView
*/ */
public function actionContact() {
public function actionContact()
{
$model = new ContactForm(); $model = new ContactForm();
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
* *
* @param $action 'add' ou 'delete' * @param $action 'add' ou 'delete'
*/ */
public function actionFavorite($action) {
public function actionFavorite($action)
{
$producer = $this->getProducer() ; $producer = $this->getProducer() ;
$user_etablissement = UserEtablissement::find() $user_etablissement = UserEtablissement::find()

Loading…
Cancel
Save