You are here

class HeartbeatFlagAttachmentPlugin in Heartbeat 7

Class HeartbeatFlagAttachmentPlugin.

Hierarchy

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'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HeartbeatBasePlugin::$label protected property
HeartbeatBasePlugin::$settings protected property
HeartbeatBasePlugin::$stream protected property
HeartbeatBasePlugin::addSettings public function addSettings().
HeartbeatBasePlugin::getLabel public function getLabel().
HeartbeatBasePlugin::getSettings public function getSettings().
HeartbeatBasePlugin::pluginStreamForm public function pluginStreamForm(). 2
HeartbeatBasePlugin::setLabel public function setLabel().
HeartbeatBasePlugin::setStream final public function setStream().
HeartbeatBasePlugin::__construct public function __construct(). 1
HeartbeatFlagAttachmentPlugin::$count public property
HeartbeatFlagAttachmentPlugin::$flag public property
HeartbeatFlagAttachmentPlugin::$link public property
HeartbeatFlagAttachmentPlugin::adaptsStream public function adaptsStream(). Overrides iHeartbeatPlugin::adaptsStream
HeartbeatFlagAttachmentPlugin::countEnabled protected function countEnabled().
HeartbeatFlagAttachmentPlugin::flagDefaults public function flagDefaults(). Defines the default flags. Overrides HeartbeatFlagPlugin::flagDefaults
HeartbeatFlagAttachmentPlugin::flagDefinitions public function flagDefinitions(). Defines the flag definition. Overrides HeartbeatFlagPlugin::flagDefinitions
HeartbeatFlagAttachmentPlugin::getAttachments public function getAttachments(). Overrides HeartbeatBasePlugin::getAttachments
HeartbeatFlagAttachmentPlugin::getMenuItems public function getMenuItems(). Overrides HeartbeatBasePlugin::getMenuItems
HeartbeatFlagAttachmentPlugin::hasAttachmentsButtons public function hasAttachmentsButtons(). True if a message has attachment buttons. Overrides iHeartbeatPlugin::hasAttachmentsButtons
HeartbeatFlagAttachmentPlugin::hasAttachmentsContent public function hasAttachmentsContent(). True if the message has attachments content. Overrides iHeartbeatPlugin::hasAttachmentsContent
HeartbeatFlagAttachmentPlugin::hasButtons public function hasButtons(). Overrides iHeartbeatPlugin::hasButtons
HeartbeatFlagAttachmentPlugin::hasContent public function hasContent(). True if a plugin provides attachments. Overrides iHeartbeatPlugin::hasContent
HeartbeatFlagAttachmentPlugin::isStreamAdaptor public function isStreamAdaptor(). Overrides iHeartbeatPlugin::isStreamAdaptor
HeartbeatFlagAttachmentPlugin::loadAttachments public function loadAttachments(). Overrides iHeartbeatPlugin::loadAttachments
HeartbeatFlagAttachmentPlugin::pluginAttachmentForm public function pluginAttachmentForm(). Overrides HeartbeatBasePlugin::pluginAttachmentForm
HeartbeatFlagAttachmentPlugin::pluginUIForm public function pluginUIForm(). Overrides HeartbeatBasePlugin::pluginUIForm
HeartbeatFlagAttachmentPlugin::renderAttachmentsContent public function renderAttachmentsContent(). Overrides iHeartbeatPlugin::renderAttachmentsContent
HeartbeatFlagAttachmentPlugin::renderButtons public function renderButtons(). Overrides iHeartbeatPlugin::renderButtons
HeartbeatFlagAttachmentPlugin::streamLoaded public function streamLoaded(). Overrides iHeartbeatPlugin::streamLoaded
HeartbeatFlagPlugin::activityRemoved public function activityRemoved() Overrides HeartbeatBasePlugin::activityRemoved
HeartbeatFlagPlugin::hasDefaultFlags public function hasDefaultFlags(). Defines if the plugin has default flags.
HeartbeatFlagPlugin::hasFlagDefinitions public function hasFlagDefinitions(). Defines if the plugin hasFlagDefinitions.
HeartbeatFlagPlugin::removeFlagContent public function removeFlagContent().