public function testGreaterThanOrEqualToCreatesOperatorPredicate() { $predicate = new Predicate(); $predicate->greaterThanOrEqualTo('foo.bar', 'bar'); $parts = $predicate->getExpressionData(); $this->assertEquals(1, count($parts)); $this->assertContains('%s >= %s', $parts[0]); $this->assertContains(array('foo.bar', 'bar'), $parts[0]); }
/** * Delete node * * @param integer $leftKey * @param integer $rightKey * @param array $filter * @param boolean $useTransaction * @return boolean|string */ public function deleteNode($leftKey, $rightKey, array $filter = [], $useTransaction = true) { try { if ($useTransaction) { $this->tableGateway->getAdapter()->getDriver()->getConnection()->beginTransaction(); } $predicate = new Predicate(); $this->tableGateway->delete([$predicate->greaterThanOrEqualTo($this->left, $leftKey), $predicate->lessThanOrEqualTo($this->right, $rightKey)] + $filter); $predicate = new Predicate(); $this->tableGateway->update([$this->left => new Expression('IF(' . $this->left . ' > ?, ' . $this->left . ' - (? - ? + 1), ' . $this->left . ')', [$leftKey, $rightKey, $leftKey]), $this->right => new Expression($this->right . ' - (? - ? + 1)', [$rightKey, $leftKey])], [$predicate->greaterThan($this->right, $rightKey)] + $filter); if ($useTransaction) { $this->tableGateway->getAdapter()->getDriver()->getConnection()->commit(); } } catch (Exception $e) { if ($useTransaction) { $this->tableGateway->getAdapter()->getDriver()->getConnection()->rollback(); } ErrorLogger::log($e); return $e->getMessage(); } return true; }
public function getReservationForAccOnDate($apartment_id, $start_date, $end_date) { return $this->fetchAll(function (Select $select) use($apartment_id, $start_date, $end_date) { $select->columns(['date_from', 'date_to']); $where = new Where(); $where->equalTo('apartment_id_assigned', $apartment_id)->equalTo('status', 1); $fromPredicate = new Predicate(); $fromPredicate->greaterThanOrEqualTo('date_from', $start_date)->lessThanOrEqualTo('date_from', $end_date); $toPredicate = new Predicate(); $toPredicate->greaterThanOrEqualTo('date_to', $start_date)->lessThanOrEqualTo('date_to', $end_date); $fromToPredicate = new PredicateSet([$fromPredicate, $toPredicate], PredicateSet::COMBINED_BY_OR); $where->addPredicate($fromToPredicate); $select->where($where); }); }