-
Notifications
You must be signed in to change notification settings - Fork 6
/
Query.php
109 lines (105 loc) · 3.21 KB
/
Query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Created by PhpStorm.
* User: daniil
* Date: 30.06.16
* Time: 12:29
*/
namespace andkon\yii2kladr;
/**
* Класс запроса
*/
class Query
{
/** @var string Тип родительского объекта для ограничения области поиска (регион, район, город) */
public $parentType;
/** @var int Идентификатор родительского объекта */
public $parentId;
/** @var string Тип искомых объектов (регион, район, город) */
public $contentType;
/** @var string Название искомого объекта (частично либо полностью) */
public $contentName;
/** @var int Почтовый индекс */
public $zip;
/** @var string Выполнить поиск по полной записи адреса, одной строкой */
public $oneString;
/** @var string Получить объекты вместе с родителями */
public $withParent;
/** @var string Ограничение количества возвращаемых объектов */
public $limit;
public $regionId;
public $cityId;
public $streetId;
public $buildingId;
/**
* @return string
*/
public function __toString()
{
$string = '';
if ($this->parentType && $this->parentId) {
$string .= $this->parentType . 'Id=' . $this->parentId;
}
if ($this->contentName) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'query=' . urlencode($this->contentName);
}
if ($this->contentType) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'contentType=' . $this->contentType;
}
if ($this->regionId) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'regionId=' . $this->regionId;
}
if ($this->cityId) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'cityId=' . $this->cityId;
}
if ($this->streetId) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'streetId=' . $this->streetId;
}
if ($this->buildingId) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'buildingId=' . $this->buildingId;
}
if ($this->zip) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'zip=' . $this->zip;
}
if ($this->oneString) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'oneString=1';
}
if ($this->withParent) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'withParent=1';
}
if ($this->limit) {
if (!empty($string)) {
$string .= '&';
}
$string .= 'limit=' . $this->limit;
}
return $string;
}
}