Permalink
Browse files

disable role_key input if role is used

added convenience method filterByRole to UserGroupQuery
  • Loading branch information...
juergmessmer committed Dec 19, 2012
1 parent c03a3db commit 25352cf7c6ddc7b072be073fd1a0e40a9f62291d
@@ -5,6 +5,9 @@
* @package propel.generator.model
*/
class UserGroupQuery extends BaseUserGroupQuery {
public function filterByRole($oRole) {
return $this->useGroupQuery()->useGroupRoleQuery()->filterByRole($oRole)->endUse()->endUse();
}
}
@@ -15,13 +15,24 @@ public function roleData() {
$aResult['CreatedInfo'] = Util::formatCreatedInfo($oRole);
$aResult['UpdatedInfo'] = Util::formatUpdatedInfo($oRole);
$aResult['rights'] = array();
$aResult['RoleIsUsed'] = self::roleIsUsed($oRole);
foreach($oRole->getRightsJoinPage() as $oRight) {
$aResult["rights"][$oRight->getId()] = $oRight->toArray();
}
$this->getModulesAndRequiredRights();
return $aResult;
}
private static function roleIsUsed($oRole) {
if($oRole->isNew()) {
return false;
}
$iCountRolesUsed = UserRoleQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count();
$iCountRolesInGroupsUsed = UserGroupQuery::create()->filterByRole($oRole)->joinUserRelatedByUserId()->count();
ErrorHandler::log('roleIsUsed', $oRole->getRoleKey(), $iCountRolesUsed, $iCountRolesInGroupsUsed);
return ($iCountRolesUsed + $iCountRolesInGroupsUsed) > 0;
}
public function getModulesAndRequiredRights() {
$aResult = array();
foreach($aAllEnabledModules = Module::listModulesByType('admin') as $sModuleName => $aAdminModule) {
@@ -26,7 +26,7 @@ Widget.types.role_detail = {
var _this = this;
this.detail_widget.disable();
this.roleData(function(role_data) {
this.content.find("input[name='role_key']").val(role_data.RoleKey);
this.content.find("input[name='role_key']").val(role_data.RoleKey).prop('disabled', role_data.RoleIsUsed);
this.content.find("textarea[name='description']").val(role_data.Description);
this.content.find(".updated_info").text(role_data.UpdatedInfo);
this.content.find(".created_info").text(role_data.CreatedInfo);

0 comments on commit 25352cf

Please sign in to comment.