DataObjects/ProjectDirectory.php
[Pman.Core] / Lock.php
index 937fc6c..79581a8 100644 (file)
--- a/Lock.php
+++ b/Lock.php
@@ -49,18 +49,24 @@ class Pman_Core_Lock extends Pman
     }
     
     function get($action)
+    {
+        // should we allow url links to lock things???
+        // only for debugging??
+        $this->post($action);
+        // 
+        $this->jerr("invalid request");
+    }
+    
+    function post($action)
     {
         
         // default action is to attempt to lock..
-        $action = empty($action) ? 'lock' : 'unlock';
-        $this->$action($curlock);
-        
-       
-        
+        $action = empty($action) || $action == 'lock' ? 'lock' : 'unlock';
+        $this->$action();
         
     }
     
-    function unlock($curlock)
+    function unlock()
     {
     
         if (empty($_REQUEST['id'])) {
@@ -68,10 +74,11 @@ class Pman_Core_Lock extends Pman
         }
         $curlock = DB_DataObject::factory('Core_locking');
         if (!$curlock->get($_REQUEST['id'])) {
-            $this->jerr("No lock exists");
+            $this->jok("No lock exists"); // been deleted before.. probably ok..
         }
         
         if ($curlock->person_id != $this->authUser->id) {
+            // this is an error conditon..
             $this->jerr("Lock id is invalid");
         }
         
@@ -99,24 +106,30 @@ class Pman_Core_Lock extends Pman
             'on_table' => $_REQUEST['on_table']
         ));
         
+        $curlock_ex = clone($curlock);
+        $curlock_ex->whereAdd('person_id != '. $this->authUser->id);
+        
         
-        $nlocks = $curlock->count() ;
+        $nlocks = $curlock_ex->count() ;
         if ($nlocks && empty($_REQUEST['force'])) {
-            $curlock->selectAdd();
-            $curlock->selectAdd('distinct(person_id), created');
-            
-            
+           // DB_DataObjecT::debugLevel(1);
             $ar = $curlock->fetchAll('person_id', 'created');
             $p = DB_DataObject::factory('Person');
-            $p->whereAddIn('id', $ar, 'int');
+            $p->selectAdd();
+            $p->selectAdd('id,name,email');
+            
+            $p->whereAddIn('id', array_keys($ar), 'int');
             $p->find();
+            $ret = array();
             while ($p->fetch()) {
-                $ret[$p->id] = $p->toRooArray();
-                $ret[$p->id]->lock_created = $ar[$p->id];
+                $ret[$p->id] = $p->toArray();
+                $ret[$p->id]['lock_created'] = $ar[$p->id];
             }
-            $this->jok($ret);
+            $this->jok(array_values($ret));
             
         }
+        // trash the lock if it belongs to current user..
+        $nlocks = $curlock->count();
         if ($nlocks) {
             // trash all the locks..
             $curlock->find();