Kaynağa Gözat

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

master
keun 8 yıl önce
ebeveyn
işleme
5df7610828
18 değiştirilmiş dosya ile 223 ekleme ve 78 silme
  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 Dosyayı Görüntüle

@@ -0,0 +1,78 @@
<?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 Dosyayı Görüntüle

@@ -49,7 +49,7 @@ class PointVenteController extends Controller
{
$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', [

+ 1
- 1
backend/controllers/ProduitController.php Dosyayı Görüntüle

@@ -60,7 +60,7 @@ class ProduitController extends Controller
$dataProvider = new ActiveDataProvider([
'query' => Produit::find()
->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'),
'pagination' => [
'pageSize' => 1000,

+ 4
- 37
backend/controllers/UserController.php Dosyayı Görüntüle

@@ -53,8 +53,8 @@ class UserController extends Controller
(new \yii\db\Query())
->select('*')
->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', [
@@ -110,39 +110,6 @@ class UserController extends Controller
]);
}
}
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.
@@ -183,8 +150,8 @@ PS : Si vous ne souhaitez plus recevoir ces emails, rendez-vous dans votre compt
$users = (new \yii\db\Query())
->select('*')
->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() ;
$arr_users = [] ;

backend/views/user/parametres.php → backend/views/etablissement/update.php Dosyayı Görüntüle


+ 2
- 2
backend/views/layouts/main.php Dosyayı Görüntüle

@@ -36,7 +36,7 @@ AppAsset::register($this);
['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-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],
];
@@ -64,7 +64,7 @@ AppAsset::register($this);
<div class="container">
<?php if(!Yii::$app->user->isGuest): ?>
<div class="nom-boulange">
<span><?= Html::encode(Yii::$app->user->identity->nom_magasin) ; ?></span>
<span><?= Html::encode(Yii::$app->user->identity->getNomMagasin()) ; ?></span>
</div>
<?php endif; ?>
<?= Breadcrumbs::widget([

+ 57
- 0
common/models/Etablissement.php Dosyayı Görüntüle

@@ -0,0 +1,57 @@
<?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 Dosyayı Görüntüle

@@ -41,8 +41,8 @@ class PointVente extends \yii\db\ActiveRecord
[['adresse','localite','horaires_lundi','horaires_mardi','horaires_mercredi','horaires_jeudi','horaires_vendredi','horaires_samedi','horaires_dimanche'], 'string'],
[['point_fabrication','vrac','pain'], 'boolean'],
['point_fabrication', 'default','value'=>0],
['id_boulangerie','integer'],
['id_boulangerie','required'],
['id_etablissement','integer'],
['id_etablissement','required'],
];
}

@@ -106,7 +106,7 @@ class PointVente extends \yii\db\ActiveRecord
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_boulangerie = Yii::$app->user->identity->id ;
$this->id_etablissement = 0 ;
$this->pain = 1 ;
return parent::save($runValidation, $attributeNames) ;

+ 3
- 3
common/models/Produit.php Dosyayı Görüntüle

@@ -44,8 +44,8 @@ class Produit extends \yii\db\ActiveRecord
[['illustration','photo'], 'file'],
[['nom', 'description', 'illustration', 'photo', 'saison','diminutif'], 'string', 'max' => 255],
[['recette'], 'string','max'=>1000],
['id_boulangerie','integer'],
['id_boulangerie','required'],
['id_etablissement','integer'],
['id_etablissement','required'],
];
}

@@ -100,7 +100,7 @@ class Produit extends \yii\db\ActiveRecord
public function save($runValidation = true, $attributeNames = NULL)
{
$this->id_boulangerie = Yii::$app->user->identity->id ;
$this->id_etablissement = 0 ;
return parent::save($runValidation, $attributeNames) ;
}
}

+ 11
- 5
common/models/User.php Dosyayı Görüntüle

@@ -229,16 +229,22 @@ class User extends ActiveRecord implements IdentityInterface
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())
->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();
}

+ 2
- 2
common/models/UserBoulangerie.php Dosyayı Görüntüle

@@ -29,8 +29,8 @@ class UserBoulangerie extends \yii\db\ActiveRecord
public function rules()
{
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 Dosyayı Görüntüle

@@ -7,16 +7,16 @@ class m161012_074719_infos_boulanger extends Migration
{
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()
{
$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 Dosyayı Görüntüle

@@ -7,16 +7,16 @@ class m161012_075736_ajout_ids_boulangerie extends Migration
{
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()
{
$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 Dosyayı Görüntüle

@@ -7,15 +7,15 @@ class m161014_084709_table_user_boulangerie extends Migration
{
public function up()
{
$this->createTable('user_boulangerie', [
$this->createTable('user_etablissement', [
'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()
{
$this->dropTable('user_boulangerie');
$this->dropTable('user_etablissement');
}
}

+ 6
- 6
console/migrations/m161020_072119_champs_boulangerie.php Dosyayı Görüntüle

@@ -7,16 +7,16 @@ class m161020_072119_champs_boulangerie extends Migration
{
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()
{
$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 Dosyayı Görüntüle

@@ -0,0 +1,37 @@
<?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 Dosyayı Görüntüle

@@ -139,7 +139,7 @@ class CommandeController extends \yii\web\Controller {
public function actionIndex() {

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

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

+ 1
- 1
frontend/views/commande/index.php Dosyayı Görüntüle

@@ -18,7 +18,7 @@ $this->title = 'Commande' ;
<div class="">
<div class="panel panel-default">
<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 class="panel-body">
<?php if(strlen($b['logo'])): ?>

Yükleniyor…
İptal
Kaydet