<?php

class FillScalesCriteria extends Seeder {

    public function run()
    {

    	$criteria=DB::table('criteria')->get();
		foreach($criteria as $criterion)
		{
			$existe=DB::table('scales')->where('title',"description12")->where('description',$criterion->description12)->where('position',1)->first();
			if(empty($existe))
			{
				$scale_id=DB::table('scales')->insertGetId(array('title'=>"description12",'description'=>$criterion->description12,'position'=>1));		
			}
			else
			{
				$scale_id=$existe->id;
			}
			DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
			$existe=DB::table('scales')->where('title',"description34")->where('description',$criterion->description34)->where('position',2)->first();
			if(empty($existe))
			{
				$scale_id=DB::table('scales')->insertGetId(array('title'=>"description34",'description'=>$criterion->description34,'position'=>2));
			}
			else
			{
				$scale_id=$existe->id;
			}
			DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
			$existe=DB::table('scales')->where('title',"description56")->where('description',$criterion->description56)->where('position',3)->first();
			if(empty($existe))
			{
				$scale_id=DB::table('scales')->insertGetId(array('title'=>"description56",'description'=>$criterion->description56,'position'=>3));
			}
			else
			{
				$scale_id=$existe->id;
			}
			DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));
			$existe=DB::table('scales')->where('title',"description78")->where('description',$criterion->description78)->where('position',4)->first();
			if(empty($existe))
			{
				$scale_id=DB::table('scales')->insertGetId(array('title'=>"description78",'description'=>$criterion->description78,'position'=>4));
			}
			else
			{
				$scale_id=$existe->id;
			}
			$existe_ya=DB::table('criterion_scale')->where('scale_id', $scale_id)->where('criterion_id', $criterion->id)->first();
			if(empty($existe_ya))DB::table('criterion_scale')->insert(array("scale_id"=>$scale_id,"criterion_id"=>$criterion->id));

		
		}

	}


}