[dev] Nag's api

Carlos Pedrinaci cpedrinaci at yahoo.es
Sun Sep 28 14:40:31 PDT 2003


Hi,

I have attached a patch for Nag's api.php. This adds
the possibility to create a task list and a param to
the _nag_add() method so that you can also specify
which list to add the new task to.

Carlos

___________________________________________________
Yahoo! Messenger - Nueva versión GRATIS
Super Webcam, voz, caritas animadas, y más...
http://messenger.yahoo.es
-------------- next part --------------
Index: api.php
===================================================================
RCS file: /repository/nag/lib/api.php,v
retrieving revision 1.47
diff -u -r1.47 api.php
--- api.php	1 Sep 2003 21:59:39 -0000	1.47
+++ api.php	28 Sep 2003 18:39:05 -0000
@@ -19,8 +19,12 @@
     'link' => '%application%/view.php?task=|task|' . ini_get('arg_separator.output') . 'tasklist=|tasklist|');
 
 $_services['add'] = array(
-    'args' => array('name', 'description', 'due'),
+    'args' => array('name', 'description', 'due', 'tasklist'),
     'type' => 'integer');
+    
+$_services['addList'] = array(
+    'args' => array('name', 'description', 'type'),
+    'type' => 'string');
 
 $_services['block'] = array(
     'args' => array('type', 'params'),
@@ -144,14 +148,27 @@
     return Nag::listTasks($sortby, $sortdir);
 }
 
-function _nag_add($name = '', $description = '', $due = 0)
+function _nag_add($name = '', $description = '', $due = 0, $tasklist = '')
 {
     global $conf;
     require_once dirname(__FILE__) . '/base.php';
 
+    if ($tasklist != '') {
+        $nag_shares = &Horde_Share::singleton('nag');
+        $share = $nag_shares->getShare($tasklist);
+        if (is_a($share, 'PEAR_Error')) {
+            return $share;
+        }
+        if (!$share->hasPermission(Auth::getAuth(), _PERMS_EDIT)) {
+            return PEAR::raiseError(_("Permission Denied"));    
+        }
+    } else {
+        $tasklist = Auth::getAuth();    
+    }
+    
     /* Create a Nag_Driver instance. */
     require_once NAG_BASE . '/lib/Driver.php';
-    $storage = &Nag_Driver::singleton(Auth::getAuth());
+    $storage = &Nag_Driver::singleton($tasklist);
     $storage->retrieve();
 
     /* Add the new task. */
@@ -159,8 +176,31 @@
     if ($result >= 0) {
         $result = $storage->store();
     }
-
+    
     return $result;
+}
+
+function _nag_addList($name, $description = '',$type = 0)
+{
+    $nag_shares = &Horde_Share::singleton('nag');
+    $list_id = md5(microtime());
+    $tasklist = $nag_shares->newShare($list_id);
+    
+    if (is_a($tasklist, 'PEAR_Error')) {
+        return $tasklist;
+    }
+    
+    $tasklist->setOwner(Auth::getAuth(), false);
+    $tasklist->setShareName($name, false);
+    $tasklist->setType($type, false);
+    $tasklist->setDescription($description, false);
+    $result = $nag_shares->addShare($tasklist);
+    
+    if (is_a($result, 'PEAR_Error')) {
+        return $result;
+    }
+ 
+    return $list_id;
 }
 
 function _nag_getLinkDescription($tasklist_id, $task_id)


More information about the dev mailing list