Using LDAP Query class in a custom module

Events happening in the community are now at Drupal community events on www.drupal.org.
humansky's picture

Hello,
I wrote a custom Drupal 7 module and I would love to utilize the LdapQuery() class but I'm running into a few issues. Is there anyway to use that class without having to go through the GUI? Here is my current code:

global $user;

$ldap_query = new LdapQuery('ldap_query_user');
$ldap_query->filter = '(uid=' . $user->name . ')';
$ldap_result = $ldap_query->query();

And this works fine, except I want to be able to recreate "'ldap_query_user" in my module and not have to create it through Drupal's LDAP Admin GUI. Is this possible? Does anyone have sample code?

Thank you,
Henry

Comments

johnbarclay's picture
  1. in the install hook of your module you could save your query
    include ldap_query/LdapQueryAdmin.class.php,
    then...
    $ldap_query = new LdapQueryAdmin();
    $ldap_query->qid = 'qod';
    $ldap_query->name = 'Query of the day';
    $ldap_query->sid = 'blah';
    $ldap_query->status = 1;
    $ldap_query->inDatabase = 0; // this means its a new one or create

... with all the public properties in ldapquery.class.php....

$ldap_query->save(); // will save it to the db

  1. We could add a hook_query_list() to the query module that could get queries from other modules.

I see, so then I

humansky's picture

I see, so then I switch:

$ldap_query = new LdapQuery('ldap_query_user');

to:

$ldap_query = new LdapQuery('qod'); //or whatever machine name I choose

Also, do you see a huge performance hit if I don't save this to the database, instead instantiate the class every time the page is rendered? The page I plan to use this query will be password protected and not used too often.

Will be faster outside the database than in it.

johnbarclay's picture

Can you add whatever works for you to the LDAP Query documentation at: http://drupal.org/node/1302080 ?

Maybe something like "Developer Notes" near the bottom of the page.

LDAP integration development and modules

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: