Ei kuvausta

Course.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. class Course extends Eloquent
  3. {
  4. protected $fillable = array('name', 'code', 'number', 'section', 'program_id', 'user_id', 'semester_id');
  5. protected $appends = array('proposed_transformative_actions');
  6. public function program()
  7. {
  8. return $this->belongsTo('Program');
  9. }
  10. public function students()
  11. {
  12. return $this->belongsToMany('Student')->orderBy('name', 'asc')->withTimestamps();
  13. }
  14. public function user()
  15. {
  16. return $this->belongsTo('User')->orderBy('surnames', 'asc')->orderBy('first_name', 'asc');
  17. }
  18. // TODO: Remove
  19. public function activities()
  20. {
  21. return $this->hasMany('Activity')->orderBy('date', 'asc');
  22. }
  23. public function activity()
  24. {
  25. return $this->belongsTo('Activity');
  26. }
  27. //paired_objective, como el typ_semester_course_id esta atado a un solo typ_semester_objective_id pues te devuelve el primero
  28. public function getPairedObjectiveAttribute()
  29. {
  30. return Objective::join('typ_semester_objectives', 'typ_semester_objectives.objective_id', '=', 'objectives.id')
  31. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  32. ->where('typ_semester_courses.id', $this->typ_semester_course_id)
  33. ->select('typ_semester_objectives.id as typ_semester_objective_id', 'objectives.*')
  34. ->first();
  35. }
  36. //future_transformative_actions
  37. public function getFutureTransformativeActionsAttribute()
  38. {
  39. if (isset($this->typ_semester_course_id)) {
  40. Log::info("entramos al isset");
  41. //Big object where data is going to turn out like
  42. /*
  43. $this->future_transformative_actions = all future transformative actions proposed in annual plan
  44. and each future_transformative_action has an attribute future_semesters where it will be an
  45. array of all future semesters proposed
  46. */
  47. $results = $this->getFutureTypSemesterCourses($this->typ_semester_course_id, $this->program_id);
  48. if (isset($results->future_transformative_actions))
  49. $results = $results->future_transformative_actions;
  50. $future_transformative_actions_ids = [];
  51. foreach ($results as $row) {
  52. //Log::info($this->typ_semester_course_id);
  53. //Log::info('row');
  54. //Log::info($row);
  55. if (isset($row->trans_id)) {
  56. if (!isset($future_transformative_actions_ids[$row->trans_id])) {
  57. $future_transformative_actions_ids[$row->trans_id] = [
  58. 'future_semesters' => []
  59. ];
  60. }
  61. Log::info('arreglo');
  62. Log::info($future_transformative_actions_ids);
  63. $future_transformative_actions_ids[$row->trans_id]['future_semesters'][] = $row->semester_id;
  64. } else continue;
  65. }
  66. $trans_actions = [];
  67. Log::info($future_transformative_actions_ids);
  68. foreach ($future_transformative_actions_ids as $trans_id => $future_semesters) {
  69. $ta = TransformativeAction::where('id', $trans_id)->first();
  70. //$ta->setAttribute('future_semesters', []);
  71. $temp_future_semesters = [];
  72. foreach ($future_semesters['future_semesters'] as $index => $semester_id) {
  73. //$ta->
  74. $temp_future_semesters[$index] = Semester::where('id', $semester_id)->first();
  75. }
  76. $ta->setAttribute('future_semesters', $temp_future_semesters);
  77. $trans_actions[] = $ta;
  78. }
  79. return $trans_actions;
  80. }
  81. }
  82. //proposed_transformative_actions
  83. public function getProposedTransformativeActionsAttribute()
  84. {
  85. if (isset($this->typ_semester_course_id)) {
  86. //return
  87. return TransformativeAction::join('annual_plan_transformative', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  88. ->where('typ_semester_course_id', $this->typ_semester_course_id)
  89. ->select('transformative_actions.*', DB::raw("{$this->semester_id} as semester_id"))
  90. ->get();
  91. $transformative_actions = DB::table('annual_plan_transformative')
  92. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  93. ->where('typ_semester_course_id', $this->typ_semester_course_id)
  94. ->select('transformative_actions.*')
  95. ->get();
  96. $trans_list = [];
  97. foreach ($transformative_actions as $trans) {
  98. $ta = TransformativeAction::where('id', $trans->id)->first();
  99. $ta->setAttribute("semester_id", $this->semester_id);
  100. $trans_list[] = $ta;
  101. }
  102. return $trans_list;
  103. }
  104. Log::info('te la viviste tm');
  105. return null;
  106. }
  107. // assessed_paired_criteria
  108. public function getAssessedPairedCriteriaAttribute()
  109. {
  110. $criteria_id = DB::table('annual_plan_objective')
  111. ->where('typ_semester_course_id', $this->typ_semester_course_id)
  112. ->lists('criteria_id');
  113. Log::info($this->typ_semester_course_id);
  114. Log::info("dame ese id");
  115. $program = Program::where('id', $this->program_id)->first();
  116. // Log::info($program->code);
  117. //Si es un programa como core, enseña todos los estudiantes
  118. if ($program->code == "") {
  119. $program_ids = DB::table('programs')
  120. ->where('school_id', $program->school->id)
  121. ->lists('programs.id');
  122. //Log::info("estamos");
  123. } else $program_ids = array($program->id);
  124. /*tabla es asi por curso codigo
  125. *
  126. *criterioDelPlan EstudiantesDelProgramaQuePasaron EstudiantesqueIntentaron
  127. *
  128. * criterio1 3 5
  129. * criterio2 2 2
  130. *
  131. *
  132. */
  133. return Criterion::join('activity_criterion', 'criteria.id', '=', 'activity_criterion.criterion_id')
  134. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  135. ->join('courses', 'courses.id', '=', 'activities.course_id')
  136. ->join('course_student', 'course_student.course_id', '=', 'courses.id')
  137. ->join('program_student_semester', 'program_student_semester.student_id', '=', 'course_student.student_id')
  138. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  139. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  140. ->join('assessments', function ($join) {
  141. $join->on("assessments.student_id", '=', 'program_student_semester.student_id')
  142. ->on('assessments.activity_criterion_id', '=', 'activity_criterion.id');
  143. })
  144. ->where('courses.semester_id', $this->semester_id)
  145. ->whereIn('courses.program_id', $program_ids)
  146. ->where('courses.code', $this->code)
  147. ->where('courses.number', $this->number)
  148. ->whereIn('program_student_semester.program_id', $program_ids)
  149. ->whereIn('activity_criterion.criterion_id', $criteria_id)
  150. ->whereIn('criteria.id', $criteria_id)
  151. ->where('program_student_semester.semester_id', $this->semester_id)
  152. ->select('criteria.*')
  153. ->addSelect(DB::raw("{$this->typ_semester_course_id} as typ_semester_course_id"))
  154. ->addSelect(DB::raw('count(case when assessments.score>= rubrics.expected_points then 1 else null end) as criteria_achieved'))
  155. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  156. ->groupBy('criteria.id')
  157. ->get();
  158. }
  159. //paired_criteria solo funciona para plan ahora_mismo, y esta puerquito
  160. public function getPairedCriteriaAttribute()
  161. {
  162. if (isset($this->typ_semester_course_id)) {
  163. return Criterion::join("annual_plan_objective", 'annual_plan_objective.criteria_id', '=', 'criteria.id')
  164. ->where('typ_semester_course_id', $this->typ_semester_course_id)
  165. ->select(
  166. 'criteria.*',
  167. 'typ_semester_course_id'
  168. )
  169. ->get();
  170. /*.
  171. $criteria_info = $this->getCriteriaPlanReport($this);
  172. $criteria_list = [];
  173. foreach ($criteria_info as $index => $criterion) {
  174. $criteria_list[$index] = Criterion::where("id", $criterion->id)->first();
  175. $criteria_list[$index]->setAttribute("criteria_attempted", $criterion->criteria_attempted);
  176. $criteria_list[$index]->setAttribute("criteria_achieved", $criterion->criteria_achieved);
  177. }
  178. return $criteria_list;
  179. }*/
  180. }
  181. return null;
  182. }
  183. public function assessedActivities()
  184. {
  185. // return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
  186. $activitiesAssessed = DB::table('activities')
  187. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  188. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  189. ->where('activities.course_id', $this->id)
  190. ->select('activities.id')
  191. ->distinct()
  192. ->lists('activities.id');
  193. //Log::info($activitiesAssessed);
  194. return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
  195. // return $this->hasMany('Activity')->where('activities.draft', 0)->orderBy('date', 'asc');
  196. }
  197. public static function get_associated_objective_outcome($typ_semester_course_id)
  198. {
  199. return DB::table('typ_semester_outcome')->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  200. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  201. ->where('typ_semester_courses.id', $typ_semester_course_id);
  202. }
  203. public static function getFutureTypSemesterCourses($typ_semester_course_id, $program_id)
  204. {
  205. $typ_info = new stdClass();
  206. $typ_info->future_semesters = DB::table('typ_semester_outcome')
  207. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  208. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  209. ->join('typ_semester_outcome as typ_o_2', 'typ_o_2.outcome_id', '=', 'typ_semester_outcome.outcome_id')
  210. ->join('semesters as sem1', 'sem1.id', '=', 'typ_semester_outcome.semester_id')
  211. ->join('typ_semester_objectives as typ_ob_2', function ($query) {
  212. $query->on('typ_ob_2.typ_semester_outcome_id', '=', 'typ_o_2.id')
  213. ->on('typ_semester_objectives.objective_id', '=', 'typ_ob_2.objective_id');
  214. })
  215. ->join('typ_semester_courses as typ_course_2', function ($join) {
  216. $join->on('typ_course_2.typ_semester_objective_id', '=', 'typ_ob_2.id')
  217. ->on('typ_semester_courses.course_id', '=', 'typ_course_2.course_id');
  218. })
  219. ->join('typ_program', 'typ_o_2.typ_program_id', '=', 'typ_program.id')
  220. ->join('semesters', 'semesters.id', '=', 'typ_o_2.semester_id')
  221. ->leftJoin('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_course_2.id')
  222. ->leftJoin('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  223. ->where('typ_semester_courses.id', $typ_semester_course_id)
  224. ->where('typ_program.program_id', $program_id)
  225. ->whereRaw('sem1.code < semesters.code')
  226. ->groupBy('typ_o_2.semester_id')
  227. ->select(
  228. 'typ_o_2.semester_id',
  229. 'typ_o_2.outcome_id',
  230. 'typ_o_2.id',
  231. 'typ_semester_courses.course_id',
  232. 'typ_semester_objectives.objective_id',
  233. 'typ_ob_2.id as typ_future_objective_id',
  234. 'typ_course_2.id as typ_future_course_id',
  235. 'semesters.name as semester_name',
  236. 'semesters.code as semester_code',
  237. 'transformative_actions.id as trans_id',
  238. 'transformative_actions.type_of_TA',
  239. 'transformative_actions.at_text',
  240. 'transformative_actions.description'
  241. ); //->get();
  242. //Log::info('El sql');
  243. $typ_info->future_transformative_actions = DB::table('typ_semester_outcome')
  244. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  245. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  246. ->join('typ_semester_outcome as typ_o_2', 'typ_o_2.outcome_id', '=', 'typ_semester_outcome.outcome_id')
  247. ->join('semesters as sem1', 'sem1.id', '=', 'typ_semester_outcome.semester_id')
  248. ->join('typ_semester_objectives as typ_ob_2', function ($query) {
  249. $query->on('typ_ob_2.typ_semester_outcome_id', '=', 'typ_o_2.id')
  250. ->on('typ_semester_objectives.objective_id', '=', 'typ_ob_2.objective_id');
  251. })
  252. ->join('typ_semester_courses as typ_course_2', function ($join) {
  253. $join->on('typ_course_2.typ_semester_objective_id', '=', 'typ_ob_2.id')
  254. ->on('typ_semester_courses.course_id', '=', 'typ_course_2.course_id');
  255. })
  256. ->join('typ_program', 'typ_o_2.typ_program_id', '=', 'typ_program.id')
  257. ->join('semesters', 'semesters.id', '=', 'typ_o_2.semester_id')
  258. ->leftJoin('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_course_2.id')
  259. ->leftJoin('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  260. ->where('typ_semester_courses.id', $typ_semester_course_id)
  261. ->where('typ_program.program_id', $program_id)
  262. ->whereRaw('sem1.code < semesters.code')
  263. //->groupBy('typ_o_2.semester_id')
  264. ->select(
  265. 'typ_o_2.semester_id',
  266. 'typ_o_2.outcome_id',
  267. 'typ_o_2.id',
  268. 'typ_semester_courses.course_id',
  269. 'typ_semester_objectives.objective_id',
  270. 'typ_ob_2.id as typ_future_objective_id',
  271. 'typ_course_2.id as typ_future_course_id',
  272. 'semesters.name as semester_name',
  273. 'semesters.code as semester_code',
  274. 'transformative_actions.id as trans_id',
  275. 'transformative_actions.type_of_TA',
  276. 'transformative_actions.at_text',
  277. 'transformative_actions.description'
  278. );
  279. //Log::info("typ_info");
  280. //Log::info($typ_info->future_semesters->toSql());
  281. $typ_info->future_semesters = $typ_info->future_semesters->get();
  282. //Log::info($typ_info->future_transformative_actions->toSql());
  283. $typ_info->future_transformative_actions = $typ_info->future_transformative_actions->get();
  284. //Log::info($typ_info->toSql());
  285. Log::info($typ_semester_course_id);
  286. Log::info($program_id);
  287. return $typ_info;
  288. }
  289. public function publishedActivities()
  290. {
  291. $activitiesAssessed = DB::table('activities')
  292. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  293. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  294. ->where('activities.course_id', $this->id)
  295. ->where('activities.draft', 0)
  296. ->where('activities.diagnostic', 0)
  297. ->select('activities.id')
  298. ->distinct()
  299. ->lists('activities.id');
  300. //$this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
  301. return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
  302. }
  303. public function diagnosticActivities()
  304. {
  305. $activitiesAssessed = DB::table('activities')
  306. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  307. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  308. ->where('activities.course_id', $this->id)
  309. ->where('activities.draft', 0)
  310. ->where('activities.diagnostic', 1)
  311. ->select('activities.id')
  312. ->distinct()
  313. ->lists('activities.id');
  314. //$this->hasMany('Activity')
  315. return $this->hasMany('Activity')->whereIn('activities.id', $activitiesAssessed)->orderBy('date', 'asc');
  316. }
  317. public function outcomes_attempted()
  318. {
  319. return DB::table('courses')
  320. ->join('activities', 'activities.course_id', '=', 'courses.id')
  321. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  322. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  323. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  324. ->where('courses.id', '=', $this->id)
  325. ->select('criterion_objective_outcome.outcome_id')
  326. ->distinct()
  327. ->orderBy('criterion_objective_outcome.outcome_id')
  328. ->get();
  329. // SELECT distinct cr.outcome_id FROM courses c, activities a, activity_criterion ac, criteria cr WHERE c.id=a.course_id and a.id=ac.activity_id and ac.criterion_id=cr.id and c.id=1
  330. // return $this->id;
  331. }
  332. public function outcomes_att()
  333. {
  334. $criteria_attempted = DB::table('courses')
  335. ->join('activities', 'activities.course_id', '=', 'courses.id')
  336. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  337. ->select('criterion_id', 'activity_criterion.id as activity_criterion_id')
  338. ->where('courses.id', $this->id)
  339. ->where('draft', 0)
  340. ->where('activities.diagnostic', 0)
  341. ->get();
  342. // Old data was formed like { "outcome1": cuantity_of_criteria_associated, "outcome2":cuantity_of_criteria}
  343. $outcomes_attempted = [];
  344. foreach ($criteria_attempted as $criterion) {
  345. $outcomes = DB::table('criterion_objective_outcome')
  346. ->where('criterion_id', $criterion->criterion_id)
  347. ->select('outcome_id')
  348. ->distinct()
  349. ->lists('outcome_id');
  350. foreach ($outcomes as $outcome_id) {
  351. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
  352. else $outcomes_attempted[$outcome_id] = 1;
  353. }
  354. }
  355. Log::info("outcomes_attempted");
  356. Log::info($outcomes_attempted);
  357. return $outcomes_attempted;
  358. }
  359. public static function getCriteriaPlanReport($course_code = null)
  360. {
  361. if ($course_code) {
  362. $criteria_id = DB::table('annual_plan_objective')
  363. ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
  364. ->lists('criteria_id');
  365. Log::info($course_code->typ_semester_course_id);
  366. Log::info("dame ese id");
  367. $program = Program::where('id', $course_code->program_id)->first();
  368. // Log::info($program->code);
  369. //Si es un programa como core, enseña todos los estudiantes
  370. if ($program->code == "") {
  371. $program_ids = DB::table('programs')
  372. ->where('school_id', $program->school->id)
  373. ->lists('programs.id');
  374. //Log::info("estamos");
  375. } else $program_ids = array($program->id);
  376. /*tabla es asi por curso codigo
  377. *
  378. *criterioDelPlan EstudiantesDelProgramaQuePasaron EstudiantesqueIntentaron
  379. *
  380. * criterio1 3 5
  381. * criterio2 2 2
  382. *
  383. *
  384. */
  385. $table_per_criterion = DB::table('program_student_semester')
  386. ->join('course_student', 'program_student_semester.student_id', '=', 'course_student.student_id')
  387. ->join('courses', 'courses.id', '=', 'course_student.course_id')
  388. ->join('activities', 'activities.course_id', '=', 'courses.id')
  389. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  390. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  391. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  392. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  393. ->join('assessments', function ($join) {
  394. $join->on("assessments.student_id", '=', 'program_student_semester.student_id')
  395. ->on('assessments.activity_criterion_id', '=', 'activity_criterion.id');
  396. })
  397. ->where('courses.semester_id', $course_code->semester_id)
  398. ->whereIn('courses.program_id', $program_ids)
  399. ->where('courses.code', $course_code->code)
  400. ->where('courses.number', $course_code->number)
  401. ->whereIn('program_student_semester.program_id', $program_ids)
  402. ->whereIn('activity_criterion.criterion_id', $criteria_id)
  403. ->whereIn('criteria.id', $criteria_id)
  404. ->where('program_student_semester.semester_id', $course_code->semester_id)
  405. ->select('criteria.*')
  406. ->addSelect(DB::raw('count(case when assessments.score>= rubrics.expected_points then 1 else null end) as criteria_achieved'))
  407. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  408. ->groupBy('criteria.id');
  409. /*Log::info($table_per_criterion->toSql());
  410. Log::info(array($course_code));
  411. Log::info($program_ids);
  412. Log::info($criteria_id);
  413. Log::info('mera 1');
  414. Log::info(array($course_code));
  415. Log::info($table_per_criterion->get()); */
  416. return $table_per_criterion->get();
  417. }
  418. }
  419. //dirty code repeated code
  420. public function getStudentReportForOutcomeAttribute()
  421. {
  422. return $this->getStudentReportForOutcome($this);
  423. }
  424. public static function getStudentReportForOutcome($course_code = null)
  425. {
  426. if ($course_code) {
  427. //Log::info('entré');
  428. $criteria_id = DB::table('annual_plan_objective')
  429. ->where('typ_semester_course_id', $course_code->typ_semester_course_id)
  430. ->lists('criteria_id');
  431. Log::info($criteria_id);
  432. $program = Program::where('id', $course_code->program_id)->first();
  433. // // Log::info($program->code);
  434. if ($program->code == "") {
  435. $program_ids = DB::table('programs')
  436. ->where('school_id', $program->school->id)
  437. ->lists('programs.id');
  438. // Log::info("estamos");
  439. } else $program_ids = array($program->id);
  440. // Log::info(array($course_code));
  441. //Table
  442. /* Student criterion_attempted criterion passed
  443. * 1 2 1
  444. * 2 7 4
  445. *
  446. *
  447. */
  448. $table_per_student = DB::table('program_student_semester')
  449. ->join('course_student', 'program_student_semester.student_id', '=', 'course_student.student_id')
  450. ->join("students", 'course_student.student_id', '=', 'students.id')
  451. ->join('courses', 'courses.id', '=', 'course_student.course_id')
  452. ->join('activities', 'activities.course_id', '=', 'courses.id')
  453. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  454. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  455. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  456. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  457. ->join('assessments', function ($join) {
  458. $join->on("assessments.student_id", '=', 'program_student_semester.student_id')
  459. ->on('assessments.activity_criterion_id', '=', 'activity_criterion.id');
  460. })
  461. ->where('courses.semester_id', $course_code->semester_id)
  462. ->whereIn('courses.program_id', $program_ids)
  463. ->where('courses.code', $course_code->code)
  464. ->where('courses.number', $course_code->number)
  465. ->whereIn('program_student_semester.program_id', $program_ids)
  466. ->whereIn('activity_criterion.criterion_id', $criteria_id)
  467. ->where('program_student_semester.semester_id', $course_code->semester_id)
  468. ->select('students.number as student_id')
  469. ->addSelect(DB::raw('count(assessments.activity_criterion_id) as criteria_attempted'))
  470. ->addSelect(DB::raw('count(case when assessments.score>=rubrics.expected_points then 1 else NULL end) as criteria_achieved'))
  471. ->groupBy('students.id');
  472. //Log::info($criteria_id);
  473. Log::info('los courseCode');
  474. // Log::info(array($course_code));
  475. Log::info('los programas');
  476. Log::info($program_ids);
  477. Log::info($table_per_student->toSql());
  478. $students = $table_per_student->get();
  479. return $students;
  480. }
  481. }
  482. public function getReportObject()
  483. {
  484. $reportObject = new stdClass();
  485. $reportObject->criteriaReport = DB::table('courses')
  486. ->join('activities', 'activities.course_id', '=', 'courses.id')
  487. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  488. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  489. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  490. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  491. ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  492. ->select(DB::raw(
  493. "count(assessments.score) as assessed,
  494. count(case when assessments.score >= rubrics.expected_points then 1 else NULL end) as achieved,
  495. criteria.*"
  496. ))
  497. ->where('courses.id', $this->id)
  498. ->groupBy('criteria.id')
  499. ->get();
  500. //Log::info($this->id);
  501. $reportObject->outcomesReport = DB::table('courses')
  502. ->join('activities', 'activities.course_id', '=', 'courses.id')
  503. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  504. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  505. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  506. ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  507. ->join('criterion_objective_outcome', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  508. ->join('outcomes', 'criterion_objective_outcome.outcome_id', '=', 'outcomes.id')
  509. ->select(
  510. DB::raw(
  511. "student_id, outcomes.name, outcomes.id,
  512. count(activity_criterion.criterion_id) as attempted,
  513. count(case when assessments.score >= rubrics.expected_points then 1 else null end) as achieved"
  514. )
  515. )
  516. ->where('courses.id', $this->id)
  517. ->groupBy(array('outcome_id', 'student_id'))
  518. ->get();
  519. return $reportObject;
  520. }
  521. public function outcomes_ach()
  522. {
  523. $criteria = DB::table('criteria')
  524. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  525. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  526. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  527. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  528. ->join('courses', 'activities.course_id', '=', 'courses.id')
  529. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  530. ->where('courses.id', '=', $this->id)
  531. ->where('activities.draft', 0)
  532. ->where('activities.diagnostic', 0)
  533. ->select(
  534. 'criteria.id',
  535. 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
  536. 'activity_criterion.activity_id'
  537. )
  538. ->distinct()
  539. ->get();
  540. // Old data was formed like { "outcome1": cuantity_of_criteria_associated_passed, "outcome2":cuantity_of_criteria}
  541. $outcomes_achieved = [];
  542. foreach ($criteria as $criterion) {
  543. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  544. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  545. Log::info('estamos aqui');
  546. Log::info($students_attempted);
  547. if ($students_attempted) {
  548. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  549. } else {
  550. $percentage_students_who_achieved = 0;
  551. }
  552. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  553. $outcomes = DB::table('criterion_objective_outcome')
  554. ->where('criterion_id', $criterion->id)
  555. ->select('outcome_id')
  556. ->distinct()
  557. ->lists('outcome_id');
  558. foreach ($outcomes as $outcome_id) {
  559. if (array_key_exists($outcome_id, $outcomes_achieved)) $outcomes_achieved[$outcome_id] += 1;
  560. else $outcomes_achieved[$outcome_id] = 1;
  561. }
  562. }
  563. }
  564. Log::info(
  565. "OUTCOMES_ACHIEVED: "
  566. );
  567. Log::info(
  568. $outcomes_achieved
  569. );
  570. return $outcomes_achieved;
  571. }
  572. public function someSectionAssessed()
  573. {
  574. $all_sections = DB::table('courses')
  575. ->join('activities', 'activities.course_id', '=', 'courses.id')
  576. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  577. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  578. ->where('courses.name', $this->name)
  579. ->where('code', $this->code)
  580. ->where('number', $this->number)
  581. ->where('semester_id', $this->semester_id)
  582. ->where(
  583. 'program_id',
  584. $this->program_id
  585. )
  586. ->where('activities.draft', 0)
  587. ->where('activities.diagnostic', 0)
  588. ->groupBy('courses.id')
  589. ->count();
  590. return $all_sections;
  591. }
  592. public function isAssessed()
  593. {
  594. $assessed = DB::table('assessments')
  595. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  596. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  597. ->where('activities.course_id', $this->id)
  598. ->count();
  599. // Log::info("aqui".$assessed);
  600. if ($assessed) return true;
  601. else return false;
  602. }
  603. public function outcomes_achieved()
  604. {
  605. $criteria = DB::table('criteria')
  606. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  607. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  608. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  609. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  610. ->join('courses', 'activities.course_id', '=', 'courses.id')
  611. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  612. ->where('courses.id', '=', $this->id)
  613. ->select(
  614. 'criteria.id',
  615. 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
  616. 'activity_criterion.activity_id'
  617. )
  618. ->distinct()
  619. ->get();
  620. $conteo = 0;
  621. foreach ($criteria as $criterion) {
  622. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  623. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  624. if ($students_attempted) {
  625. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  626. } else {
  627. $percentage_students_who_achieved = 0;
  628. }
  629. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  630. $conteo++;
  631. }
  632. }
  633. return $conteo;
  634. }
  635. public function semester()
  636. {
  637. return $this->belongsTo('Semester');
  638. }
  639. public function sectionsWithOutcome($outcome_id)
  640. {
  641. return Course::has('activities')->with(array('activities' => function ($query) use (&$outcome_id) {
  642. $query->where('outcomes_attempted', 'not like', '\'%"' . $outcome_id . '":0%\'');
  643. }))->where('code', $this->code)->where('number', $this->number)->get();
  644. }
  645. }