[limb-svn] r7038 - in 3.x/trunk/limb/macro: src/tags/pager tests/cases/tags/pager
svn at limb-project.com
svn at limb-project.com
Thu May 22 18:10:59 MSD 2008
Author: serega
Date: 2008-05-22 18:10:59 +0400 (Thu, 22 May 2008)
New Revision: 7038
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7038
Modified:
3.x/trunk/limb/macro/src/tags/pager/paginate.tag.php
3.x/trunk/limb/macro/tests/cases/tags/pager/lmbMacroPaginateTagTest.class.php
Log:
-- {{paginate}} tag now supports "total_items" attribute. The value of this attribute will be used instead of $iterator->getCount();
Modified: 3.x/trunk/limb/macro/src/tags/pager/paginate.tag.php
===================================================================
--- 3.x/trunk/limb/macro/src/tags/pager/paginate.tag.php 2008-05-22 09:52:05 UTC (rev 7037)
+++ 3.x/trunk/limb/macro/src/tags/pager/paginate.tag.php 2008-05-22 14:10:59 UTC (rev 7038)
@@ -30,8 +30,18 @@
if($this->has('limit'))
$code->writePhp("{$pager}->setItemsPerPage({$this->get('limit')});\n");
+
+ if($this->has('total_items'))
+ {
+ $total_items_var = $code->generateVar();
+ $code->writePhp("{$total_items_var} = " . $this->get('total_items') .";");
+ $code->writePhp("if ({$total_items_var}) {$pager}->setTotalItems({$total_items_var});\n");
+ }
+ else
+ {
+ $code->writePhp("{$pager}->setTotalItems({$iterator}->count());\n");
+ }
- $code->writePhp("{$pager}->setTotalItems({$iterator}->count());\n");
$code->writePhp("{$pager}->prepare();\n");
$offset = $code->generateVar();
$code->writePhp("{$offset} = {$pager}->getCurrentPageBeginItem();\n");
Modified: 3.x/trunk/limb/macro/tests/cases/tags/pager/lmbMacroPaginateTagTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/tags/pager/lmbMacroPaginateTagTest.class.php 2008-05-22 09:52:05 UTC (rev 7037)
+++ 3.x/trunk/limb/macro/tests/cases/tags/pager/lmbMacroPaginateTagTest.class.php 2008-05-22 14:10:59 UTC (rev 7038)
@@ -103,5 +103,20 @@
$expected = 'BobToddSerega';
$this->assertEqual($page->render(), $expected);
}
+
+ function testPaginateWithPager_TotalItemsByAttribute()
+ {
+ $template = '{{paginate iterator="$#test_iterator" pager="test_pager" total_items="2"/}}'.
+ '{{list using="$#test_iterator" as="$item"}}{{list:item}}{$item}{{/list:item}}{{/list}}'.
+ '{{pager id="test_pager" items="2"/}}';
+
+ $_GET['test_pager'] = 2; // offset = 2 since the second page
+
+ $page = $this->_createMacroTemplate($template, 'tpl.html');
+ $page->set('test_iterator', new lmbArrayIterator(array('Ivan', 'Pavel', 'Mike', 'Bob', 'Todd')));
+
+ $expected = 'IvanPavel'; // since forced to know about only 2 elements in array
+ $this->assertEqual($page->render(), $expected);
+ }
}
More information about the limb-svn
mailing list