feed loop is now countable
This commit is contained in:
@@ -37,7 +37,7 @@ class LoopResult implements \Iterator
|
||||
public function __construct($modelCollection = null)
|
||||
{
|
||||
$this->position = 0;
|
||||
if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager) {
|
||||
if ($modelCollection instanceof ObjectCollection || $modelCollection instanceof PropelModelPager || is_array($modelCollection)) {
|
||||
$this->modelCollection = $modelCollection;
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,17 @@ class LoopResult implements \Iterator
|
||||
return count($this->collection);
|
||||
}
|
||||
|
||||
public function getModelCollectionCount()
|
||||
{
|
||||
if ($this->modelCollection instanceof ObjectCollection || $this->modelCollection instanceof PropelModelPager) {
|
||||
return $this->modelCollection->count();
|
||||
} elseif (is_array($this->modelCollection)) {
|
||||
return count($this->modelCollection);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* (PHP 5 >= 5.0.0)<br/>
|
||||
* Return the current element
|
||||
|
||||
@@ -107,7 +107,7 @@ class LoopResultRow
|
||||
}
|
||||
if (true === $this->countable) {
|
||||
$this->set('LOOP_COUNT', 1 + $this->loopResult->getCount());
|
||||
$this->set('LOOP_TOTAL', $this->loopResult->modelCollection->count());
|
||||
$this->set('LOOP_TOTAL', $this->loopResult->getModelCollectionCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +73,14 @@ class Feed extends BaseLoop
|
||||
|
||||
$limit = min(count($items), $this->getLimit());
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
|
||||
$indexes = array();
|
||||
for ($idx = 0; $idx < $limit; $idx++) {
|
||||
$indexes[] = $idx;
|
||||
}
|
||||
|
||||
$loopResult = new LoopResult($indexes);
|
||||
|
||||
foreach ($indexes as $idx) {
|
||||
|
||||
$item = $items[$idx];
|
||||
|
||||
@@ -87,7 +92,7 @@ class Feed extends BaseLoop
|
||||
|
||||
$date = $item->get_date('d/m/Y');
|
||||
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$loopResultRow = new LoopResultRow($loopResult, null, $this->versionable, $this->timestampable, $this->countable);
|
||||
|
||||
$loopResultRow->set("URL", $item->get_permalink());
|
||||
$loopResultRow->set("TITLE", $item->get_title());
|
||||
|
||||
Reference in New Issue
Block a user