<?php
/**
 * Created by PhpStorm.
 * User: varun
 * Date: 24/11/15
 * Time: 1:20 AM
 */

namespace App\Http\Controllers\Action;

use DB;


class Tender
{
    public function getTenderByCountry($country_name)
    {
        $result = DB::connection('mysql')
            ->table('tender_id')
            ->select('tbl_tenders_region')
            ->where('country_name' , '=' ,$country_name ) ;
        DB::disconnect('mysql');

        if(count ($result) > 0 )
            return $result;
        abort("Database error") ;
    }

    public function getTenderByState($state_name)
    {
        $result = DB::connection('mysql')
            ->table('tender_id')
            ->select('tbl_tenders_region')
            ->where('state_name' , '=' ,$state_name ) ;
        DB::disconnect('mysql');
        if(count ($result) > 0 )
            return $result;
        abort("Database error") ;
    }

    public function qryToCommaSepString($sqlQry, $uniqueResult = 'Y', &$countOfArr = 0)
    {
        $result = DB::connection('mysql')->select(DB::raw($sqlQry)) ;
        $namesW=array();
        foreach($result as  $row )
        {
            $namesW[]=reset($row);
        }
        $countOfArr = count($namesW);
        if( 'Y' == $uniqueResult )
            $dist_emails = implode(',',array_values(array_unique(array_filter($namesW))));
        else
            $dist_emails = implode(',',$namesW);

        DB::disconnect('mysql');
        return $dist_emails;
    }

    public function query($qry)
    {
        $result = DB::connection('mysql')->select(DB::raw($qry));;
        DB::disconnect('mysql');
        return $result;
    }

    public function getCategory()
    {
        return DB::connection('mysql')
            ->table('tbl_tenders')
            ->select('category')
            ->distinct()
			->where('category' , '<>' ,'index' )
			->where('category' , '<>' ,'' )
            ->get();
    }

    public function tenderEnquiry()
    {

    }

}