use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGatewayInterface;
use Zend\Db\Sql\Sql;
+use Zend\Db\Sql\Where;
+use Zend\Db\Sql\Select;
use Custom\Model\Entity;
}
- public function select($where = null)
+ public function select($where = null, $order = null, $limit = null, $offset = null)
{
$select = $this->sql->select()
- ->columns(array('name', 'description'))
+ ->columns(array('id', 'name', 'description'))
->join('user', 'gallery.id_user = user.id', array(
'username' => new \Zend\Db\Sql\Expression("user.firstname || ' ' || user.lastname")
))
->join('photo', 'gallery.id = photo.id_gallery', array(
'nb' => new \Zend\Db\Sql\Expression('count(photo.id)')
- ))
+ ), Select::JOIN_LEFT)
->group(array(
'user.lastname',
'user.firstname',
if ($where) {
$select->where($where);
}
+ if ($order) {
+ $select->order($order);
+ }
+ if ($limit) {
+ $select->limit($limit);
+ }
+ if ($offset) {
+ $select->offset($offset);
+ }
// prepare and execute
$statement = $this->sql->prepareStatementForSqlObject($select);
throw new \Exception('delete is not allowed');
}
+ public function all()
+ {
+ return $this->select();
+ }
+
+ public function one($id)
+ {
+ if ($id === null) {
+ $row = null;
+ } else {
+ $row = $this->select(array('gallery.id' => (int) $id))->current();
+ }
+ if (!$row) {
+ throw new \Exception("cannot get row {id: {$id}} in table 'galerie'");
+ }
+ return $row;
+ }
+
+ public function any($id)
+ {
+ if ($id === null) {
+ $row = null;
+ } else {
+ $row = $this->select(array('gallery.id' => (int) $id))->current();
+ }
+ return $row;
+ }
+
+ public function all_by_user($id_user)
+ {
+ return $this->select(array('gallery.id_user' => (int) $id_user));
+ }
+
+
+
+
+ public function count_all()
+ {
+ $select = $this->sql->select()->columns(array(
+ 'nb' => new \Zend\Db\Sql\Expression('count(gallery.id)')
+ ));
+
+ // prepare and execute
+ $statement = $this->sql->prepareStatementForSqlObject($select);
+ $result = $statement->execute()->current();
+
+ return $result['nb'];
+ }
+
+ public function getPartial($start, $length, $tri, $senstri, $filtre)
+ {
+ $where = new Where;
+ $where->like('gallery.name', "%{$filtre}%");
+ $where->or;
+ $where->like('gallery.description', "%{$filtre}%");
+
+ return $this->select($where, "{$tri} {$senstri}", $length, $start);
+ }
+
+
+ public function csvHeader()
+ {
+ return "Id;Nom;Description;Propriétaire;Nombre";
+ }
+
+
}