Ingen beskrivning

FillNewCriterionRubric.php 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. class FillNewCriterionRubric extends Seeder {
  3. public function run()
  4. {
  5. $rubrics=DB::table('rubrics')->get();
  6. $i=0;
  7. foreach ($rubrics as $rubric)
  8. {
  9. $datos=json_decode($rubric->contents, true);
  10. // print_r($datos);
  11. // print"\n";
  12. // print $rubric->id;print"\t";
  13. // if($rubric->id==29){var_dump($datos);}
  14. foreach($datos as $dato)
  15. {
  16. if($rubric->id==29){print $dato["id"];print"Entrando\n";}
  17. $new_criterion=(array)DB::table('criteria')->where('id', $dato["id"])->first();
  18. // var_dump($new_criterion);
  19. $program_id=(array)DB::table('courses')
  20. ->join('activities', 'courses.id', '=', 'activities.course_id')
  21. ->join('new_rubric_activity', 'new_rubric_activity.activity_id', '=', 'activities.id')
  22. ->select('courses.program_id')
  23. ->where('new_rubric_activity.rubric_id',$rubric->id)
  24. ->first();
  25. if(empty($program_id))$program_id['program_id']=1;
  26. // else var_dump($program_id);
  27. // var_dump($program_id);
  28. // var_dump($new_criterion);
  29. if(!empty($new_criterion))
  30. {
  31. $existe=(array)DB::table('objectives')->where('id', $new_criterion["id"])->first();
  32. $objective_id=$new_criterion["id"];
  33. if(empty($existe))
  34. {
  35. $existe4=(array)DB::table('objectives')->where('program_id', $program_id['program_id'])->where('text', $new_criterion["name"])->first();
  36. // print_r($existe4);print"\n";
  37. if(!empty($existe4))
  38. {
  39. // DB::table('objectives')->insert(array("id"=> $new_criterion["id"],"program_id"=>$program_id['program_id'],"text"=>$new_criterion["name"],'outcome_id'=>$new_criterion['outcome_id']));
  40. $objective_id=$existe4["id"];
  41. }
  42. else
  43. {
  44. print "A crear entrada en objectives: $objective_id";
  45. // var_dump(array("id"=> $objective_id,"program_id"=>$program_id['program_id'],"text"=>$new_criterion["name"],'outcome_id'=>$new_criterion['outcome_id']));
  46. DB::table('objectives')->insert(array("id"=> $objective_id,"program_id"=>$program_id['program_id'],"text"=>$new_criterion["name"],'outcome_id'=>$new_criterion['outcome_id']));
  47. }
  48. }
  49. else
  50. {
  51. $existe4=(array)DB::table('objectives')->where('program_id', $program_id['program_id'])->where('text', $new_criterion["name"])->first();
  52. // print_r($existe4);print"\n";
  53. if(empty($existe4))
  54. {
  55. $objective_id=DB::table('objectives')->insertGetId(array("program_id"=>$program_id['program_id'],"text"=>$new_criterion["name"],'outcome_id'=>$new_criterion['outcome_id']));
  56. }
  57. }
  58. $new_criterion["objective_id"]=$objective_id;
  59. unset($new_criterion['outcome_id']);
  60. // var_dump($new_criterion);
  61. $existe2=(array)DB::table('new_criteria')->where('id', $new_criterion["id"])->first();
  62. if(empty($existe2))
  63. {
  64. DB::table('new_criteria')->insert($new_criterion);
  65. }
  66. $existe3=(array)DB::table('new_criterion_rubric')->where('criterion_id', $new_criterion["id"])->where('rubric_id', $rubric->id)->first();
  67. if(empty($existe3))
  68. {
  69. DB::table('new_criterion_rubric')->insert(
  70. array('criterion_id' => $dato["id"], 'rubric_id' => $rubric->id)
  71. );
  72. }
  73. }
  74. // if($i)exit();
  75. }
  76. // if($rubric->id==29){exit();}
  77. $i++;
  78. }
  79. // $course = Rubric::where('code', $code)->where('number', $number)->where('section', $section)->where('semester_id', $semester_id)->first();
  80. }
  81. }