A few left-over notes from DGD7 DBTNG select info from block table
Also, the isset variables discovery!
Note that non-dynamic select queries such as these should NOT use the DBTNG query builder. The below should be instead SQL statements with db_query.
<?php
$stats['total'] = $select
->fields('block')
->condition('theme', $theme)
->countQuery()
->execute()
->fetchField();
// db_select('block')->condition('theme', $theme)->countQuery()->execute()->fetchField();
$query = db_select('block') // $select
->fields('block', array('theme'))
->condition('region', -1, '<>');
// ->condition('theme', $theme);
$count_alias = $query->addExpression('COUNT(bid)', 'num');
// ->countQuery()
$result = $query
// ->groupBy('region')
->groupBy('theme')
->execute()
->fetchAll();
$stats['by_theme'] = $result;
return $stats;
?>
Status message
Debug: array ( 'total' => '16', 'by_theme' => array ( 0 => stdClass::__set_state(array( 'theme' => 'bartik', 'num' => '8', )), 1 => stdClass::__set_state(array( 'theme' => 'seven', 'num' => '6', )), ), ) in _xray_help_admin_structure() (line 40 of /home/ben/workspace/dgd7all/sites/default/modules/xray/xray.module).
Much nicer:
For the count all-blocks (not overcounting for more than one theme) query in one step:
<?php
db_select('block')->condition('theme', $theme)->countQuery()->execute()->fetchField();
?>
These isset statements are happy when handed a string!\
<?php
$variables = "A string.";
if (isset($variables['#theme']) || isset($variables['#theme_wrappers'])) {
debug("It's true!");
}
?>
Crazy, but we see: It's true.
I guess #theme resolves to the numeral one, and a string is treated as an array of characters, and as long as it has a second character (the 1 position) this comes out true.
// If not provided, set the theme to the default.
if (!$theme) {
$theme = variable_get('theme_default', 'bartik');
}
Comments
Post new comment