public function group_save($id = null)
 {
     //  Validate Requested Item
     if ($id && !GroupItem::find($id)) {
         return Redirect::route("groups")->with(FLASH_MSG_ERROR, trans("auth-module::message.group_not_found"));
     }
     //  Success
     $success = true;
     //  Error Messages
     $error_messages = array();
     //  Get User
     $group = $id ? GroupItem::find($id) : new GroupItem();
     //  Assign Values
     $group->group_name = Input::get("group_name");
     $group->group_description = Input::get("group_description");
     //  Check if Group Already Exists
     if ($this->groupExists($id, $group->group_name)) {
         //  Set Invalid
         $success = false;
         //  Add Error Message
         $error_messages[] = sizeof($error_messages) + 1 . ". " . trans("auth-module::message.group_already_exists", array("group" => $group->group_name));
     }
     //  Check Validation was successful
     if ($success) {
         //  Save the Group
         $group->save();
         //  Permissions
         $permissions = (array) Input::get("permissions");
         //  Validate Dashboard Permission
         $dash_perm = PermissionItem::forDashboard();
         //  Loop Existings
         foreach ($group->permissionIds() as $e_perm_id) {
             //  Check Still Exists
             if ($e_perm_id != $dash_perm->id && !in_array($e_perm_id, $permissions)) {
                 //  Remove Permission
                 $group->removePermissionById($e_perm_id);
             }
         }
         //  Add Permissions
         $group->addPermissionsById($permissions);
         //  Validate Dashboard Permission
         $dash_perm->getAdded($group);
         //  Redirect
         return Redirect::route("groups")->with(FLASH_MSG_SUCCESS, trans("auth-module::message.group_saved"));
     } else {
         //  Redirect with Error
         return Redirect::route($id ? "edit_group" : "create_group", $id ? array("id" => $id) : null)->with(FLASH_MSG_ERROR, implode("<br/>", $error_messages));
     }
 }
Example #2
0
/**
 * Get Dashboard Permission
 */
function getDashboardPermission()
{
    return \Developeryamhi\AuthModule\PermissionItem::forDashboard();
}