Ingen beskrivning

FillScalesCriteria.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class FillScalesCriteria extends Seeder {
  3. public function run()
  4. {
  5. $criteria=DB::table('criteria')->get();
  6. foreach($criteria as $criterion)
  7. {
  8. $existe=DB::table('scales')->where('title',"description12")->where('description',$criterion->description12)->where('position',1)->first();
  9. if(empty($existe))
  10. {
  11. $scale_id=DB::table('scales')->insertGetId(array('title'=>"description12",'description'=>$criterion->description12,'position'=>1));
  12. }
  13. else
  14. {
  15. $scale_id=$existe->id;
  16. }
  17. DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
  18. $existe=DB::table('scales')->where('title',"description34")->where('description',$criterion->description34)->where('position',2)->first();
  19. if(empty($existe))
  20. {
  21. $scale_id=DB::table('scales')->insertGetId(array('title'=>"description34",'description'=>$criterion->description34,'position'=>2));
  22. }
  23. else
  24. {
  25. $scale_id=$existe->id;
  26. }
  27. DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
  28. $existe=DB::table('scales')->where('title',"description56")->where('description',$criterion->description56)->where('position',3)->first();
  29. if(empty($existe))
  30. {
  31. $scale_id=DB::table('scales')->insertGetId(array('title'=>"description56",'description'=>$criterion->description56,'position'=>3));
  32. }
  33. else
  34. {
  35. $scale_id=$existe->id;
  36. }
  37. DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
  38. $existe=DB::table('scales')->where('title',"description78")->where('description',$criterion->description78)->where('position',4)->first();
  39. if(empty($existe))
  40. {
  41. $scale_id=DB::table('scales')->insertGetId(array('title'=>"description78",'description'=>$criterion->description78,'position'=>4));
  42. }
  43. else
  44. {
  45. $scale_id=$existe->id;
  46. }
  47. $existe_ya=DB::table('criterion_scale')->where('scale_id', $scale_id)->where('criterion_id', $criterion->id)->first();
  48. if(empty($existe_ya))DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
  49. }
  50. }
  51. }