Adding and displaying your own notice from your custom module
Last modified: March 20, 2008 - 17:17
Lets assume you have a module that creates a cake, we'll call this module 'cake'.
Everytime a user adds a cake you want that user's friends to know and then be displayed on the Notice Feed or Mini Feed.
Action: When user adds new cake
After doing the insert into the database, you'll want to record this into the notice board.
<?php
If (module_exists(“notice”)){
$new_id = db_last_insert_id('cake_table','cake_id');
$notice_array = array(
'nb_type' => NOTICE_NORMAL,
'module_type' => “cake”,
'source_uid' => $user_id, // the person that just added the cake
'prime_id' => $new_id,
'op' => “cake_add”,
);
noticeapi_notice_add(“cake”,$notice_array);
}
?>Now we want to be able to display the action in a feed. For this we need to hook into notice
<?php
// $record will contain the information we just added in the above example .
function cake_notice($op, $type, $record){
switch($op){
case 'feed':
$SQL = “SELECT C.*
FROM {cake_table} C
WHERE C.cake_id = %d
“;
$record = db_fetch_object(db_query($SQL,$record->prime_id));
$output .= '<div claass=”notice-'.$record->module_type.'”>';
$output .= 'somebody added a new cake called '. $record->title;
$output .= '</div>';
return $output;
break;
};
}
?>In other words, use the notice function to insert your own information and then use the hook to format the feed display for your module type.
