... | ... |
@@ -12,25 +12,44 @@ namespace vonRotenberg\RealEstateListingBundle\EventListener; |
12 | 12 |
|
13 | 13 |
use Contao\CoreBundle\ServiceAnnotation\Callback; |
14 | 14 |
use Contao\DataContainer; |
15 |
+use Doctrine\DBAL\Connection; |
|
15 | 16 |
use vonRotenberg\RealEstateListingBundle\Model\ManagedPropertyModel; |
16 | 17 |
|
17 | 18 |
class RealEstateAssetsContainerListener |
18 | 19 |
{ |
19 |
- /** |
|
20 |
- * @Callback(table="tl_vr_real_estate_assets", target="fields.managedPropertyId.options") |
|
21 |
- */ |
|
22 |
- public function onAddCustomRegexp(?DataContainer $dc): array |
|
20 |
+ private $db; |
|
21 |
+ public function __construct(Connection $db) |
|
23 | 22 |
{ |
24 |
- $arrOptions = []; |
|
23 |
+ $this->db = $db; |
|
24 |
+ } |
|
25 |
+ |
|
26 |
+ /** |
|
27 |
+ * @Callback(table="tl_vr_real_estate_assets", target="fields.managedPropertyId.options") |
|
28 |
+ */ |
|
29 |
+ public function onAddCustomRegexp(?DataContainer $dc): array |
|
30 |
+ { |
|
31 |
+ $arrOptions = []; |
|
32 |
+ |
|
33 |
+ if (($Properties = ManagedPropertyModel::findAllPublished()) !== null) |
|
34 |
+ { |
|
35 |
+ foreach ($Properties as $property) |
|
36 |
+ { |
|
37 |
+ $arrOptions[$property->city][$property->id] = $property->address . ' [' . $property->city . ']'; |
|
38 |
+ } |
|
39 |
+ } |
|
25 | 40 |
|
26 |
- if (($Properties = ManagedPropertyModel::findAllPublished()) !== null) |
|
27 |
- { |
|
28 |
- foreach ($Properties as $property) |
|
29 |
- { |
|
30 |
- $arrOptions[$property->city][$property->id] = $property->address . ' [' . $property->city . ']'; |
|
31 |
- } |
|
32 |
- } |
|
41 |
+ return $arrOptions; |
|
42 |
+ } |
|
43 |
+ |
|
44 |
+ /** |
|
45 |
+ * @Callback(table="tl_vr_real_estate_assets", target="config.onsubmit") |
|
46 |
+ */ |
|
47 |
+ public function setCoordinatesToAsset(DataContainer $dc) |
|
48 |
+ { |
|
49 |
+ if (!$dc->id || !$dc->activeRecord->managedPropertyId || ($Property = ManagedPropertyModel::findByPk($dc->activeRecord->managedPropertyId)) === null) { |
|
50 |
+ return; |
|
51 |
+ } |
|
33 | 52 |
|
34 |
- return $arrOptions; |
|
53 |
+ $this->db->update('tl_vr_real_estate_assets', ['geox' => $Property->geox, 'geoy' => $Property->geoy],['id' => $dc->id]); |
|
35 | 54 |
} |
36 | 55 |
} |