You are here

class views_oai_pmh_plugin_row_misc in Views OAI-PMH 7.2

Same name and namespace in other branches
  1. 6.2 plugins/views_oai_pmh_plugin_row_misc.inc \views_oai_pmh_plugin_row_misc

@file Definition of the views_oai_pmh_plugin_row_misc class.

Hierarchy

Expanded class hierarchy of views_oai_pmh_plugin_row_misc

1 string reference to 'views_oai_pmh_plugin_row_misc'
views_oai_pmh_plugin_row_auto::_check_row_objects in plugins/views_oai_pmh_plugin_row_auto.inc
Clones this object's properties into its row objects. Only performs this action the first time the function is called; subsequent calls just run the validity test.

File

plugins/views_oai_pmh_plugin_row_misc.inc, line 7
Definition of the views_oai_pmh_plugin_row_misc class.

View source
class views_oai_pmh_plugin_row_misc extends views_plugin_row {

  /**
   * The metadata type that the object represents, e.g. 'oai_dc' for Dublin Core.
   * @var string
   */
  private $_metadata_format = '';

  /**
   * The root node of the XML tree representing this structure.
   * @var views_oai_pmh_xml_node
   */
  public $nodes;

  /**
   * Class constructor-like function. 'Views' calls this when it creates the
   * object. Takes a metadata format type, such as 'oai_dc' for Dublin Core, as
   * a parameter. This is used to grab the necessary details of the format
   * whenever required from the $GLOBALS['views_oai_pmh'] configuration array.
   * If the value is not provided, it will attempt to detect it automatically
   * from the query string.
   *
   * @param string $type The metadata format type.
   */
  public function construct($type = '') {
    if ($type) {

      // Save the given metadata format value.
      $this->_metadata_format = $type;
    }
    else {

      // See if a particular data type is being requested in the query string.
      $metadata_prefix = array_key_exists('metadataPrefix', $_GET) && $_GET['metadataPrefix'] != '' ? $_GET['metadataPrefix'] : '';
      if (array_key_exists($metadata_prefix, $GLOBALS['views_oai_pmh'])) {

        // Save the metadata format in this object's property.
        $this->_metadata_format = $metadata_prefix;
      }
      elseif (array_key_exists('#metadata_format', $this->definition) && $this->definition['#metadata_format'] != '') {

        // See if the selected data type contains the metadata format we need to use.
        $this->_metadata_format = $this->definition['#metadata_format'];
      }
    }

    // Create our root XML node to build upon using the global data type definition.
    $this->nodes = new views_oai_pmh_xml_node($GLOBALS['views_oai_pmh'][$this->_metadata_format]->base_xml_node->key, $GLOBALS['views_oai_pmh'][$this->_metadata_format]->base_xml_node->value, $GLOBALS['views_oai_pmh'][$this->_metadata_format]->base_xml_node->attributes);
  }

  /**
   * Theme up the given row and return the resulting code.
   *
   * @param array $row The row to render.
   * @return string Themed content for the given row.
   */
  public function render($row) {
    $theme_options = array(
      'view' => $this->view,
      'options' => $this->options,
      'row' => $row,
      'metadata_format' => $this->_metadata_format,
      'nodes' => &$this->nodes,
    );
    $return = theme($this
      ->theme_functions(), $theme_options);

    // Reset the internal nodes list to just the top level node.
    $this->nodes->value = NULL;
    return $return;
  }

  /**
   * Check the values of the Views form.
   *
   * @return array An array of errors; empty if none.
   */
  function validate() {

    // Call the parent class' validation function.
    $errors = parent::validate();
    $link = $this->display->handler
      ->option_link('Row options', 'row_options');
    $field_handlers = $this->display->handler
      ->get_handlers('field');
    foreach ($field_handlers as $id => $field) {
      $ui_label = $field
        ->ui_name();
      $label_string = $field
        ->label();

      // See if the label contains formatting HTML that we need to remove.
      if (strpos($label_string, '<span') !== FALSE) {

        // Grab the contents of the first 'span' tag in the label.
        $label_string = substr($label_string, 0, strpos($label_string, '<span>', 1));

        // Strip the span tag, leaving us with just the labels.
        $label_string = strip_tags($label_string);
      }

      // Break the label string into its component labels, which are separated by commas.
      $labels[$id] = explode(', ', $label_string);
      $found_label = FALSE;
      foreach ($labels[$id] as $label) {

        // Does this label exist in our array of element names?
        if (array_key_exists($label, $GLOBALS['views_oai_pmh'][$this->_metadata_format]->elements)) {
          $found_label = TRUE;
          break;
        }
      }

      // Check that we found a valid label for this data type.
      if (!$found_label) {
        $errors[] = t('The field "@title" does not have a @name label associated with it. Go to the !link page to fix it.', array(
          '@title' => $ui_label,
          '@name' => $GLOBALS['views_oai_pmh'][$this->_metadata_format]->name,
          '!link' => $link,
        ));
      }
    }
    return $errors;
  }

