<?php

/**
 *--------------------------------------
 * 广告位
 *--------------------------------------
 * @project		: uwa
 * @author		: cblee
 * @created		: 2012-10-18
 * @copyright	: (c)2012 AsThis
 *--------------------------------------
 */

class AdSpaceModl extends Modl
{
	public function get_spaceList($status = true)
	{
		$_ASL = F('~ad/~asl');
		if(empty($_AML))
		{
			$_ASL = $this->select();
			F('~ad/~asl', $_ASL);
		}
		if(!empty($_ASL) and $asStatus)
		{
			foreach($_ASL as $k => $space)
			{
				if(1 != $space['as_status'])
				{
					unset($_ASL[$k]);
				}
			}
		}
		return $_ASL;
	}

	public function get_spaceInfo($adSpaceId)
	{
		$_ASI = F('~ad/~asi_'.$adSpaceId);
		if(empty($_ASI))
		{
			$_ASI = $this->where('ad_space_id = \''.$adSpaceId.'\'')->find();
			F('~ad/~asi_'.$adSpaceId, $_ASI); /* 缓存广告位信息 */
		}
		return $_ASI;
	}

	public function add_space($data)
	{
		$result = array('data' => '', 'error' => '');

		$_t_id = $this->insert($data);
		if(false === $_t_id)
		{
			$result['error'] = L('ADD_FAILED');
			return $result;
		}
		$result['data'] = $_t_id;

		F('~ad/~asl', null);

		return $result;
	}

	public function edit_space($data)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->update($data))
		{
			$result['error'] = L('EDIT_FAILED');
			return $result;
		}

		F('~ad/~asi_'.$data['ad_space_id'], null); /* 删除广告位信息缓存 */
		F('~ad/~asl', null);

		return $result;
	}

	public function delete_space($adSpaceId)
	{
		$result = array('data' => '', 'error' => '');

		if(false === $this->delete($adSpaceId))
		{
			$result['error'] = L('DELETE_FAILED');
			return $result;
		}

		F('~ad/~asi_'.$adSpaceId, null); /* 删除广告位信息缓存 */
		F('~ad/~asl', null);

		return $result;
	}
}

?>