You are here

static function flag_flag::factory_by_row in Flag 7.3

Same name and namespace in other branches
  1. 5 flag.inc \flag_flag::factory_by_row()
  2. 6.2 flag.inc \flag_flag::factory_by_row()
  3. 6 flag.inc \flag_flag::factory_by_row()
  4. 7.2 flag.inc \flag_flag::factory_by_row()

Creates a flag from a database row. Returns it.

This is static method.

The reason this isn't a non-static instance method --like Views's init()-- is because the class to instantiate changes according to the 'entity_type' database column. This design pattern is known as the "Single Table Inheritance".

1 call to flag_flag::factory_by_row()
flag_get_flags in ./flag.module
List all flags available.

File

includes/flag/flag_flag.inc, line 120
Contains the flag_flag class. Flag type classes use an 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

static function factory_by_row($row) {
  $flag = flag_create_handler($row->entity_type);

  // Lump all data unto the object...
  foreach ($row as $field => $value) {
    $flag->{$field} = $value;
  }

  // ...but skip the following two.
  unset($flag->options, $flag->type);

  // Populate the options with the defaults.
  $options = (array) unserialize($row->options);
  $options += $flag
    ->options();

  // Make the unserialized options accessible as normal properties.
  foreach ($options as $option => $value) {
    $flag->{$option} = $value;
  }
  if (!empty($row->type)) {

    // The loop loading from the database should further populate this
    // property.
    $flag->types[] = $row->type;
  }
  return $flag;
}