<?php
class Property{

    public $model;
    
    public function __construct(){
        $this->model = new Model();
    }

    /** Property *************************************************************************************/
    
    public function getPropertyInfo($condition){
        return $this->model->findOne("property", $condition);
    }
    public function checkIfPropertyExists($condition){
        return count($this->model->findOne("property", $condition)) > 0 ? true : false;
    }
    public function registerProperty($fields, $values){
        return $this->model->insertdata("property", $fields, $values);
    }
    public function retrieveAllProperty($pageno, $limit){
        $data = $this->model->paginate("property", " 1 ORDER BY location ASC", $pageno, $limit);
        return $data;
    }
    public function retrievePropertyByStatus($status, $pageno, $limit){
        $data = $this->model->paginate("property", "status LIKE '$status' ORDER BY id ASC", $pageno, $limit);
        return $data;
    }    
    public function retrievePropertyByQuery($query, $pageno, $limit,$field = "*"){
        $data = $this->model->paginate("property", $query, $pageno, $limit,$field);
        return $data;
    }    
    public function updatePropertyDetails($query, $id){
        return $this->model->update('property', $query, "WHERE id = $id");
    }    
    public function getLastID(){
        return $this->model->lastId();
    }    
    /** End of Property **************************************************************************************************/

    /** Property Unit ******************************************************************************************************************/
    public function getPropertyUnitInfo($condition){
        return $this->model->findOne("propertyunit", $condition);
    }
    public function checkIfPropertyUnitExists($condition){
        return count($this->model->findOne("propertyunit", $condition)) > 0 ? true : false;
    }
    public function registerPropertyUnit($fields, $values){
        $result = $this->model->insertdata("propertyunit", $fields, $values);
        if($result){
            return $this->model->lastId();
        }else{
            return null;
        }            
        
    }
    public function updatePropertyUnitDetails($query, $id){
        return $this->model->update('propertyunit', $query, "WHERE id = $id");
    }    
    /** End of Property Unit ***********************************************************************************************************/    

    /** Tenants ******************************************************************************************************************/
    public function getTenantInfo($condition){
        return $this->model->findOne("tenants", $condition);
    }
    public function checkIfTenantExists($condition){
        return count($this->model->findOne("tenants", $condition)) > 0 ? true : false;
    }
    public function registerTenant($fields, $values){
        $result = $this->model->insertdata("tenants", $fields, $values);
        if($result){
            return $this->model->lastId();
        }else{
            return null;
        }           
    }
    public function updateTenantDetails($query, $id){
        return $this->model->update('tenants', $query, "WHERE id = $id");
    }    
    /** End of Property Unit ***********************************************************************************************************/    

    /** Rent A Property ******************************************************************************************************************/
    public function getRentAPropertyInfo($condition){
        return $this->model->findOne("rentedproperty", $condition);
    }
    public function checkIfRentAPropertyExists($condition){
        return count($this->model->findOne("rentedproperty", $condition)) > 0 ? true : false;
    }
    public function registerRentAProperty($fields, $values){
        $result = $this->model->insertdata("rentedproperty", $fields, $values);
        if($result){
            return $this->model->lastId();
        }else{
            return null;
        }            
        
    }
    public function updateRentAPropertyDetails($query, $id){
        return $this->model->update('rentedproperty', $query, "WHERE id = $id");
    }    
    /** End of Rent A Property ***********************************************************************************************************/    

    /** Accounts ******************************************************************************************************************/
    public function getAccountInfo($condition){
        return $this->model->findOne("accounts", $condition);
    }
    public function checkIfAccountExists($condition){
        return count($this->model->findOne("accounts", $condition)) > 0 ? true : false;
    }
    public function registerAccount($fields, $values){
        return $this->model->insertdata("accounts", $fields, $values);
    }
    public function updateAccountDetails($query, $id){
        return $this->model->update('accounts', $query, "WHERE id = $id");
    }    
    /** End of Accounts ***********************************************************************************************************/    

    /** More Fees ******************************************************************************************************************/
    public function getMoreFeesInfo($condition){
        return $this->model->findOne("morefees", $condition);
    }
    public function registerMoreFees($fields, $values){
        return $this->model->insertdata("morefees", $fields, $values);
    }
    public function updateMoreFeesDetails($query, $id){
        return $this->model->update('morefees', $query, "WHERE id = $id");
    }    
    /** End of Accounts ***********************************************************************************************************/    

    /** Tenancy Images ******************************************************************************************************************/
    public function getTenancyDocsInfo($condition){
        return $this->model->findOne("tenancydocs", $condition);
    }
    public function registerTenancyDocs($fields, $values){
        return $this->model->insertdata("tenancydocs", $fields, $values);
    }
    public function updateTenancyDocsDetails($query, $id){
        return $this->model->update('tenancydocs', $query, "WHERE id = $id");
    }    
    /** End of Accounts ***********************************************************************************************************/    

    /** Rental Fees ******************************************************************************************************************/
    public function getRentalFeesInfo($condition){
        return $this->model->findOne("rentalfees", $condition);
    }
    public function registerRentalFees($fields, $values){
        $result = $this->model->insertdata("rentalfees", $fields, $values);
        if($result){
            return $this->model->lastId();
        }else{
            return null;
        }            
        
    }
    public function updateRentalFeesDetails($query, $id){
        return $this->model->update('rentalfees', $query, "WHERE id = $id");
    }    
    /** End of Rental Fees ***********************************************************************************************************/    

    /** Dependents ******************************************************************************************************************/
    public function getDependentInfo($condition){
        return $this->model->findOne("dependents", $condition);
    }
    public function registerDependent($fields, $values){
        $result = $this->model->insertdata("dependents", $fields, $values);
        if($result){
            return $this->model->lastId();
        }else{
            return null;
        }            
        
    }
    public function updateDependentDetails($query, $id){
        return $this->model->update('dependents', $query, "WHERE id = $id");
    }    
    /** End of Dependents***********************************************************************************************************/    

    public function getRowsNumber($table){
        return count($this->model->findAll($table));
    }

    public function executeByQuerySelector($query){
        $data = $this->model->exec_query($query);
        return $data;
    }
}
?>