class HeartbeatFlagAttachmentPlugin in Heartbeat 7
Class HeartbeatFlagAttachmentPlugin.
Hierarchy
- class \HeartbeatBasePlugin
- class \HeartbeatFlagPlugin
- class \HeartbeatFlagAttachmentPlugin implements iHeartbeatPlugin
- class \HeartbeatFlagPlugin
Expanded class hierarchy of HeartbeatFlagAttachmentPlugin
File
- modules/
heartbeat_plugins/ plugins/ flagattachment.inc, line 14
View source
class HeartbeatFlagAttachmentPlugin extends HeartbeatFlagPlugin implements iHeartbeatPlugin {
public $flag = NULL;
public $count = 0;
public $link = '';
/**
* getAttachments().
*
* @param $template
* The Heartbeat Template
* @param $component_type
* The type of attachment [buttons, content]
*/
public function getAttachments($template, $component_type) {
$attachments = array();
$flags = flag_get_flags('heartbeat_activity');
foreach ($flags as $flag) {
$args = array(
'@flag' => $flag->name,
);
$attachments[] = array(
'name' => $this->settings['plugin_name'] . ':' . $flag->name,
'title' => $component_type == 'buttons' ? t('Heartbeat flag buttons for "@flag"', $args) : t('Heartbeat flag count for "@flag"', $args),
'enabled' => isset($template->attachments[$component_type]['enabled'][$this->settings['plugin_name'] . ':' . $flag->name]) ? $template->attachments[$component_type]['enabled'][$this->settings['plugin_name'] . ':' . $flag->name] : 0,
'weight' => 0,
);
}
return $attachments;
}
/**
* loadAttachments().
*
* @param HeartbeatActivity $heartbeatActivity
* The Heartbeat Activity Message object
* @param String $name
* The Flagname of the flag attached to the Message.
*/
public function loadAttachments(HeartbeatActivity &$heartbeatActivity, $name = NULL) {
// We need the flagname for flagmessages.
if (!isset($name)) {
return;
}
$pluginId = $this->settings['plugin_name'] . ":" . $name;
$attachments = $heartbeatActivity->template->attachments;
// Always load the flag (for content or buttons).
$this->flag = flag_get_flag($name);
// Load the count for this message if needed.
if (isset($attachments['content']['enabled'][$pluginId])) {
$counts = flag_get_counts('heartbeat_activity', $heartbeatActivity->uaid);
$this->count = isset($counts[$name]) ? $counts[$name] : 0;
}
// Load the link for this message if needed.
if (isset($attachments['buttons']['enabled'][$pluginId])) {
$this->link = flag_create_link($name, $heartbeatActivity->uaid);
}
// Add the plugin to this message.
if ($this->flag && _flag_content_enabled($this->flag, 'heartbeat_activity')) {
$heartbeatActivity
->add_plugin($pluginId, $this);
}
else {
$heartbeatActivity
->remove_plugin($pluginId);
}
}
/**
* hasContent().
* True if a plugin provides attachments.
*/
public function hasContent() {
return TRUE;
}
/**
* hasAttachmentsContent().
* True if the message has attachments content.
*/
public function hasAttachmentsContent() {
// TODO add correct evaluation.
return TRUE;
}
/**
* renderAttachmentsContent().
*/
public function renderAttachmentsContent(HeartbeatActivity $heartbeatActivity) {
if ($this->count > 0) {
$heartbeatActivity
->add_attachment('<span class="heartbeat-flag-count">' . $this->flag
->get_label('flag_message', $heartbeatActivity) . '</span>');
}
}
/**
* hasButtons().
*/
public function hasButtons() {
return TRUE;
}
/**
* hasAttachmentsButtons().
* True if a message has attachment buttons.
*/
public function hasAttachmentsButtons() {
// TODO add correct evaluation.
return TRUE;
}
/**
* renderButtons().
*/
public function renderButtons(HeartbeatActivity $heartbeatActivity) {
if (isset($this->link)) {
$heartbeatActivity
->add_button($this->link);
}
elseif ($this->flag && $this->flag
->access($heartbeatActivity->uaid)) {
$link = $this->flag
->theme($this->flag
->is_flagged($heartbeatActivity->uaid) ? 'unflag' : 'flag', $heartbeatActivity->uaid, FALSE);
$heartbeatActivity
->add_button($link);
}
}
/**
* isStreamAdaptor().
*/
public function isStreamAdaptor() {
return TRUE;
}
/**
* adaptsStream().
*/
public function adaptsStream() {
return TRUE;
}
/**
* streamLoaded().
*/
public function streamLoaded(HeartbeatStream $heartbeatStream) {
$heartbeatStream
->needsModal(TRUE);
}
/**
* getMenuItems().
*/
public function getMenuItems() {
return array(
'heartbeat/%ctools_js/flagged/%heartbeat_activity' => array(
'title' => 'People who liked this',
'type' => MENU_CALLBACK,
'page callback' => 'heartbeat_plugins_modal_flagging_users',
'page arguments' => array(
1,
3,
),
'access arguments' => array(
'access heartbeat activity profiles',
),
'file' => 'includes/heartbeatflagplugin.inc',
),
);
}
/**
* flagDefinitions().
* Defines the flag definition.
*/
public function flagDefinitions() {
return array(
'heartbeat_activity' => array(
'title' => t('Heartbeat activity instance'),
'description' => t("Heartbeat activity messages."),
'handler' => 'flag_heartbeat_message',
),
);
}
/**
* flagDefaults().
* Defines the default flags.
*/
public function flagDefaults() {
$flags = array();
// Exported flag: "I like".
$flags['like'] = array(
'content_type' => 'heartbeat_activity',
'title' => 'I like',
'global' => '0',
'types' => array(),
'flag_short' => 'I like this',
'flag_long' => 'you like this',
'flag_message' => '[heartbeat_activity:flag-like-count-linked] liked this',
'unflag_short' => 'I don\'t like this',
'unflag_long' => 'you don\'t like this',
'unflag_message' => 'you don\'t like this',
'unflag_denied_text' => '',
'link_type' => 'toggle',
'roles' => array(
'flag' => array(
'0' => '2',
),
'unflag' => array(
'0' => '2',
),
),
'api_version' => 2,
);
return $flags;
}
/**
* pluginUIForm().
*/
public function pluginUIForm(&$form, &$form_state) {
$form['settings']['count_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable the count data'),
'#default_value' => isset($this->settings['count_enabled']) ? $this->settings['count_enabled'] : '',
);
}
/**
* pluginAttachmentForm().
*
* @param $form
* @param $form_values
* @param $component_type [buttons, content]
*/
public function pluginAttachmentForm(&$form, $form_values, $component_type) {
// If no count is available, then this plugin has no content, only buttons.
if ($component_type == 'content' && !$this
->countEnabled()) {
// unset
}
}
/**
* countEnabled().
*/
protected function countEnabled() {
return isset($this->settings['count_enabled']) && $this->settings['count_enabled'];
}
}