1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Use viewlevel or user_id to filter view for a list

Discussion in 'Community' started by paulsteigel, Jul 24, 2018.

  1. paulsteigel

    paulsteigel Member

    Level: Community
    Dear All,
    I would like to have your advice with following case:
    I have a table named product(Id, name, descriptio,user_id).
    Requirements: I would like the list to view all records of that user (edit/deleting allowed) and also records created by other users of the same access level/ view level (edit but not delete).
    Please show me whether I am right or wrong with filed settings in table products? Whether it can be done with just Pre-filter options?
    I am newbie to fabrikar but having great interest in fabrik
    THank you very much for tour attention.
    Yours very faithfully
    Dang DInh Ngoc
     
  2. danielbidala

    danielbidala Member

    Level: Community
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    What do you mean by "the same access level / view level"?

    For example, if I belong to "Registered" and "Office Staff" ... should I see all records by anyone in both Registered and Office Staff?

    Or do you have a single, specific Access Level you want to restrict the test to?

    -- hugh
     
    paulsteigel likes this.
  4. paulsteigel

    paulsteigel Member

    Level: Community
    Hi Cheesgrit
    Thank you very much for your post.
    I have been guided by Hugh by giving a prefilter for user_id Or 1=1. This has somewhat solved my requirement but not for all the cases.
    Given an Example that
    I am belong to a group name FoodSafety Authority (A) and I myselft under the Board of Director(B) Of higher level than Food Safety Authority
    There are also user those are producer of food(C).
    So I would like: When A access they can see all things proposed by C but not B, When B log in they can see all A and C posted while C can only see what he posted.
    THis is a bit complicated as I am helping farmer to register their food chain with agriculture management authority. And still stuck in this circumstances.
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Trying to use view levels in a query is problematic, because for reasons I don't quite understand, J! decided to use a flat, JSON structure for the group / access level relationship. So instead of having a (say) #__viewlevel_group_map table, with entries like ...

    level_id, group_id
    2,7
    2,8
    3,7
    3,4
    3,5
    etc

    ... they have a single #__viewlevels table with the group ids as a JSON array

    id, title, ordering, rules
    1,Public,0,[1]
    2,Registered, 1,[6,2,8]
    etc

    ... so the group ids are in the [6,2,8]. WHICH makes it pretty much impossible to do any direct querying of the sort you need, where you would need to join the user table, the user_usergroup_map table to the groups in a viewlevel.

    So you'd probably have to do this with a PHP prefilter (type 'eval'), which returns a set of user ID's.

    I have a feeling I provided someone else with a similar solution in the last year or so. Try searching the forums for getAuthorisedViewLevels, see if you come up with anything.

    -- hugh
     
    paulsteigel likes this.
  6. marozen

    marozen New Member

    Level: Community
    If you want the list of all records to be visible for a user-group you can do that at List - Access.
    Likewise you can also set that records cannot be deleted, by allowing delete only to the super-user.
    If you want that users can only delete their own records you can select "or use field" = UserID.
    If you want to make the list also visible for other usergroups than you can set Access of list to public and use Pre-filters to exclude specific groups.
    By the way you can also make an extra joomla menu of the same fabrik list where the user can see only his own products, by prefilters (WHERE UserID = {$my->id})
     

Share This Page