Re: Re: [hermes] Making clients

Bo Daley <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <[email protected]>
Quoting Chuck Hagenbuch <[email protected]>:

> > I'll see if I can achieve the same result without the change to the Turba
> API
> > first and send through another set of patches. So you can hold off on
> > committing this just for now.. I'd prefer to get this working properly
> before
> > we build on it too much further.
>
> Great, I'll look forward to your new patch!

OK here it is. This is only a slight modification on what I sent earlier, but it
fixes the CODING_STANDARDS problem (thank Jason!) and it no longer requires a
change to the Turba API. I still think there might be a problem with the Turba
API's search() method because I can only get it to work for my default localsql
addressbook (whereas my initial list() method worked for all my addressbooks),
but I think that's a separate issue.

Before going much further, the main thing I still haven't checked out thoroughly
is how this affects the old links from tickets to Turba contacts. I remember
when the Links API first appeared there was talk about extending it so that it
could handle different types of objects inside applications (eg. to support
links to both tickets _and_ modules) but I'm unsure about where that got to.
Did anyone ever look into that?

thanks,

bo.


--
Bo Daley
Tilda Communications
http://www.tilda.com.au
[email protected]


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
admin.php.diff (text/diff, 2.8 KB)
Index: whups/admin.php
===================================================================
RCS file: /repository/whups/admin.php,v
retrieving revision 1.43
diff -u -r1.43 admin.php
--- whups/admin.php	14 Jun 2003 04:07:08 -0000	1.43
+++ whups/admin.php	17 Jul 2003 03:03:51 -0000
@@ -293,6 +293,38 @@
                                         $vars->getVar('subjectlist'), $vars->getVar('subjects'),
                                         $vars->getVar('versioned'));
          if (!is_a($result, 'PEAR_Error')) {
+             if (isset($conf['client']['driver'])) {
+                 /* Update client links. */
+                 switch ($conf['client']['driver']) {
+                     case 'turba':
+                         $clients = $vars->getVar('clients');
+                         $clientsource = $conf['client']['params']['addressbook'];
+                         require_once HORDE_BASE . '/lib/Links.php';
+                         $links = &Horde_Links::singleton($registry->getApp());
+                         $from_application = 'projects'; 
+                         $from_parameters  = array('module_id' => $vars->getVar('module'));
+                         $to_application = 'contacts';
+                         $link_type = 'client';
+                         /* Delete all current client links for this module. */
+                         $delete_status = $links->deleteLink($from_application, $from_parameters, $to_application, '', $link_type);
+                         /* Now add in all the new client links. */
+                         foreach ($clients as $client) {
+                             $to_parameters = array('source' => $clientsource, 'id' => $client); 
+                             $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+                             if (is_a($status, 'PEAR_Error')) {
+                                 $notification->push($status, 'horde.error');
+                             } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
+                                 $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
+                                 $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
+                             } else {
+                                 $notification->push(_("Link added."), 'horde.success');
+                             }
+                         }
+                         break;
+                     /* Any future client sources can be added here. */
+                 }
+             }
+            
              $notification->push(_("The module has been modified."), 'horde.success');
              _open();
              $form->renderInactive($RENDERER, $vars);
conf.xml.diff (text/diff, 944 B)
Index: whups/config/conf.xml
===================================================================
RCS file: /repository/whups/config/conf.xml,v
retrieving revision 1.4
diff -u -r1.4 conf.xml
--- whups/config/conf.xml	4 Jul 2003 19:05:01 -0000	1.4
+++ whups/config/conf.xml	17 Jul 2003 03:04:08 -0000
@@ -111,6 +111,23 @@
   </configmultienum>
  </configsection>
 
+ <configsection name="client">
+   <configheader>
+        Client Driver Settings
+   </configheader>
+
+   <configenum name="driver" desc="What type of client driver should we use?">
+    <values>
+     <value desc="Turba Addressbook">turba</value>
+     <value desc="None">none</value>
+    </values>
+   </configenum>
+
+   <configsection name="params">
+    <configstring name="addressbook" desc="Name of client addressbook (Turba only)">localsql</configstring>
+   </configsection>
+ </configsection>
+
  <configsection name="menu">
    <configheader>
         Menu Settings
Admin.php.diff (text/diff, 1.2 KB)
Index: whups/lib/Admin.php
===================================================================
RCS file: /repository/whups/lib/Admin.php,v
retrieving revision 1.40
diff -u -r1.40 Admin.php
--- whups/lib/Admin.php	12 Jun 2003 04:35:12 -0000	1.40
+++ whups/lib/Admin.php	17 Jul 2003 03:04:32 -0000
@@ -139,7 +139,8 @@
 
         $module = $vars->getVar('module');
         $info = $whups->getModule($module);
-
+        $clients = $whups->getClients();
+        
         parent::Horde_Form($vars, sprintf(_("Edit %s"), $info['name']));
 
         $this->addHidden('', 'module', 'int', true, true);
@@ -149,6 +150,11 @@
 
         $mdesc = &$this->addVariable(_("Module Description"), 'description', 'text', true);
         $mdesc->setDefault($info['description']);
