Esempio n. 1
0
 public function getAcl()
 {
     //if (!isset($this->persistent->acl)) {
     $acl = new Phalcon\Acl\Adapter\Memory();
     $acl->setDefaultAction(Phalcon\Acl::DENY);
     //Register roles
     $rol = Role::find(array("cache" => array("key" => "role")));
     foreach ($rol as $ros) {
         $roles[strtolower($ros->name)] = new Phalcon\Acl\Role($ros->name);
     }
     foreach ($roles as $role) {
         $acl->addRole($role);
     }
     foreach (Action::find(array("cache" => array("key" => "action"))) as $actions) {
         $acl->addResource(new Phalcon\Acl\Resource($actions->controller->name), $actions->name);
     }
     //Grant access to public areas to both users and guests
     foreach ($rol as $role) {
         foreach ($role->action as $action) {
             $roledann[$role->name][$action->controller->name][] = $action->name;
         }
     }
     // print_r($roledann);
     foreach ($roledann as $keys => $dann) {
         foreach ($dann as $key => $dan) {
             $acl->allow($keys, $key, $dan);
         }
     }
     //The acl is stored in session, APC would be useful here too
     //$this->persistent->acl = $acl;
     //	}
     //return $this->persistent->acl;
     return $acl;
 }
Esempio n. 2
0
 /**
  * [editedAction description]
  * @param  [type] $id [description]
  * @return [type]     [description]
  */
 public function editedAction($id)
 {
     $data = Input::all();
     $rules = array('actionname' => array('min:3', 'required'));
     // Build the custom messages array.
     $messages = array('action.min' => 'กรุณาระบุชื่อการกระทำอย่างน้อย :min ตัวอักษร.', 'action.required' => 'กรุณาระบุชื่อการกระทำ');
     $action_content = trim($data['actionname']);
     // Create a new validator instance.
     $validator = Validator::make($data, $rules, $messages);
     if ($validator->passes()) {
         $action = new Action();
         $chk_action = $action->checkAction($action_content);
         if ($chk_action) {
             $action = Action::find($id);
             $action->action_name = $action_content;
             $action->save();
             return Redirect::to('action')->with('success', 'แก้ไขชื่อการกระทำสำเร็จ');
         } else {
             return Redirect::to('action-edit/' . $id)->with('warning', 'มีชื่อการกระทำในระบบแล้ว');
         }
     } else {
         // $errors = $validator->messages();
         return Redirect::to('action-edit/' . $id)->withErrors($validator);
     }
 }
 public function initialize($entity = null, $options = null)
 {
     $action = new Select('actionid', Action::find(), array('using' => array('id', 'action'), 'useEmpty' => TRUE, 'emptyText' => $this->di->get('translate')->_('Seleccione una Acción')));
     $action->setLabel('Acción');
     $this->add($action);
     //añadimos un botón de tipo submit
     $submit = $this->add(new Submit('Guardar', array('class' => 'btn btn-success')));
 }
 public function actionEdit()
 {
     //echo "<pre>";var_dump($_REQUEST);exit;
     $action = new Action();
     $actionInfo = array();
     $label = '';
     foreach ($_REQUEST as $k => $v) {
         $_REQUEST[$k] = trim($v);
     }
     $menutype = isset($_REQUEST['menu_type']) ? intval($_REQUEST['menu_type']) : '0';
     $whichFirstMenu = isset($_REQUEST['firstmenu']) ? intval($_REQUEST['firstmenu']) : '-1';
     $menusort = isset($_REQUEST['menusort']) ? intval($_REQUEST['menusort']) : 0;
     $firstmenus = Action::model()->findAll('is_menu=1');
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
         // 修改
         $actionInfo = $action->find('aid=:id', array(':id' => $_REQUEST['id']));
         if (!empty($_REQUEST['modify'])) {
             $action->updateByPk($_REQUEST['id'], array('aname' => $_REQUEST['name'], 'route' => $_REQUEST['route'], 'is_menu' => $menutype, 'menusort' => $menusort, 'first_menu' => $whichFirstMenu));
             $this->redirect('/main/action/list');
         }
     } elseif (!empty($_REQUEST['name'])) {
         // 新增
         $actionInfo = $action->find('aname=:name or route=:route', array(':name' => $_REQUEST['name'], ':route' => $_REQUEST['route']));
         if (!empty($actionInfo)) {
             $this->render('edit', array('firstmenus' => $firstmenus, 'entity' => $actionInfo, 'label' => 'has_action'));
             exit;
         }
         if (!empty($_REQUEST['modify'])) {
             $action->aname = $_REQUEST['name'];
             $action->route = $_REQUEST['route'];
             $action->is_menu = $menutype;
             $action->first_menu = $whichFirstMenu;
             $action->menusort = $menusort;
             $action->save();
             $this->redirect('/main/action/list');
         }
         //echo "<pre>";var_dump($_REQUEST,$actionInfo);exit;
     }
     $this->render('edit', array('firstmenus' => $firstmenus, 'entity' => $actionInfo, 'label' => $label));
 }
Esempio n. 5
0
 public static function initActions()
 {
     $actions = (include Yii::app()->basePath . '/config-dist/actions.php');
     foreach ($actions as $k => $v) {
         $action = new Action();
         $ret = $action->find('aname=:name', array(':name' => $v['aname']));
         if (empty($ret)) {
             $action->aname = $v['aname'];
             $action->route = $v['route'];
             $action->is_menu = $v['is_menu'];
             $action->save();
         }
     }
 }