Browse Source

Ajouter une entité "Etablissement" pour plus de rigueur au niveau de la structure des données

master
keun 8 years ago
parent
commit
5df7610828
18 changed files with 223 additions and 78 deletions
  1. +78
    -0
      backend/controllers/EtablissementController.php
  2. +1
    -1
      backend/controllers/PointVenteController.php
  3. +1
    -1
      backend/controllers/ProduitController.php
  4. +4
    -37
      backend/controllers/UserController.php
  5. +0
    -0
      backend/views/etablissement/update.php
  6. +2
    -2
      backend/views/layouts/main.php
  7. +57
    -0
      common/models/Etablissement.php
  8. +3
    -3
      common/models/PointVente.php
  9. +3
    -3
      common/models/Produit.php
  10. +11
    -5
      common/models/User.php
  11. +2
    -2
      common/models/UserBoulangerie.php
  12. +6
    -6
      console/migrations/m161012_074719_infos_boulanger.php
  13. +6
    -6
      console/migrations/m161012_075736_ajout_ids_boulangerie.php
  14. +4
    -4
      console/migrations/m161014_084709_table_user_boulangerie.php
  15. +6
    -6
      console/migrations/m161020_072119_champs_boulangerie.php
  16. +37
    -0
      console/migrations/m161021_073634_table_etablissement.php
  17. +1
    -1
      frontend/controllers/CommandeController.php
  18. +1
    -1
      frontend/views/commande/index.php

+ 78
- 0
backend/controllers/EtablissementController.php View File

<?php

namespace backend\controllers;

use Yii;
use common\models\User;
use backend\models\MailForm;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\helpers\Upload ;

/**
* UserController implements the CRUD actions for User model.
*/
class EtablissementController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN
|| Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
}
]
],
],
];
}
public function actionUpdate()
{
$request = Yii::$app->request ;
$model = $this->findModel(Yii::$app->user->identity->id);
$logo_filename_old = $model->logo ;
$photo_filename_old = $model->photo ;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Upload::uploadFile($model, 'logo', $logo_filename_old) ;
Upload::uploadFile($model, 'photo', $photo_filename_old) ;
$delete_logo = $request->post('delete_logo',0) ;
if($delete_logo) {
$model->logo = '' ;
$model->save() ;
}

$delete_photo = $request->post('delete_photo',0) ;
if($delete_photo) {
$model->photo = '' ;
$model->save() ;
}
return $this->redirect(['parametres', 'id' => $model->id, 'edit_ok' => true]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
}

+ 1
- 1
backend/controllers/PointVenteController.php View File

{ {
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => PointVente::find()->where(['id_boulangerie'=>Yii::$app->user->identity->id])
'query' => PointVente::find()->where(['id_etablissement'=>Yii::$app->user->identity->id])
]); ]);


return $this->render('index', [ return $this->render('index', [

+ 1
- 1
backend/controllers/ProduitController.php View File

$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => Produit::find() 'query' => Produit::find()
->where('(vrac IS NULL OR vrac = 0)') ->where('(vrac IS NULL OR vrac = 0)')
->andWhere(['id_boulangerie'=>Yii::$app->user->identity->id])
->andWhere(['id_etablissement'=>Yii::$app->user->identity->id])
->orderBy('order ASC'), ->orderBy('order ASC'),
'pagination' => [ 'pagination' => [
'pageSize' => 1000, 'pageSize' => 1000,

+ 4
- 37
backend/controllers/UserController.php View File

(new \yii\db\Query()) (new \yii\db\Query())
->select('*') ->select('*')
->from('user, user_boulangerie') ->from('user, user_boulangerie')
->where('user.id = user_boulangerie.id_user')
->andWhere('user_boulangerie.id_boulangerie = '.Yii::$app->user->identity->id)
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
]); ]);


return $this->render('index', [ return $this->render('index', [
]); ]);
} }
} }
public function actionParametres()
{
$request = Yii::$app->request ;
$model = $this->findModel(Yii::$app->user->identity->id);
$logo_filename_old = $model->logo ;
$photo_filename_old = $model->photo ;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Upload::uploadFile($model, 'logo', $logo_filename_old) ;
Upload::uploadFile($model, 'photo', $photo_filename_old) ;
$delete_logo = $request->post('delete_logo',0) ;
if($delete_logo) {
$model->logo = '' ;
$model->save() ;
}

$delete_photo = $request->post('delete_photo',0) ;
if($delete_photo) {
$model->photo = '' ;
$model->save() ;
}
return $this->redirect(['parametres', 'id' => $model->id, 'edit_ok' => true]);
} else {
return $this->render('parametres', [
'model' => $model,
]);
}
}


