function flag_get_flags in Flag 5
Same name and namespace in other branches
- 6.2 flag.module \flag_get_flags()
- 6 flag.module \flag_get_flags()
- 7.3 flag.module \flag_get_flags()
- 7.2 flag.module \flag_get_flags()
List all flags available.
If node type or account are entered, a list of all possible flags will be returned.
Parameters
$content_type: Optional. The type of content for which to load the flags. Usually 'node'.
$content_subtype: Optional. The node type for which to load the flags.
$account: Optional. The user accont to filter available flags. If not set, all flags for will this node will be returned.
$reset: Optional. Reset the internal query cache.
Return value
$flags An array of the structure [fid] = flag_object.
15 calls to flag_get_flags()
- flag_actions_add_form in ./
flag_actions.module - Modified version of the Add action form that redirects back to the flag list.
- flag_admin_page in includes/
flag.admin.inc - Flag administration page. Display a list of existing flags.
- flag_form_alter in ./
flag.module - Implementation of hook_form_alter().
- flag_get_flag in ./
flag.module - Load a single flag either by name or by flag ID.
- flag_link in ./
flag.module - Implementation of hook_link().
File
- ./
flag.module, line 913 - The Flag module.
Code
function flag_get_flags($content_type = NULL, $content_subtype = NULL, $account = NULL, $reset = FALSE) {
static $flags;
// Retrieve a list of all flags, regardless of the parameters.
if (!isset($flags) || $reset) {
$flags = array();
// Database flags.
$result = db_query("SELECT f.*, fn.type FROM {flags} f LEFT JOIN {flag_types} fn ON fn.fid = f.fid");
while ($row = db_fetch_object($result)) {
if (!isset($flags[$row->name])) {
$flags[$row->name] = flag_flag::factory_by_row($row);
}
else {
$flags[$row->name]->types[] = $row->type;
}
}
// Add code-based flags provided by modules.
$default_flags = flag_get_default_flags();
foreach ($default_flags as $name => $default_flag) {
// Insert new enabled flags into the database to give them an FID.
if ($default_flag->status && !isset($flags[$name])) {
$default_flag
->save();
$flags[$name] = $default_flag;
}
if (isset($flags[$name])) {
// Ensure overridden flags are associated with their parent module.
$flags[$name]->module = $default_flag->module;
// Update the flag with any properties that are "locked" by the code version.
if (isset($default_flag->locked)) {
$flags[$name]->locked = $default_flag->locked;
foreach ($default_flag->locked as $property) {
$flags[$name]->{$property} = $default_flag->{$property};
}
}
}
}
}
// Make a variable copy to filter types and account.
$filtered_flags = $flags;
// Filter out flags based on type and subtype.
if (isset($content_type) || isset($content_subtype)) {
foreach ($filtered_flags as $name => $flag) {
if (!flag_content_enabled($flag, $content_type, $content_subtype)) {
unset($filtered_flags[$name]);
}
}
}
// Filter out flags based on account permissions.
if (isset($account) && $account->uid != 1) {
foreach ($filtered_flags as $name => $flag) {
if (!flag_access($flag, $account)) {
unset($filtered_flags[$name]);
}
}
}
return $filtered_flags;
}