SummerModel.class.php 1.93 KB
<?php
Class SummerModel extends Model{
	//自动完成
	protected $_auto = array (
    	array('addtime','time',1,'function'),// 新增 	   	     对time字段在新增的时候写入当前时间戳
    	array('updatetime','time',3,'function'),  // 新增和修改 	 对optime字段 写入当前时间戳
		array('aid','getUid',1,'callback'),   // 新增 	   	     对aid字段在新增的时候写入当前用户id
		array('sid','getSchool',1,'callback'),   // 新增 	   	     对aid字段在新增的时候写入当前用户id
		array('rfields','getRfields',3,'callback'),
		array('starttime','strtotime',3,'function'),
		array('endtime','strtotime',3,'function'),
	);
	//自动验证
	protected  $_validate =array(
		array('year','checkYear','该年份夏令营信息已经存在',0,'callback',3),
		array('title','require','夏令营名称必须填写',0,'',3),			//新增和修改标题    标题必须填写、
		array('starttime','require','申请起始时间不能为空',0,'',3),
		array('endtime','require','申请结束时间不能为空',0,'',3),
		array('content','require','夏令营内容必须填写',0,'',3),
		array('rfields','checkRfields','申请应填信息不能为空',1,'callback',3),
	);
	protected function checkRfields($rfields)//检验 申请应填信息
	{
		if($rfields){
			$back = true;
		}else{
			$back = false;
		}
		return $back;
	}
	protected function getRfields($rfields){	//申请填写字段合并
		$r=implode(',',$rfields);
		return $r;
	}
	protected function getUid(){	//发布人id(后台管理人)
		return cookie('ADMIN_KEY');
	}
	protected function getSchool(){	//夏令营所关联的学院id
		return cookie('ADMIN_SCHOOL');
	}
	protected function checkYear($year){
		$m=M('Summer');
		$where['year']=array('eq',$year);
		if(I('id')) $where['id']=array('neq',I('id'));
		$data=$m->field('id')->where($where)->find();
		if($data)
			return false;
		else
			return true;
	}
}