<?php namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class comunicacion extends Sximo  {
	
	protected $table = 'comunicacion';
	protected $primaryKey = 'ComID';

	public function __construct() {
		parent::__construct();
		$id = Auth::id();
		
		$dbcon = 0;
		$sql = \DB::table('tb_users')->where('id',$id)->get();
		if(count($sql)){
			$row = $sql[0];
			$dbcon =$row->dbcon;
			 $this->setConnection($dbcon);
		}		
		
		
		
	}

	public static function querySelect(  ){
		
		return " SELECT comunicacion.* FROM comunicacion ";
	}	

	public static function queryWhere(  ){
	      $id = Auth::id();

		$dbcon = 0;
		$sql = \DB::table('tb_users')->where('id',$id)->get();
		if(count($sql)){
			$row = $sql[0];
			$Email =$row->email;
			$Condominio = $row->Condominio;
			$Label = $row->Label;
		}	
	    
	    if($Label== 'Supervisor' || $Label == 'Seguridad'){
		
	     return "WHERE comunicacion.ComID IS NOT NULL AND (comunicacion.Email='$Email' OR comunicacion.Usuario LIKE '%".$Email."%')";   
	
	    }else{
	       
	     	return "WHERE (comunicacion.ComID IS NOT NULL AND comunicacion.Residente = 'Si' AND comunicacion.Condominio='$Condominio') OR comunicacion.Email='$Email' 
		OR comunicacion.Usuario LIKE '%".$Email."%'";
	        
	    }
	
	}
	
	public static function queryGroup(){
		return "  ";
	}
	

}
