Brand.class.php 9.04 KB
<?php

/**
 *  品牌
 *
 * @name Facade_Brand
 * @version 1.0 (2013-5-27)
 * @package Facade/Brand
 * @author hbomb
 * @since 1.0
 */

class Facade_Brand
{

    private static $service = null;
    /**
     * 返回service对象
     *
     * @return Service_Brand_Brand
     */
    public static function service()
    {
        if (null === self::$service)
        {
            self::$service = new Service_Brand();
        }
        return self::$service;
    }
    
    /**
     * 获取品牌
     * 
     * @param unknown_type $offset
     * @param unknown_type $limit
     * @param unknown_type $status
     * @return Ambigous <multitype:, Util_Dao_Db_PdoQuery>
     */
    public static function getBrandByState ($offset, $limit, $state)
    {
        return self::service()->getBrandByState($offset, $limit, $state);
    }
    
    /**
     * 根据状态获取所有品牌个数. 用于前端分页
     * 
     * @param $status
     */
    public static function getBrandTotal ($state)
    {
        return self::service()->getBrandTotal($state);
    }
    
    /**
     * 根据id更新品牌状态. 用于管理员更新一个品牌的操作.
     * @param string $id
     * @param string $name
     * @param string $logo
     * @param string $description
     * @param string $state
     * @param string $pics
     * @param string $person
     * @param string $seq
     * @param string $news_ids
     * @param int $boothId
     * @param string $link
     * @return boolean
     */
    public static function updateBrand ($id, $name,$logo,$description,$state,$pics,$person,$seq,$news_ids, $boothId, $link)
    {
        return self::service()->updateBrand($id, $name, $logo, $description, $state, $pics, $person, $seq, $news_ids, $boothId, $link);
    }
    
    /**
     * 用户提交品牌. 
     * @param string $name
     * @param string $logo
     * @param string $description
     * @param string $pics
     * @param string $person
     * @param string $news_ids
     * @param string $seq
     * @param string $state
     * @param int $boothId
     * @param string $link
     * @return int
     */
    public static function submitBrand ($name,$logo,$description,$state,$pics,$person,$seq, $news_ids, $boothId, $link)
    {
       return self::service()->submitBrand($name, $logo, $description, $pics, $person, $news_ids, $seq, $state, $boothId, $link);
    }
    
    /**
     * 根据ID获取品牌
     * @param unknown_type $id
     * @return Ambigous <multitype:, Util_Dao_Db_PdoQuery>
     */
    public static function getBrandByID($id)
    {
        return self::service()->getBrandByID($id);
    }
    
    /**
     * 设置booth
     *
     * @param string $booth_id
     * @param string $position
     * @return boolean
     */    
    public static function setBooth($booth_id, $position)
    {
    	return self::service()->setBooth($booth_id, $position);
    }
    
    /**
     * 获取booth
     *
     * @return array
     */
    public static function getBoothList()
    {
    	return self::service()->getBoothList();
    }
    
    /**
     * 删除booth
     *
     * @return bolean
     */    
    public static function delBooth($booth_id)
    {
    	return self::service()->delBooth($booth_id);
    }
    
    
    /**
     * 获取签到布局
     *
     * @return array
     */
    public static function getSignLayout()
    {
    	$key = 'yohood_sign_layout_v1';
    	$result = array();
    	$result = Lib_Utils_Cache_Data::get($key);
    	if(empty($result))
    	{
    		$layoutList = self::service()->getSignLayoutList();
    		$picList = self::service()->getSignPicList();
    		$positions = self::getSignPosition();	
    		foreach($layoutList as $layout)
    		{
    			$place = $layout['place'];
    			$picId = $layout['pic_id'];
    			$image = $picList[$picId]['pic'];
    			$picSignPositon = array();
    			foreach($positions as $position)
    			{
    				if($position['imageId'] == $picId)
    				{
    					$picSignPositon [] = $position;
    				}
    			}
    			if(isset($result[$place]))
    			{
    				$result[$place]['images'][] = array('id' => $picId, 'image'=> $image, 'boothList'=> $picSignPositon, 'place'=> $place);
    			}
    			else
    			{
    				$result[$place] = array('place'=> $place, 'images'=> array(array('id'=> $picId, 'image'=> $image, 'boothList'=> $picSignPositon, 'place'=> $place)));
    			}
    		}
    		Lib_Utils_Cache_Data::set($key, $result);
    	}
    	return $result;
    }
    