  /**
   * Build the Views options form.
   */
  function options_form(&$form, &$form_state) {

    // Call the parent class' form builder function.
    parent::options_form($form, $form_state);
    $field_handlers = $this->display->handler
      ->get_handlers('field');
    foreach ($field_handlers as $id => $handler) {
      $ui_labels[$id] = $handler
        ->ui_name();
      if ($label_string = $handler
        ->label()) {

        // See if the label contains formatting HTML that we need to remove.
        if (strpos($label_string, '<span') !== FALSE) {

          // Grab the contents of the first 'span' tag in the label.
          $label_string = substr($label_string, 0, strpos($label_string, '<span>', 1));

          // Strip the span tag, leaving us with just the labels.
          $label_string = strip_tags($label_string);
        }

        // Break the label string into its component labels, which are separated by commas.
        $labels[$id] = explode(', ', $label_string);
      }
    }

    // Copy the name of the form field into a local variable for easy reference.
    $form_group_name = $GLOBALS['views_oai_pmh'][$this->_metadata_format]->form_group_name;
    $form[$form_group_name] = array(
      '#type' => 'fieldset',
      '#title' => t('Drupal field to @name mapping', array(
        '@name' => $GLOBALS['views_oai_pmh'][$this->_metadata_format]->name,
      )),
      '#theme' => 'oai_field_mapper_form',
    );
    foreach ($ui_labels as $id => $label) {

      // Determine the default value for this element name.
      $default_value = 'none';
      if (isset($labels[$id]) && is_array($labels[$id])) {
        foreach ($labels[$id] as $label) {

          // Does this label exist in our elements names array above?
          if (array_key_exists($label, $GLOBALS['views_oai_pmh'][$this->_metadata_format]->elements)) {
            $default_value = $label;
          }
        }
      }
      $form[$form_group_name][$id] = array(
        '#type' => 'select',
        '#options' => $GLOBALS['views_oai_pmh'][$this->_metadata_format]->elements,
        '#default_value' => $default_value,
      );
      $form[$form_group_name][$id]['drupal_label'] = array(
        '#markup' => $ui_labels[$id],
      );
    }
  }

  /**
   * Save the changes made in the Views form.
   *
   * @param array $form
   * @param array $form_state
   * @param bool $apply_changes Set to FALSE to return the form changes as a
   *  response to the function call. TRUE (default) makes the changes directly
   *  to the $form_state variable.
   * @return array An array of the form changes.
   */
  function options_submit(&$form, &$form_state, $apply_changes = TRUE) {

    // It is very important to call the parent function here.
    parent::options_submit($form, $form_state);

    // Create an array to save the changes that we make to the form.
    $form_item_options = array();
    $section = $form_state['section'];
    switch ($section) {
      case 'row_options':
        $field_handlers = $this->display->handler
          ->get_handlers('field');
        $form_group_name = $GLOBALS['views_oai_pmh'][$this->_metadata_format]->form_group_name;
        $labels = $form_state['values'][$section][$form_group_name];
        foreach ($field_handlers as $id => $field) {
          $options = $field->options;
          if ($labels[$id] != 'none') {
            $options['custom_label'] = TRUE;
            $options['label'] = $labels[$id];
            $options['hide_empty'] = 1;
          }
          else {
            unset($options['custom_label']);
            $options['label'] = '';
          }
          $form_item_options[$id] = $options;

          // See if we should be applying the changes to the form state now, or
          // returning it to the calling function. The default behaviour is to
          // apply the changes now; the alternative of returning the changes to
          // the calling function is provided for the Auto class to combine all
          // the results of multiple calls to this function in various classes.
          if ($apply_changes) {

            // Save the field info in the view.
            $form_state['view']
              ->set_item($form_state['display_id'], 'field', $id, $options);
          }
        }
        break;
    }
    if (!$apply_changes) {
      return $form_item_options;
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_oai_pmh_plugin_row_misc::$nodes public property The root node of the XML tree representing this structure.
views_oai_pmh_plugin_row_misc::$_metadata_format private property The metadata type that the object represents, e.g. 'oai_dc' for Dublin Core.
views_oai_pmh_plugin_row_misc::construct public function Class constructor-like function. 'Views' calls this when it creates the object. Takes a metadata format type, such as 'oai_dc' for Dublin Core, as a parameter. This is used to grab the necessary details of the format whenever… Overrides views_object::construct
views_oai_pmh_plugin_row_misc::options_form function Build the Views options form. Overrides views_plugin_row::options_form
views_oai_pmh_plugin_row_misc::options_submit function Save the changes made in the Views form. Overrides views_plugin_row::options_submit
views_oai_pmh_plugin_row_misc::render public function Theme up the given row and return the resulting code. Overrides views_plugin_row::render
views_oai_pmh_plugin_row_misc::validate function Check the values of the Views form. Overrides views_plugin::validate
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin_row::init public function 2
views_plugin_row::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_row::option_definition public function Information about options for all kinds of purposes will be held here. Overrides views_object::option_definition 9
views_plugin_row::pre_render public function Allow the style to do stuff before each row is rendered. 5
views_plugin_row::query public function Add anything to the query that we might need to. Overrides views_plugin::query
views_plugin_row::uses_fields public function