-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.sql
More file actions
44 lines (44 loc) · 2.26 KB
/
context.sql
File metadata and controls
44 lines (44 loc) · 2.26 KB
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
SELECT jsonb_build_object(
'dataset_name', (SELECT slug FROM projects WHERE id = ?) || '-' || substring(md5(random()::text) from 1 for 10),
'skill_titles', (
SELECT jsonb_object_agg(r.resource_id::text, r.title)
FROM published_resources pr
JOIN publications pub ON pub.id = pr.publication_id
JOIN projects p ON p.id = pub.project_id
JOIN revisions r ON r.id = pr.revision_id
WHERE p.id = ? AND pub.published IS NULL AND r.resource_type_id = 4
),
'hierarchy', (
SELECT jsonb_object_agg(r.resource_id::text, jsonb_build_object(
'title', r.title,
'graded', r.graded,
'children', r.children
))
FROM published_resources pr
JOIN publications pub ON pub.id = pr.publication_id
JOIN projects p ON p.id = pub.project_id
JOIN revisions r ON r.id = pr.revision_id
WHERE p.id = ? AND pub.published IS NULL AND (r.resource_type_id = 1 OR r.resource_type_id = 2)
),
'activities', (
SELECT jsonb_object_agg(r.resource_id::text, jsonb_build_object(
'choices', r.content->'choices',
'type', a.slug,
'parts', (
SELECT jsonb_agg(
jsonb_build_object(
'id', part->>'id',
'hints', part->'hints'
)
)
FROM jsonb_array_elements(r.content->'authoring'->'parts') AS part
)
))
FROM published_resources pr
JOIN publications pub ON pub.id = pr.publication_id
JOIN projects p ON p.id = pub.project_id
JOIN revisions r ON r.id = pr.revision_id
JOIN activity_registrations a ON a.id = r.activity_type_id
WHERE p.id = ? AND pub.published IS NULL AND r.resource_type_id = 3
)
) AS result;