postgresql7.1
select
e.element_id,
e.name,
e.description,
case when e.exportable_p = 't' then 1 else 0 end as exportable_p,
case when d.configurable_p = 't' then 1 else 0 end as configurable_p,
case when acs_permission__permission_p(e.element_id, :user_id, 'write') = 't' then 1 else 0 end as write_p,
case when m.portal_id = e.controlling_portal_id then 1 else 0 end as local_p
from portal_elements e, portal_available_element_map m, portal_datasources d
where
m.portal_id = :default_portal_id and
m.element_id = e.element_id and
e.datasource_id = d.datasource_id