You are here

function flag_flag::insert in Flag 6

Same name and namespace in other branches
  1. 5 flag.inc \flag_flag::insert()
  2. 6.2 flag.inc \flag_flag::insert()
  3. 7.3 includes/flag/flag_flag.inc \flag_flag::insert()
  4. 7.2 flag.inc \flag_flag::insert()

Saves a new flag to the database. Better use save().

1 call to flag_flag::insert()
flag_flag::save in ./flag.inc
Saves a flag to the database. It is a wrapper around update() and insert().

File

./flag.inc, line 712
Implements various flags. Uses object oriented style inspired by that of Views 2.

Class

flag_flag
This abstract class represents a flag, or, in Views 2 terminology, "a handler".

Code

function insert() {
  if (function_exists('db_last_insert_id')) {

    // Drupal 6. We have a 'serial' primary key.
    db_query("INSERT INTO {flags} (content_type, name, title, roles, global, options) VALUES ('%s', '%s', '%s', '%s', %d, '%s')", $this->content_type, $this->name, $this->title, implode(',', $this->roles), $this->global, $this
      ->get_serialized_options());
    $this->fid = db_last_insert_id('flags', 'fid');
  }
  else {

    // Drupal 5. We have an 'integer' primary key.
    $this->fid = db_next_id('{flags}_fid');
    db_query("INSERT INTO {flags} (fid, content_type, name, title, roles, global, options) VALUES (%d, '%s', '%s', '%s', '%s', %d, '%s')", $this->fid, $this->content_type, $this->name, $this->title, implode(',', $this->roles), $this->global, $this
      ->get_serialized_options());
  }
  foreach ($this->types as $type) {
    db_query("INSERT INTO {flag_types} (fid, type) VALUES (%d, '%s')", $this->fid, $type);
  }
}