We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    I'm trying to compare a list of users groups to another list of [Active Directory] groups in a custom table, then store the results in an session variable array so it's handy [and not called a hundred million times!]

    The code I have works in a snippet perfectly so far, but as soon as I try to put it in a plugin on the onWebLogin event, it breaks completely.

    After a bit of testing, it appears that the logging in user's ID is not yet available when the onWebLogin event fires.... [grrr!]

    Any thoughts on which event I can attach this plugin so that it get's executed after the user's id is available?

    here's the code:

    <?php
    
    $user = $modx->getObject('modUser', $modx->user->get('id'));
    
    $groups = $user->getUserGroupNames();
    
    $sql = "select * from `flow_location`";
    
    $query = $modx->query($sql);
    
    $memberof = array();
    
    if ($query) {
    
    	while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
    
    		if (array_search($row['group'], $groups)){
    
    			array_push($memberof, $row);
    
    		}
    
        }
    }
    
    $_SESSION['memberof'] = $memberof;
    
    echo '<pre>';print_r($_SESSION['memberof']);echo '</pre>';exit();
    
    return;

    This question has been answered by BobRay. See the first response.

      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
    • discuss.answer
      • 3749
      • 24,544 Posts
      Your mistake is using $modx->user.

      That works fine in a snippet, but in plugins (including ones attached to OnWebLogin), it's just $user.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 26503
        • 620 Posts
        Perfect - thanks Bob.

        Quote from: BobRay at Mar 13, 2014, 05:11 PM
        Your mistake is using $modx->user.

        That works fine in a snippet, but in plugins (including ones attached to OnWebLogin), it's just $user.
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525