Last active
August 29, 2015 14:02
-
-
Save mockiemockiz/7d4cfa95fcadc9489524 to your computer and use it in GitHub Desktop.
model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$paginator = $this->getPropertyTable()->exploreProperty($cond); | |
$paginator->setCurrentPageNumber((int)$this->params()->fromQuery('page', 1)); | |
$paginator->setItemCountPerPage(2); | |
return array('paginator' => $paginator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function exploreProperty($cond) | |
{ | |
$select = new Select(); | |
$select->from($this->tableName)->columns(array( | |
'id', | |
'title', | |
'price', | |
'period', | |
'wideLand', | |
'wideBuilding', | |
'insertDate', | |
'status', | |
'type', | |
'purpose', | |
'floor', | |
'bathroom', | |
'bedroom', | |
'userId', | |
'longitude', | |
'latitude' | |
)); | |
$select->join( | |
'property_image', | |
"property_property.id = property_image.propertyId", | |
array('path'), | |
$select::JOIN_INNER | |
); | |
$select->join( | |
'intl_city', | |
"property_property.city = intl_city.ID", | |
array('name'), | |
$select::JOIN_INNER | |
); | |
if ($cond) { | |
$spec = function (Where $where, $combination = Predicate::COMBINED_BY_AND) use ($cond) { | |
if (isset($cond['greaterThan'])) { | |
foreach ($cond['greaterThan'] as $k => $c) { | |
$where->greaterThan('property_property.'.$k, (int)$c); | |
} | |
} | |
if (isset($cond['lessThanOrEqualTo'])) { | |
foreach ($cond['lessThanOrEqualTo'] as $k => $c) { | |
$where->lessThanOrEqualTo('property_property.'.$k, (int)$c); | |
} | |
} | |
if (isset($cond['like'])) { | |
foreach ($cond['like'] as $k => $c) { | |
$where->like('property_property.'.$k, '%' . $c . '%'); | |
} | |
} | |
if (isset($cond['equal'])) { | |
foreach ($cond['equal'] as $k => $c) { | |
$where->equalTo('property_property.'.$k, $c); | |
} | |
} | |
}; | |
$select->where($spec); | |
} | |
$select->group(array('id')); | |
$select->order(array('insertDate' => 'DESC')); | |
// create a new result set based on the Album entity | |
$resultSetPrototype = new ResultSet(); | |
// $resultSetPrototype->setArrayObjectPrototype(new PropertyBaseInputFilter()); | |
// create a new pagination adapter object | |
$paginatorAdapter = new DbSelect( | |
// our configured select object | |
$select, | |
// the adapter to run it against | |
$this->adapter, | |
// the result set to hydrate | |
$resultSetPrototype | |
); | |
$paginator = new Paginator($paginatorAdapter); | |
// $paginator->setCache($this->fileSystem); | |
return $paginator; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT THIS TO Application/view/partial/paginator.phtml | |
<?php if ($this->pageCount): ?> | |
<?php | |
if(isset($_GET)) | |
{ | |
unset($_GET['page']); | |
$where=''; | |
foreach($_GET as $key => $g) | |
{ | |
$where .= '&'.$key.'='.$g; | |
} | |
} | |
?> | |
<div class="pagination pagination-centered"> | |
<ul class="pagination" id="pagination"> | |
<!-- Previous page link --> | |
<?php if (isset($this->previous)): ?> | |
<li> | |
<a href="<?php echo $link; ?>?page=<?php echo $this->previous.$where; ?>" class="next-prev"> | |
<< | |
</a> | |
</li> | |
<?php else: ?> | |
<li class="disabled"> | |
<a href="#" class="next-prev"> | |
<< | |
</a> | |
</li> | |
<?php endif; ?> | |
<!-- Numbered page links --> | |
<?php foreach ($this->pagesInRange as $page): ?> | |
<?php if ($page != $this->current): ?> | |
<li> | |
<a href="<?php echo $link; ?>?page=<?php echo $page.$where; ?>"> | |
<?php echo $page; ?> | |
</a> | |
</li> | |
<?php else: ?> | |
<li class="active"> | |
<a href="#"><?php echo $page; ?></a> | |
</li> | |
<?php endif; ?> | |
<?php endforeach; ?> | |
<!-- Next page link --> | |
<?php if (isset($this->next)): ?> | |
<li> | |
<a href="<?php echo $link; ?>?page=<?php echo $this->next.$where; ?>" class="next-prev next"> | |
>> | |
</a> | |
</li> | |
<?php else: ?> | |
<li class="disabled"> | |
<a href="#" class="next-prev"> | |
>> | |
</a> | |
</li> | |
<?php endif; ?> | |
</ul> | |
</div> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add at the end of the file after the table | |
echo $this->paginationControl( | |
// the paginator object | |
$paginator, | |
// the scrolling style | |
'sliding', | |
// the partial to use to render the control | |
array('partial/paginator.phtml'), // see paginator.phtml (application/view/partial) | |
// the route to link to when a user clicks a control link | |
array( | |
'route' => 'realestate/default', | |
'controller' => 'realestateproperty', | |
'action' => 'test', | |
'link' => $this->propertyHelper()->exploreUrl(array('typeId' => $typeId)), | |
) | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment