// Check if user is logged in and get user group
$user = (!empty($userId)) ? $modx->getObject('modUser', $userId) : $modx->user;
if (is_object($user)) {
/*
* modUser Groups
*/
$group = print_r($user->getUserGroups(), true);
$modx->toPlaceHolder('user.groups', $group);
}
// Define vars
if($_SERVER['REQUEST_METHOD'] == "POST") {
if ($_POST['submit'] == 'Submit') {
$accNo = $_POST['accNo'];
$accName = $_POST['accName'];
$saleProperty = $_POST['saleProperty'];
$clientContact = $_POST['clientContact'];
}
// Initial query against user group
echo $group;
$query = $DBH->query("
SELECT * FROM whc_relationships
WHERE UGroup = `$group`
");
// Print Query for debugging
echo $query;
}
print $query->toSQL();
$query->prepare(); print $query->toSQL();
$groups = array();
if (is_object($modx->user)) {
$groups = $modx->user->getUserGroups();
}
return (print_r($groups, true));
$group = $modx->user->getPrimaryGroup();
$groupName = $group->get('name');
$groupId = $group->get('id');
If that doesn't work, try:
$query->prepare(); print $query->toSQL();
BTW, I think this would be a lot simpler:
$groups = array(); if (is_object($modx->user)) { $groups = $modx->user->getUserGroups(); } return (print_r($groups, true));
getUserGroups() returns an array containing the IDs of every group the user belongs to. There is also getUserGroupNames() if that would work better for you.
In addition, each user can have a primary user group (set on the Create/Edit User panel) and available with:
$group = $modx->user->getPrimaryGroup();
Unlike the first two methods, it returns the modUserGroup object, so you need a next step:
$groupName = $group->get('name'); $groupId = $group->get('id');