You are here

class uc_addresses_views_plugin_row_address_view in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 views/uc_addresses_views_plugin_row_address_view.inc \uc_addresses_views_plugin_row_address_view

Plugin which performs a address_view on the resulting object.

Most of the code on this object is in the theme function.

Hierarchy

Expanded class hierarchy of uc_addresses_views_plugin_row_address_view

1 string reference to 'uc_addresses_views_plugin_row_address_view'
uc_addresses_views_plugins in views/uc_addresses.views.inc
Implements hook_views_plugins().

File

views/uc_addresses_views_plugin_row_address_view.inc, line 13
Contains the address view row style plugin.

View source
class uc_addresses_views_plugin_row_address_view extends views_plugin_row {

  // Basic properties that let the row style follow relationships.
  public $base_table = 'uc_addresses';
  public $base_field = 'aid';

  /**
   * The assumed name of the uid field in the Views' results.
   *
   * @var string
   * @access protected
   */
  protected $uid_field_alias = 'unknown';

  /**
   * Overrides views_plugin_row::option_definition().
   *
   * @return array
   *   The available options and their default values.
   */
  public function option_definition() {
    $options = parent::option_definition();
    $options['view_link'] = array(
      'default' => FALSE,
    );
    $options['edit_link'] = array(
      'default' => TRUE,
    );
    $options['delete_link'] = array(
      'default' => TRUE,
    );
    $options['default_flags'] = array(
      'default' => FALSE,
    );
    return $options;
  }

  /**
   * Overrides views_plugin_row::options_form().
   *
   * @return void
   */
  public function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['view_link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display view links'),
      '#default_value' => $this->options['view_link'],
    );
    $form['edit_link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display edit links'),
      '#description' => t('Note that edit links are only shown for addresses that the current user may edit.'),
      '#default_value' => $this->options['edit_link'],
    );
    $form['delete_link'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display delete links'),
      '#description' => t('Note that delete links are only shown for addresses that the current user may delete.'),
      '#default_value' => $this->options['delete_link'],
    );
    $form['default_flags'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display default flags'),
      '#description' => t('This adds the "default" label to default addresses. For example, the default billing address will get the label "!label".', array(
        '!label' => t('Default billing address'),
      )),
      '#default_value' => $this->options['default_flags'],
    );
  }

  /**
   * Overrides views_plugin_row::query().
   *
   * Ensures the 'uid' field is added to the query.
   *
   * @return void
   */
  public function query() {
    parent::query();
    $this->uid_field_alias = $this->view->query
      ->add_field($this->view->query->base_table, 'uid');
  }

  /**
   * Implements views_plugin_row::pre_render().
   *
   * Loads all addresses.
   *
   * @return void
   */
  public function pre_render($values) {
    $aid_field_alias = $this->field_alias;
    $uid_field_alias = $this->uid_field_alias;
    $this->addresses = array();
    if (!empty($values)) {
      foreach ($values as $row) {
        $addressBook = UcAddressesAddressBook::get($row->{$uid_field_alias});

        // Set performance hint to load all addresses.
        $addressBook
          ->setPerformanceHint(UcAddressesAddressBook::PERF_HINT_LOAD_ALL);
        $address = $addressBook
          ->getAddressById($row->{$aid_field_alias});
        $this->addresses[$address
          ->getId()] = $address;
      }
    }
  }

  /**
   * Overrides views_plugin_row::render().
   *
   * Renders a single address.
   *
   * @return string
   *   Rendered HTML.
   */
  function render($row) {
    if (isset($this->addresses[$row->{$this->field_alias}])) {
      $address = $this->addresses[$row->{$this->field_alias}];
      $address->view = $this->view;
      return theme('uc_addresses_list_address', array(
        'address' => $address,
        'options' => $this->options,
      ));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
uc_addresses_views_plugin_row_address_view::$base_field public property
uc_addresses_views_plugin_row_address_view::$base_table public property
uc_addresses_views_plugin_row_address_view::$uid_field_alias protected property The assumed name of the uid field in the Views' results.
uc_addresses_views_plugin_row_address_view::options_form public function Overrides views_plugin_row::options_form(). Overrides views_plugin_row::options_form
uc_addresses_views_plugin_row_address_view::option_definition public function Overrides views_plugin_row::option_definition(). Overrides views_plugin_row::option_definition
uc_addresses_views_plugin_row_address_view::pre_render public function Implements views_plugin_row::pre_render(). Overrides views_plugin_row::pre_render
uc_addresses_views_plugin_row_address_view::query public function Overrides views_plugin_row::query(). Overrides views_plugin_row::query
uc_addresses_views_plugin_row_address_view::render function Overrides views_plugin_row::render(). Overrides views_plugin_row::render
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::construct public function Views handlers use a special construct function. 4
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::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_row::init public function 2
views_plugin_row::options_submit public function Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. Overrides views_plugin::options_submit 1
views_plugin_row::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_row::uses_fields public function