function flag_flag::factory_by_row in Flag 5
Same name and namespace in other branches
- 6.2 flag.inc \flag_flag::factory_by_row()
- 6 flag.inc \flag_flag::factory_by_row()
- 7.3 includes/flag/flag_flag.inc \flag_flag::factory_by_row()
- 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 'content_type' database column. This design pattern is known as the "Single Table Inheritance".
@static
1 call to flag_flag::factory_by_row()
- flag_get_flags in ./
flag.module - List all flags available.
File
- ./
flag.inc, line 128 - 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 factory_by_row($row) {
$flag = flag_create_handler($row->content_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);
$options = (array) unserialize($row->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;
}
$flag->roles = empty($row->roles) ? array() : explode(',', $row->roles);
return $flag;
}