<?php namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;


class PortfolioModel extends Model 

{

protected $table      = 'portfolio';
protected $primaryKey = 'Id';
protected $allowedFields = ['image','imageTitle','slug','category','info'];
protected $limit;
protected $offset;
protected $Id;
protected $imageTitle;
protected $slug;
protected $category;
protected $info;
	

public function index()
{
$db = \Config\Database::connect("default");
		
		$query = $db->query("SELECT COUNT(*) FROM portfolio where category='Art'");
$row   = $query->getRow();
//var_dump($row);
echo $row->Id;
}
    



        public function count()
	{
	
	return $this->countAll(); 
	
	
	
	
	
	}


       public function getOneToDel($id)
       { 
       
      return $this->find($id);
       
      // return $this->asArray()
      // ->where(['Id'=>$id]);
       
       }


	


       




	

	public function insertPortfolio($image,$imageTitle,$slug,$category,$info)

	{
	$data = [
		'image' => $image,
		'imageTitle'    => $imageTitle,
		'slug'=> $slug,
		'category'=>$category,
		'info'=>$info
	];

	$this->save($data);



	}

       public function deleteOne($id)
       {
       $this->where('Id',$id )->delete();
       //need to get name image associated with blog and unlink it 
       
       return True;
       
       
       }
    


   public function isEmptyArt()
    
    {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Art' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}


      public function isEmptyLadies()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Ladies' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}




 public function isEmptyMens()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Mens' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}


      public function isEmptyBoys()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Boys' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}

public function isEmptyGirls()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Girls' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}




public function isEmptyBaby()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Baby' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}



public function isEmptyAccessory()
    
       {
           $db = \Config\Database::connect("default");
		   $query = $db->query("SELECT COUNT(*) FROM portfolio where category='Accessory' ");
		   $count   = $query->getRowArray();
                return  $count;

		
		}









public function getAll()

	{
	return $this->orderBy('Id', 'desc')->findAll();




	}

public function mens()
{
	return $this->where('category', 'Mens')
                   ->findAll();

}	











}
