<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Request1;	
use Illuminate\Http\Request;
use App\Models\PatternsModel;

class PatternsController extends Controller {

	public function getPatterns()
	{
		//if(Request::ajax()){
			$m 		= new PatternsModel;
			$data 	= $m->selectAllPattern();
			
			foreach ($data as $row) {
				if($row->PatternName == "None"){
					echo '<option value="'.$row->PatternId.'" data-img="'.url("/public/images"). "/" .$row->PatternThumbnail.'" selected="selected" aria-disabled="true" disabled>'.$row->PatternName.'</option>';
				}else{
					echo '<option value="'.$row->PatternId.'" data-img="'.url("/public/images"). "/" .$row->PatternThumbnail.'">'.$row->PatternName.'</option>';
				}
				
			}

		//}
	}
	
	public function getPatternsWithPostValue(Request $request)
	{
		$m 		= new PatternsModel;
		$data 	= $m->selectAllPattern();
		
		$post 	=	$request->all();

		$pattern_list = array();
		foreach($post['patterns'] as $pt) {
		    $pattern_list[] = $pt;  
			//echo $pt;
		}

		foreach ($data as $row) {
			if(in_array($row->PatternId, $pattern_list)) {
		       echo '<option value="'.$row->PatternId.'" data-img="'.url("/public/images"). "/" . $row->PatternThumbnail.'" selected="selected">'.$row->PatternName.'</option>';
		    }else{
		    	echo '<option value="'.$row->PatternId.'" data-img="'.url("/public/images"). "/" . $row->PatternThumbnail.'" >'.$row->PatternName.'</option>';
		    }
			
		}

	}
}
