You are here

class SearchApiAttachmentsUserContentAlterSettings in Search API attachments 7

Hierarchy

Expanded class hierarchy of SearchApiAttachmentsUserContentAlterSettings

1 string reference to 'SearchApiAttachmentsUserContentAlterSettings'
search_api_attachments_user_content_search_api_alter_callback_info in contrib/search_api_attachments_user_content/search_api_attachments_user_content.module
Implements hook_search_api_alter_callback_info().

File

contrib/search_api_attachments_user_content/includes/callback_attachments_user_content_settings.inc, line 11
Search API data alteration callback.

View source
class SearchApiAttachmentsUserContentAlterSettings extends SearchApiAttachmentsAlterSettings {

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

  /**
   * {@inheritdoc}
   */
  public function alterItems(array &$items) {

    // Get the file fields.
    $file_fields = $this
      ->getFileFields();
    if (empty($file_fields)) {
      return;
    }

    // Get all nodes authored by the indexed users.
    $uids = array();
    foreach ($items as $item) {
      $uids[] = $item->uid;
    }
    $sql = 'SELECT nid FROM {node} WHERE uid IN (:uids)';
    $nids = db_query($sql, array(
      ':uids' => $uids,
    ));
    $user_nodes = array();
    foreach (node_load_multiple($nids
      ->fetchCol()) as $node) {
      $user_nodes[$node->uid][] = $node;
    }
    foreach ($items as $item) {

      // Index the files content.
      if (!empty($user_nodes[$item->uid])) {
        foreach ($user_nodes[$item->uid] as $node) {
          foreach ($file_fields as $file_field) {

            // The node has the file field.
            if (!empty($node->{$file_field['field_name']})) {

              // Get the files.
              $files = field_get_items('node', $node, $file_field['field_name']);
              if (!empty($files)) {

                // Limit to the max number of value per field.
                if (!empty($this->options['number_indexed']) && count($files) > $this->options['number_indexed']) {
                  $files = array_slice($files, 0, $this->options['number_indexed']);
                }
                foreach ($files as $file) {
                  if ($this
                    ->isFileIndexable($file, $item, $file_field['field_name'])) {
                    $attachments = 'attachments_' . $file_field['field_name'];
                    if (isset($item->{$attachments})) {
                      $item->{$attachments} .= ' ' . $this
                        ->getFileContent($file);
                    }
                    else {
                      $item->{$attachments} = $this
                        ->getFileContent($file);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function propertyInfo() {
    $ret = array();
    $fields = $this
      ->getFileFields();
    foreach ($fields as $name => $field) {
      $ret['attachments_' . $name] = array(
        'label' => 'Attachment content: ' . $name,
        'description' => $name,
        'type' => 'text',
      );
    }
    return $ret;
  }

  /**
   * {@inheritdoc}
   */
  protected function getFileFields() {
    $ret = array();
    foreach (field_info_fields() as $name => $field) {
      if ($field['type'] == 'file' && array_key_exists('node', $field['bundles'])) {
        $ret[$name] = $field;
      }
    }
    return $ret;
  }

}

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::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
SearchApiAttachmentsAlterSettings::CACHE_TABLE constant 1
SearchApiAttachmentsAlterSettings::configurationForm public function Adds configuration form. Overrides SearchApiAbstractAlterCallback::configurationForm
SearchApiAttachmentsAlterSettings::extractExif protected function Extracts images metadata.
SearchApiAttachmentsAlterSettings::extractPdftotext protected function Extracts pdf file content using pdftotext.
SearchApiAttachmentsAlterSettings::extractPythonPdf2txt protected function Extracts pdf file content using python pdf2txt script.
SearchApiAttachmentsAlterSettings::extractSimple protected function Extracts file content for text files.
SearchApiAttachmentsAlterSettings::extractSolr protected function Extract data using Solr.
SearchApiAttachmentsAlterSettings::extractTika protected function Extracts file content using local tika executable.
SearchApiAttachmentsAlterSettings::extractTikaServer protected function Extracts file content using a tika server.
SearchApiAttachmentsAlterSettings::getFileContent protected function Extracts th file content.
SearchApiAttachmentsAlterSettings::getIndexableFileFields protected function Retrieve list of fields, that should be indexed.
SearchApiAttachmentsAlterSettings::getRealpath protected function Helper method to get a file's real path.
SearchApiAttachmentsAlterSettings::imageMimetypes protected function Helper function to store image's mimetypes.
SearchApiAttachmentsAlterSettings::isFileIndexable public function Checks if file is allowed to be indexed. 1
SearchApiAttachmentsAlterSettings::isMultipleIndexWithFile protected function
SearchApiAttachmentsAlterSettings::isPrivate protected function Check if the file is private.
SearchApiAttachmentsAlterSettings::isTemporary protected function Check if the file is temporary.
SearchApiAttachmentsAlterSettings::pdfMimetypes protected function Helper function to store pdf's mimetypes.
SearchApiAttachmentsAlterSettings::textMimetypes protected function Helper function to store text's mimetypes.
SearchApiAttachmentsUserContentAlterSettings::alterItems public function Alter items before indexing. Overrides SearchApiAttachmentsAlterSettings::alterItems
SearchApiAttachmentsUserContentAlterSettings::getFileFields protected function Helper method to get all file fields. Overrides SearchApiAttachmentsAlterSettings::getFileFields
SearchApiAttachmentsUserContentAlterSettings::propertyInfo public function Adds attachments property. Overrides SearchApiAttachmentsAlterSettings::propertyInfo
SearchApiAttachmentsUserContentAlterSettings::supportsIndex public function Implements SearchApiAlterCallbackInterface::supportsIndex(). Overrides SearchApiAbstractAlterCallback::supportsIndex