Beispiel #1
0
 public function testGreaterThanCreatesOperatorPredicate()
 {
     $predicate = new Predicate();
     $predicate->greaterThan('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;
 }
Beispiel #3
0
 /**
  * @param bool $reservationId
  * @return array|\DDD\Domain\Booking\FirstCharge|null|ResultSet
  */
 public function getForCharge($reservationId = false)
 {
     $this->resultSetPrototype->setArrayObjectPrototype(new \DDD\Domain\Booking\FirstCharge());
     $result = $this->fetchAll(function (Select $select) use($reservationId) {
         $select->columns(['id', 'res_number', 'guest_currency_code', 'apartment_currency_code', 'price', 'currency_rate', 'is_refundable', 'refundable_before_hours', 'date_from', 'date_to', 'penalty_fixed_amount', 'model', 'apartment_id_assigned', 'partner_commission', 'rate_capacity' => 'man_count', 'occupancy', 'guest_email', 'partner_id', 'partner_ref', 'channel_name', 'nights' => new Expression('datediff(date_to, date_from)')]);
         $select->join(['city' => DbTables::TBL_CITIES], $this->getTable() . '.acc_city_id = city.id', [], Select::JOIN_LEFT)->join(['location_detail' => DbTables::TBL_LOCATION_DETAILS], 'city.detail_id = location_detail.id', ['tot', 'tot_type', 'tot_included', 'tot_additional', 'tot_max_duration', 'vat', 'vat_type', 'vat_included', 'vat_additional', 'vat_max_duration', 'sales_tax', 'sales_tax_type', 'sales_tax_included', 'sales_tax_additional', 'sales_tax_max_duration', 'city_tax', 'city_tax_type', 'city_tax_included', 'city_tax_additional', 'city_tax_max_duration'], Select::JOIN_LEFT)->join(['charge' => DbTables::TBL_CHARGE], $this->getTable() . '.id = charge.reservation_id', ['addons_type'], Select::JOIN_LEFT)->join(['logs' => DbTables::TBL_ACTION_LOGS], new Expression($this->getTable() . '.id = logs.identity_id AND logs.user_id = ' . UserService::USER_GUEST), ['remarks' => 'value'], Select::JOIN_LEFT);
         $select->join(['country' => DbTables::TBL_COUNTRIES], $this->getTable() . '.acc_country_id = country.id', [], Select::JOIN_LEFT);
         $select->join(['country_currency_tbl' => DbTables::TBL_CURRENCY], 'country.currency_id = country_currency_tbl.id', ['country_currecny' => 'code'], Select::JOIN_LEFT);
         if ($reservationId) {
             $select->where->equalTo($this->getTable() . '.id', $reservationId);
         } else {
             $where = new Where();
             $where->notEqualTo($this->getTable() . '.check_charged', 1)->equalTo($this->getTable() . '.status', BookingService::BOOKING_STATUS_BOOKED)->isNull('charge.addons_type')->expression('(' . $this->getTable() . '.is_refundable = 2 or ' . $this->getTable() . '.refundable_before_hours >= TIMESTAMPDIFF(HOUR, NOW(), ' . $this->table . '.date_from))', array());
             $apartelChannelResPredicate = new Predicate();
             $apartelChannelResPredicate->greaterThan($this->getTable() . '.apartel_id', 0)->greaterThan($this->getTable() . '.channel_res_id', 0);
             $apartelChargePredicate = new Predicate();
             $apartelChargePredicate->addPredicate($apartelChannelResPredicate);
             $apartelChargePredicate->or->equalTo($this->getTable() . '.apartel_id', 0);
             $where->addPredicate($apartelChargePredicate);
             $select->where($where);
         }
     });
     if ($reservationId && $result->count()) {
         return $result->current();
     }
     return $result;
 }