/** /**
* Deletes an existing User model. * Deletes an existing User model.
$users = (new \yii\db\Query()) $users = (new \yii\db\Query())
->select('*') ->select('*')
->from('user, user_boulangerie') ->from('user, user_boulangerie')
->where('user.id = user_boulangerie.id_user')
->andWhere('user_boulangerie.id_boulangerie = '.Yii::$app->user->identity->id)
->where('user.id = user_etablissement.id_user')
->andWhere('user_etablissement.id_etablissement = '.Yii::$app->user->identity->id)
->all() ; ->all() ;
$arr_users = [] ; $arr_users = [] ;

backend/views/user/parametres.php → backend/views/etablissement/update.php View File


+ 2
- 2
backend/views/layouts/main.php View File

['label' => '<span class="glyphicon glyphicon-grain"></span> Produits', 'url' => ['/produit/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-grain"></span> Produits', 'url' => ['/produit/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-map-marker"></span> Points de vente', 'url' => ['/point-vente/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-map-marker"></span> Points de vente', 'url' => ['/point-vente/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-user"></span> Utilisateurs', 'url' => ['/user/index'], 'visible'=> !Yii::$app->user->isGuest], ['label' => '<span class="glyphicon glyphicon-user"></span> Utilisateurs', 'url' => ['/user/index'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-cog"></span> Paramètres', 'url' => ['/user/parametres'], 'visible'=> !Yii::$app->user->isGuest],
['label' => '<span class="glyphicon glyphicon-cog"></span> Paramètres', 'url' => ['/etablissement/update'], 'visible'=> !Yii::$app->user->isGuest],
//['label' => 'Statistiques', 'url' => ['/stats/index'], 'visible'=> !Yii::$app->user->isGuest], //['label' => 'Statistiques', 'url' => ['/stats/index'], 'visible'=> !Yii::$app->user->isGuest],
]; ];
<div class="container"> <div class="container">
<?php if(!Yii::$app->user->isGuest): ?> <?php if(!Yii::$app->user->isGuest): ?>
<div class="nom-boulange"> <div class="nom-boulange">
<span><?= Html::encode(Yii::$app->user->identity->nom_magasin) ; ?></span>
<span><?= Html::encode(Yii::$app->user->identity->getNomMagasin()) ; ?></span>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?= Breadcrumbs::widget([ <?= Breadcrumbs::widget([

+ 57
- 0
common/models/Etablissement.php View File

<?php

namespace common\models;

use Yii;

/**
* This is the model class for table "etablissement".
*
* @property integer $id
* @property string $nom
* @property string $siret
* @property string $logo
* @property string $photo
* @property string $description
* @property string $code_postal
* @property string $ville
*/
class Etablissement extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'etablissement';
}

/**
* @inheritdoc
*/
public function rules()
{
return [
[['nom', 'siret'], 'required'],
[['description'], 'string'],
[['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville'], 'string', 'max' => 255],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'nom' => 'Nom',
'siret' => 'Siret',
'logo' => 'Logo',
'photo' => 'Photo',
'description' => 'Description',
'code_postal' => 'Code postal',
'ville' => 'Ville',
];
}
}

+ 3
- 3
common/models/PointVente.php View File

[['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'], [['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'],
[['point_fabrication','vrac','pain'], 'boolean'], [['point_fabrication','vrac','pain'], 'boolean'],
['point_fabrication', 'default','value'=>0], ['point_fabrication', 'default','value'=>0],
['id_boulangerie','integer'],
['id_boulangerie','required'],
['id_etablissement','integer'],
['id_etablissement','required'],
]; ];
} }


