Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Documentation
Docs Publisher
Commits
7a21d0d4
Commit
7a21d0d4
authored
Feb 02, 2017
by
Sean Madsen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding book sorting functionality to close
#31
parent
dac7975d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
app/config/books/dev.yml
app/config/books/dev.yml
+2
-1
app/config/books/user.yml
app/config/books/user.yml
+1
-0
src/AppBundle/Utils/BookLoader.php
src/AppBundle/Utils/BookLoader.php
+26
-0
No files found.
app/config/books/dev.yml
View file @
7a21d0d4
name
:
Developer guide
weight
:
10
description
:
For CiviCRM developers
langs
:
en
:
repo
:
'
https://github.com/civicrm/civicrm-dev-docs'
latest
:
master
#
stable: master
stable
:
master
app/config/books/user.yml
View file @
7a21d0d4
name
:
User guide
weight
:
-100
description
:
Aimed at day to day users of CiviCRM.
langs
:
en
:
...
...
src/AppBundle/Utils/BookLoader.php
View file @
7a21d0d4
...
...
@@ -26,6 +26,31 @@ class BookLoader
$this
->
configDir
=
$configDir
;
}
/**
* Compares 2 books, side by side, for the purpose of sorting an array of
* books with uasort()
* @param array $bookA
* @param array $bookB
* @return int
*/
private
function
compareBooksBySortOrder
(
$bookA
,
$bookB
)
{
$aWeight
=
isset
(
$bookA
[
'weight'
])
?
$bookA
[
'weight'
]
:
0
;
$bWeight
=
isset
(
$bookB
[
'weight'
])
?
$bookB
[
'weight'
]
:
0
;
if
(
$aWeight
==
$bWeight
)
{
return
strnatcmp
(
$bookA
[
'name'
],
$bookB
[
'name'
]);
}
return
$aWeight
-
$bWeight
;
}
/**
* Modifies the internal book cache by sorting the array of books correctly
*/
private
function
cacheSort
()
{
if
(
isset
(
$this
->
cache
)
)
{
uasort
(
$this
->
cache
,
[
$this
,
'compareBooksBySortOrder'
]);
}
}
/**
* @return array
*/
...
...
@@ -40,6 +65,7 @@ class BookLoader
$books
[
basename
(
$file
,
'.yml'
)]
=
$yaml
->
parse
(
file_get_contents
(
"
$file
"
));
}
$this
->
cache
=
$books
;
$this
->
cacheSort
();
}
return
$this
->
cache
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment