/** * Output a menu.. * */ public function menu(Twig_Environment $env, $identifier = "") { global $app; $menus = $app['config']['menu']; if (!empty($identifier) && isset($menus[$identifier])) { $name = strtolower($identifier); $menu = $menus[$identifier]; } else { $name = strtolower(util::array_first_key($menus)); $menu = util::array_first($menus); } foreach ($menu as $key => $item) { $menu[$key] = $this->menu_helper($item); if (isset($item['submenu'])) { foreach ($item['submenu'] as $subkey => $subitem) { $menu[$key]['submenu'][$subkey] = $this->menu_helper($subitem); } } } // echo "<pre>\n" . util::var_dump($menu, true) . "</pre>\n"; echo $env->render('_sub_menu.twig', array('name' => $name, 'menu' => $menu)); }
/** * Get the taxonomy for one or more units of content, return the array with the taxonomy attached. * * @param array $content * * @return array $content */ protected function getTaxonomy($content) { $tablename = $this->prefix . "taxonomy"; $ids = util::array_pluck($content, 'id'); if (empty($ids)) { return $content; } // Get the contenttype from first $content $contenttype = $content[util::array_first_key($content)]->contenttype['slug']; $taxonomytypes = array_keys($this->config['taxonomy']); $query = sprintf("SELECT * FROM {$tablename} WHERE content_id IN (%s) AND contenttype=%s AND taxonomytype IN ('%s')", implode(", ", $ids), $this->db->quote($contenttype), implode("', '", $taxonomytypes)); $rows = $this->db->fetchAll($query); foreach ($rows as $key => $row) { $content[$row['content_id']]->setTaxonomy($row['taxonomytype'], $row['slug']); } }
public function test_array_first_key() { $test = array('a' => array('a' => 'b', 'c' => 'd')); $this->assertEquals('a', util::array_first_key(util::array_get($test, 'a'))); }