You are here

class LinkitViewsPlugin in Linkit views 7.2

Plugin class.

Hierarchy

Expanded class hierarchy of LinkitViewsPlugin

1 string reference to 'LinkitViewsPlugin'
linkit_views.inc in plugins/linkit_plugins/linkit_views.inc

File

plugins/linkit_plugins/linkit_views.class.php, line 7

View source
class LinkitViewsPlugin extends LinkitPlugin {

  /**
   * The uniq table name.
   *
   * @var string
   */
  var $table_name;

  /**
   * Initialize this plugin.
   */
  function __construct($plugin, $profile) {
    parent::__construct($plugin, $profile);
    $this->table_name = 'linkit_tmp_view_table_' . rand(0, 1000) . rand(0, 1000);
  }

  /**
   * Created a temporary table.
   */
  function create_tmp_table() {

    // If this can be done in a more nice way, please tell me.
    $temp_table = 'CREATE TEMPORARY TABLE {' . $this->table_name . '} (human_name VARCHAR(255) NOT NULL, display_title VARCHAR(65) NOT NULL, path VARCHAR(255) NOT NULL)';
    return db_query($temp_table);
  }

  /**
   * Populate the temporary table with display name and path.
   */
  function populate_tmp_table() {

    // Get all displays that is "page" and their path
    $query = db_select('views_view', 'w')
      ->condition('wd.display_plugin', 'page')
      ->fields('wd', array(
      'display_options',
      'display_title',
    ))
      ->fields('w', array(
      'human_name',
    ));
    $query
      ->join('views_display', 'wd', 'w.vid = wd.vid');
    $result = $query
      ->execute();
    foreach ($result as $view) {
      $optinos = unserialize($view->display_options);
      $fields = array(
        'display_title' => $view->display_title,
        'human_name' => $view->human_name,
        'path' => $optinos['path'],
      );
      db_insert($this->table_name)
        ->fields($fields)
        ->execute();
    }
  }

  /**
   * The autocomplete callback function for the Linkit Entity plugin.
   */
  function autocomplete_callback() {

    // Create the tmp table.
    $this
      ->create_tmp_table();

    // Populate the tmp table.
    $this
      ->populate_tmp_table();
    $matches = array();
    $query = db_select($this->table_name, 'tmp')
      ->fields('tmp', array(
      'path',
      'display_title',
      'human_name',
    ))
      ->condition('tmp.display_title', '%' . db_like($this->serach_string) . '%', 'LIKE')
      ->addTag('linkit_views_autocomplete')
      ->execute();
    foreach ($query as $view) {
      $matches[] = array(
        'title' => $view->display_title,
        'path' => base_path() . $view->path,
        'description' => t('View: %view', array(
          '%view' => $view->human_name,
        )),
        'group' => t('View pages'),
      );
    }
    return $matches;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkitPlugin::broken function Determine if the handler is considered 'broken', meaning it's a a placeholder used when a handler can't be found. 1
LinkitPlugin::buildDescription function Build the search row description. 1
LinkitPlugin::buildGroup function Returns a string to use as the search result group name. 1
LinkitPlugin::buildLabel function Build the label that will be used in the search result for each row. 1
LinkitPlugin::buildPath function Build an URL based in the path and the options. 1
LinkitPlugin::buildRowClass function Returns a string with CSS classes that will be added to the search result row for this item. 1
LinkitPlugin::buildSettingsForm function Generate a settings form for this handler. Uses the standard Drupal FAPI. 1
LinkitPlugin::setSearchString function Set the search string.
LinkitPlugin::ui_description function Return a string representing this handler's description in the UI. 2
LinkitPlugin::ui_title function Return a string representing this handler's name in the UI. 2
LinkitViewsPlugin::$table_name property The uniq table name.
LinkitViewsPlugin::autocomplete_callback function The autocomplete callback function for the Linkit Entity plugin. Overrides LinkitPluginInterface::autocomplete_callback
LinkitViewsPlugin::create_tmp_table function Created a temporary table.
LinkitViewsPlugin::populate_tmp_table function Populate the temporary table with display name and path.
LinkitViewsPlugin::__construct function Initialize this plugin. Overrides LinkitPlugin::__construct