Fork me on GitHub

Loading data from other modules into form fileds?  Bottom

  • Hey all in the process of building my next module I have stumbled across a problem I am not quit sure how to overcome, so I come to you all for advice. I have a form built and I am currently populating fileds with user name and email address using the pnUserGetVar API call, this works awesome thanks to the help from you all on this one. Now what I need to be able to do is grab a phone number for the given user from another modules table so the problem is how to accomplish this without doing an API call inside the fucntion. Is this a place where hooks should be used, and if so does anyone have an example of doing a procedure like this?



    Thanks all
    -SUNADMN
  • You want to call the API function of another module?

    Code

    if(!pnModAPILoad('mymod', 'user'))
    {
       echo 'api load failed!';
    }

    $phoneno = pnModAPIFunc('mymod', 'user', 'getphonenumber', array('uid' => $uid));

    echo $phoneno;


    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • in .760 you don't have to load the API first, it is automatically loaded when the function is called.
  • Yep, but presuming you want to be backwards compatible ;)

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • nawww - isn't EVERYONE running the bleeding edge?
  • Well I am - all my recent new modules call the Groups module API at some point, so .760 only here....

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • No the object is not going to call an API call of another module, yet rather talk directly to the other modules ( pnAddressbook ) tables to gather info ( phone number ). I would need to actually do a SQL query against the other modules table like so:

    Code

    $sql = SELECT $element FROM nuke_pnAddressbook_address WHERE CONCAT($address_column[fname],' ',$address_column[lname]) = $uname;


    Something to that effect, but do I have to write an API call that will talk to the other DB or can this be done right in the function??



    Thanks all
    -SUNADMN
  • i'm not sure, and by no means an expert on this. But i think as far as i know you can make an API function in you're module, and load the tables from the addressbook module.

    Code

    // Get datbase setup
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $exampletable = $pntable['example'];
        $examplecolumn = &$pntable['example_column'];
        $addresstable = &$pntable['pnaddressbook_address'];
        $addresscolumn = &$pntable['pnaddressbook_address_column'];
       
        $sql = "SELECT * from $exampletable, $addresstable


    Might be wise to check if pnAddressBook is installed before you make the query. There is a function like modAvailable(modname) or something like that.
  • You'd need to load the module's pntable array first. I can't remember the function call offhand, but it's something like pnModDBLoadInfo('themod')

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • hmm is this the best way of doing such a thing?? The reason I ask is for performance I need a very speedy system.




    Thanks
    -SUNADMN
  • The microsecond you'll gain is not worth it in my opinion...

    Code

    if (pnModAvailable('pnAddressBook')) {

        // If a API function exists, take it instead of loosing time
        if (!pnModAPILoad('pnAddressBook', 'user')) {
            pnSessionSetVar('errormsg', 'pnAddressBook load failed')
            return false;
        }

        // You could do an else here
        // pnModDBInfoLoad('pnAddressBook');
        // And buil your query bla bla bla bla...

        $pnabinfo = pnModAPIFunc('pnAddressBook', 'user', 'getuserinfo', array('uname' => $uname));

        if ($pnabinfo['phone'] != "") {

            // You have your phone

        } else {

            // No phone....
        }

    }
    //etc... etc...


    ;)
  • Yep, you are much better using the API of a module. But, if that's not available, all pnModDBInfoLoad does is include the module's pntables.php file, if I remember correctly..

    --
    itbegins.co.uk - Zikula Consulting

    birtwistle.me.uk - Personal Blog


    Please read the Support Guide
  • kewl well I thinhk that'll work I guess I could even just write a function to do what I need and include it in the other mods API.



    -SUNADMN

This list is based on users active over the last 60 minutes.