[limb-svn] r5826 - in 3.x/trunk/limb/web_app: src/fetcher tests/cases/db/fetcher

svn at limb-project.com svn at limb-project.com
Mon May 7 18:07:42 MSD 2007


Author: pachanga
Date: 2007-05-07 18:07:42 +0400 (Mon, 07 May 2007)
New Revision: 5826
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5826

Modified:
   3.x/trunk/limb/web_app/src/fetcher/lmbActiveRecordFetcher.class.php
   3.x/trunk/limb/web_app/tests/cases/db/fetcher/lmbActiveRecordFetcherTest.class.php
Log:
-- custom method support for single record retrieval added

Modified: 3.x/trunk/limb/web_app/src/fetcher/lmbActiveRecordFetcher.class.php
===================================================================
--- 3.x/trunk/limb/web_app/src/fetcher/lmbActiveRecordFetcher.class.php	2007-05-07 13:44:40 UTC (rev 5825)
+++ 3.x/trunk/limb/web_app/src/fetcher/lmbActiveRecordFetcher.class.php	2007-05-07 14:07:42 UTC (rev 5826)
@@ -77,9 +77,10 @@
       else
       {
         $method = 'find' . lmb_camel_case($this->find);
-        if(!method_exists($class_name, $method))
+        $callback = array($class_name, $method);
+        if(!is_callable($callback))
          throw new lmbException('Active record of class "'. $class_name . '" does not support method "'. $method . '"');
-        return call_user_func_array(array($class_name, $method), $this->find_params);
+        return call_user_func_array($callback, $this->find_params);
       }
     }
 
@@ -87,7 +88,16 @@
     {
       try
       {
-        $record = lmbActiveRecord :: findById($class_name, $this->record_id);
+        if($this->find)
+        {
+          $method = 'find' . lmb_camel_case($this->find);
+          $callback = array($class_name, $method);
+          if(!is_callable($callback))
+            throw new lmbException('Active record of class "'. $class_name . '" does not support method "'. $method . '"');
+          $record = call_user_func_array($callback, array($this->record_id));
+        }
+        else
+          $record = lmbActiveRecord :: findById($class_name, $this->record_id);
       }
       catch(lmbARNotFoundException $e)
       {

Modified: 3.x/trunk/limb/web_app/tests/cases/db/fetcher/lmbActiveRecordFetcherTest.class.php
===================================================================
--- 3.x/trunk/limb/web_app/tests/cases/db/fetcher/lmbActiveRecordFetcherTest.class.php	2007-05-07 13:44:40 UTC (rev 5825)
+++ 3.x/trunk/limb/web_app/tests/cases/db/fetcher/lmbActiveRecordFetcherTest.class.php	2007-05-07 14:07:42 UTC (rev 5826)
@@ -21,6 +21,11 @@
     return new lmbCollection(array(array('special' => 1)));
   }
 
+  static function findSpecialById($id)
+  {
+    return new lmbSet(array('id' => $id));
+  }
+
   static function findWithParams($param1, $param2)
   {
     return new lmbCollection(array(array('param' => $param1),
@@ -108,7 +113,7 @@
     $this->assertEqual($rs->current()->get('param'), 'Value2');
   }
 
-  function testFetchSingleARIfFetchWithIdNotDefined()
+  function testFetchSingleIfFetchWithIdNotDefined()
   {
     $course1 = $this->_createCourse();
     $course2 = $this->_createCourse();
@@ -126,9 +131,26 @@
     $this->assertFalse($rs->valid());
   }
 
-  function testFetchSingleARReturnsNothongIfNoId()
+  function testFetchSingleWithCustomFinder()
   {
     $course1 = $this->_createCourse();
+
+    $fetcher = new lmbActiveRecordFetcher();
+    $fetcher->setClassPath('CourseForFetcherTestVersion');
+    $fetcher->setFind('special_by_id');
+    $fetcher->setRecordId($course1->getId());
+
+    $rs = $fetcher->fetch();
+    $rs->rewind();
+    $this->assertTrue($rs->valid());
+    $this->assertEqual($rs->current()->get('id'), $course1->getId());
+    $rs->next();
+    $this->assertFalse($rs->valid());
+  }
+
+  function testFetchSingleReturnsNothingIfNoId()
+  {
+    $course1 = $this->_createCourse();
     $course2 = $this->_createCourse();
 
     $fetcher = new lmbActiveRecordFetcher();



More information about the limb-svn mailing list