Exemple #1
0
 public function getTeamListDetails($offset, $limit, $sortCol, $sortDir, $like, $deactivatedIncluded = '1')
 {
     $oldEntityPrototype = $this->resultSetPrototype->getArrayObjectPrototype();
     $this->resultSetPrototype->setArrayObjectPrototype(new PeopleTeamsTableRow());
     $result = $this->fetchAll(function (Select $select) use($offset, $limit, $sortCol, $sortDir, $like, $deactivatedIncluded) {
         $sortColumns = ['is_disable', 'name', 'description', 'size', 'usage_department', 'usage_notifiable', 'usage_frontier', 'usage_security', 'usage_taskable', 'usage_procurement', 'usage_hiring', 'usage_storage'];
         $select->columns(['id' => 'id', 'is_active' => 'is_disable', 'name' => 'name', 'description' => 'description', 'usage_department' => 'usage_department', 'usage_notifiable' => 'usage_notifiable', 'usage_frontier' => 'usage_frontier', 'usage_security' => 'usage_security', 'usage_taskable' => 'usage_taskable', 'usage_procurement' => 'usage_procurement', 'usage_hiring' => 'usage_hiring', 'usage_storage' => 'usage_storage'])->join(['creator' => DbTables::TBL_TEAM_STAFF], new Expression($this->getTable() . '.id = creator.team_id AND creator.type =' . TeamService::STAFF_CREATOR), [])->join(['staff' => DbTables::TBL_TEAM_STAFF], new Expression($this->getTable() . '.id = staff.team_id AND staff.type !=' . TeamService::STAFF_CREATOR . ' AND staff.type !=' . TeamService::STAFF_DIRECTOR . ' AND staff.user_id !=' . UserService::ANY_TEAM_MEMBER_USER_ID), ['size' => new Expression('COUNT(distinct(staff.user_id))')], Select::JOIN_LEFT);
         switch ($deactivatedIncluded) {
             case '2':
                 $select->where->equalTo($this->getTable() . '.is_disable', 1);
                 // only inactive ones
                 break;
             case '1':
                 $select->where->equalTo($this->getTable() . '.is_disable', 0);
                 // only active ones
                 break;
             case '0':
                 // all
                 break;
         }
         if ($like !== '') {
             $nestedWhere = new Predicate();
             $nestedWhere->like($this->getTable() . '.description', '%' . $like . '%');
             $nestedWhere->or;
             $nestedWhere->like($this->getTable() . '.name', '%' . $like . '%');
             $select->where->andPredicate($nestedWhere);
         }
         $select->group($this->getTable() . '.id')->order($sortColumns[$sortCol] . ' ' . $sortDir)->offset((int) $offset)->limit((int) $limit);
     });
     $this->resultSetPrototype->setArrayObjectPrototype($oldEntityPrototype);
     return $result;
 }
Exemple #2
0
 public function testLikeCreatesLikePredicate()
 {
     $predicate = new Predicate();
     $predicate->like('foo.bar', 'bar%');
     $parts = $predicate->getExpressionData();
     $this->assertEquals(1, count($parts));
     $this->assertContains('%1$s LIKE %2$s', $parts[0]);
     $this->assertContains(array('foo.bar', 'bar%'), $parts[0]);
 }
