Forums

group id as DB REad condition

gate 08 Apr, 2015
Hi folks,

I can't get my DBRead condition to work

If I use following condition it works fine, but this is too restrictive, because it would disable the form most of the users

<?php
$user = JFactory::getUser();
return array( "text39" =>  $user->get('id'))
?>


When I tried to specifize the condition with the following code it works no more... the goal was to restrict the view of users of the usergroup with the id 16, but let everyone else who is not part of that group see all database entries

<?php

$user = JFactory::getUser();

if($user->get('groups') = 16) {
    return array( "text39" =>  $user->get('id'))
}else {
    return array()
}

?>


greetings
Max_admin 08 Apr, 2015
Hi gate,

If you are trying to block access to the form then you need an Authenticator action.

Or this is not what you are trying to do ?

Regards,
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
gate 09 Apr, 2015
Hi Max,

no, you've got it wrong.
I don't want to block the access to the form itself, but to the database entries, which are loaded into the form.


<?php
$user = JFactory::getUser();
return array( "text39" =>  $user->get('id'))
?>


This condition compares the user-id with the database field "text39" and gives back all the database entries where they are matching, nontheless the usergroup.
But I want to use this condition only for users with the group-id '16', for every other user, the form should load all database entries. I thought the easiest way to accomplish this, was to use an "if-clause", but I can't get it to work correctly

greetings
Max_admin 09 Apr, 2015
Answer
1 Likes
Ok, I think $user->get('groups') returns an array, so you need to change your previous code to:
if( in_array( 16, $user->get('groups') ) ) {


Regards,
Max

Later: fixed typos, Bob
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
gate 09 Apr, 2015
thanks Max it worked fine... after I figured that there shouldn't be a space in "in_array" and that at the end there is missing a closing bracket 😉
This topic is locked and no more replies can be posted.