Last active
December 29, 2015 06:29
-
-
Save settermjd/7629509 to your computer and use it in GitHub Desktop.
Rather basic TableGateway class
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
namespace MaltBlue\Model; | |
use Zend\Db\TableGateway\TableGateway; | |
use Zend\Db\Sql\Select; | |
class CountryDebtTable extends QuickSearchTable | |
{ | |
protected $tableGateway; | |
public function __construct(TableGateway $tableGateway) | |
{ | |
$this->tableGateway = $tableGateway; | |
} | |
public function fetchAll() | |
{ | |
$resultSet = $this->tableGateway->select(); | |
return $resultSet; | |
} | |
public function fetchAllByDebtId($eventId) | |
{ | |
$cacheKeySuffix = (is_array($eventId)) ? md5(implode("", $eventId)) : md5($eventId); | |
$cacheKey = sprintf("countrydebt_fetchallbycountryid_%s", $cacheKeySuffix); | |
if ($this->_hasCache()) { | |
if (($resultSet = $this->cache->getItem($cacheKey)) == FALSE) { | |
$resultSet = $this->_doFetchAllByCountryId($eventId); | |
$this->cache->setItem($cacheKey, $resultSet); | |
} | |
} else { | |
$resultSet = $this->_doFetchAllByCountryId($eventId); | |
} | |
return $resultSet; | |
} | |
protected function _doFetchAllByCountryId($eventId) | |
{ | |
$resultSet = $this->tableGateway->select(function (Select $select) use($eventId) { | |
if (is_array($eventId)) { | |
$eventId = array_unique($eventId, SORT_NUMERIC); | |
$select->where->in('CountryID', $eventId); | |
} else { | |
$select->where(array('CountryID' => $eventId)); | |
} | |
$select->order("DebtLevel DESC"); | |
})->toArray(); | |
return $resultSet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment