<?php

class LegalTable extends Doctrine_Table
{
   
    public static function getInstance()
    {
        return Doctrine_Core::getTable('Legal');
    }
   
    public function getCompanies($type = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal c')
                ->orderBy('c.published_at DESC');        
				
		if($type!=-1){
			
			  $q->andWhere('c.type=?',$type);
		}		
				
         return $q->execute();
    }
	public function getDataFront($category = -1,$year = -1,$s = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal l')
				->orderBy('l.published_at DESC')
				->where('l.category_id>=?',308)
				->andWhere('l.category_id<=?',312);   
		
         if($category!=-1){
			
			  $q->andWhere('l.category_id=?',$category);
		}
			
			
		
		if($year!=-1){
			
		      
			  if($s!=-1) 
				  
				  {
					  $year=$year.'-'.$s.'-01';
				     $q->andWhere('l.adopt_date = ?',$year);
				  }
				  
			  else { $year=$year.'-01-01';
			
			  $futureDate=date('Y-m-d', strtotime('+1 year', strtotime($year)) );
			  
			  $q->andWhere('l.adopt_date >= ?',$year);
			  $q->andWhere('l.adopt_date <= ?',$futureDate);
			  
			  }
			  
		}
		
				
         return $q;
    }
	public function getArgachlal($category = -1,$type = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal c')
				->innerJoin('c.Category ct')
				->where('ct.is_visible=?',$category)
				->andWhere('c.requirement=?',$type)
                ->orderBy('c.published_at DESC');   
				
         return $q->execute();
    }
	
	public function getLegal($category = -1,$type = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal l')
				->innerJoin('l.Category c')
				->orderBy('l.published_at DESC');   
		
         if($category!=-1){
			
			  $q->where('l.category_id=?',$category);
		}	
		
		if($type!=-1){
			
			  $q->where('c.is_visible=?',$type);
		}			
				
				
         return $q;
    }
	 public function getJuram($type = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal c')
				->innerJoin('c.Category ct')
				->where('ct.is_visible=?',6)
                ->orderBy('c.published_at DESC');   
				
         return $q->execute();
    }
	 public function getReportBackend($date = -1) {
       
        $q = Doctrine_Query::create()
                ->from('Legal c')
				->where('c.requirement=1001')
                ->orderBy('c.published_at DESC');   
				
         return $q->execute();
    }
	 public function getReport($dates = NULL,$type = 1001) {
       
        $q = Doctrine_Query::create()
                ->from('Legal c')
				->where('c.requirement=?',$type)
                ->orderBy('c.published_at DESC');   
				
		if($dates){
			
			
			
			$q->andWhere('c.adopt_date = ?',$dates);
			
		}
	
         return $q->fetchOne();
    }
	
}