You are here

function panels_views_save in Panels 5.2

Write a view pane to the database.

1 call to panels_views_save()
panels_views_edit_view_form_submit in panels_views/panels_views.module
Submit the edit form and save the values.

File

panels_views/panels_views.module, line 1316
panels_views.module

Code

function panels_views_save($panel_view) {
  $fields = $types = $values = $pairs = array();

  // If pvid is empty, this is an insert, otherwise an update.
  $insert = empty($panel_view->pvid);

  // Build arrays of fields and types (resp. pairs of both) and of values.
  foreach (panels_views_pane_fields() as $field => $data) {
    $primary = !empty($data['primary']);

    // Skip primary key and empty values.
    if (!$primary && isset($panel_view->{$field})) {
      if ($insert) {
        $fields[] = $field;
        $types[] = $data['arg'];
      }
      else {
        $pairs[] = "{$field} = {$data['arg']}";
      }

      // Build the $values array, serializing some fields.
      $serialize = !empty($data['serialize']);
      $values[] = $serialize ? serialize($panel_view->{$field}) : $panel_view->{$field};
    }
  }
  if ($insert) {

    // Determine the new primary key.
    $panel_view->pvid = db_next_id('{panels_views}_pvid');

    // Build the query adding the new primary key.
    $sql = 'INSERT INTO {panels_views} (' . implode(', ', $fields) . ', pvid) VALUES (' . implode(', ', $types) . ', %d)';
  }
  else {

    // Build the query filtering by the primary key.
    $sql = 'UPDATE {panels_views} SET ' . implode(', ', $pairs) . ' WHERE pvid = %d';
  }
  $values[] = $panel_view->pvid;
  db_query($sql, $values);
}