We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37258
    • 34 Posts
    I'm developing a 3rd party component which does a simple search and display of an additional table which I've added to the database.

    The components working well, but the client has now asked me to limit the search by resource group id, so that logged in users can only retrieve info from their rows, we've updated the database so that user id's now reflect resource group id's so all I need to do now is update the search in my script.

    Is the logged in resource group id freely available to snippets? I was hoping it would be and I could just place it in a variable and search against that. I've done some searching this morning but havnt been able to find a lot of info, which leaves me thinking maybe I'm approaching things from the wrong angle.

    This is my current query.

    $query->where(array('accNumber:LIKE' => "$accNo%"));
    $query->andCondition(array('accName:LIKE' => "%$accName%"));
    $query->andCondition(array('saleProperty:LIKE' => "%$saleProperty%"));

    // Search against resource group
    $query->andCondition(array('clientNumber' => "3"));

      • 37258
      • 34 Posts
      This is weird, I've found out how to get the current users member group, its just a case of calling this:

      $user = (!empty($userId)) ? $modx->getObject('modUser', $userId) : $modx->user;
      
      if (is_object($user)) {
          /*
          * modUser Groups
          */
          $arry = print_r($user->getUserGroups(), true);
          $modx->toPlaceHolder('user.groups', $arry);
      }
      
      return $arry;
      


      However the number it returns from the database is always 1 less than the group id displayed in the access groups section of the manager. It shouldn't cause me any issues as I'll just add 1 to the number I get back so it matches up with whats in our table, but I am curious as to why this might be.