Exemple #3
0
 /**
  * Prepare filter parameters
  *
  * @param   array|string $binds A bind variable array
  * @param   \Zend\Db\Sql\Predicate\PredicateInterface $predicate
  * @return  Predicate
  */
 public function prepareFilterParams($binds = [], $predicate = null)
 {
     if (null === $predicate) {
         $predicate = new Predicate();
     }
     $fields = $this->getRepository()->fields;
     if (is_array($binds)) {
         foreach ($binds as $v) {
             if (!is_array($v) || empty($v['predicate'])) {
                 continue;
             }
             if (isset($v['nesting']) && (Enums\PredicateType::NEST === $v['nesting'] || Enums\PredicateType::UNNEST === $v['nesting'])) {
                 /* @see \Zend\Db\Sql\Predicate\Predicate::nest
                  * @see \Zend\Db\Sql\Predicate\Predicate::unnest */
                 $predicate = $predicate->{$v['nesting']}();
             }
             if (isset($v['combine']) && (Predicate::OP_OR === $v['combine'] || strtolower(Predicate::OP_OR) === $v['combine'])) {
                 $predicate->or;
             }
             switch ($v['predicate']) {
                 case Enums\PredicateType::BETWEEN:
                 case Enums\PredicateType::NOT_BETWEEN:
                     if (empty($v['identifier']) || !isset($v['minValue']) || !isset($v['maxValue']) || !isset($fields[$v['identifier']])) {
                         continue;
                     }
                     /* @see \Zend\Db\Sql\Predicate\Predicate::between
                      * @see \Zend\Db\Sql\Predicate\Predicate::notBetween */
                     $predicate->{$v['predicate']}($v['identifier'], "'" . $this->filter($v['minValue'], true) . "'", "'" . $this->filter($v['maxValue'], 86399) . "'");
                     break;
                 case Enums\PredicateType::EQUAL_TO:
                 case Enums\PredicateType::NOT_EQUAL_TO:
                 case Enums\PredicateType::GREATER_THAN:
                 case Enums\PredicateType::LESS_THAN:
                 case Enums\PredicateType::GREATER_THAN_OR_EQUAL_TO:
                 case Enums\PredicateType::LESS_THAN_OR_EQUAL_TO:
                 case Enums\PredicateType::EQ:
                 case Enums\PredicateType::NEQ:
                 case Enums\PredicateType::GT:
                 case Enums\PredicateType::LT:
                 case Enums\PredicateType::GTE:
                 case Enums\PredicateType::LTE:
                     if (!isset($v['left']) || !isset($v['right'])) {
                         continue;
                     }
                     if (empty($v['leftType']) || Predicate::TYPE_VALUE !== $v['leftType']) {
                         $v['leftType'] = Predicate::TYPE_IDENTIFIER;
                     }
                     if (empty($v['rightType']) || Predicate::TYPE_IDENTIFIER !== $v['rightType']) {
                         $v['rightType'] = Predicate::TYPE_VALUE;
                     }
                     if ($v['leftType'] == $v['rightType']) {
                         $v['leftType'] = Predicate::TYPE_IDENTIFIER;
                         $v['rightType'] = Predicate::TYPE_VALUE;
                     }
                     if (Predicate::TYPE_IDENTIFIER !== $v['leftType']) {
                         $v['left'] = "'" . $this->filter($v['left'], true) . "'";
                     } elseif (!isset($fields[$v['left']])) {
                         continue;
                     }
                     if (Predicate::TYPE_IDENTIFIER !== $v['rightType']) {
                         $v['right'] = "'" . $this->filter($v['right'], true) . "'";
                     } elseif (!isset($fields[$v['right']])) {
                         continue;
                     }
                     /* @see \Zend\Db\Sql\Predicate\Predicate::equalTo
                      * @see \Zend\Db\Sql\Predicate\Predicate::notEqualTo
                      * @see \Zend\Db\Sql\Predicate\Predicate::lessThan
                      * @see \Zend\Db\Sql\Predicate\Predicate::greaterThan
                      * @see \Zend\Db\Sql\Predicate\Predicate::lessThanOrEqualTo
                      * @see \Zend\Db\Sql\Predicate\Predicate::greaterThanOrEqualTo */
                     $predicate->{$v['predicate']}($v['left'], $v['right'], $v['leftType'], $v['rightType']);
                     break;
                 case Enums\PredicateType::EXPR:
                 case Enums\PredicateType::EXPRESSION:
                     if (empty($v['expression'])) {
                         continue;
                     }
                     if (isset($v['parameters'])) {
                         if (!is_array($v['parameters'])) {
                             $v['parameters'] = [$v['parameters']];
                         }
                         foreach ($v['parameters'] as $key => &$value) {
                             if (!is_scalar($value)) {
                                 unset($v['parameters'][$key]);
                             } elseif (!isset($fields[$value])) {
                                 $value = "'" . str_replace('%', '%%', $this->filter($value)) . "'";
                             }
                         }
                         unset($value);
                         $v['parameters'] = array_values($v['parameters']);
                     }
                     $v['expression'] = str_replace(['&lt;', '&gt;'], ['<', '>'], $this->filter($v['expression']));
                     $predicate->expression($v['expression'], @$v['parameters']);
                     break;
                 case Enums\PredicateType::IN:
                 case Enums\PredicateType::NIN:
                 case Enums\PredicateType::NOT_IN:
                     if (empty($v['identifier']) || empty($v['valueSet']) || !is_array($v['valueSet'])) {
                         continue;
                     }
                     if (is_array($v['identifier'])) {
                         foreach ($v['identifier'] as $key => $value) {
                             if (!isset($fields[$value])) {
                                 unset($v['identifier'][$key]);
                             }
                         }
                         if (empty($v['identifier'])) {
                             continue;
                         }
                         $v['identifier'] = array_values($v['identifier']);
                     } elseif (!isset($fields[$v['identifier']])) {
                         continue;
                     }
                     foreach ($v['valueSet'] as &$value) {
                         $value = "'" . $this->filter($value) . "'";
                     }
                     unset($value);
                     /* @see \Zend\Db\Sql\Predicate\Predicate::in
                      * @see \Zend\Db\Sql\Predicate\Predicate::notIn */
                     $predicate->{$v['predicate']}($v['identifier'], $v['valueSet']);
                     break;
                 case Enums\PredicateType::IS_NOT_NULL:
                 case Enums\PredicateType::IS_NULL:
                     if (empty($v['identifier']) || !isset($fields[$v['identifier']])) {
                         continue;
                     }
                     /* @see \Zend\Db\Sql\Predicate\Predicate::isNull
                      * @see \Zend\Db\Sql\Predicate\Predicate::isNotNull */
                     $predicate->{$v['predicate']}($v['identifier']);
                     break;
                 case Enums\PredicateType::LIKE:
                 case Enums\PredicateType::NOT_LIKE:
                     if (empty($v['identifier']) || empty($v[$v['predicate']]) || !isset($fields[$v['identifier']]) || !is_string($v[$v['predicate']])) {
                         continue;
                     }
                     $v[$v['predicate']] = "'%" . str_replace('%', '%%', $this->filter($v[$v['predicate']])) . "%'";
                     /* @see \Zend\Db\Sql\Predicate\Predicate::like
                      * @see \Zend\Db\Sql\Predicate\Predicate::notLike */
                     $predicate->{$v['predicate']}($v['identifier'], $v[$v['predicate']]);
                     break;
                 case Predicate::TYPE_LITERAL:
                     if (empty($v['literal']) || !is_string($v['literal'])) {
                         continue;
                     }
                     $predicate->literal(str_replace(['&lt;', '&gt;', '&#39;', '&#039;'], ['<', '>', "'", "'"], $this->filter($v['literal'])));
                     break;
                 default:
             }
         }
     } elseif (is_string($binds)) {
         $predicateSet = new Predicate();
         $searchable = $this->getConfig()->get('app.minSearchChars') <= strlen($binds);
         $binds = $this->filter($binds);
         $equalValue = "'" . $binds . "'";
         $likeValue = "'%" . str_replace('%', '%%', $binds) . "%'";
         $count = 0;
         foreach ($fields as $k => $v) {
             if ((Types\Type::STRING_TYPE === $v['type'] || Types\Type::TEXT_TYPE === $v['type']) && ($searchable || ($isChar = isset($v['options']) && isset($v['options']['fixed'])))) {
                 $predicateSet->or;
                 isset($isChar) && $isChar ? $predicateSet->equalTo($k, $equalValue) : $predicateSet->like($k, $likeValue);
                 if (CHAOS_MAX_QUERY <= ++$count) {
                     break;
                 }
             }
         }
         if (0 !== count($predicateSet)) {
             $predicate->predicate($predicateSet);
         }
     }
     return $predicate;
 }
