class SearchApiSavedSearch in Search API Saved Searches 7
Class representing "Saved searches" settings.
Hierarchy
- class \Entity implements EntityInterface
- class \SearchApiSavedSearch
Expanded class hierarchy of SearchApiSavedSearch
1 string reference to 'SearchApiSavedSearch'
File
- ./
search_api_saved_searches.search_entity.inc, line 11 - Contains the entity class for saved searches.
View source
class SearchApiSavedSearch extends Entity {
/**
* The user that owns this saved search.
*
* @var stdClass
*/
protected $user;
/**
* The settings this saved search uses.
*
* @var SearchApiSavedSearchesSettings
*/
protected $settings;
/**
* The search index this saved search uses.
*
* @var SearchApiIndex
*/
protected $index;
// Database values that will be set when object is loaded
/**
* @var integer
*/
public $id;
/**
* @var integer
*/
public $uid;
/**
* @var string
*/
public $settings_id;
/**
* @var boolean
*/
public $enabled;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $mail;
/**
* @var integer
*/
public $created;
/**
* @var integer
*/
public $last_queued;
/**
* @var integer
*/
public $last_execute;
/**
* @var integer
*/
public $notify_interval;
/**
* Array representing the search query to execute, containing:
* keys: The parsed fulltext keys.
* fields: The fields that will be fulltext-searched.
* filters: An array of filters, as used in SearchApiQueryFilterInterface.
* options: The query options.
*
* @var array
*/
public $query;
/**
* @var array
*/
public $options;
/**
* @var string
*/
public $results;
/**
* Constructor as a helper to the parent constructor.
*/
public function __construct(array $values = array()) {
parent::__construct($values, 'search_api_saved_search');
}
/**
* Permanently saves the entity.
*
* @see entity_save()
*/
public function save() {
$settings = $this
->settings();
if (!$this->enabled && empty($this->options['key']) || !empty($settings->options['registered_user_delete_key'])) {
$this->options['key'] = drupal_hash_base64(drupal_random_bytes(12));
}
$date_field = isset($settings->options['date_field']) ? $settings->options['date_field'] : NULL;
if ($this->enabled && !isset($this->results) && !$date_field) {
$results = array();
$response = $this
->query()
->execute();
$this->results = implode(',', array_keys($response['results']));
}
$ret = parent::save();
if ($ret == SAVED_NEW && !$this->enabled) {
$params = array(
'user' => user_load($this->uid),
'search' => $this,
);
drupal_mail('search_api_saved_searches', 'activate', $this->mail, user_preferred_language($params['user']), $params);
}
return $ret;
}
/**
* @return
* The user that owns this saved search.
*/
public function user() {
if (!isset($this->user)) {
$this->user = user_load($this->uid);
}
return $this->user;
}
/**
* @return SearchApiSavedSearchesSettings
* The settings this saved search uses.
*
* @throws SearchApiException
* If the settings don't exist.
*/
public function settings() {
if (!isset($this->settings)) {
$this->settings = search_api_saved_searches_settings_load($this->settings_id);
}
if (!$this->settings) {
throw new SearchApiException(t("The saved search settings with the ID %id don't exist, but are used by an existing saved search.", array(
'%id' => $this->settings_id,
)));
}
return $this->settings;
}
/**
* @return SearchApiIndex
* The index this saved search uses.
*
* @throws SearchApiException
* If the index doesn't exist.
*/
public function index() {
if (!isset($this->index)) {
$this->index = search_api_index_load($this
->settings()->index_id);
}
if (!$this->index) {
throw new SearchApiException(t("The index with the ID %id doesn't exist, but has saved search settings attached.", array(
'%id' => $this
->settings()->index_id,
)));
}
return $this->index;
}
/**
* @return SearchApiQueryInterface
* A query for getting all new results for this saved search.
*
* @throws SearchApiException
* If the saved search's index is disabled.
*/
public function query() {
$index = $this
->index();
$query = $index
->query($this->query['options']);
if ($this->query['keys']) {
$query
->keys($this->query['keys']);
}
if ($this->query['fields']) {
$fields = (array) $this->query['fields'];
$fields = array_intersect($fields, $index
->getFulltextFields());
if ($fields) {
$query
->fields($fields);
}
}
if ($this->query['filters']) {
$filters =& $query
->getFilter()
->getFilters();
$filters = $this->query['filters'];
}
return $query;
}
/**
* Return the URL where this search can be viewed, if any.
*/
public function url() {
if (isset($this->options['page']['path'])) {
return url($this->options['page']['path'], $this->options['page']);
}
}
/**
* Return a link to the URL where this search can be viewed, if any.
*/
public function l($text) {
if (isset($this->options['page']['path'])) {
return l($text, $this->options['page']['path'], $this->options['page']);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Defines the entity label if the 'entity_class_label' callback is used. | 1 |
Entity:: |
protected | function | Override this in order to implement a custom default URI and specify 'entity_class_uri' as 'uri callback' hook_entity_info(). | |
Entity:: |
public | function |
Permanently deletes the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. | |
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
protected | property | The search index this saved search uses. | |
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | Array representing the search query to execute, containing: keys: The parsed fulltext keys. fields: The fields that will be fulltext-searched. filters: An array of filters, as used in SearchApiQueryFilterInterface. options: The query options. | |
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
protected | property | The settings this saved search uses. | |
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
public | property | ||
SearchApiSavedSearch:: |
protected | property | The user that owns this saved search. | |
SearchApiSavedSearch:: |
public | function | ||
SearchApiSavedSearch:: |
public | function | Return a link to the URL where this search can be viewed, if any. | |
SearchApiSavedSearch:: |
public | function | ||
SearchApiSavedSearch:: |
public | function |
Permanently saves the entity. Overrides Entity:: |
|
SearchApiSavedSearch:: |
public | function | ||
SearchApiSavedSearch:: |
public | function | Return the URL where this search can be viewed, if any. | |
SearchApiSavedSearch:: |
public | function | ||
SearchApiSavedSearch:: |
public | function |
Constructor as a helper to the parent constructor. Overrides Entity:: |