We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3743
    • 42 Posts
    can’t get working OnBeforeAddToGroup


    $wlpe was added to $parameters.
    usrrole is the name of the radio and stylist is its value.

    What am i doing wrong?

    plugin code:
    <tt>

    $e = &$modx->Event;
    switch ($e->name) {
    case "OnBeforeAddToGroup":

    if $wlpe->User[’usrrole’]==’stylist’
    {
    $GLOBAL[’groups’][]=`stylists`;
    }
    break;


    default :
    return; // stop here
    break;
    }

    </tt>

    ps:how to debug such plugin? how’d i check and print params?
      • 10449
      • 956 Posts
        • 3743
        • 42 Posts
        Quote from: ganeshXL at Dec 27, 2007, 02:34 AM

        Wouldn’t you rather use $GLOBALS instead of $GLOBAL?

        http://ch2.php.net/manual/en/reserved.variables.php#reserved.variables.globals
        http://ch2.php.net/global

        I tried to use it as mentioned in docs (-;
        Using $GLOBALS changes nothing.

        plugin (even simplier case):
        ---------
        $e = &$modx->Event;
        switch ($e->name) {
        case "OnBeforeAddToGroup":
        $GLOBALS[’groupsArray’][]=’stylists’;
        break;

        default :
        return; // stop here
        break;
        }
        ---------

        i’ve also changed a line in webloginpe class, register function from

        if (count($groupArray > 0))

        //(i havenot found any definition of what is $groupArray)
        to

        if (count($GLOBALS[’groupsArray’] > 0))

        and my OnBeforeAddToGroup looks like this:

        function OnBeforeAddToGroup($groups = array())
        {
        global $modx;
        $parameters = array(’groups’ => $groups, ’wlpe’ => &$this); // pixelchutes - reference $wlpe instance);
        $modx->invokeEvent(’OnBeforeAddToGroup’, $parameters);
        }


        ps: could anybody answer me how to debug plugin calls like this? How can i output some debug info?
          • 11975
          • 2,542 Posts
          Hi,

          for debug purpose, you could use the $modx->logEvent();


          :-)

          from document.parser

          
          <?php
              # Add an a alert message to the system event log
              function logEvent($evtid, $type, $msg, $source= 'Parser') {
                  $msg= mysql_escape_string($msg);
                  $source= mysql_escape_string($source);
                  $evtid= intval($evtid);
                  if ($type < 1) {
                      $type= 1;
                  }
                  elseif ($type > 3) {
                      $type= 3; // Types: 1 = information, 2 = warning, 3 = error
                  }
                  $sql= "INSERT INTO " . $this->getFullTableName("event_log") . " (eventid,type,createdon,source,description,user) " .
                  "VALUES($evtid,$type," . time() . ",'$source','$msg','" . $this->getLoginUserID() . "')";
                  $ds= @mysql_query($sql);
                  if (!$ds) {
                      echo "Error while inserting event log into database.";
                      exit();
                  }
              }
          
          
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 3743
            • 42 Posts
            Quote from: heliotrope at Dec 27, 2007, 07:29 AM

            Hi,
            for debug purpose, you could use the $modx->logEvent();

            Thanks, that was exactly what i need. Helped a to find out OnBeforeAddToGroup bug. It was my bug, not weblogin’s (-;