BoxBrand.php 1.89 KB
<?php

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

/**
 * BoxBrand helper
 *
 * @uses viewHelper Zend_View_Helper
 */
class Web_View_Helper_BoxBrand extends Zend_View_Helper_Abstract {

	/**
	 * @var Zend_View_Interface
	 */
	public $view;

	/**
	 *
	 */
	public function boxBrand($sort_ids, $brand_id = 0) {
		$max_sort_id = empty($sort_ids['msort']) ? 0 : $sort_ids['msort'];
		$middle_sort_id = empty($sort_ids['misort']) ? 0 : $sort_ids['misort'];
		$small_sort_id = empty($sort_ids['sort']) ? 0 : $sort_ids['sort'];
		#获取所有品牌
		$boxBrandAll = QINProduct_Models_Brand_Client::getAllBaseBrand();
		$sortBrands = $this->getBrandsByOneSort($boxBrandAll, $max_sort_id, $middle_sort_id, $small_sort_id);
		if (isset($this->view->view_is_promotion)) {
			$promotionBrands = QModels_Product_Client::getPromotionBrandIds($this->view->view_is_promotion);
			foreach ($sortBrands as $k => $v) {
				if (!in_array($k, $promotionBrands, true)) {
					unset($sortBrands[$k]);
				}
			}
		}
		$this->view->brands = $brands = $sortBrands;
		$boxBrand = array_slice($brands, 0, 10);
		if ($brand_id > 0 && !empty($boxBrandAll[$brand_id])) {
			$this->view->nowBrand = $boxBrandAll[$brand_id];
		}
		$this->view->boxBrand = $boxBrand;

		$this->view->boxBrandAll = $boxBrandAll = QModels_Brand_Sort_Client::makeBrandsAlifGroup(array_keys($brands), $boxBrandAll);
		return $this->view->render('box/brand.phtml');
	}

	public function getBrandsByOneSort(array $brand, $max_sort_id, $middle_sort_id = 0, $small_sort_id = 0) {
		$brandIds = QModels_Brand_Sort_Client::getBrandIdsByOneSort($max_sort_id, $middle_sort_id, $small_sort_id);
		$result = array();
		foreach ($brandIds as $k => $v) {
			if (isset($brand[$k])) {
				$result[$k] = $brand[$k];
			}
		}
		return $result;
	}

	/**
	 * Sets the view field
	 * @param $view Zend_View_Interface
	 */
	public function setView(Zend_View_Interface $view) {
		$this->view = $view;
	}

}