You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

m190226_084104_lien_utilisateur_point_de_vente.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. use yii\db\Migration;
  3. use common\logic\Producer\Producer\Producer;
  4. use common\logic\PointSale\PointSale\PointSale;
  5. use common\logic\PointSale\UserPointSale\UserPointSale;
  6. class m190226_084104_lien_utilisateur_point_de_vente extends Migration
  7. {
  8. public function up()
  9. {
  10. $producersArray = Producer::find()->all() ;
  11. foreach($producersArray as $producer) {
  12. $pointsSaleArray = PointSale::find()
  13. ->where([
  14. 'id_producer' => $producer->id
  15. ])
  16. ->all();
  17. foreach($pointsSaleArray as $pointSale) {
  18. $usersArray = UserModel::find()->innerJoin(
  19. 'order',
  20. 'user.id = order.id_user AND order.id_point_sale = :id_point_sale',
  21. [':id_point_sale' => $pointSale->id]
  22. )
  23. ->groupBy('user.id')
  24. ->all();
  25. foreach($usersArray as $user) {
  26. $userPointSale = UserPointSale::find()
  27. ->where([
  28. 'id_user' => $user->id,
  29. 'id_point_sale' => $pointSale->id
  30. ])->one() ;
  31. if(!$userPointSale) {
  32. $userPointSale = new UserPointSale() ;
  33. $userPointSale->id_user = $user->id ;
  34. $userPointSale->id_point_sale = $pointSale->id ;
  35. $userPointSale->save() ;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. public function down()
  42. {
  43. echo "m190226_084104_lien_utilisateur_point_de_vente cannot be reverted.\n";
  44. return false;
  45. }
  46. }