Esempio n. 1
0
 /**
  * Aktualizacja roli i jej uprawnień
  *
  * @param Base_Form_Abstract $form formularz z danymi do zapisania
  * @param integer $id id edytowanej roli
  * @return integer liczba zmienionych wierszy
  */
 public function updateRole($form, $id)
 {
     $roleModel = new Role();
     $roleGroupModel = new RoleGroup();
     $dane = $values = $form->getValues();
     $subForms = $form->getSubForms();
     foreach ($subForms as $subForm) {
         unset($dane[get_class($subForm)]);
     }
     $roleModel->getAdapter()->beginTransaction();
     try {
         $tmp = $roleModel->update($dane, 'id = ' . $id);
         $roleGroupModel->delete('id_role = ' . $id);
         foreach ($subForms as $subForm) {
             $groups = $values[get_class($subForm)];
             foreach ($groups['group'] as $group) {
                 $subValues['id_group'] = $group;
                 $subValues['id_role'] = $id;
                 $row = $roleGroupModel->createRow($subValues);
                 $row->save();
             }
         }
         $roleModel->getAdapter()->commit();
         $cm = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cachemanager');
         $cache = $cm->getCache('rolecache');
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     } catch (Exception $e) {
         $roleModel->getAdapter()->rollBack();
         throw $e;
     }
     return $tmp;
 }