sonata admin - how to give custom query to admin class - sonata-admin

I Am Developing website using sonata-admin Bundle in Symfony2
I Have Two Entity UserOne(id,name,pass ...) And UserTwo(id ,user_one_id ,...)
this two table are related by one two many using UserOne(id)->UserTwo(user_one_id)
each records of user_one table are admin of related company and
each records of user_two table are employees of related user_one(id) company
user_one ------------------ user_two
1 - james - **** ------------------ 1 - 1 - employee1
2 - kevin - **** ------------------ 2 - 1 - employee2
3 - jack - **** ------------------ 3 - 2 - employee1
when user of user_one table login they get admin panel which is developed using sonata-admin
I Have Requirement To Give only that employee of user_two to admin which user_one_id match to login admin means userone(id)
for example if james is login and open dashboard for user management then only employee1 and employee2 is shown
i have created admin class of UserTwo Entity for Admin functionality (UserTwoAdmin.php)
but problem is that when james open dashboard all the records of user_two table is shown
i want to filter to show only those data which id match to login id

Related

Simple user permissions database structure

I'm looking for a right solution for database structure regarding user permissions.
Tables:
users
companies (relevant columns: id)
projects (relevant columns: id,company_id)
jobs (relevant columns: id, company_id,project_id)
Scenarios I want to accomplish is to have specific user and/or users assigned to:
all the projects within company ("Cindy is assigned to all projects and all jobs within company")
select projects within company ("Cindy is assigned to three out of five projects and is assigned to all jobs within those three projects")
selected job(s) within project(s) ("Cindy is assigned to five jobs out of ten within one project and two jobs within the other project")
I think about separate permissions table where I just insert permissions to relevant jobs and to use the relevant columns from jobs table to cascade permissions upwards. In other words - if a user has permission for a specific job then it also has permission for parent project and parent company.
SQL Fiddle: http://sqlfiddle.com/#!9/74a4d3/2
Here is a proposed table structure for permissions:
USER_ID OBJ_TYPE OBJ_ID PERMISSION
JDOE COMPANY 1 1-READONLY
JDOE COMPANY 2 2-READWRITE
JDOE PROJECT 1 2-READWRITE
Then code to check user access could look something like:
SELECT MAX(permission) FROM permissions
WHERE user_id = :USERID
AND ( (obj_type = 'JOB' and obj_id = :JOBID)
OR (obj_type = 'PROJECT' and obj_id = :PROJECTID)
OR (obj_type = 'COMPANY' and obj_id = :COMPANYID))

How to implement same userrole with different set of permissions in sql server

I want to create such a system in which multiple user can have same user role but different permission.
e.g.
User 1: as Author can create page as well as add image.
User 2: as Author can only create page
I have tried this:
- Added comma separated User Role into UserRole columns.
- But i think it will not a scalable,long term and right approach.
Please guide me.
Build up a table of permissions
Permission_id, Permission_name
1 'Create page'
2 'Add image'
Then assign these permissions to each user through a second table user_permissions
user_id, permission_id
1 1
1 2
2 1
Edit:
or, if you want to build specific roles
Do the same with permissions, but build up additional structure like a table user_role
user_role_id, user_role_description
1 "User can create page and add image"
2 "User can add image"
And add permissions to these roles through user_role_permissions
user_role_id, permission_id
1 1
1 2
2 1
And assign these roles to the users with an additional table similar to user_permissions (if you want the user to be able to have multiple roles) or an extra column user_role_id in the user table

Ms Access Relationship between subform and form

I am beginner with Ms Access and databases
I am building meeting management database. I am stuck at some point please help
Database purpose is to manage meetings with different firms which are in most cases reoccurs time to time
Table that I have created.
Table 1 - Firms
FirmID - AutoNo - PK
FirmName - Text
....
Table 2 - FirmReps (to store multiple reps of each firm)
FirmRepID - AutoNo
FirmID - FK
RepName - Text
...
Table 3 - Meeting Details (will be the main form)
MeetingID - AutoNo
MeetingDate - Date/Time
MeetingTime - Date/time
Venue - Text
FirmName - FK
...
I am looking for solution that when I enter meeting details and select the firm name all individuals will be shown in separate sub-form where I can select (tick) the interested reps for meeting
I have created a subform for FirmReps and link the master with FirmID but Every time I select the firm name all the reps are shown and not saved/linked with the meeting ID.
To get only the selected firm in the combobox on the subform, you can refer to the main form FirmID. Set the Row Source for the combo like so:
SELECT FirmRepID, RepName FROM FirmReps
WHERE FirmID = Forms!NameOfMeetingsFormHere!FirmID

What is a sensible approach for enabling/disabling features on a database object?

Say I have a User database table with the regular username, password, email fields. What is a sensible way to add additional boolean fields that enable/disable features for any given user.
e.g.,
user_can_view_page_x
user_can_send_emails
user_can_send_pms
etc
Adding a bunch of boolean columns to the existing user table seems like the wrong way to go.
Yes, I would think that this is the wrong approach.
I would rather create a
User_Features Table
with columns something like
UserID
FeatureName
And check if a given user has the feature in question enabled/entered in the table.
You could even go as far as creating a Users_Groups table, where users are also assosiated with groups and features can be inherited/disallowed from group settings.
I would use three tables.
One is your existing user table:
USER table
----
user_id (pk)
name
email
...
Another is a table containing possible user privileges:
PRIVILEGE table
----
privilege_id (pk)
name
Lastly is a join table containing an entry for each privilege setting for each user:
USER_PRIVILEGE table
----
user_id (pk) (fk)
privilege_id (pk) (fk)
allowed
Here is some sample data for two users, one with the send email privilege and the send pms privilege and another with a view page privilege:
USER data
USER_ID NAME EMAIL
------- ----- -------------------
1 USER1 user1#somewhere.com
2 USER2 user2#somewhere.com
PRIVILEGE data
PRIVILEGE_ID NAME
------------ -----------
1 view_page_x
2 send_email
3 send_pms
USER_PRIVILEGE data
USER_ID PRIVILEGE_ID ALLOWED
------- ------------ -------
1 1 'N'
1 2 'Y'
1 3 'Y'
2 1 'Y'
2 2 'N'
2 3 'N'

Aggregate/concatenate values from a column into a single row

I have a couple thousand franchises, and about 3 or 4 service groups. The service groups are in a separate table, then i have third table joining them together. A franchise may be connected to 1 or many service groups. What I am trying to achieve is listing out the franchises, with a column labeled "Service Categories". It would then be a comma separated list of which services they provide. So right now, here's my output:
id Service Groups name email address City State
1 Cleaning Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
2 Disaster Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
I would like to have it so it becomes this:
id Service Groups name email address City State
1 Cleaning Services, Disaster Services Franchise of LocationX example#example.com 123 Fake st. Springfield TheOneTheSimpsonsLiveIn
Any suggestions or references of methods/functions I can use to do this would be greately appreciated. Thanks!
try this
Declare #TempServiceGroups varchar(max)=''
Select COALESCE(#TempServiceGroups,'')+ServiceGroups+',' from MyTable
Select #TempServiceGroups AS ServiceGroups , Name,Email,Address,City,State
from MyTable

Resources