You are here

class SearchApiAlterAddUserContent in Search API 7

Adds the nodes created by the indexed user for indexing.

Hierarchy

Expanded class hierarchy of SearchApiAlterAddUserContent

1 string reference to 'SearchApiAlterAddUserContent'
search_api_search_api_alter_callback_info in ./search_api.module
Implements hook_search_api_alter_callback_info().

File

includes/callback_user_content.inc, line 11
Contains SearchApiAlterAddUserContent.

View source
class SearchApiAlterAddUserContent extends SearchApiAbstractAlterCallback {

  /**
   * {@inheritdoc}
   */
  public function supportsIndex(SearchApiIndex $index) {
    return $index
      ->getEntityType() === 'user';
  }

  /**
   * {@inheritdoc}
   */
  public function propertyInfo() {
    return array(
      'search_api_user_content' => array(
        'label' => t('User content'),
        'description' => t('The nodes created by this user'),
        'type' => 'list<node>',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function alterItems(array &$items) {
    $uids = array();
    foreach ($items as $item) {
      $uids[] = $item->uid;
    }
    $sql = 'SELECT nid, uid FROM {node} WHERE uid IN (:uids)';
    $nids = db_query($sql, array(
      ':uids' => $uids,
    ));
    $user_nodes = array();
    foreach ($nids as $row) {
      $user_nodes[$row->uid][] = $row->nid;
    }
    foreach ($items as $item) {
      $item->search_api_user_content = array();
      if (!empty($user_nodes[$item->uid])) {
        $item->search_api_user_content = $user_nodes[$item->uid];
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SearchApiAbstractAlterCallback::$index protected property The index whose items will be altered.
SearchApiAbstractAlterCallback::$options protected property The configuration options for this callback, if it has any.
SearchApiAbstractAlterCallback::configurationForm public function Implements SearchApiAlterCallbackInterface::configurationForm(). Overrides SearchApiAlterCallbackInterface::configurationForm 6
SearchApiAbstractAlterCallback::configurationFormSubmit public function Implements SearchApiAlterCallbackInterface::configurationFormSubmit(). Overrides SearchApiAlterCallbackInterface::configurationFormSubmit 4
SearchApiAbstractAlterCallback::configurationFormValidate public function Implements SearchApiAlterCallbackInterface::configurationFormValidate(). Overrides SearchApiAlterCallbackInterface::configurationFormValidate 1
SearchApiAbstractAlterCallback::isMultiEntityIndex protected function Determines whether the given index contains multiple types of entities.
SearchApiAbstractAlterCallback::__construct public function Implements SearchApiAlterCallbackInterface::__construct(). Overrides SearchApiAlterCallbackInterface::__construct 1
SearchApiAlterAddUserContent::alterItems public function Alter items before indexing. Overrides SearchApiAlterCallbackInterface::alterItems
SearchApiAlterAddUserContent::propertyInfo public function Implements SearchApiAlterCallbackInterface::propertyInfo(). Overrides SearchApiAbstractAlterCallback::propertyInfo
SearchApiAlterAddUserContent::supportsIndex public function Implements SearchApiAlterCallbackInterface::supportsIndex(). Overrides SearchApiAbstractAlterCallback::supportsIndex