Skip to content

Instantly share code, notes, and snippets.

@settermjd
Last active December 29, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save settermjd/7629509 to your computer and use it in GitHub Desktop.
Save settermjd/7629509 to your computer and use it in GitHub Desktop.
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