<?php
class CacheBehavior extends CActiveRecordBehavior
{
    public function afterSave($event)
    {
        $permission = Permission::model()->findAll(array('condition'=>'gid='.$this->Owner->groupid));
        $array = array();
        if (!empty($permission))
        {
            foreach ($permission as $value)
            {
                $array[$value->rkey] = $value->rvalue;
            }
        }
        else
        {
            $id = $this->Owner->gptype == 'system' && in_array($this->Owner->groupid, Front::getAdminGroup())? '00' : '0';
            $array = $this->Owner->getGroupCache($id);
        }
        $array = array('groupid'=>$this->Owner->groupid,'grouptitle'=>$this->Owner->grouptitle,'grouptitle1'=>$this->Owner->grouptitle1,'grouptitle2'=>$this->Owner->grouptitle2,'grouptype'=>$this->Owner->gptype,'creditshigher'=>$this->Owner->creditshigher,'creditslower'=>$this->Owner->creditslower)+$array;
        $this->Owner->saveGroupCache($this->Owner->groupid, $array);
        
        return true;
    }
}