/** * @param int $userId * @param Captions $captions * @return array */ public function GetUserGrants($userId, Captions $captions) { $queryBuilder = new SelectCommand($this->connectionFactory->CreateEngCommandImp()); $queryBuilder->AddField($this->usersTable, $this->users_UserId, FieldType::Number, 'users_user_id'); $queryBuilder->AddField($this->usersTable, $this->users_UserName, FieldType::String, 'users_user_name'); $queryBuilder->AddField($this->userPermsTable, $this->userPerms_UserId, FieldType::Number, 'userperms_user_id'); $queryBuilder->AddField($this->userPermsTable, $this->userPerms_PageName, FieldType::String, 'userperms_pagename'); $queryBuilder->AddField($this->userPermsTable, $this->userPerms_Grant, FieldType::String, 'userperms_grant'); $queryBuilder->SetSourceTableName($this->userPermsTable); $queryBuilder->AddJoin(JoinKind::LeftOuter, $this->usersTable, 'userperms_user_id', $this->users_UserId); $queryBuilder->AddFieldFilter('userperms_user_id', new FieldFilter($userId, '=')); $dataset = new QueryDataset($this->connectionFactory, $this->connectionOptions, $queryBuilder->GetSQL(), array(), array(), array(), 'user_grants'); $dataset->AddField(new StringField('userperms_grant'), false); $dataset->AddField(new StringField('userperms_pagename'), false); $dataset->Open(); $pages = array(); $pages[''] = array('name' => '', 'caption' => $captions->GetMessageString('Application'), 'selectGrant' => false, 'updateGrant' => false, 'insertGrant' => false, 'deleteGrant' => false, 'adminGrant' => false); foreach ($this->tableCaptions as $name => $caption) { $pages[$name] = array('name' => $name, 'caption' => $captions->RenderText($caption), 'selectGrant' => false, 'updateGrant' => false, 'insertGrant' => false, 'deleteGrant' => false, 'adminGrant' => false); } while ($dataset->Next()) { $grant = $dataset->GetFieldValueByName('userperms_grant'); $pageName = $dataset->GetFieldValueByName('userperms_pagename'); if (isset($pages[$pageName])) { $pages[$pageName]['selectGrant'] = $pages[$pageName]['selectGrant'] || StringUtils::SameText($grant, 'select'); $pages[$pageName]['updateGrant'] = $pages[$pageName]['updateGrant'] || StringUtils::SameText($grant, 'update'); $pages[$pageName]['insertGrant'] = $pages[$pageName]['insertGrant'] || StringUtils::SameText($grant, 'insert'); $pages[$pageName]['deleteGrant'] = $pages[$pageName]['deleteGrant'] || StringUtils::SameText($grant, 'delete'); $pages[$pageName]['adminGrant'] = $pages[$pageName]['adminGrant'] || StringUtils::SameText($grant, 'admin'); } } $dataset->Close(); return array_values($pages); }
/** * @param Field $field * @return void */ protected function DoAddField($field) { $this->selectCommand->AddField($field->GetSourceTable(), $field->GetName(), $field->GetEngFieldType(), $field->GetAlias()); }