<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use DB;

class TemplatesModel extends Model {

    function selectTemplates($id){
        $i = DB::table('templates')->where('SportsId', '=', $id)->get();
        return $i;
    }

    function selectTemplateTypes(){
        $i = DB::table('template_types')->get();
        return $i;
    }

    function selectTemplateLastId(){
        $i = DB::table('templates')->orderBy('Id', 'DESC')->first();
        return $i;
    }


    function insertNewTempalte($data){
        $i = DB::table('templates')->insert($data);
        return $i;
	}

	function insertTempaltePaths($data){
        $i = DB::table('template_paths')->insert($data);
        return $i;
	}

	function selectTemplate($tempCode){
        $i = DB::table('templates')->where('TemplateCode', '=', $tempCode)->get();
        return $i;
	}

	function selectTemplatePaths($tempCode){
        $i = DB::table('template_paths')->where('TemplateCode', '=', $tempCode)->get();
        return $i;
	}

	function updateNewTemplate($data, $templatecode){
        $i = DB::table('templates')->where('TemplateCode', $templatecode)->update($data);
        return $i;
    }

    function updateTemplatePaths($data, $Id){

        // $i = DB::table('template_paths')->where([
								// 				['TemplateCode', '=', $templatecode],
								// 				['Type', '=', $data['Type']],
								// 				['Side', '=', $data['Side']]
								// 				])->update($data);
    	$i = DB::table('template_paths')->where('Id', '=', $Id)->update($data);
        return $i;
	}

}