    /**
     * 获取签到坐标
     *
     * @return array
     */
    public static function getSignPosition()
    {
    	$positions =  self::service()->getSignPosition();
    	$result = array();
    	$picList = self::service()->getSignPicList();
    	$signBrands = self::service()->getSignBrand();
    	$brands = self::service()->getBrand();
    	foreach($positions as $position)
    	{
    		$width = (float) $picList[$position['pic_id']]['width'];
    		$height = (float) $picList[$position['pic_id']]['height'];
    		$bias = array('android' => array('x' => 50, 'y'=> 70 + 245), 'ios' => array('x' => 32, 'y'=> 52 + 245));
    		if(preg_match('/(java .+)/isU', $_SERVER['HTTP_USER_AGENT']))
    		{
    			$platform = 'android';
    		}
    		else
    		{
    			$platform = 'ios';
    		}
    		$x = $position['x'] - $bias[$platform]['x'];
    		$y = $position['y'] - $bias[$platform]['y'];
    		foreach($signBrands as $signBrand)
    		{
    			$position['booth_id'] = trim($position['booth_id']);
    			$signBrand['booth_id'] = trim($signBrand['booth_id']);
    			$ret = array();
    			if($signBrand['brand_name'] == '潮流市集' || $signBrand['brand_name'] == 'BE@RBRICK展区')
    			{
    				if($signBrand['brand_name'] == '潮流市集')
    				{
    					$ret = array('brand_name' => '潮流市集', 'url' => SITE_MAIN, 'image'=> SITE_IMG.'/yohood/sign_market_logo.png');
    				}
    				else
    				{
    					$ret = array('brand_name' => 'BE@RBRICK展区', 'url' => SITE_MAIN, 'image'=> SITE_IMG.'/yohood/sign_block_logo.jpg');
    				}
    			}
    			else
    			{
    				foreach($brands as $brand)
    				{
    					if( trim(strtolower($signBrand['brand_name']))  == trim(strtolower($brand['name'])))
    					{
    						$ret = $brand;
    						break;
    					}
    				}
    				if(empty($ret))
    				{
    					continue;
    				}
    				$styles = json_decode($ret['pics'], true);
    				$ret['image'] = '';
    				$ret['url'] = SITE_MAIN.'/brand/detail/id/'.$ret['id'];
    				foreach($styles as $style)
    				{
    					if($style['type'] == 'pic')
    					{
    						$ret['image'] = Lib_Images::getImageUrl($style['url'], 'source','fragmentimg');
    					}
    					else
    					{
    						$ret['image'] = Lib_Video::getVideoUrl($style['url']);
    					}
    				}
    			}
    			if($signBrand['booth_id'] == $position['booth_id'])
    			{
    				$result[] = array('id'=> $signBrand['brand_id'], 'x' => strval( $x / $width), 'brandName'=> $signBrand['brand_name'], 'tag' => strval(intval(crc32($position['booth_id'])/10000)),
    						'brandImage' => $ret['image'],'brandUrl'=> $ret['url'],'y'=> strval($y / $height), 'imageId' => $position['pic_id']);
    			}
    		}
    	}
    	return $result;
    }
    
    /**
     * 获取签到品牌
     *
     * @return array
     */
    public static function getSignBrand()
    {
    	return self::service()->getSignBrand();
    }
    
    /**
     * 获取有货品牌
     *
     * @return array
     */    
    public static function getYohobuyBrand()
    {
    	return self::service()->getYohobuyBrand();
    }
    
    /**
     * 设置品牌和资讯对应关系
     * 
     * @param int $news_id
     * @param int $brand_id
     * @return boolean
     */
    public static function setBrandNewsRela($news_id, $brand_id)
    {
    	return self::service()->setBrandNewsRela($news_id, $brand_id);
    }

    /**
     * 根据news_id获取品牌和资讯对应关系
     * 
     * @param int|array $news_id
     * @return array
     */
    public static function getBrandNewsRelaByNewsID($news_id)
    {
        return self::service()->getBrandNewsRelaByNewsID($news_id);
    }

    /**
     * 根据brand_id获取品牌和资讯对应关系
     *
     * @param int|array $brand_id
     * @return array
     */
    public static function getBrandNewsRelaByBrandID($brand_id)
    {
        return self::service()->getBrandNewsRelaByBrandID($brand_id);
    }
    
    /**
     * 根据news_id删除品牌和资讯对应关系
     *
     * @param int $news_id
     * @return array
     */
    public static function deleteBrandNewsRelaByNewsID($news_id)
    {
        return self::service()->deleteBrandNewsRelaByNewsID($news_id);
    }
    
    /**
     * 获取相同的news_ids
     *
     * @param int $news_id
     * @return array
     */
    public static function getSameNewsByNewsID($news_id)
    {
        return self::service()->getSameNewsByNewsID($news_id);
    }
    
    
    /**
     * 根据名称获取品牌列表
     * 
     * @param string $name
     * @param int $state
     * @return array
     */
    public static function getBrandByName($name, $state)
    {
    	return self::service()->getBrandByName($name, $state);
    }
    
}