<?php

/**
 * NoteModel
 * This is basically a simple CRUD (Create/Read/Update/Delete) demonstration.
 */
class CategoryModel
{
   
    public static function getCategory()
    {
        HeaderModel::postMethod();
         
        $database = DatabaseFactory::getFactory()->getConnection();
        
        $sql  = "SELECT *";
        $sql .= " FROM `sf_image_category`";
	
	 $database = DatabaseFactory::getFactory()->getConnection();
	 $query = $database->prepare($sql);
	 $query->execute();
	 
	 if($query->rowCount()>0) {

     $images = $query->fetchAll();
     
     $imgg = [];
    
    foreach($images as &$img) {
        
        $img->value = $img->id;
        unset($img->id); 
        $img->label = $img->name;
        unset($img->name); 
        
    }
    
    
    
            $response['status_code_header'] = 'HTTP/1.1 200 ok';
            $response['message'] = 'Data Fetched Successfully';
          
            $response['data'] = $images;
            
            http_response_code(200);
            
            
            echo  json_encode($response);
            return true;

}

else {
    
    $response['status_code_header'] = 'HTTP/1.1 404';
            $response['message'] = 'Data Not Found';
           
            $response['data'] = [];
            
            http_response_code(404);
            echo  json_encode($response);
            return false;
    
    
}
 


       
    }
    
    
    
     public static function sub($id)
    {
        HeaderModel::postMethod();
        
        if(!$id) {
            
             $response['status_code_header'] = 'HTTP/1.1 404';
            $response['message'] = 'Data Not Found';
           
            $response['data'] = [];
            
            http_response_code(404);
            echo  json_encode($response);
            return false;
        }
         
        $database = DatabaseFactory::getFactory()->getConnection();
     
    $sql = "SELECT * FROM sf_sub_category WHERE category_id='".$id."'";

   
$query = $database->prepare($sql);
$query->execute();

if($query->rowCount()>0) {
    
    $images = $query->fetchAll();
    
     foreach($images as &$img) {
        
        $img->value = $img->id;
        unset($img->id); 
        $img->label = $img->name;
        unset($img->name); 
        unset($img->category_id);
        
    }
    
    
            $response['status_code_header'] = 'HTTP/1.1 200 ok';
            $response['message'] = 'Data Fetched Successfully';
           
            $response['data'] = $images;
            
            http_response_code(200);
            
            
            echo  json_encode($response);
            return true;
            
}

else {
    
    $response['status_code_header'] = 'HTTP/1.1 404';
            $response['message'] = 'Data Not Found';
           
            $response['data'] = [];
            
            http_response_code(404);
            echo  json_encode($response);
            return false;
    
    
}


 


       
    }
    
    
      public static function getStatus()
    {
        HeaderModel::postMethod();
         
        $database = DatabaseFactory::getFactory()->getConnection();
        
        $sql  = "SELECT *";
        $sql .= " FROM `sf_shaps`";
	
	 $database = DatabaseFactory::getFactory()->getConnection();
	 $query = $database->prepare($sql);
	 $query->execute();
	 
	 if($query->rowCount()>0) {

     $images = $query->fetchAll();
     
     $imgg = [];
    
    foreach($images as &$img) {
        
        $img->value = $img->name;
        unset($img->id); 
        $img->label = $img->name;
        unset($img->name); 
        
    }
    
    
    
            $response['status_code_header'] = 'HTTP/1.1 200 ok';
            $response['message'] = 'Data Fetched Successfully';
          
            $response['data'] = $images;
            
            http_response_code(200);
            
            
            echo  json_encode($response);
            return true;

}

else {
    
    $response['status_code_header'] = 'HTTP/1.1 404';
            $response['message'] = 'Data Not Found';
           
            $response['data'] = [];
            
            http_response_code(404);
            echo  json_encode($response);
            return false;
    
    
}
 


       
    }
    
    
  
   
}