<?php

class OpinionController extends Zend_Controller_Action {

	public function init() {		
		$this->view->menuSel = 'opinion';		
	}
	
	
	public function indexAction() {	
		$v = $this->_request->getParams();
		$db = Zend_Registry::get('db');

		$sort1 = 'opinion_ins';
		$sort2 = 'DESC';
		
		if( $v['sort1'] == 2 ){
			$sort1 = 'opinion_type';
			$this->view->sort1 = 2;
		}else{
			$sort1 = 'opinion_ins';
			$this->view->sort1 = 1;
		}
		
		if( $v['sort2'] == 2 ){
			$sort2 = 'ASC';
			$this->view->sort2 = 2;
		}else{
			$sort2 = 'DESC';
			$this->view->sort2 = 1;
		}
		
		
		
		$Opinion = new Opinion();		
		$data = $Opinion->fetchAll(null , $sort1.' '.$sort2);
		$this->view->dataTable = $data;
		
		$select = $db->select();
		$select->from('opinion',array('COUNT(opinion.opinion_id) as count', 'opinion.opinion_id'));
	//	$select->where('opinion_type = ');
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();
		$this->view->opinionCount = $data[0]['count'];
		
		$select = $db->select();
		$select->from('opinion',array('COUNT(opinion.opinion_id) as count', 'opinion.opinion_id'));
		$select->where('opinion_type = 0');
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();
		$this->view->opinionCount0 = $data[0]['count'];
		
		$select = $db->select();
		$select->from('opinion',array('COUNT(opinion.opinion_id) as count', 'opinion.opinion_id'));
		$select->where('opinion_type = 1');
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();
		$this->view->opinionCount1 = $data[0]['count'];
		
		$select = $db->select();
		$select->from('opinion',array('COUNT(opinion.opinion_id) as count', 'opinion.opinion_id'));
		$select->where('opinion_type = 2');
		$stmt = $db->query($select);
		$data = $stmt->fetchAll();
		$this->view->opinionCount2 = $data[0]['count'];
	}

	
}
