flag_heartbeat.module in Heartbeat 6.4
Same filename and directory in other branches
File
modules/flag_heartbeat/flag_heartbeat.moduleView source
<?php
// by Stalski (Jochen Stals) - Menhir - www.menhir.be
/**
* @file
* Provides flag integration on heartbeat messages.
*/
include 'class.flag_heartbeat_message.inc';
/**
* Implementation of hook_flag_definitions().
*/
function flag_heartbeat_flag_definitions() {
return array(
'heartbeat_message' => array(
'title' => t('Heartbeat message'),
'description' => t("Heartbeat messages are activity streams for occurring actions."),
'handler' => 'flag_heartbeat_message',
),
);
}
/**
* Implementation of hook_heartbeat_attachments().
* @return unknown_type
*/
function flag_heartbeat_heartbeat_attachments($message = NULL) {
$flags = flag_get_flags('heartbeat_message');
foreach ($flags as $option) {
$options[$option->name] = $option->title;
}
return array(
'flags' => array(
'#type' => 'checkboxes',
'#default_value' => isset($message->attachments['flags']) ? drupal_map_assoc($message->attachments['flags']) : array(),
'#title' => t('Add flags to this message'),
'#options' => $options,
'#weight' => 25,
),
);
}
/**
* Implementation of <attchement>_widget().
*/
function flags_widget($attachments, $message) {
$flags = $attachments['flags'];
$widgetfields = array();
if (!empty($flags)) {
foreach ($flags as $flagname) {
if (!empty($flagname) && !is_numeric($flagname)) {
// Two possibilities.
// 1. with a persistent rendered flag message.
//$flag = flag_get_flag($flagname);
//$widgetfield = $flag->theme($flag->is_flagged($message->uaid) ? 'unflag' : 'flag', $message->uaid, TRUE);
// 2. showing the link and the count separately.
$widgetfield = flag_create_link($flagname, $message->uaid);
// $counts = flag_get_counts('heartbeat_message', $message->uaid);
// $widgetfield .= ' ' . t('@count users like this', array('@count' => (isset($counts[$flagname]) ? $counts[$flagname] : 0)));
// Solution is coming up from Drupal7 version.
$widgetfields[] = $widgetfield;
}
}
}
return implode(' - ', $widgetfields);
}
/**
* Implementation of hook_heartbeat_activity_delete().
* Delete the attached comments to a heartbeat activity object.
* @param $message
* HeartbeatActivity ID
* @see module_invoke_all('heartbeat_activity_delete', $activity);
*/
function flag_heartbeat_heartbeat_activity_delete($activity) {
db_query("DELETE FROM {flag_content} WHERE content_type = 'heartbeat_message' AND content_id = %d ", $activity->uaid);
}
Functions
Name | Description |
---|---|
flags_widget | Implementation of <attchement>_widget(). |
flag_heartbeat_flag_definitions | Implementation of hook_flag_definitions(). |
flag_heartbeat_heartbeat_activity_delete | Implementation of hook_heartbeat_activity_delete(). Delete the attached comments to a heartbeat activity object. |
flag_heartbeat_heartbeat_attachments | Implementation of hook_heartbeat_attachments(). |