<?php
/**
 * 紫斑马软件
 * @author afan
 * @link http://www.zibanma.com
 */
class NavigationModel{
	private $_model;
	public function __construct(){
		$this->_model = ZibanmaModel::get_instance();
	}
	
	/**
	 * 添加导航
	 */
	public function zibanma_navigation_add($post){
		if($post){
			return $this->_model->_db->execute("insert into ".ZIBANMA_DB_PREFIX."site_navigation (title, target, url, sort, attribute, status) values ('{$post[title]}', '{$post[target]}',  '{$post[url]}', 0, '', 1); ");
		}
		return null;
	}
	
	/**
	 * 获取导航列表
	 */
	public function zibanma_navigation_list($sort='asc'){
		return $this->_model->_db->query("select * from ".ZIBANMA_DB_PREFIX."site_navigation where status=1 order by sort {$sort}; ");
	}
	
	/**
	 * 更新排序
	 * @param $arr id/value
	 */
	public function zibanma_update_sort($arr){
		if($arr){
			return $this->_model->_db->execute("update ".ZIBANMA_DB_PREFIX."site_navigation set sort={$arr[value]} where id={$arr[id]}; ");
		}
	}
	
	/**
	 * 删除导航
	 */
	public function zibanma_delete($id){
		if($id>0){
			return $this->_model->_db->execute("update ".ZIBANMA_DB_PREFIX."site_navigation set status=0 where id={$id}; ");
		}
		return null;
	}
}
?>