You are here

function _panels_page_insert in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_page/panels_page.admin.inc \_panels_page_insert()

Insert a new panel page into the database.

1 call to _panels_page_insert()
panels_page_save in panels_page/panels_page.write.inc
Main entry point for panels_page save functions.

File

panels_page/panels_page.write.inc, line 68
panels_page.write.inc

Code

function _panels_page_insert(&$panel_page) {
  $fields = $types = $values = array();

  // Save the primary display, thus creating a $display->did.
  panels_save_display($panel_page->primary);
  $schema = drupal_get_schema('panels_page');
  $clone = drupal_clone($panel_page);
  $clone->did = $panel_page->primary->did;
  foreach ($schema['fields'] as $field => $info) {
    if (isset($panel_page->{$field}) && $info['type'] != 'serial') {
      $fields[] = $field;
      $placeholders[] = db_type_placeholder($info['type']);
      $values[] = _panels_page_save_value($info, $clone->{$field});
    }
  }

  // Build the query adding the new pid and did.
  $sql = 'INSERT INTO {panels_page} (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $placeholders) . ')';
  db_query($sql, $values);
  $panel_page->pid = db_last_insert_id('panels_page', 'pid');

  // Return the pid for convenience.
  return $panel_page->pid;
}