You are here

function views_db_object::export_row in Views (for Drupal 7) 6.2

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

Export a loaded row, such as an argument, field or the view itself to PHP code.

Parameters

$identifier: The variable to assign the PHP code for this object to.

$indent: An optional indentation for prettifying nested code.

1 call to views_db_object::export_row()
view::export in includes/view.inc
Export a view as PHP code.

File

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

Class

views_db_object
Base class for views' database objects.

Code

function export_row($identifier = NULL, $indent = '') {
  if (!$identifier) {
    $identifier = $this->db_table;
  }
  $schema = drupal_get_schema($this->db_table);
  $output = $indent . '$' . $identifier . ' = new ' . get_class($this) . ";\n";

  // Go through our schema and build correlations.
  foreach ($schema['fields'] as $field => $info) {
    if (!empty($info['no export'])) {
      continue;
    }
    if (!isset($this->{$field})) {
      if (isset($info['default'])) {
        $this->{$field} = $info['default'];
      }
      else {
        $this->{$field} = '';
      }

      // serialized defaults must be set as serialized.
      if (isset($info['serialize'])) {
        $this->{$field} = unserialize(db_decode_blob($this->{$field}));
      }
    }
    $value = $this->{$field};
    if ($info['type'] == 'int') {
      $value = $info['size'] == 'tiny' ? (bool) $value : (int) $value;
    }
    $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . views_var_export($value, $indent) . ";\n";
  }
  return $output;
}