/** * @group AppKit */ public function testSubSort() { $test = array(array('field1' => 'Z', 'field2' => 0), array('field1' => 'Y', 'field2' => 1), array('field1' => 'X', 'field2' => 2), array('field1' => 'W', 'field2' => 3), array('field1' => 'V', 'field2' => 4)); AppKitArrayUtil::subSort($test, 'field1', '<'); $test = array_values($test); // RESET KEYS $this->assertEquals('V', $test[0]['field1']); $this->assertEquals(4, $test[0]['field2']); $this->assertEquals('Z', $test[4]['field1']); $this->assertEquals(0, $test[4]['field2']); }
/** * Get all categories from system * @param boolean $get_all * @param boolean $show_invisible * @return array */ public function getCategories($get_all = false, $show_invisible = false) { static $cronks = null; $isCategoryAdmin = $this->agaviUser->hasCredential('icinga.cronk.category.admin'); if ($cronks === null) { $cronks = $this->getCronkModel()->getCronks($get_all); } if ($show_invisible == true && !$isCategoryAdmin) { $show_invisible = false; } $categories = $this->getXmlCategories(); $categories = (array) $this->getDbCategories($get_all) + $categories; AppKitArrayUtil::subSort($categories, 'title'); AppKitArrayUtil::subSort($categories, 'position'); foreach ($categories as $cid => $category) { $count = 0; /** * This implementation is cached and more fast than * using the CronksData model * @todo More fast, request needs 300-400ms, too slow! */ foreach ($cronks as $cronk) { if (AppKitArrayUtil::matchAgainstStringList($cronk['categories'], $cid)) { $count++; } } $categories[$cid]['count_cronks'] = $count; if (!$category['visible'] && !$show_invisible) { unset($categories[$cid]); } } return $categories; }