/* =========================================================================
PAGE 11 — Article (alias: article) Item P11_SLUG, P11_ID
Before Header: :P11_ID := ecp_web.post_page(:P11_SLUG);
========================================================================= */
-- Header Static ID: ecp_article Template: article.html
select p.*, ecp_store.url_blog(p.category_slug) cat_url, ecp_web.post_art(p.id) art_html,
substr(p.author_name, 1, 1) author_initial
from ecp_v_posts p where p.id = :P11_ID and p.company_id = :G_COMPANY_ID and p.branch_id = :G_BRANCH_ID;
-- Body: Dynamic Content region (PL/SQL Function Body returning CLOB)
-- return ecp_web.render_post_body(:P11_ID);
-- Aside "الكتب في هذا المقال" Static ID: ecp_article_products Template: aside-product.html
select c.*, ecp_store.url_product(c.slug) url, ecp_web.cover_html(c.id, 100) cover_html
from ecp_v_catalog c
where c.company_id = :G_COMPANY_ID and c.branch_id = :G_BRANCH_ID
and c.id in (select jt.id from ecp_posts p,
json_table(p.body_json, '$[*]' columns (btype varchar2(10) path '$.type', id number path '$.id')) jt
where p.id = :P11_ID and p.company_id = :G_COMPANY_ID and p.branch_id = :G_BRANCH_ID and jt.btype = 'book');
-- Related posts Static ID: ecp_article_related Template: post-card.html
select p.*, ecp_store.url_post(p.slug) url, ecp_store.url_blog(p.category_slug) cat_url, ecp_web.post_art(p.id) art_html
from ecp_v_posts p
join ecp_posts me on me.id = :P11_ID and me.company_id = p.company_id and me.branch_id = p.branch_id
where p.company_id = :G_COMPANY_ID and p.branch_id = :G_BRANCH_ID and p.status = 'PUBLISHED' and p.id <> me.id
order by case when p.category_id = me.category_id then 0 else 1 end, p.published_at desc
fetch first 3 rows only;