<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | Common database model class. It use for common functions             |
// | File name : common.php                                               |
// | PHP version >= 5.2                                                   |
// | Created On 4 January 2012                                            |
// +----------------------------------------------------------------------+
// | Author: Rajath Kamal <rajath.k@armiasystems.com>                     |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems ? 2010                                      |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------|



class ControllerBusiness extends BaseController
{
	/*
		construction function. we can initialize the models here
	*/
     public function init()
    {
        parent::init();
		
		$this->_common		= new ModelCommon;
                $this->_indexmodel      = new ModelIndex;

        }
    
	public function authenticate()
	{
	
	}
	

		
    public function dashboard()
    {
        echo "am in business  dashboard"; die;
        $traficArray = array();
        $table  = 'statistics';
        $field  = 'nCount,dTrackingDate';

        $traficArray = $this->_indexmodel->getSiteTraffic($table,$field);
        if(sizeof($traficArray)>0)
        {
            foreach ($traficArray as $tRecord)
            {
            $this->graph->setCategory(date("M",strtotime($tRecord->dTrackingDate)));
            $this->graph->adddata($tRecord->nCount);
            }
            $this->graph->setAxis();
        }
        $this->view->graph   = $this->graph ;

        //Listing area creation
        $listFields  = array();
        $table  = 'productdesc';
        $field  = 'vFldname';
        $order  = " ORDER BY id ASC LIMIT 0,3";
        $listFieldString='';
        $listFields   = $this->_indexmodel->getListFields($table,$field,$order);
        if(sizeof($listFields)>0)
        {
            foreach ($listFields as $lRecord)
            {
                $listFieldString.=$lRecord->vFldname.',';
            }
        }
        substr($listFieldString,0,strlen($listFieldString)-1);
        $listArray   = array();
        $table  = 'product';
        $field  = substr($listFieldString,0,strlen($listFieldString)-1);
        $order  = " ORDER BY dPostDate DESC";
        $listArray   = $this->_indexmodel->getTopList($table,$field,$order,$where);
        if(sizeof($listArray)>0)
        {
            $this->view->listFields = explode(',',$field);
            $this->view->listArray  = $listArray;
        }
        // Category listing
        $catArray   = array();
        $table  = 'category';
        $field  = 'vCategoryDesc,nCount';
        $order  = " ORDER BY nCount DESC LIMIT 0,5";
        $where  = '';
        $catArray   = $this->_indexmodel->getTopCategory($table,$field,$order,$where);
        $this->view->catArray   = $catArray ;

    }

    public function ProductRatingStar($pid,$units='',$static='')
{


        if($pid!='')

    {

       $select_rating_count=$this->_common->selectQuery("SELECT ROUND(SUM(nRate)/COUNT(nProductId)) AS average_rating
                                      FROM ".MYSQL_TABLE_PREFIX."productrating
                                     WHERE nProductId = '1' AND nStatus='1'");
//            $select_rating_count = mysqli_query("SELECT ROUND(SUM(nrating_id)/COUNT(nrating_id)) AS average_rating FROM ".$tableprefix."record_ratings WHERE
//                                                   vType='p' AND nrseller_id = ".$pid);

       $average_rating_count    =0;

       if(sizeof($select_rating_count)>0)
       {

//                     $rating_count = @mysqli_fetch_array($select_rating_count);


                  if($rating_count->$rating_count['average_rating']!='')
                  {
                            $average_rating_count    = $rating_count['average_rating'];

                  }
                  else
                  {
                           $average_rating_count    =0;
                  }

       }


    }



      return $average_rating_count;


}

		

}
?>