... | ... |
@@ -123,7 +123,7 @@ class ManagedPropertyModel extends Model |
123 | 123 |
|
124 | 124 |
if (!isset($arrOptions['order'])) |
125 | 125 |
{ |
126 |
- $arrOptions['order'] = "$t.city ASC, $t.livingSpace ASC"; |
|
126 |
+ $arrOptions['order'] = "$t.city ASC, $t.address ASC"; |
|
127 | 127 |
} |
128 | 128 |
|
129 | 129 |
$arrOptions['limit'] = $intLimit; |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,178 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * OBG Customizations |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2021 vonRotenberg |
|
7 |
+ * |
|
8 |
+ * @license commercial |
|
9 |
+ */ |
|
10 |
+ |
|
11 |
+namespace vonRotenberg\RealEstateListingBundle\Model; |
|
12 |
+ |
|
13 |
+use Contao\Date; |
|
14 |
+use Contao\Model; |
|
15 |
+use Contao\Model\Collection; |
|
16 |
+ |
|
17 |
+/** |
|
18 |
+ * Reads and writes assets |
|
19 |
+ * |
|
20 |
+ * @property string|integer $id |
|
21 |
+ * @property string|integer $tstamp |
|
22 |
+ * @property string $address |
|
23 |
+ * @property string $postal |
|
24 |
+ * @property string $city |
|
25 |
+ * @property string|null $gallerySRC |
|
26 |
+ * @property string|null $orderSRC |
|
27 |
+ * @property string|null $description |
|
28 |
+ * @property string|boolean $published |
|
29 |
+ * @property string|integer $start |
|
30 |
+ * @property string|integer $stop |
|
31 |
+ * |
|
32 |
+ * @method static ManagedPropertyModel|null findById($id, array $opt = array()) |
|
33 |
+ * @method static ManagedPropertyModel|null findByPk($id, array $opt = array()) |
|
34 |
+ * @method static ManagedPropertyModel|null findOneBy($col, $val, array $opt = array()) |
|
35 |
+ * @method static ManagedPropertyModel|null findOneByTstamp($val, array $opt = array()) |
|
36 |
+ * @method static ManagedPropertyModel|null findOneByAddress($val, array $opt = array()) |
|
37 |
+ * @method static ManagedPropertyModel|null findOneByPostal($val, array $opt = array()) |
|
38 |
+ * @method static ManagedPropertyModel|null findOneByCity($val, array $opt = array()) |
|
39 |
+ * @method static ManagedPropertyModel|null findOneByGallerySRC($val, array $opt = array()) |
|
40 |
+ * @method static ManagedPropertyModel|null findOneByDescription($val, array $opt = array()) |
|
41 |
+ * @method static ManagedPropertyModel|null findOneByPublished($val, array $opt = array()) |
|
42 |
+ * @method static ManagedPropertyModel|null findOneByStart($val, array $opt = array()) |
|
43 |
+ * @method static ManagedPropertyModel|null findOneByStop($val, array $opt = array()) |
|
44 |
+ * |
|
45 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByTstamp($val, array $opt = array()) |
|
46 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByAddress($val, array $opt = array()) |
|
47 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByPostal($val, array $opt = array()) |
|
48 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByCity($val, array $opt = array()) |
|
49 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByGallerySRC($val, array $opt = array()) |
|
50 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByDescription($val, array $opt = array()) |
|
51 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByPublished($val, array $opt = array()) |
|
52 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByStart($val, array $opt = array()) |
|
53 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findByStop($val, array $opt = array()) |
|
54 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findMultipleByIds($val, array $opt = array()) |
|
55 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findBy($col, $val, array $opt = array()) |
|
56 |
+ * @method static Collection|ManagedPropertyModel[]|ManagedPropertyModel|null findAll(array $opt = array()) |
|
57 |
+ * |
|
58 |
+ * @method static integer countById($id, array $opt = array()) |
|
59 |
+ * @method static integer countByTstamp($val, array $opt = array()) |
|
60 |
+ * @method static integer countByAddress($val, array $opt = array()) |
|
61 |
+ * @method static integer countByPostal($val, array $opt = array()) |
|
62 |
+ * @method static integer countByCity($val, array $opt = array()) |
|
63 |
+ * @method static integer countByGallerySRC($val, array $opt = array()) |
|
64 |
+ * @method static integer countByDescription($val, array $opt = array()) |
|
65 |
+ * @method static integer countByPublished($val, array $opt = array()) |
|
66 |
+ * @method static integer countByStart($val, array $opt = array()) |
|
67 |
+ * @method static integer countByStop($val, array $opt = array()) |
|
68 |
+ * |
|
69 |
+ * @author Benjamin Roth <https://www.vonrotenberg.de> |
|
70 |
+ */ |
|
71 |
+class ManagedPropertyModel extends Model |
|
72 |
+{ |
|
73 |
+ |
|
74 |
+ /** |
|
75 |
+ * Table name |
|
76 |
+ * @var string |
|
77 |
+ */ |
|
78 |
+ protected static $strTable = 'tl_vr_re_managedProperties'; |
|
79 |
+ |
|
80 |
+ /** |
|
81 |
+ * Find a published assets from one or more categories |
|
82 |
+ * |
|
83 |
+ * @param mixed $varId The numeric id or alias name |
|
84 |
+ * @param array $arrOptions An optional options array |
|
85 |
+ * |
|
86 |
+ * @return ManagedPropertyModel|null A model or null if there is no asset |
|
87 |
+ */ |
|
88 |
+ public static function findPublishedByIdOrAlias($varId, array $arrOptions = array()) |
|
89 |
+ { |
|
90 |
+ $t = static::$strTable; |
|
91 |
+ $arrColumns = !preg_match('/^[1-9]\d*$/', $varId) ? array("BINARY $t.alias=?") : array("$t.id=?"); |
|
92 |
+ |
|
93 |
+ if (!static::isPreviewMode($arrOptions)) |
|
94 |
+ { |
|
95 |
+ $time = Date::floorToMinute(); |
|
96 |
+ $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; |
|
97 |
+ } |
|
98 |
+ |
|
99 |
+ return static::findOneBy($arrColumns, $varId, $arrOptions); |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ /** |
|
103 |
+ * Find a published assets from one or more categories |
|
104 |
+ * |
|
105 |
+ * @param array $arrPids An array of parent IDs |
|
106 |
+ * @param integer $intLimit An optional limit |
|
107 |
+ * @param integer $intOffset An optional offset |
|
108 |
+ * @param array $arrOptions An optional options array |
|
109 |
+ * |
|
110 |
+ * @return Collection|ManagedPropertyModel[]|ManagedPropertyModel|null A collection of models or null if there are no assets |
|
111 |
+ */ |
|
112 |
+ public static function findAllPublished($intLimit = 0, $intOffset = 0, array $arrOptions = array()) |
|
113 |
+ { |
|
114 |
+ $t = static::$strTable; |
|
115 |
+ $arrColumns = []; |
|
116 |
+ $arrValues = []; |
|
117 |
+ |
|
118 |
+ if (!static::isPreviewMode($arrOptions)) |
|
119 |
+ { |
|
120 |
+ $time = Date::floorToMinute(); |
|
121 |
+ $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; |
|
122 |
+ } |
|
123 |
+ |
|
124 |
+ if (!isset($arrOptions['order'])) |
|
125 |
+ { |
|
126 |
+ $arrOptions['order'] = "$t.city ASC, $t.livingSpace ASC"; |
|
127 |
+ } |
|
128 |
+ |
|
129 |
+ $arrOptions['limit'] = $intLimit; |
|
130 |
+ $arrOptions['offset'] = $intOffset; |
|
131 |
+ |
|
132 |
+ if (isset($arrOptions['column'])) |
|
133 |
+ { |
|
134 |
+ $arrColumns = array_merge($arrColumns,array_values($arrOptions['column'])); |
|
135 |
+ unset($arrOptions['column']); |
|
136 |
+ } |
|
137 |
+ if (isset($arrOptions['value'])) |
|
138 |
+ { |
|
139 |
+ $arrValues = array_merge($arrValues,array_values($arrOptions['value'])); |
|
140 |
+ unset($arrOptions['value']); |
|
141 |
+ } |
|
142 |
+ |
|
143 |
+ return static::findBy($arrColumns, $arrValues, $arrOptions); |
|
144 |
+ } |
|
145 |
+ |
|
146 |
+ /** |
|
147 |
+ * Find a published assets from one or more categories |
|
148 |
+ * |
|
149 |
+ * @param array $arrPids An array of parent IDs |
|
150 |
+ * @param array $arrOptions An optional options array |
|
151 |
+ * |
|
152 |
+ * @return integer The number of matching rows |
|
153 |
+ */ |
|
154 |
+ public static function countAllPublished(array $arrOptions = array()) |
|
155 |
+ { |
|
156 |
+ $t = static::$strTable; |
|
157 |
+ $arrColumns = []; |
|
158 |
+ $arrValues = []; |
|
159 |
+ |
|
160 |
+ if (!static::isPreviewMode($arrOptions)) |
|
161 |
+ { |
|
162 |
+ $time = Date::floorToMinute(); |
|
163 |
+ $arrColumns[] = "$t.published='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'$time')"; |
|
164 |
+ } |
|
165 |
+ |
|
166 |
+ if (isset($arrOptions['column'])) |
|
167 |
+ { |
|
168 |
+ $arrColumns = array_merge($arrColumns,array_values($arrOptions['column'])); |
|
169 |
+ unset($arrOptions['column']); |
|
170 |
+ } |
|
171 |
+ if (isset($arrOptions['value'])) |
|
172 |
+ { |
|
173 |
+ $arrValues = array_merge($arrValues,array_values($arrOptions['value'])); |
|
174 |
+ unset($arrOptions['value']); |
|
175 |
+ } |
|
176 |
+ return static::countBy($arrColumns, $arrValues, $arrOptions); |
|
177 |
+ } |
|
178 |
+} |