You are here

class SearchApiLiveResultsSearch in Search API live results 7

Class describing the settings for a certain search for which autocompletion is available.

Hierarchy

Expanded class hierarchy of SearchApiLiveResultsSearch

1 string reference to 'SearchApiLiveResultsSearch'
search_api_live_results_entity_info in ./search_api_live_results.module
Implements hook_entity_info().

File

./search_api_live_results.module, line 291

View source
class SearchApiLiveResultsSearch extends Entity {

  // Entity properties, loaded from the database:

  /**
   * @var integer
   */
  public $id;

  /**
   * @var string
   */
  public $machine_name;

  /**
   * @var string
   */
  public $name;

  /**
   * @var integer
   */
  public $index_id;

  /**
   * @var string
   */
  public $type;

  /**
   * @var boolean
   */
  public $enabled;

  /**
   * An array of options for this search, containing any of the following:
   * - results: Boolean indicating whether to also list the estimated number of
   *   results for each suggestion (if possible).
   * - custom: An array of type-specific settings.
   *
   * @var array
   */
  public $options = array();

  // Inferred properties, for caching:

  /**
   * @var SearchApiIndex
   */
  protected $index;

  /**
   * @var SearchApiServer
   */
  protected $server;

  /**
   * Constructor.
   *
   * @param array $values
   *   The entity properties.
   */
  public function __construct(array $values = array()) {
    parent::__construct($values, 'search_api_live_results_search');
  }

  /**
   * @return SearchApiIndex
   *   The index this search belongs to.
   */
  public function index() {
    if (!isset($this->index)) {
      $this->index = search_api_index_load($this->index_id);
      if (!$this->index) {
        $this->index = FALSE;
      }
    }
    return $this->index;
  }

  /**
   * @return SearchApiServer
   *   The server this search would at the moment be executed on.
   */
  public function server() {
    if (!isset($this->server)) {
      if (!$this
        ->index() || !$this
        ->index()->server) {
        $this->server = FALSE;
      }
      else {
        $this->server = $this
          ->index()
          ->server();
        if (!$this->server) {
          $this->server = FALSE;
        }
      }
    }
    return $this->server;
  }

  /**
   * Helper method for altering a textfield form element to use live results.
   */
  public function alterElement(array &$element) {
    if (user_access('use_search_api_live_results')) {
      $element['#type'] = 'live_results_search';
      if (isset($this->options['caching']) && $this->options['caching']) {
        $element['#autocomplete_path'] = drupal_get_path('module', 'search_api_live_results') . '/search_api_live_results.results.php';
        $element['#autocomplete_query'] = array(
          'search' => $this->machine_name,
        );
      }
      else {
        $element['#autocomplete_path'] = 'search_api_live_results/' . $this->machine_name;
      }
    }
  }

  /**
   * Create the query that would be issued for this search for the complete keys.
   *
   * @param $complete
   *   A string containing the complete search keys.
   * @param $incomplete
   *   A string containing the incomplete last search key.
   *
   * @return SearchApiQueryInterface
   *   The query that would normally be executed when only $complete was entered
   *   as the search keys for this search.
   */
  public function getQuery($keys) {
    $info = search_api_live_results_get_types($this->type);
    if (empty($info['create query'])) {
      return NULL;
    }
    $query = $info['create query']($this, $keys);
    return $query;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Entity::$defaultLabel protected property 1
Entity::$entityInfo protected property
Entity::$entityType protected property
Entity::$idKey protected property
Entity::$wrapper protected property
Entity::buildContent public function Builds a structured array representing the entity's content. Overrides EntityInterface::buildContent 1
Entity::bundle public function Returns the bundle of the entity. Overrides EntityInterface::bundle
Entity::defaultLabel protected function Defines the entity label if the 'entity_class_label' callback is used. 1
Entity::defaultUri protected function Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info().
Entity::delete public function Permanently deletes the entity. Overrides EntityInterface::delete
Entity::entityInfo public function Returns the info of the type of the entity. Overrides EntityInterface::entityInfo
Entity::entityType public function Returns the type of the entity. Overrides EntityInterface::entityType
Entity::export public function Exports the entity. Overrides EntityInterface::export
Entity::getTranslation public function Gets the raw, translated value of a property or field. Overrides EntityInterface::getTranslation
Entity::hasStatus public function Checks if the entity has a certain exportable status. Overrides EntityInterface::hasStatus
Entity::identifier public function Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface::identifier
Entity::internalIdentifier public function Returns the internal, numeric identifier. Overrides EntityInterface::internalIdentifier
Entity::isDefaultRevision public function Checks whether the entity is the default revision. Overrides EntityInterface::isDefaultRevision
Entity::label public function Returns the label of the entity. Overrides EntityInterface::label
Entity::save public function Permanently saves the entity. Overrides EntityInterface::save
Entity::setUp protected function Set up the object instance on construction or unserializiation.
Entity::uri public function Returns the uri of the entity just as entity_uri(). Overrides EntityInterface::uri
Entity::view public function Generate an array for rendering the entity. Overrides EntityInterface::view
Entity::wrapper public function Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface::wrapper
Entity::__sleep public function Magic method to only serialize what's necessary.
Entity::__wakeup public function Magic method to invoke setUp() on unserialization.
SearchApiLiveResultsSearch::$enabled public property
SearchApiLiveResultsSearch::$id public property
SearchApiLiveResultsSearch::$index protected property
SearchApiLiveResultsSearch::$index_id public property
SearchApiLiveResultsSearch::$machine_name public property
SearchApiLiveResultsSearch::$name public property
SearchApiLiveResultsSearch::$options public property An array of options for this search, containing any of the following:
SearchApiLiveResultsSearch::$server protected property
SearchApiLiveResultsSearch::$type public property
SearchApiLiveResultsSearch::alterElement public function Helper method for altering a textfield form element to use live results.
SearchApiLiveResultsSearch::getQuery public function Create the query that would be issued for this search for the complete keys.
SearchApiLiveResultsSearch::index public function
SearchApiLiveResultsSearch::server public function
SearchApiLiveResultsSearch::__construct public function Constructor. Overrides Entity::__construct