-- 
-- 
-- 
-- @author Jade Rubick (SAFE Dev) (jade-safe4all-dev@safe4all.org)
-- @creation-date 2004-10-05
-- @arch-tag: 442eb06b-a32b-4dd6-a15b-07f74e80acae
-- @cvs-id $Id: upgrade-1.5-1.6.sql,v 1.1.2.1 2004/10/05 19:08:40 jader Exp $
--

create or replace function rl_resource__new_root_folder (integer)
returns integer as '
declare
        p_package_id            alias for $1;

        v_folder_id             cr_folders.folder_id%TYPE;
        v_folder_name           cr_items.name%TYPE;
begin

        raise notice ''in new root folder'';

        -- Set the folder name
        v_folder_name := rl_resource__new_name (p_package_id);

        v_folder_id := content_folder__new (
            v_folder_name,                              -- name
            ''Resources'',                              -- label
            ''Resources Repository'',                   -- description
            null,                                       -- parent_id
            p_package_id,                               -- context_id
            null,                                       -- folder_id
            null,                                       -- creation_date
            null,                                       -- creation_user
            null                                        -- creation_ip
        );

        -- Register the standard content types
        PERFORM content_folder__register_content_type (
                v_folder_id,            -- folder_id
                ''rl_resource'',        -- content_type
                ''f''                   -- include_subtypes
        );

        -- there is no facility in the API for adding in the package_id,
        -- so we have to do it ourselves

        update cr_folders 
        set package_id = p_package_id 
        where folder_id = v_folder_id;

        -- TODO: Handle Permissions here for this folder.

        return v_folder_id;
end;' language 'plpgsql';
