/**
  * Save role privileges
  *
  * @service role write
  * @param Gpf_Rpc_Params $params
  * @return Gpf_Rpc_Form
  */
 public function saveRolePrivileges(Gpf_Rpc_Params $params)
 {
     $form = new Gpf_Rpc_Form($params);
     $role = new Gpf_Db_Role();
     $role->setId($form->getFieldValue('roleid'));
     $role->load();
     if (!strlen($role->getAccountId())) {
         $form->setErrorMessage($this->_('It is not possible to changes privileges for default role %s', $role->getName()));
         return $form;
     }
     //delete all privileges for selected role
     Gpf_Db_Table_RolePrivileges::getInstance()->deleteAllPrivileges($role->getId());
     //insert all privileges again to database
     $objects = new Gpf_Data_RecordSet();
     $objects->loadFromArray($form->getFieldValue('objects'));
     foreach ($objects as $record) {
         $rights = explode(',', $record->get('privileges'));
         foreach ($rights as $right) {
             $privilege = new Gpf_Db_RolePrivilege();
             $privilege->setObject($record->get('object'));
             $privilege->setRoleId($role->getId());
             $privilege->setPrivilege($right);
             $privilege->insert();
         }
     }
     $form->setInfoMessage($this->_('Changes saved'));
     return $form;
 }