BoxOrderBy.php 1.95 KB
<?php

/**
 *
 * @author liuziyang
 * @version 
 */

/**
 * BoxOrderBy helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Web_View_Helper_BoxOrderBy {
	
	/**
	 * @var Zend_View_Interface 
	 */
	public $view;
	
	/**
	 * 
	 */
	public function boxOrderBy(array $order_list) {
		$this->view->s_t_class = isset($order_list['s_t']) ? $this->selectOreder($order_list['s_t']) : $this->selectOreder();
		$this->view->s_t_url = isset($order_list['s_t']) ? $this->getOrder($order_list['s_t']) : $this->getOrder();
		$orderData = array(
			'class' => '', 
			'name_txt' => '默认排序'
		);
		if (isset($order_list['s_p'])) {
			$orderData = $this->getClass($order_list['s_p']);
		}
		elseif (isset($order_list['s_n'])) {
			$orderData = $this->getClass($order_list['s_n'], 's_n');
		}
		$this->view->order_by_default = $orderData;
		return $this->view->render('box/orderby.phtml');
	}
	
	public function getClass($order = '', $act = 's_p') {
		$data = array(
			'class' => '', 
			'name_txt' => '默认排序'
		);
		$act_txt = ($act == 's_p') ? '价格' : '销量';
		switch ($order) {
			case 'asc' :
				$data = array(
					'class' => 'pr_up', 
					'name_txt' => $act_txt . '由低到高'
				);
				break;
			case 'desc' :
				$data = array(
					'class' => 'pr_down', 
					'name_txt' => $act_txt . '由高到低'
				);
				break;
		}
		return $data;
	}
	
	public function getOrder($opt = '') {
		$order = '';
		switch ($opt) {
			case 'asc' :
				$order = 'desc';
				break;
			case 'desc' :
				$order = 'asc';
				break;
			default :
				$order = 'desc';
		}
		return $order;
	}
	
	public function selectOreder($select = '') {
		$class = 'p_up';
		switch ($select) {
			case 'asc' :
				$class = 'p_down_act';
				break;
			case 'desc' :
				$class = 'p_up_act';
				break;
			default :
				$class = 'p_up';
		}
		return $class;
	}
	
	/**
	 * Sets the view field 
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}

}