/** * Tests the sorting of an array of arrays by key. */ public function test_asort_array_of_arrays_by_key() { $array = array('a' => array('name' => 'bravo'), 'b' => array('name' => 'charlie'), 'c' => array('name' => 'alpha')); $this->assertSame(array('a', 'b', 'c'), array_keys($array)); $this->assertTrue(core_collator::asort_array_of_arrays_by_key($array, 'name')); $this->assertSame(array('c', 'a', 'b'), array_keys($array)); $array = array('a' => array('name' => 'b'), 'b' => array('name' => 1), 'c' => array('name' => 0)); $this->assertSame(array('a', 'b', 'c'), array_keys($array)); $this->assertTrue(core_collator::asort_array_of_arrays_by_key($array, 'name')); $this->assertSame(array('c', 'b', 'a'), array_keys($array)); $array = array('a' => array('name' => 'áb'), 'b' => array('name' => 'ab'), 1 => array('name' => 'aa'), 'd' => array('name' => 'cc'), 0 => array('name' => 'Áb')); $this->assertSame(array('a', 'b', 1, 'd', 0), array_keys($array)); $this->assertTrue(core_collator::asort_array_of_arrays_by_key($array, 'name')); $this->assertSame(array(1, 'b', 'a', 0, 'd'), array_keys($array)); $this->assertSame(array(1 => array('name' => 'aa'), 'b' => array('name' => 'ab'), 'a' => array('name' => 'áb'), 0 => array('name' => 'Áb'), 'd' => array('name' => 'cc')), $array); }
/** * Displays definition summaries * * @param array $definitions * @return string HTML */ public function definition_summaries(array $definitions, context $context) { $table = new html_table(); $table->head = array(get_string('definition', 'cache'), get_string('mode', 'cache'), get_string('component', 'cache'), get_string('area', 'cache'), get_string('mappings', 'cache'), get_string('sharing', 'cache'), get_string('actions', 'cache')); $table->colclasses = array('definition', 'mode', 'component', 'area', 'mappings', 'sharing', 'actions'); $table->data = array(); core_collator::asort_array_of_arrays_by_key($definitions, 'name'); $none = new lang_string('none', 'cache'); foreach ($definitions as $id => $definition) { $actions = cache_administration_helper::get_definition_actions($context, $definition); $htmlactions = array(); foreach ($actions as $action) { $action['url']->param('definition', $id); $htmlactions[] = $this->output->action_link($action['url'], $action['text']); } if (!empty($definition['mappings'])) { $mapping = join(', ', $definition['mappings']); } else { $mapping = '<em>' . $none . '</em>'; } $row = new html_table_row(array($definition['name'], get_string('mode_' . $definition['mode'], 'cache'), $definition['component'], $definition['area'], $mapping, join(', ', $definition['selectedsharingoption']), join(', ', $htmlactions))); $row->attributes['class'] = 'definition-' . $definition['component'] . '-' . $definition['area']; $table->data[] = $row; } $html = html_writer::start_tag('div', array('id' => 'core-cache-definition-summaries')); $html .= $this->output->heading(get_string('definitionsummaries', 'cache'), 3); $html .= html_writer::table($table); $url = new moodle_url('/cache/admin.php', array('action' => 'rescandefinitions', 'sesskey' => sesskey())); $link = html_writer::link($url, get_string('rescandefinitions', 'cache')); $html .= html_writer::tag('div', $link, array('id' => 'core-cache-rescan-definitions')); $html .= html_writer::end_tag('div'); return $html; }