⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modulemodel.php

📁 a short sketch about linux syntex lines.
💻 PHP
字号:
<?php
/*
秀影EasyFramework框架
qq:24498936
msn:jdzcn_net@hotmail.com
website:http://www.vodcms.com
系统后台管理菜单控制模型
*/
class ModuleModel extends DBModel {
	protected $_name = VODCMS_MODULE;
	public function Init(){
		$this->edition = $GLOBALS['license']['edition'];
		//print_r($this->_Response->getSession());
	}
	public function addModule($array){
		if (is_array($array)){
			$select = $this->_DB->select();
			$select->from($this->_name,'sort')->where('parentid='.$array['parentid'])->order('sort DESC')->limit(1);
			$sql = $select->toString();
			$data = $this->_DB->fetRow($sql);
			if (!$array['sort']){
				$array['sort'] = $data['sort']+1;
			}
			unset($data, $sql);
			if ($this->Exists($array['name']) ===true){
				$this->error = _('菜单名已经存在!请更换!');
				return false;
			}else{
				return $this->_DB->insert($this->_name, $array);
			}	
		}else{
			$this->error = _('程序内部错误:调用方法参数错误!');
			return false;
		}
	}
	/*
	列出全部的管理菜单
	$where 为可选项.接受参数为SQl条件字符或者数组
	return array();
	*/
	public function listModule($where = null){
		$select = $this->_DB->select();
		$rows = $this->_DB->fetAll($select->from($this->_name)->where($where)->order('sort,id')->toString());
		return $rows;
	}
	/*获取全部菜单数据*/
	public function getAll($where=null)
	{
		$select = $this->_DB->select();
		$rows = $this->_DB->fetAll($select->from($this->_name)->where($where)->order('sort,id')->toString());
		/*如果是超级管理员*/
		if ($where['parentid'] > 0 ){
			if( (int)$this->_Response->getSession('flag') == 1 || $this->edition != 'Enterprice') {
				return $rows;
			}else{
				$allow = array();
				$Permission = new Permission();
				$group = $this->_Response->getSession('group');
				$allgroups = $Permission->getAll( array('group' => $group ));
				foreach($allgroups[$group] as $key=>$val){
					foreach($rows as $k=>$row){
						parse_str(depathinfo($row['url']), $url);
						if(  $key == $url['mod'].'controller' && in_array($url['action'], $val)) {
							$allow[] = $row;
						}
					}
				}
				//print_r($allow);
				return $allow;
			}
		}else{
			return $rows;
		}
	}
	/*获取后台顶部管理菜单*/
	public function getTopMenu() {
		$select = $this->_DB->select();
		$select->from($this->_name);
		$select->where('parentid=0');
		$select->order('sort,id');
		$sql = $select->toString();
		$rows = $this->_DB->fetAll($sql);
		/*如果是超级管理员*/
		if( (int)$this->_Response->getSession('flag') == 1  || $this->edition != 'Enterprice' ) {
			return $rows;
		}else{
			$allow = array();
			$Permission = new Permission();
			$group = $this->_Response->getSession('group');
			$allgroups = $Permission->getAll( array('group' => $group ));
			if (is_array($allgroups)){
				foreach($allgroups[$group] as $key=>$val){
					foreach($rows as $k=>$rs){
						foreach($this->listModule( array('parentid'=> $rs['id'])) as $row){
							parse_str(depathinfo($row['url']), $url);
							if(  $key == $url['mod'].'controller' && in_array($url['action'], $val)) {
								$allow[$rs['id']] = $rs;
							}
						}

					}
				}
				return $allow;
			}else{
				return array();
			}
		}
	}
	/*
	$name 检测菜单名是否已经存在!
	return bool
	*/
	public function Exists($name){
		if ($this->_DB->fetRow($this->_DB->select()->from($this->_name)->where("`name`= '$name'")->limit(1)->toString())){
			return true;	//存在
		}else{
			return false;
		}
	}
	public function CreateOption($id=0, $selected=0){
		$select = $this->_DB->select();
		$sql = $select->from($this->_name)->where('parentid='.$id)->order('sort,id')->toString();
		//echo $sql;
		$data = $this->_DB->fetAll($sql);
		unset($option);
		if (is_array($data))
		foreach($data as $row){
			$option.= '<option value="'.$row['id'].'" '.($row['id'] == $selected) ? 'selected' : ''.'>'.$row['name'].'</option>'.$this->CreateOption($row['id']);
		}
		return $option;
	}
	public function getAllModule(){
		$select = $this->_DB->select();
		$sql = $select->from($this->_name)->order('sort ASC')->toString();
		//echo $sql;
		$result = $this->_DB->fetAll($sql);
		foreach($result as $val){
			if($val['parentid'] == 0){
				$data[$val['id']]['self'] = $val;
			}else{
				$data[$val['parentid']]['nodes'][] = $val;
			}
		}
		unset($result);
		return $data;
	}
	public function getRightModule(){
		$module = $this->_Response->getParam('controller');
		$select = $this->_DB->select();
		$select->from($this->_name.' AS a','DISTINCT a.parentid');
		$select->join($this->_name.' AS b', 'a.parentid=b.parentid', 'b.*');
		$select->where("b.islink = 'true' AND a.url like '".$module."%'");
		$sql = $select->toString();
		//echo $sql;
		return $this->_DB->fetAll($sql);
	}
	/*获取一行指定条件的数据记录*/
	public function getModule($where = null){
		if (is_null($where)===false){
			$sql = $this->_DB->select()->from($this->_name)->where($where)->limit(1)->toString();
			return $this->_DB->fetRow($sql);
		}
	}
	/*
	修改模块信息
	@param array
	*/
	public function modifyModule($data, $where){
		if (is_array($data)){
			if (empty($data['name'])){
				$this->error = _('模块名不能为空!');
				return false;
			}elseif ($data['id'] == $data['parentid']){
				$this->error = _('不能选择自身为父分类!');
				return false;
			}else{
				return $this->_DB->update($this->_name, $data, $where);
			}
		}else{
			$this->error = _('第一个传入参数必须为数组!');
			return false;
		}
	}
	/*删除一条模块信息*/
	public function delete($id){
		$row = $this->getModule('parentid='.$id);
		if ($row['id']){
			$this->error = _('必须删除子模块后才能删除父模块!');
			return false;
		}else{
			return $this->_DB->delete($this->_name, 'id='.(int)$id);
		}
	}
	public function sort($sort){
		$i=0;
		foreach($sort as $id){
			$i++;
			$this->_DB->update($this->_name, array('sort'=> $i), 'id='.(int)$id);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -