<?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, | |||||
]); | |||||
} | |||||
} | |||||
} |
{ | { | ||||
$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', [ |
$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, |
(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 = [] ; |
['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([ |
<?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', | |||||
]; | |||||
} | |||||
} |
[['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) ; |
[['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) ; | ||||
} | } | ||||
} | } |
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(); | ||||
} | } | ||||
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'], | |||||
]; | ]; | ||||
} | } | ||||
{ | { | ||||
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') ; | |||||
} | } | ||||
/* | /* |
{ | { | ||||
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') ; | |||||
} | } | ||||
/* | /* |
{ | { | ||||
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'); | |||||
} | } | ||||
} | } |
{ | { | ||||
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'); | |||||
} | } | ||||
/* | /* |
<?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() | |||||
{ | |||||
} | |||||
*/ | |||||
} |
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() |
<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'])): ?> |