//get current logged in user $c = $modx->newQuery('modUser', array('internalKey' => $currentUser,)); // get member group id of logged in user $c->innerJoin ('modUserGroupMember','UserGroupMembers'); $c->innerJoin ('modUserGroup','UserGroup','`UserGroupMembers`.`user_group` = `UserGroup`.`id`'); // get user-array together, 8,9 are "superuser" groups $c->select(array( 'modUserGroupMembers.*' )); $c->where(array( 'UserGroupMembers.user_group:IN' => array('8','9') //user groups with full listing rights )); $users = $modx->getCollection("modUser",$c); //copied script - part, article "creating a multi-select-box", working $parent = $modx->getOption('parent',$scriptProperties,47); $parentObj = $modx->getObject('modResource',$parent); if (!($parentObj instanceof modResource)) { return ''; } $resArray = $parentObj->getMany('Children'); $resources = array(); foreach($resArray as $res) { if ($res instanceof modResource) { //addition to working code - check if user is in 'superlevel' group by checking if $ user !=null AND if ressource is limited by marker (marker: [[*description]] == 'eingeschraenkt') if (($res->get('description')!= "eingeschraenkt") && ($users != null) ) { //finish addition $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); // closing brake } } } $out = implode("||",$resources); return $out;
This question has been answered by multiple community members. See the first response.
<?php $superusergroups = $modx->getOption('superusergroups', $scriptProperties, '8,9'); $parent = $modx->getOption('parent', $scriptProperties, 47); $superusergroups = explode(',', $superusergroups); $groups = $modx->user->getUserGroups(); $has_permission = false; foreach ($superusergroups as $group) { if (in_array($group, $groups)) { $has_permission = true;//user is in one of the superusergroups } } $resources = array(); if ($has_permission && $parentObj = $modx->getObject('modResource', $parent)) { $c = $modx->newQuery('modResource'); $c->where(array('description:!=' => 'eingeschraenkt')); if ($resArray = $parentObj->getMany('Children', $c)) { foreach ($resArray as $res) { if ($res instanceof modResource) { $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); } } } } $out = implode("||", $resources); return $out;
<?php $superusergroups = $modx->getOption('superusergroups', $scriptProperties, '8,9'); $parent = $modx->getOption('parent', $scriptProperties, 47); $superusergroups = explode(',', $superusergroups); $groups = $modx->user->getUserGroups(); $has_permission = false; $accepted = false; //see below foreach ($superusergroups as $group) { if (in_array($group, $groups)) { $has_permission = true;//user is in one of the superusergroups } } $resources = array(); if ($parentObj = $modx->getObject('modResource', $parent)) { $c = $modx->newQuery('modResource'); if ($resArray = $parentObj->getMany('Children', $c)) { foreach ($resArray as $res) { if ($res instanceof modResource) { //Getting group of Ressource $rgrouplist = $res->getGroupsList(); $rgroups = array(); foreach ($rgroupslist['collection'] as $rgroup) { if ($resource->isMember($rgroup->get('Profikurs'),false) //Ressource is not Member of Ressourcegroup "Profikurs", so listing is always allowed and not dependend on rights. { $accepted = true; //set accepted to true } else if ($resource->isMember($rgroup->get('Profikurs')) && $has_permission) { // do something $accepted = true; } else { $accepted = false; } } } if ($accepted) { $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); $accepted = false; //reset accepted to false } } } } } $out = implode("||", $resources); return $out;
$parent = $modx->getOption('parent', $scriptProperties, 47); $resources = array(); if ($collection = $modx->getCollection('modResource',array('parent' => $parent)){ foreach ($collection as $res){ $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); } } $out = implode("||", $resources); return $out;
<?php $superusergroups = $modx->getOption('superusergroups', $scriptProperties, '8,9'); $parent = $modx->getOption('parent', $scriptProperties, 47); $superusergroups = explode(',', $superusergroups); $groups = $modx->user->getUserGroups(); $has_permission = false; $accepted = false; //see below foreach ($superusergroups as $group) { if (in_array($group, $groups)) { $has_permission = true;//user is in one of the superusergroups } } $resources = array(); if ($collection = $modx->getCollection('modResource',array('parent' => $parent))){ foreach ($collection as $res){ if ($res instanceof modResource) { //Getting group of Ressource $rgrouplist = $res->getGroupsList(); $rgroups = array(); foreach ($rgroupslist['collection'] as $rgroup) { if ($resource->isMember($rgroup->get('Profikurs'),false)) //Ressource is not Member of Ressourcegroup "Profikurs", so listing is always allowed and not dependend on rights. { $accepted = true; //set accepted to true } else if ($resource->isMember($rgroup->get('Profikurs')) && $has_permission) { // do something $accepted = true; } else { $accepted = false; } } } if ($accepted) { $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); $accepted = false; //reset accepted to false } } } $out = implode("||", $resources); return $out; ?>
<?php $superusergroups = $modx->getOption('superusergroups', $scriptProperties, '8,9'); $parent = $modx->getOption('parent', $scriptProperties, 47); $superusergroups = explode(',', $superusergroups); $groups = $modx->user->getUserGroups(); $has_permission = false; $accepted = false; //see below foreach ($superusergroups as $group) { if (in_array($group, $groups)) { $has_permission = true; //user is in one of the superusergroups } } $resources = array(); if ($collection = $modx->getCollection('modResource', array('parent' => $parent))) { foreach ($collection as $res) { if ($res instanceof modResource) { if ($res->isMember('Profikurs')) { if ($has_permission) { $accepted = true; } } else { $accepted = true; } } if ($accepted) { $resources[] = $res->get('pagetitle') . '==' . $res->get('id'); } $accepted = false; //reset accepted to false } } $out = implode("||", $resources); return $out; ?>