+
+        if (!empty($clients)) {
+            $mclients = &$this->addVariable(_("Clients associated with this Module"), 'clients', 'multienum', true, false, null, array($clients));
+            $mclients->setDefault(array_keys($whups->getClients($module)));
+        }
 
         $mtypes = &$this->addVariable(_("Ticket Types associated with this Module"), 'types', 'set', true, false, null, array($whups->getAllTypes()));
         $mtypes->setDefault(array_keys($whups->getTypes($module)));
Driver.php.diff (text/diff, 3.3 KB)
Index: whups/lib/Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.45
diff -u -r1.45 Driver.php
--- whups/lib/Driver.php	25 Jun 2003 19:54:34 -0000	1.45
+++ whups/lib/Driver.php	17 Jul 2003 03:04:42 -0000
@@ -69,6 +69,77 @@
                      'resolved' => _("Resolved"));
     }
 
+    function getClients($module=null)
+    {
+        /* Gets list of clients from the client source. */
+        
+        $clients = array();
+        global $conf;
+        
+        if (!empty($conf['client']['driver'])) {
+            $clientsource = $conf['client']['driver'];
+        } else {
+            $clientsource = '';
+        }
+
+        switch($clientsource) {
+            case 'turba';
+                /* get client data from a Turba addressbook. */
+                if (!empty($conf['client']['params']['addressbook'])) {
+                    $addressbook = $conf['client']['params']['addressbook'];
+                    global $registry;
+                    $clients = array();
+                    $args = array('addresses' => array(''), 
+                                    'addressbooks' => array($addressbook), 
+                                    'fields' => array('name')
+                                    );
+                    $results = $registry->call('contacts/search', $args);
+                    $clientlist = $results[''];
+                    foreach ($clientlist as $client) {
+                        $clients[$client['id']] = $client['name'];
+                    }
+                    if (!empty($module)) {
+                        $clients = $this->filterClientsByModule($clients, $module);
+                    }
+                    if (is_a('PEAR_Error', $clients)) {
+                        $notification->push(_("Could not access client list from Turba."));
+                    }
+                } else {
+                    $notification->push(_("No Turba addressbook specificified in Whups configuration."));
+                }
+                break;
+        }
+
+        return $clients;
+        
+    }
+
+    function filterClientsByModule($clients, $module) 
+    {
+        /* 
+        Take a list of clients and return only those associated with the specified module. 
+        Client/module associations come from the Links API.
+        */
+        global $registry;
+        $clients_filtered = array();
+        require_once HORDE_BASE . '/lib/Links.php';
+        $links = &Horde_Links::singleton($registry->getApp());
+        $from_application = 'projects'; 
+        // TODO: add from/to_application to listLinks in Links API so it only returns links for this application
+        $from_parameters = array('module_id' => $module);
+        $to_application = 'contacts';
+        $link_type = 'projects/client';
+        $client_links = $links->listLinks($link_type, $from_parameters);
+        foreach($clients as $client_id => $name) {
+            foreach ($client_links as $l) {
+                if ($client_id == $l['to_parameters']['id']) {
+                    $clients_filtered[$client_id] = $name;        
+                }
+            }
+        }
+        return $clients_filtered;
+    }
+
     function notifyTicket($ticket_id, $summary, $module_name, $creator)
     {
         $subject = sprintf(_("New ticket (%s): %s"), $ticket_id, $summary);
Links_sql.php.diff (text/diff, 1.6 KB)
Index: lib/Links/sql.php
===================================================================
RCS file: /repository/horde/lib/Links/sql.php,v
retrieving revision 1.8
diff -u -r1.8 sql.php
--- lib/Links/sql.php	19 Jun 2003 18:47:46 -0000	1.8
+++ lib/Links/sql.php	17 Jul 2003 03:04:58 -0000
@@ -107,13 +107,22 @@
     {
         $this->_connect();
 
-        $query = sprintf('DELETE FROM %s WHERE link_type = %s AND link_from_provider = %s AND link_from_parameter = %s AND link_to_provider = %s AND link_to_parameter = %s',
+        /* Treat empty values in $from_parameters and $to_parameters as wildcards 
+           so we can delete multiple links at once. */
+        $from_param_txt = '';
+        $to_param_txt = '';
+        if (!empty($from_parameters)) {
+            $from_param_txt = ' AND link_from_parameter = ' . $this->_db->quote(serialize($from_parameters));
+        }
+        if (!empty($to_parameters)) {
+            $to_param_txt = ' AND link_to_parameter = ' . $this->_db->quote(serialize($to_parameters));
+        }
+
+        $query = sprintf('DELETE FROM %s WHERE link_type = %s AND link_from_provider = %s ' . $from_param_txt . ' AND link_to_provider = %s ' . $to_param_txt,
             $this->_params['table'],
             $this->_db->quote($link_type),
             $this->_db->quote($from_application),
-            $this->_db->quote(serialize($from_parameters)),
-            $this->_db->quote($to_application),
-            $this->_db->quote(serialize($to_parameters))
+            $this->_db->quote($to_application)
         );
 
         $result = $this->_db->query($query);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.