Sfoglia il codice sorgente

Adaptations refactoring/traduction backend/controllers/CommandeautoController > SubscriptionController

refactoring
parent
commit
23d1b23a01
2 ha cambiato i file con 54 aggiunte e 51 eliminazioni
  1. +49
    -51
      backend/controllers/SubscriptionController.php
  2. +5
    -0
      common/models/User.php

backend/controllers/CommandeautoController.php → backend/controllers/SubscriptionController.php Vedi File

@@ -73,7 +73,7 @@ termes.

namespace backend\controllers;

class CommandeautoController extends BackendController
class SubscriptionController extends BackendController
{
var $enableCsrfValidation = false;

@@ -87,7 +87,7 @@ class CommandeautoController extends BackendController
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->identity->status == USER::STATUS_ADMIN || Yii::$app->user->identity->status == USER::STATUS_BOULANGER;
return User::hasAccessBackend() ;
}
]
],
@@ -103,11 +103,11 @@ class CommandeautoController extends BackendController
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => CommandeAuto::find()
'query' => Subscription::find()
->with(['user', 'etablissement', 'pointVente', 'commandeAutoProduit'])
->joinWith(['user'])
->where(['commande_auto.id_etablissement' => Yii::$app->user->identity->id_etablissement])
->orderBy('commande_auto.id_point_vente ASC, CASE `commande_auto`.`username` WHEN "" THEN `user`.`nom` ELSE `commande_auto`.`username` END ASC'),
->where(['subscription.id_producer' => Producer::getId()])
->orderBy('subscription.id_point_sale ASC, CASE `subscription`.`username` WHEN "" THEN `user`.`name` ELSE `subscription`.`username` END ASC'),
'pagination' => [
'pageSize' => 1000,
],
@@ -126,25 +126,22 @@ class CommandeautoController extends BackendController
public function actionCreate()
{
// form
$model = new CommandeAutoForm;
$model->id_etablissement = Yii::$app->user->identity->id_etablissement;
$model = new SubscriptionForm;
$model->id_producer = Producer::getId();

// produits
$produits = Produit::find()
->where(['id_etablissement' => $model->id_etablissement])
->orderBy('order ASC')
->all();

$products = Product::searchAll() ;
if ($model->load(Yii::$app->request->post()) && $model->validate()
&& $model->save())
{
$this->redirect(['commandeauto/index']);
$this->redirect(['subscription/index']);
}

return $this->render('create', [
'model' => $model,
'produits' => $produits
]);
'model' => $model,
'products' => $products
]);
}

/**
@@ -157,56 +154,57 @@ class CommandeautoController extends BackendController
public function actionUpdate($id)
{
// form
$model = new CommandeAutoForm;
$commandeauto = CommandeAuto::findOne($id);
if ($commandeauto) {
$model = new SubscriptionForm;
$subscription = Subscription::findOne($id);
if ($subscription) {
$model->id = $id;
$model->id_etablissement = $commandeauto->id_etablissement;
$model->id_user = $commandeauto->id_user;
$model->username = $commandeauto->username;
$model->id_point_vente = $commandeauto->id_point_vente;
$model->date_debut = date('d/m/Y', strtotime($commandeauto->date_debut));
if (strlen($commandeauto->date_fin))
$model->date_fin = date('d/m/Y', strtotime($commandeauto->date_fin));
$model->lundi = $commandeauto->lundi;
$model->lundi = $commandeauto->lundi;
$model->mardi = $commandeauto->mardi;
$model->mercredi = $commandeauto->mercredi;
$model->jeudi = $commandeauto->jeudi;
$model->vendredi = $commandeauto->vendredi;
$model->samedi = $commandeauto->samedi;
$model->dimanche = $commandeauto->dimanche;
$model->paiement_automatique = $commandeauto->paiement_automatique;
$model->periodicite_semaine = $commandeauto->periodicite_semaine;
$model->id_producer = $subscription->id_producer;
$model->id_user = $subscription->id_user;
$model->username = $subscription->username;
$model->id_point_sale = $subscription->id_point_sale;
$model->date_begin = date('d/m/Y', strtotime($subscription->date_begin));
if (strlen($subscription->date_end)) {
$model->date_end = date('d/m/Y', strtotime($subscription->date_end));
}
$model->monday = $subscription->monday;
$model->tuesday = $subscription->tuesday;
$model->wednesday = $subscription->wednesday;
$model->thursday = $subscription->thursday;
$model->friday = $subscription->friday;
$model->saterday = $subscription->saterday;
$model->sunday = $subscription->sunday;
$model->auto_payment = $subscription->auto_payment;
$model->week_frequency = $subscription->week_frequency;


// produits
$commandeauto_produits = CommandeAutoProduit::find()->where(['id_commande_auto' => $model->id])->all();
foreach ($commandeauto_produits as $commandeauto_produit) {
$model->produits['produit_' . $commandeauto_produit->id_produit] = $commandeauto_produit->quantite;
$arrayProductsSubscription = ProductSubscription::searchAll([
'id_subscription' => $model->id
]) ;
foreach ($arrayProductsSubscription as $productSubscription) {
$model->products['product_' . $productSubscription->id_product] = $productSubscription->quantity;
}
} else {
throw new NotFoundHttpException('La commande récurrente est introuvable.', 404);
throw new NotFoundHttpException('L\'abonnement est introuvable.', 404);
}

// produits
$produits = Produit::find()
->where(['id_etablissement' => $model->id_etablissement])
->orderBy('order ASC')
->all();
$products = Product::searchAll() ;

if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (!strlen($model->date_fin)) {
$model->date_fin = null;
if (!strlen($model->date_end)) {
$model->date_end = null;
}
if ($model->save()) {
$this->redirect(['commandeauto/index']);
$this->redirect(['subscription/index']);
}
}

return $this->render('update', [
'model' => $model,
'produits' => $produits
'products' => $products
]);
}

@@ -217,9 +215,9 @@ class CommandeautoController extends BackendController
*/
public function actionDelete($id)
{
CommandeAutoProduit::deleteAll(['id_commande_auto' => $id]);
CommandeAuto::findOne($id)->delete();
$this->redirect(['commandeauto/index']);
ProductSubscription::deleteAll(['id_subscription' => $id]);
Subscription::findOne($id)->delete();
$this->redirect(['subscription/index']);
}

}

+ 5
- 0
common/models/User.php Vedi File

@@ -539,5 +539,10 @@ class User extends ActiveRecordCommon implements IdentityInterface
return false ;
}
public static function hasAccessBackend()
{
return User::getStatus() == USER::STATUS_ADMIN || User::getStatus() == USER::STATUS_PRODUCER;
}

}

Loading…
Annulla
Salva