Exemple #4
0
 public function getTranslationListForSearch($filterParams = array())
 {
     $where = new Where();
     if ((int) $filterParams["id_translation"] > 0) {
         $where->equalTo($this->getTable() . '.id', $filterParams["id_translation"]);
     } else {
         if ($filterParams["srch_txt"] != '') {
             $pred = new Predicate();
             $pred->like($this->getTable() . '.name', '%' . strip_tags(trim($filterParams["srch_txt"])) . '%')->or->like($this->getTable() . '.information_text_html_clean', '%' . strip_tags(trim($filterParams["srch_txt"])) . '%');
             $where->addPredicate($pred);
         }
     }
     $columns = ['id' => 'id', 'tx_2' => 'information_text', 'name' => 'name', 'name_en' => 'name'];
     $sortColumns = ['id', 'information_text', 'name_en'];
     $result = $this->fetchAll(function (Select $select) use($columns, $sortColumns, $where) {
         $select->columns($columns);
         $select->join(DbTables::TBL_COUNTRIES, $this->getTable() . '.id = ' . DbTables::TBL_COUNTRIES . '.detail_id', array('country' => 'id'), 'left');
         $select->join(DbTables::TBL_PROVINCES, $this->getTable() . '.id = ' . DbTables::TBL_PROVINCES . '.detail_id', array('provinces' => 'id'), 'left');
         $select->join(DbTables::TBL_CITIES, $this->getTable() . '.id = ' . DbTables::TBL_CITIES . '.detail_id', array('city' => 'id'), 'left');
         $select->join(DbTables::TBL_POI, $this->getTable() . '.id = ' . DbTables::TBL_POI . '.detail_id', array('poi' => 'id'), 'left');
         if ($where !== null) {
             $select->where($where);
         }
         $select->group($this->getTable() . '.id');
     });
     $count = $this->getCount($where);
     return ['result' => $result, 'count' => $count];
 }
