Skip to content

Commit

Permalink
modify sql view to display signages states
Browse files Browse the repository at this point in the history
  • Loading branch information
juggler31 committed Nov 22, 2023
1 parent c66cefc commit 23b5809
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions geotrek/signage/templates/signage/sql/post_10_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CREATE VIEW {{ schema_geotrek }}.v_signages AS WITH v_signage_tmp AS
t.code,
t.printed_elevation,
t.manager_id,
{% comment %} t.condition_id, {% endcomment %}
p.labels AS "Condition",
t.sealing_id,
t.access_id,
Expand All @@ -29,13 +28,16 @@ CREATE VIEW {{ schema_geotrek }}.v_signages AS WITH v_signage_tmp AS
FROM signage_signage t
left join core_topology e on t.topo_object_id = e.id
left join signage_signagetype b on t.type_id = b.id
-- FROM signage_signage t,
-- signage_signagetype b,
-- core_topology e
LEFT JOIN
(SELECT a.signagecondition_id, b.label AS labels, a.signage_id
FROM signage_signagecondition b
JOIN signage_signage_conditions a ON a.signagecondition_id = b.id) p
(with signage_condition as
( SELECT a.signagecondition_id,
b.label AS labels,
a.signage_id
FROM signage_signagecondition b
JOIN signage_signage_conditions a ON a.signagecondition_id = b.id)
select array_to_string(ARRAY_AGG (labels), ', ', '_')::varchar as labels, signage_id
from signage_condition
group by signage_id) p
ON t.topo_object_id = p.signage_id
WHERE e.deleted = FALSE )
SELECT a.id,
Expand All @@ -47,7 +49,7 @@ SELECT a.id,
{% endfor %}
a.code AS "Code",
b.label AS "Type",
-- c.label AS "State",
c.labels AS "State",
{% for lang in MODELTRANSLATION_LANGUAGES %}
a.description_{{ lang }} AS "Description {{ lang }}",
{% endfor %}
Expand All @@ -70,11 +72,16 @@ SELECT a.id,
a.geom
FROM v_signage_tmp a
LEFT JOIN signage_signagetype b ON a.type_id = b.id
LEFT JOIN (SELECT a.signagecondition_id, b.label AS labels, a.signage_id
FROM signage_signagecondition b
JOIN signage_signage_conditions a ON a.signagecondition_id = b.id) c
LEFT JOIN (with signage_condition as
( SELECT a.signagecondition_id,
b.label AS labels,
a.signage_id
FROM signage_signagecondition b
JOIN signage_signage_conditions a ON a.signagecondition_id = b.id)
select array_to_string(ARRAY_AGG (labels), ', ', '_')::varchar as labels, signage_id
from signage_condition
group by signage_id) c
ON a.id = c.signage_id
-- LEFT JOIN infrastructure_infrastructurecondition c ON a.condition_id = c.id
LEFT JOIN signage_sealing d ON a.sealing_id = d.id
LEFT JOIN authent_structure e ON a.structure_id = e.id
LEFT JOIN infrastructure_infrastructureaccessmean i ON a.access_id = i.id
Expand Down

0 comments on commit 23b5809

Please sign in to comment.