public function chkPermission_Click($strFormId, $strControlId, $strParameter) { if (is_numeric($strParameter)) { $chkPermission = $this->Form->GetControl($strControlId); if ($chkPermission->Checked) { $objRolePermission = new NarroRolePermission(); $objRolePermission->RoleId = $this->objRole->RoleId; $objRolePermission->PermissionId = $strParameter; try { $objRolePermission->Save(); } catch (QMySqliDatabaseException $objExc) { if (strpos($objExc->getMessage(), 'Duplicate entry') === false) { throw $objExc; } else { // } } } else { $objRolePermission = NarroRolePermission::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroRolePermission()->RoleId, $this->objRole->RoleId), QQ::Equal(QQN::NarroRolePermission()->PermissionId, $strParameter))); if ($objRolePermission instanceof NarroRolePermission) { $objRolePermission->Delete(); } } } else { $this->dtgPermission_Bind(); } }
protected function Form_Create() { parent::Form_Create(); // Instantiate the Meta DataGrid $this->dtgNarroRolePermissions = new NarroRolePermissionDataGrid($this); // Style the DataGrid (if desired) $this->dtgNarroRolePermissions->CssClass = 'datagrid'; $this->dtgNarroRolePermissions->AlternateRowStyle->CssClass = 'alternate'; // Add Pagination (if desired) $this->dtgNarroRolePermissions->Paginator = new QPaginator($this->dtgNarroRolePermissions); $this->dtgNarroRolePermissions->ItemsPerPage = __FORM_DRAFTS_FORM_LIST_ITEMS_PER_PAGE__; // Use the MetaDataGrid functionality to add Columns for this datagrid // Create an Edit Column $strEditPageUrl = __VIRTUAL_DIRECTORY__ . __FORM_DRAFTS__ . '/narro_role_permission_edit.php'; $this->dtgNarroRolePermissions->MetaAddEditLinkColumn($strEditPageUrl, 'Edit', 'Edit'); // Create the Other Columns (note that you can use strings for narro_role_permission's properties, or you // can traverse down QQN::narro_role_permission() to display fields that are down the hierarchy) $this->dtgNarroRolePermissions->MetaAddColumn('RolePermissionId'); $this->dtgNarroRolePermissions->MetaAddColumn(QQN::NarroRolePermission()->Role); $this->dtgNarroRolePermissions->MetaAddColumn(QQN::NarroRolePermission()->Permission); }
/** * Used internally by the Meta-based Add Column tools. * * Given a QQNode or a Text String, this will return a NarroRolePermission-based QQNode. * It will also verify that it is a proper NarroRolePermission-based QQNode, and will throw an exception otherwise. * * @param mixed $mixContent * @return QQNode */ protected function ResolveContentItem($mixContent) { if ($mixContent instanceof QQNode) { if (!$mixContent->_ParentNode) { throw new QCallerException('Content QQNode cannot be a Top Level Node'); } if ($mixContent->_RootTableName == 'narro_role_permission') { if ($mixContent instanceof QQReverseReferenceNode && !$mixContent->_PropertyName) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } $objCurrentNode = $mixContent; while ($objCurrentNode = $objCurrentNode->_ParentNode) { if (!$objCurrentNode instanceof QQNode) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } if ($objCurrentNode instanceof QQReverseReferenceNode && !$objCurrentNode->_PropertyName) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } } return $mixContent; } else { throw new QCallerException('Content QQNode has a root table of "' . $mixContent->_RootTableName . '". Must be a root of "narro_role_permission".'); } } else { if (is_string($mixContent)) { switch ($mixContent) { case 'RolePermissionId': return QQN::NarroRolePermission()->RolePermissionId; case 'RoleId': return QQN::NarroRolePermission()->RoleId; case 'Role': return QQN::NarroRolePermission()->Role; case 'PermissionId': return QQN::NarroRolePermission()->PermissionId; case 'Permission': return QQN::NarroRolePermission()->Permission; default: throw new QCallerException('Simple Property not found in NarroRolePermissionDataGrid content: ' . $mixContent); } } else { if ($mixContent instanceof QQAssociationNode) { throw new QCallerException('Content QQNode cannot go through any "To Many" association nodes.'); } else { throw new QCallerException('Invalid Content type'); } } } }
/** * Count NarroRolePermissions * by PermissionId Index(es) * @param integer $intPermissionId * @return int */ public static function CountByPermissionId($intPermissionId) { // Call NarroRolePermission::QueryCount to perform the CountByPermissionId query return NarroRolePermission::QueryCount(QQ::Equal(QQN::NarroRolePermission()->PermissionId, $intPermissionId)); }
public static function LoadByUserId($intUserId, $objOptionalClauses = null) { $objUser = NarroUser::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroUser()->UserId, $intUserId)), QQ::ExpandAsArray(QQN::NarroUser()->NarroUserRoleAsUser)); if (!$objUser instanceof NarroUser) { return false; } foreach ($objUser->_NarroUserRoleAsUserArray as $objRole) { /* @var $objRole NarroUserRole */ $arrRolePermission = NarroRolePermission::LoadArrayByRoleId($objRole->RoleId, QQ::Expand(QQN::NarroRolePermission()->Permission)); foreach ($arrRolePermission as $objRolePermission) { $objUser->arrPermissions[$objRolePermission->Permission->PermissionName . '-' . $objRole->LanguageId . '-' . $objRole->ProjectId] = $objRolePermission; } } if (isset($objUser->Preferences['Language'])) { $objLanguage = NarroLanguage::LoadByLanguageCode($objUser->Preferences['Language']); if ($objLanguage instanceof NarroLanguage) { $objUser->Language = $objLanguage; } elseif (QApplication::$TargetLanguage instanceof NarroLanguage) { $objUser->Language = QApplication::$TargetLanguage; } } elseif (QApplication::$TargetLanguage instanceof NarroLanguage) { $objUser->Language = QApplication::$TargetLanguage; } return $objUser; }