public function save($runValidation = true, $attributeNames = NULL) public function save($runValidation = true, $attributeNames = NULL)
{ {
$this->id_boulangerie = Yii::$app->user->identity->id ;
$this->id_etablissement = 0 ;
$this->pain = 1 ; $this->pain = 1 ;
return parent::save($runValidation, $attributeNames) ; return parent::save($runValidation, $attributeNames) ;

+ 3
- 3
common/models/Produit.php View File

[['illustration','photo'], 'file'], [['illustration','photo'], 'file'],
[['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255], [['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255],
[['recette'], 'string','max'=>1000], [['recette'], 'string','max'=>1000],
['id_boulangerie','integer'],
['id_boulangerie','required'],
['id_etablissement','integer'],
['id_etablissement','required'],
]; ];
} }


public function save($runValidation = true, $attributeNames = NULL) public function save($runValidation = true, $attributeNames = NULL)
{ {
$this->id_boulangerie = Yii::$app->user->identity->id ;
$this->id_etablissement = 0 ;
return parent::save($runValidation, $attributeNames) ; return parent::save($runValidation, $attributeNames) ;
} }
} }

+ 11
- 5
common/models/User.php View File

public function isBoulanger() public function isBoulanger()
{ {
return $this->is_boulanger ;
return $this->id_etablissement ;
} }
public function getBoulangeriesFavoris()
public function getNomMagasin()
{
$etablissement = Etablissement::find($this->id_etablissement)->one() ;
return $etablissement->nom ;
}
public function getEtablissementsFavoris()
{ {
return (new \yii\db\Query()) return (new \yii\db\Query())
->select('*') ->select('*')
->from(['user_boulangerie','user'])
->where('user_boulangerie.id_boulangerie = user.id')
->andWhere(['user_boulangerie.id_user' => $this->id])
->from(['user_etablissement', 'etablissement'])
->where('user_etablissement.id_etablissement = etablissement.id')
->andWhere(['user_etablissement.id_user' => $this->id])
->all(); ->all();
} }

+ 2
- 2
common/models/UserBoulangerie.php View File

public function rules() public function rules()
{ {
return [ return [
[['id_user', 'id_boulangerie'], 'required'],
[['id_user', 'id_boulangerie'], 'integer'],
[['id_user', 'id_etablissement'], 'required'],
[['id_user', 'id_etablissement'], 'integer'],
]; ];
} }



+ 6
- 6
console/migrations/m161012_074719_infos_boulanger.php View File

