User login

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.