Same name and namespace in other branches
  1. 7.x-3.x 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 2106
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') {
      if (isset($info['size']) && $info['size'] == 'tiny') {
        $value = (bool) $value;
      }
      else {
        $value = (int) $value;
      }
    }
    $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . views_var_export($value, $indent) . ";\n";
  }
  return $output;
}