<?php
// If it's going to need the database, then it's
// probably smart to require it before we start.
//error_reporting(0);
require_once("initializer.php");

class Reviews extends DatabaseObject {

  protected static $table_name="BVIS_Reviews";


  //we will populate this array of attribure dynamically
	//protected static $db_fields = array('id','Username','Privilege','First_Name','Last_Name','Password');

  protected static $db_fields;
  protected static $exclu_fields = array ("");

	// public  $id;
	// public $Username;
	// public $Privilege;
	// public $Last_Name;
  // public $First_Name;
  // public $Password;

  public function __construct($options=""){
    if ($options=="Blank") {
      $myFields = static::Get_Object_Fields ();
      foreach($myFields as $field) {
        $this->{$field} = "";
      }
    }

   // unset ($this->id);

  }



  public static function TotalReviews($busId="" ) {
    global $database;

    $sql = "SELECT COUNT(*) FROM `BVIS_Reviews` WHERE  `Bus_id`='{$busId}'";
    
    //$result = self::find_by_sql($sql, 'Reviews') ;

    $result = $database->query($sql);
    $object = mysqli_fetch_assoc($result);

    return  $object[ "COUNT(*)"];


  }




  public static function BusinessStarts($Bus_id="" ) {
    global $database;

    // if ($unit != "") {
    //   $sql = "SELECT SUM(`Stars`) AS TotalRevies, COUNT(`id`) AS NumberOfReviews,  AVG(`Stars`) AS Average FROM `BVIS_Reviews` WHERE `Business_id`={$bus} ";

    //   $result = $database->query($sql);
    //   $object = mysqli_fetch_assoc($result);

    //   return  $object ;
      

    //   # code...
    // } else {
      $sql = "SELECT SUM(`Stars`) AS TotalRevies, COUNT(`id`) AS NumberOfReviews,  AVG(`Stars`) AS Average FROM `BVIS_Reviews` WHERE `Bus_id`={$Bus_id}";
      $result = $database->query($sql);
      $total = mysqli_fetch_assoc($result);
       $result = $total ['Average'];
 
       if ($result > 5) {
         return 5 ;
       } else {
         return round($result,0,PHP_ROUND_HALF_DOWN) ;
       }
       

    // }
    

  



  }

  


  public static function findOrderClass ($order_ID="") {
    //we create an and return the order details here
    //error_log(print_r( "inside findOrder",true));

    //error_log(print_r( $_POST,true));
   return  OrdersInfo::findDishInfo($order_ID,"")  ;




  }


  public static function testGetField () {
    return self::$db_fields;
  }

  public static function createProperty( $name, $value ){
     $this->{$name} = $value;
}

  public static function setGetField ($idf) {
    return self::$db_fields['id'] = $idf;
  }

 
 


}

?>