You are here

function views_db_object::init in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 6.2 includes/view.inc \views_db_object::init()
  2. 7.3 includes/view.inc \views_db_object::init()

Initialize this object, setting values from schema defaults.

Parameters

$init: If an array, this is a set of values from db_fetch_object to load. Otherwse, if TRUE values will be filled in from schema defaults.

2 calls to views_db_object::init()
view::__construct in includes/view.inc
Constructor
views_display::views_display in includes/view.inc

File

includes/view.inc, line 1983
view.inc Provides the view object type and associated methods.

Class

views_db_object
Base class for views' database objects.

Code

function init($init = TRUE) {
  if (is_array($init)) {
    return $this
      ->load_row($init);
  }
  if (!$init) {
    return;
  }
  $schema = drupal_get_schema($this->db_table);
  if (!$schema) {
    return;
  }

  // Go through our schema and build correlations.
  foreach ($schema['fields'] as $field => $info) {
    if ($info['type'] == 'serial') {
      $this->{$field} = NULL;
    }
    if (!isset($this->{$field})) {
      if (!empty($info['serialize']) && isset($info['serialized default'])) {
        $this->{$field} = unserialize($info['serialized default']);
      }
      else {
        if (isset($info['default'])) {
          $this->{$field} = $info['default'];
        }
        else {
          $this->{$field} = '';
        }
      }
    }
  }
}