SystemFunction.inc 1.81 KB
<?php
/**
 * 管理员权限分配用静态类
 * $Id$
 * @author zongbiao
 * @package jp.fishow.entity.definition
 */
class SystemFunction
{
	public $name;
	public $title;
	
	function __construct($record) {
		$this->name = $record["name"];
		$this->title = $record["title"];
	}
	
	/**
	 * このクラスのインスタンスのリストを返します。
	 * @return array ImageType一覧
	 */
	public static function getList() {
		static $result;
			
		if ((!is_array($result)) || (count($result) < 1)) {
			
			$data = array();
			//下级账号添加权限
			$tmp = array("name"=>'ACCOUNT', "title"=>"下级账号发行");
			array_push($data, $tmp);
			
			//活动发布权限
			$tmp = array("name"=>'EVENT', "title"=>"活动发布");
			array_push($data, $tmp);
			
			//下级发起的活动审核权限
			$tmp = array("name"=>'CHECK', "title"=>"活动审核");
			array_push($data, $tmp);
			
			
			$result = array();
			foreach ($data as $row) {
				$tmp2 = new SystemFunction($row);
				array_push($result, $tmp2);
			}
		}
		return $result;
	}
	
	/**
	 * 定義名から対応するインスタンスを返します。
	 * @return SystemFunction 対応するインスタンス。ない場合null。
	 */
	public static function getByName($name) {
		$list = SystemFunction::getList();
		foreach ($list as $tmp) {
			if ($tmp->name == $name) {
				return $tmp;
			}
		}
		return null;
	}
	
	/**
	 * 通过定义名取得标题,用于显示
	 * @return 
	 */
	public static function getTitlesByNames($names) {
		if (empty($names)) {
			return "拥有全部权限";
		}
		if (!is_array($names)) {
			$names = explode(",", $names);
		}
		$list = SystemFunction::getList();
		$result = array();
		foreach ($list as $tmp) {
			if (in_array($tmp->name, $names)) {
				array_push($result, $tmp->title);
			}
		}
		return implode(",", $result);
	}
}