{ {
public function up() public function up()
{ {
$this->addColumn('user', 'is_boulanger', Schema::TYPE_BOOLEAN) ;
$this->addColumn('user', 'nom_magasin', Schema::TYPE_STRING) ;
$this->addColumn('user', 'siret', Schema::TYPE_STRING) ;
$this->addColumn('user', 'id_etablissement', Schema::TYPE_INTEGER) ;
//$this->addColumn('user', 'nom_magasin', Schema::TYPE_STRING) ;
//$this->addColumn('user', 'siret', Schema::TYPE_STRING) ;
} }


public function down() public function down()
{ {
$this->dropColumn('user', 'is_boulanger') ;
$this->dropColumn('user', 'nom_magasin') ;
$this->dropColumn('user', 'siret') ;
$this->dropColumn('user', 'id_etablissement') ;
//$this->dropColumn('user', 'nom_magasin') ;
//$this->dropColumn('user', 'siret') ;
} }
/* /*

+ 6
- 6
console/migrations/m161012_075736_ajout_ids_boulangerie.php View File

{ {
public function up() public function up()
{ {
$this->addColumn('produit', 'id_boulangerie', Schema::TYPE_INTEGER) ;
$this->addColumn('production', 'id_boulangerie', Schema::TYPE_INTEGER) ;
$this->addColumn('point_vente', 'id_boulangerie', Schema::TYPE_INTEGER) ;
$this->addColumn('produit', 'id_etablissement', Schema::TYPE_INTEGER) ;
$this->addColumn('production', 'id_etablissement', Schema::TYPE_INTEGER) ;
$this->addColumn('point_vente', 'id_etablissement', Schema::TYPE_INTEGER) ;
} }


public function down() public function down()
{ {
$this->dropColumn('produit', 'id_boulangerie') ;
$this->dropColumn('production', 'id_boulangerie') ;
$this->dropColumn('point_vente', 'id_boulangerie') ;
$this->dropColumn('produit', 'id_etablissement') ;
$this->dropColumn('production', 'id_etablissement') ;
$this->dropColumn('point_vente', 'id_etablissement') ;
} }
/* /*

+ 4
- 4
console/migrations/m161014_084709_table_user_boulangerie.php View File

{ {
public function up() public function up()
{ {
$this->createTable('user_boulangerie', [
$this->createTable('user_etablissement', [
'id_user' => Schema::TYPE_INTEGER . ' NOT NULL', 'id_user' => Schema::TYPE_INTEGER . ' NOT NULL',
'id_boulangerie' => Schema::TYPE_INTEGER . ' NOT NULL',
'PRIMARY KEY (`id_user`, `id_boulangerie`)'
'id_etablissement' => Schema::TYPE_INTEGER . ' NOT NULL',
'PRIMARY KEY (`id_user`, `id_etablissement`)'
]); ]);
} }


public function down() public function down()
{ {
$this->dropTable('user_boulangerie');
$this->dropTable('user_etablissement');
} }
} }

+ 6
- 6
console/migrations/m161020_072119_champs_boulangerie.php View File

{ {
public function up() public function up()
{ {
$this->addColumn('user', 'logo', Schema::TYPE_STRING) ;
$this->addColumn('user', 'photo', Schema::TYPE_STRING) ;
$this->addColumn('user', 'description', Schema::TYPE_TEXT) ;
//$this->addColumn('user', 'logo', Schema::TYPE_STRING) ;
//$this->addColumn('user', 'photo', Schema::TYPE_STRING) ;
//$this->addColumn('user', 'description', Schema::TYPE_TEXT) ;
} }


public function down() public function down()
{ {
$this->dropColumn('user', 'logo');
$this->dropColumn('user', 'photo');
$this->dropColumn('user', 'description');
//$this->dropColumn('user', 'logo');
//$this->dropColumn('user', 'photo');
//$this->dropColumn('user', 'description');
} }


/* /*

+ 37
- 0
console/migrations/m161021_073634_table_etablissement.php View File

<?php

use yii\db\Migration;
use yii\db\Schema;

class m161021_073634_table_etablissement extends Migration
{
public function up()
{
$this->createTable('etablissement', [
'id' => 'pk',
'nom' => Schema::TYPE_STRING . ' NOT NULL',
'siret' => Schema::TYPE_STRING . ' NOT NULL',
'logo' => Schema::TYPE_STRING,
'photo' => Schema::TYPE_STRING,
'description' => Schema::TYPE_TEXT,
'code_postal' => Schema::TYPE_STRING,
'ville' => Schema::TYPE_STRING,
]);
}

public function down()
{
$this->dropTable('etablissement') ;
}

/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}

public function safeDown()
{
}
*/
}

+ 1
- 1
frontend/controllers/CommandeController.php View File

public function actionIndex() { public function actionIndex() {


// liste des boulangeries // liste des boulangeries
$boulangeries = Yii::$app->user->identity->getBoulangeriesFavoris();
$boulangeries = Yii::$app->user->identity->getEtablissementsFavoris();


// liste des commandes // liste des commandes
$commandes = Commande::find() $commandes = Commande::find()

+ 1
- 1
frontend/views/commande/index.php View File

<div class=""> <div class="">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title"><?php echo Html::encode($b['nom_magasin']); ?></h3>
<h3 class="panel-title"><?php echo Html::encode($b['nom']); ?></h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<?php if(strlen($b['logo'])): ?> <?php if(strlen($b['logo'])): ?>

Loading…
Cancel
Save