<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class StudentCriteriaAchievedView extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		//
		DB::statement(' CREATE VIEW `student_criteria_achieved`
AS SELECT
   `a`.`student_id` AS `student_id`,
   `c`.`semester_id` AS `semester_id`,
   `coo`.`criterion_id` AS `criterion_id`,
   `coo`.`outcome_id` AS `outcome_id`,count(0) AS `total_achieved`
FROM ((((((((`assessments` `a` join `activity_criterion` `acn`) join `activities` `ac`) join `courses` `c`) join `students` `s`) join `criterion_objective_outcome` `coo`) join `rubric_activity` `ra`) join `rubrics` `r`) join `semesters` `sm`) where ((`r`.`id` = `ra`.`rubric_id`) and (`ra`.`activity_id` = `ac`.`id`) and (`a`.`activity_criterion_id` = `acn`.`id`) and (`acn`.`activity_id` = `ac`.`id`) and (`ac`.`course_id` = `c`.`id`) and (`a`.`student_id` = `s`.`id`) and (`acn`.`criterion_id` = `coo`.`criterion_id`) and (`a`.`score` >= `r`.`expected_points`) and (`sm`.`id` = `c`.`semester_id`) and (`sm`.`is_visible` = 1)) group by `a`.`student_id`,`c`.`semester_id`,`coo`.`criterion_id`,`coo`.`outcome_id`;
');
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		//
		DB::statement('DROP VIEW IF EXISTS student_criteria_achieved');

	}

}
