History of CreatingServices

Version 1

CreatingServices

a developers guide to generating services

Created by: xing, Last modification: 15 Feb 2006 (21:44 UTC) by xing
a brief outline of what a service is and what it does, can be found on LibertyServices


Turning a package into a service

register the package as service

to turn any package into a service, you need to modify your <pkg>/bit_setup_inc.php file and declare your package into a service. this can be done by modifying the way the package is registered:

<?php
$gBitSystem
->registerPackage'pigeonholes'dirname__FILE__).'/'TRUELIBERTY_SERVICE_CATEGORIZATION );
?>

explaining the parameters of registerPackage:
  1. name of the package
  2. package path
  3. specify if the package can be activated
  4. specify what type of service the package belongs to

the service type needs to be defined as a constant in liberty/LibertySystem.php - this is also the place where you can check what types of services we already have and if your's fits into one of the existing ones, please use one of those.

register the service

this is the cruicial bit. we register the service and when to display what and where.


<?php
if( $gBitSystem->isPackageActive'pigeonholes' ) ) {
    
$gLibertySystem->registerServiceLIBERTY_SERVICE_CATEGORIZATIONPIGEONHOLES_PKG_NAME, array(
        
'content_display_function' => 'pigeonholes_content_display',
        
'content_preview_function' => 'pigeonholes_content_preview',
        
'content_edit_function' => 'pigeonholes_content_input',
        
'content_store_function' => 'pigeonholes_content_store',
        
'content_expunge_function' => 'pigeonholes_content_expunge',
        
'content_edit_tab_tpl' => 'bitpackage:pigeonholes/pigeonholes_input_inc.tpl',
        
'content_view_tpl' => 'bitpackage:pigeonholes/display_members.tpl',
        
'content_nav_tpl' => 'bitpackage:pigeonholes/display_paths.tpl',
    ) );
?>


you can see that the pigeonholes package first checks to see if it's active, if so, it adds the service specifications.

Service Options

Sql Extensions

content_list_sql_function
allows the extension of existing SQL while getList() is called. table aliases are kept constant throughout so you can easily join pertinent data to the existing SQL when getList() is called from any package.

<?php
function protector_content_list() {
    global 
$gBitUser;
    
$groups array_keys($gBitUser->mGroups);
    
$ret = array(
        
'join_sql' => " LEFT JOIN `".BIT_DB_PREFIX."liberty_content_group_map` lcgm ON ( lc.`content_id`=lcgm.`content_id` ) LEFT OUTER JOIN `".BIT_DB_PREFIX."users_groups_map` ugm ON ( ugm.`group_id`=lcgm.`group_id` ) ",
        
'where_sql' => " AND (lcgm.`content_id` IS NULL OR lcgm.`group_id` IN("implode(','array_fill(0count($groups), '?')) ." ) OR ugm.`user_id`=?) ",
        
'bind_vars' => array( $gBitUser->mUserId ),
    );
    
$ret['bind_vars'] = array_merge$groups$ret['bind_vars'] );
    return 
$ret;
}
?>

You can also insert some select_sql as well, to limit the selection critieria.

content_load_sql_function
This is basically the same as content_list_sql_function but it's called during the load() process. the output should be virtually the same.

Functions

content_display_function
This function is called during the displaying of the content, i.e. while the page is being loaded. this means, you can add more sophisticated queries and checks in here, if there is no possibility to do this with the SQL functions above.

content_preview_function
This function is called when a page is being editied and a user hits preview. it's mostly there for you to make any selections the user has made persistent during the preview phase.

content_edit_function
When a user wants to edit content, this function is called. it allows you to generate data for any templates you need to fill in the edit page (more below).

content_store_function
Here you can store the content data in your serice tables.

content_expunge_function
Make sure the data from your tables is removed when a user removes the content it belongs to.

Templates

content_edit_tab_tpl
This template is displayed as a seperate tab when a user is editing content. this is useful for services that might contain several lines of code and want to have their own section when a user edits a page. This template is only available when the user is editing data.

content_edit_mini_tpl
This template is displayed during the edit process and is particularly useful when you have a single dropdown to display, since it's displayed below the textarea a user uses to edit the content. This template is only available when the user is editing data.

content_view_tpl
This template is appended to the bottom of the page, like a list of pages in the same category. This is only visible when the full content is loaded i.e.: when an article is being read but not just viewed on the front page.

content_nav_tpl
You can use this to insert a narrow template at the top of a page. this can be useful to display the path to an object or the status of a page. This is only visible when the full content is loaded i.e.: when an article is being read but not just viewed on the front page.

content_icon_tpl
insert an icon in the list of existing icons in the top right on a page. This will enable you to get your users to link to a template in your own package and deal with certain needs that way.

content_body_tpl
insert a small template into the top of the
part of the content. this template will be visible in listings such as the articles front page as well.
</pkg>
Page History
Date/CommentUserIPVersion
28 Aug 2006 (17:22 UTC)
adds image
Will68.174.111.477
Current • Source
Will68.174.111.474
View • Compare • Difference • Source
xing194.152.164.452
View • Compare • Difference • Source
xing194.152.164.451
View • Compare • Difference • Source