Нет описания

FillNewCriterionRubric.php 3.3KB

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