No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

56 líneas
1.8KB

  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. }