public function saveData($aRoleData) { $oRole = null; if ($this->sRoleId === null) { $oRole = new Role(); } else { $oRole = RoleQuery::create()->findPk($this->sRoleId); // If the role_key has changed and the new key does not exist yet, delete the current role and create a new one if ($oRole->getRoleKey() !== $aRoleData['role_key']) { if (RoleQuery::create()->filterByRoleKey($aRoleData['role_key'])->count() === 0) { $oRole->delete(); $oRole = new Role(); } } } $this->validate($aRoleData, $oRole); if (!Flash::noErrors()) { throw new ValidationException(); } $oRole->setRoleKey($aRoleData['role_key']); $oRole->setDescription($aRoleData['description']); if (isset($aRoleData['page_id'])) { if (!$oRole->isNew()) { RightQuery::create()->filterByRole($oRole)->delete(); } $aRights = array(); foreach ($aRoleData['page_id'] as $iCounter => $sPageId) { $sRightKey = $sPageId . ($aRoleData['is_inherited'][$iCounter] ? "_inherited" : "_uninherited"); if (isset($aRights[$sRightKey])) { $oRight = $aRights[$sRightKey]; $oRight->setMayEditPageContents($oRight->getMayEditPageContents() || $aRoleData['may_edit_page_contents'][$iCounter]); $oRight->setMayEditPageDetails($oRight->getMayEditPageDetails() || $aRoleData['may_edit_page_details'][$iCounter]); $oRight->setMayDelete($oRight->getMayDelete() || $aRoleData['may_delete'][$iCounter]); $oRight->setMayCreateChildren($oRight->getMayCreateChildren() || $aRoleData['may_create_children'][$iCounter]); $oRight->setMayViewPage($oRight->getMayViewPage() || $aRoleData['may_view_page'][$iCounter]); } else { $oRight = new Right(); $oRight->setPageId($sPageId); $oRight->setRole($oRole); $oRight->setIsInherited($aRoleData['is_inherited'][$iCounter]); $oRight->setMayEditPageContents($aRoleData['may_edit_page_contents'][$iCounter]); $oRight->setMayEditPageDetails($aRoleData['may_edit_page_details'][$iCounter]); $oRight->setMayDelete($aRoleData['may_delete'][$iCounter]); $oRight->setMayCreateChildren($aRoleData['may_create_children'][$iCounter]); $oRight->setMayViewPage($aRoleData['may_view_page'][$iCounter]); $aRights[$sRightKey] = $oRight; } } foreach ($aRights as $oRight) { $oRight->save(); } } $oRole->save(); return array('id' => $oRole->getRoleKey()); }