Quellcode durchsuchen

Liaison utilisateur/point de vente (UserPointSale) des données existantes via migration

Adaptation de la recherche des utilisateurs pour uniquement se baser sur UserPointSale
dev
Guillaume Bourgeois vor 5 Jahren
Ursprung
Commit
79249a86d3
2 geänderte Dateien mit 52 neuen und 10 gelöschten Zeilen
  1. +1
    -10
      common/models/UserSearch.php
  2. +51
    -0
      console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php

+ 1
- 10
common/models/UserSearch.php Datei anzeigen

@@ -90,16 +90,7 @@ class UserSearch extends User
if(isset($this->id_point_sale) && $this->id_point_sale) {
$pointSale = PointSale::findOne(['id' => $this->id_point_sale]) ;
if($pointSale->restricted_access) {
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
else {
$query->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $this->id_point_sale]
)->groupBy('user.id') ;
}
$query->innerJoin('user_point_sale','user.id = user_point_sale.id_user AND user_point_sale.id_point_sale = :id_point_sale',[':id_point_sale' => $this->id_point_sale]) ;
}
if(isset($this->inactive) && $this->inactive) {

+ 51
- 0
console/migrations/m190226_084104_lien_utilisateur_point_de_vente.php Datei anzeigen

@@ -0,0 +1,51 @@
<?php

use yii\db\Migration;

class m190226_084104_lien_utilisateur_point_de_vente extends Migration
{
public function up()
{
$producersArray = \common\models\Producer::find()->all() ;
foreach($producersArray as $producer) {
$pointsSaleArray = common\models\PointSale::find()
->where([
'id_producer' => $producer->id
])
->all();
foreach($pointsSaleArray as $pointSale) {
$usersArray = common\models\User::find()->innerJoin(
'order',
'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
[':id_point_sale' => $pointSale->id]
)
->groupBy('user.id')
->all();
foreach($usersArray as $user) {
$userPointSale = \common\models\UserPointSale::find()
->where([
'id_user' => $user->id,
'id_point_sale' => $pointSale->id
])->one() ;
if(!$userPointSale) {
$userPointSale = new \common\models\UserPointSale() ;
$userPointSale->id_user = $user->id ;
$userPointSale->id_point_sale = $pointSale->id ;
$userPointSale->save() ;
}
}
}
}
}

public function down()
{
echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
return false;
}
}

Laden…
Abbrechen
Speichern