BUGFIX: Resolve navigation sorting using natural sort

This commit is contained in:
Saophalkun Ponlu 2010-09-05 02:29:07 +00:00
parent a069dbd9d9
commit 6ba14bed75
7 changed files with 26 additions and 10 deletions

View File

@ -384,7 +384,8 @@ class DocumentationParser {
/** /**
* Return the children from a given module. Used for building the tree of the page * Return the children from a given module sorted by Title using natural ordering.
* It is used for building the tree of the page.
* *
* @param String module name * @param String module name
* *
@ -393,6 +394,7 @@ class DocumentationParser {
public static function get_pages_from_folder($folder) { public static function get_pages_from_folder($folder) {
$handle = opendir($folder); $handle = opendir($folder);
$output = new DataObjectSet(); $output = new DataObjectSet();
$files = array();
if($handle) { if($handle) {
$extensions = DocumentationService::get_valid_extensions(); $extensions = DocumentationService::get_valid_extensions();
@ -400,6 +402,13 @@ class DocumentationParser {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
if(!in_array($file, $ignore)) { if(!in_array($file, $ignore)) {
$files[] = $file;
}
}
natsort($files);
foreach($files as $file) {
$file = strtolower($file); $file = strtolower($file);
$clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file; $clean = ($pos = strrpos($file, '.')) ? substr($file, 0, $pos) : $file;
@ -411,7 +420,6 @@ class DocumentationParser {
))); )));
} }
} }
}
return $output; return $output;
} }

View File

@ -211,6 +211,14 @@ class DocumentationParserTest extends SapphireTest {
$this->assertContains('subfolder', $pages->column('Filename'), 'Foldername'); $this->assertContains('subfolder', $pages->column('Filename'), 'Foldername');
$this->assertContains('test', $pages->column('Filename'), 'Filename'); $this->assertContains('test', $pages->column('Filename'), 'Filename');
$this->assertNotContains('_images', $pages->column('Filename'), 'Ignored files'); $this->assertNotContains('_images', $pages->column('Filename'), 'Ignored files');
// test the order of pages
$pages = DocumentationParser::get_pages_from_folder(BASE_PATH . '/sapphiredocs/tests/docs/en/sort');
$this->assertEquals(
array('1 basic', '2 intermediate', '3 advanced', '10 some page', '21 another page'),
$pages->column('Title')
);
} }
} }

View File

View File

View File

View File

View File