Exemple #5
0
 public function constructWhereFromFilterParams($filterParams, $download = false)
 {
     /* @var $auth \Library\Authentication\BackofficeAuthenticationService */
     $auth = $this->getServiceLocator()->get('library_backoffice_auth');
     $where = new Where();
     $table = DbTables::TBL_BOOKINGS;
     if (isset($filterParams["res_number"]) && $filterParams["res_number"] != '') {
         $where->like($table . '.res_number', '%' . $filterParams["res_number"] . '%');
     }
     if (isset($filterParams["rooms_count"])) {
         $apartmentTableName = $download ? DbTables::TBL_APARTMENTS : 'apartments';
         $roomsCount = $filterParams["rooms_count"] - 1;
         if ($roomsCount >= 0) {
             if ($roomsCount == 2) {
                 $where->greaterThanOrEqualTo($apartmentTableName . '.bedroom_count', $roomsCount);
             } else {
                 $where->equalTo($apartmentTableName . '.bedroom_count', $roomsCount);
             }
         }
     }
     if (isset($filterParams["status"]) && $filterParams["status"]) {
         if ($filterParams["status"] == Constants::NOT_BOOKED_STATUS) {
             $where->notEqualTo($table . '.status', Booking::BOOKING_STATUS_BOOKED);
         } else {
             $where->equalTo($table . '.status', $filterParams["status"]);
         }
     }
     if (isset($filterParams["arrival_status"]) && $filterParams['arrival_status'] != -1) {
         $where->equalTo($table . '.arrival_status', $filterParams["arrival_status"]);
     }
     if (isset($filterParams["overbooking_status"]) && $filterParams["overbooking_status"] != -1) {
         $where->equalTo($table . '.overbooking_status', $filterParams["overbooking_status"]);
     }
     if (isset($filterParams["apartel_id"]) && $filterParams["apartel_id"] != -2) {
         $where->equalTo($table . '.apartel_id', $filterParams["apartel_id"]);
     }
     if (isset($filterParams["product_id"]) && isset($filterParams["product"]) && $filterParams["product_id"] != '' && $filterParams["product"] != '') {
         $where->equalTo($table . '.apartment_id_origin', $filterParams["product_id"]);
     }
     if (isset($filterParams["assigned_product_id"]) && isset($filterParams["assigned_product"]) && $filterParams["assigned_product_id"] != '' && $filterParams["assigned_product"] != '') {
         $where->equalTo($table . '.apartment_id_assigned', $filterParams["assigned_product_id"]);
     }
     if (isset($filterParams["booking_date"]) && $filterParams["booking_date"] != '') {
         $dates = explode(' - ', $filterParams["booking_date"]);
         $startDate = $dates[0];
         $endDate = $dates[1];
         $where->expression('DATE(' . $table . '.timestamp) >= \'' . $startDate . '\'', []);
         $where->expression('DATE(' . $table . '.timestamp) <= \'' . $endDate . '\'', []);
     }
     if (isset($filterParams["arrival_date"]) && $filterParams["arrival_date"] != '') {
         $dates = explode(' - ', $filterParams["arrival_date"]);
         $startDate = $dates[0];
         $endDate = $dates[1];
         $where->lessThanOrEqualTo($table . ".date_from", $endDate);
         $where->greaterThanOrEqualTo($table . ".date_from", $startDate);
     }
     if (isset($filterParams["departure_date"]) && $filterParams["departure_date"] != '') {
         $dates = explode(' - ', $filterParams["departure_date"]);
         $startDate = $dates[0];
         $endDate = $dates[1];
         $where->lessThanOrEqualTo($table . ".date_to", $endDate);
         $where->greaterThanOrEqualTo($table . ".date_to", $startDate);
     }
     if (isset($filterParams["guest_first_name"]) && $filterParams["guest_first_name"] != '') {
         $where->like($table . '.guest_first_name', '%' . $filterParams["guest_first_name"] . '%');
     }
     if (isset($filterParams["guest_last_name"]) && $filterParams["guest_last_name"] != '') {
         $where->like($table . '.guest_last_name', '%' . $filterParams["guest_last_name"] . '%');
     }
     if (isset($filterParams["guest_phone"]) && $filterParams["guest_phone"] != '') {
         $nestedWhere = new Predicate();
         $nestedWhere->like($table . '.guest_phone', '%' . $filterParams["guest_phone"] . '%');
         $nestedWhere->OR;
         $nestedWhere->like($table . '.guest_travel_phone', '%' . $filterParams["guest_phone"] . '%');
         $where->addPredicate($nestedWhere);
     }
     if (isset($filterParams["guest_email"]) && $filterParams["guest_email"] != '') {
         $where->like($table . '.guest_email', '%' . $filterParams["guest_email"] . '%');
     }
     if (isset($filterParams["guest_secondary_email"]) && $filterParams["guest_secondary_email"] != '') {
         $where->like($table . '.secondary_email', '%' . $filterParams["guest_secondary_email"] . '%');
     }
     if (isset($filterParams["guest_country_id"]) && $filterParams["guest_country_id"] != '' && $filterParams["guest_country"] != '') {
         $where->equalTo($table . '.guest_country_id', $filterParams["guest_country_id"]);
     }
     if (isset($filterParams["apt_location_id"]) && $filterParams["apt_location_id"] != '') {
         $nestedWhere = new Predicate();
         $nestedWhere->equalTo($table . '.acc_country_id', $filterParams["apt_location_id"]);
         $nestedWhere->OR;
         $nestedWhere->equalTo($table . '.acc_city_id', $filterParams["apt_location_id"]);
         $where->addPredicate($nestedWhere);
     }
     if (isset($filterParams["partner_id"]) && $filterParams["partner_id"] != '0') {
         $where->equalTo($table . '.partner_id', $filterParams["partner_id"]);
     }
     if (isset($filterParams["partner_reference"]) && $filterParams["partner_reference"] != '') {
         $where->like($table . '.partner_ref', '%' . $filterParams["partner_reference"] . '%');
     }
     if (isset($filterParams["payment_model"]) && $filterParams["payment_model"] != '0') {
         $where->equalTo($table . '.model', $filterParams["payment_model"]);
     }
     if (!$auth->hasRole(Roles::ROLE_DEVELOPMENT_TESTING)) {
         $where->expression($table . '.apartment_id_assigned NOT IN(' . Constants::TEST_APARTMENT_1 . ', ' . Constants::TEST_APARTMENT_2 . ')', []);
     }
     if (isset($filterParams["no_collection"]) && $filterParams["no_collection"] > 1) {
         $where->equalTo($table . '.no_collection', $filterParams["no_collection"] == 2 ? 1 : 0);
     }
     if (isset($filterParams["channel_res_id"]) && $filterParams["channel_res_id"]) {
         $where->equalTo($table . '.channel_res_id', $filterParams["channel_res_id"]);
     }
     return $where;
 }