<?php
/**
 * 创建行为,把权限加入auth_item表中
 * @author ouyang
 * @email oyjqdlp@126.com
 * @updated 2010-07-08 优化代码操作,减少对数据库的操作
 */
class CreateOperationAction extends BaseAction
{
	public function run()
	{
        
        if(Yii::app()->request->getIsAjaxRequest())
        {
             $operation = $_POST['assign'];
             $operation = $this->getController()->removeOperations( $operation );
             $this->assignOperation($operation);
        }
	}
    
    //Yii创建行为权限
    private function assignOperation($operation)
    {
        if(!isset ($operation))
        {
            return;
        }

        $auth = Yii::app()->getAuthManager();
           // $auth->removeAuthItem();
        foreach ($operation as $value)
        {
            try
            {
                $auth->createOperation($value);
            }
            catch (Exception $e)
            {
                // Yii RBAC authitem表的name字段的值不能重复，但本身又没提供一个检测重复的机制，所以此处抛出异常后不做任何处理
            }
        }
    }
}