Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rather basic TableGateway class
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
You can’t perform that action at this time.