Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
b1a9b01e
Commit
b1a9b01e
authored
Jan 16, 2011
by
Petr Skoda
Browse files
refactor chapter title proccessing
parent
97619edd
Changes
7
Hide whitespace changes
Inline
Side-by-side
delete.php
View file @
b1a9b01e
...
...
@@ -70,7 +70,7 @@ if ($confirm) { // the operation was confirmed.
add_to_log
(
$course
->
id
,
'course'
,
'update mod'
,
'../mod/book/view.php?id='
.
$cm
->
id
,
'book '
.
$book
->
id
);
add_to_log
(
$course
->
id
,
'book'
,
'update'
,
'view.php?id='
.
$cm
->
id
,
$book
->
id
,
$cm
->
id
);
book_preload_chapters
(
$book
->
id
);
//fix structure
book_preload_chapters
(
$book
);
//fix structure
redirect
(
'view.php?id='
.
$cm
->
id
);
}
...
...
edit.php
View file @
b1a9b01e
...
...
@@ -102,7 +102,7 @@ if ($mform->is_cancelled()) {
add_to_log
(
$course
->
id
,
'book'
,
'update'
,
'view.php?id='
.
$cm
->
id
.
'&chapterid='
.
$data
->
id
,
$book
->
id
,
$cm
->
id
);
}
book_preload_chapters
(
$book
->
id
);
// fix structure
book_preload_chapters
(
$book
);
// fix structure
redirect
(
"view.php?id=
$cm->id
&chapterid=
$data->id
"
);
}
...
...
import.php
View file @
b1a9b01e
...
...
@@ -107,7 +107,7 @@ if ($mform->is_cancelled()) {
print_box_start('generalbox boxaligncenter centerpara');
echo '<strong>'.get_string('importing', 'book').':</strong>';
echo '<table cellpadding="2" cellspacing="2" border="1">';
book_preload_chapters($book
->id
); // fix structure
book_preload_chapters($book); // fix structure
foreach($refs as $ref) {
$chapter = book_read_chapter($coursebase, $ref);
if ($chapter) {
...
...
locallib.php
View file @
b1a9b01e
...
...
@@ -39,9 +39,9 @@ require_once($CFG->libdir.'/filelib.php');
* @param $cm
* @return array of id=>chapter
*/
function
book_preload_chapters
(
$book
id
)
{
function
book_preload_chapters
(
$book
)
{
global
$DB
;
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$bookid
),
'pagenum'
,
'id, pagenum, subchapter, title, hidden'
);
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
),
'pagenum'
,
'id, pagenum, subchapter, title, hidden'
);
if
(
!
$chapters
)
{
return
array
();
}
...
...
@@ -71,7 +71,11 @@ function book_preload_chapters($bookid) {
$chapters
[
$prev
]
->
next
=
$ch
->
id
;
}
if
(
$ch
->
hidden
)
{
$ch
->
number
=
null
;
if
(
$book
->
numbering
==
BOOK_NUM_NUMBERS
)
{
$ch
->
number
=
'x'
;
}
else
{
$ch
->
number
=
null
;
}
}
else
{
$i
++
;
$ch
->
number
=
$i
;
...
...
@@ -96,7 +100,11 @@ function book_preload_chapters($bookid) {
$ch
->
hidden
=
1
;
}
if
(
$ch
->
hidden
)
{
$ch
->
number
=
null
;
if
(
$book
->
numbering
==
BOOK_NUM_NUMBERS
)
{
$ch
->
number
=
'x'
;
}
else
{
$ch
->
number
=
null
;
}
}
else
{
$j
++
;
$ch
->
number
=
$j
;
...
...
@@ -112,6 +120,26 @@ function book_preload_chapters($bookid) {
return
$chapters
;
}
function
book_get_chapter_title
(
$chid
,
$chapters
,
$book
,
$context
)
{
$ch
=
$chapters
[
$chid
];
$title
=
trim
(
format_string
(
$ch
->
title
,
true
,
array
(
'context'
=>
$context
)));
$numbers
=
array
();
if
(
$book
->
numbering
==
BOOK_NUM_NUMBERS
)
{
if
(
$ch
->
parent
and
$chapters
[
$ch
->
parent
]
->
number
)
{
$numbers
[]
=
$chapters
[
$ch
->
parent
]
->
number
;
}
if
(
$ch
->
number
)
{
$numbers
[]
=
$ch
->
number
;
}
}
if
(
$numbers
)
{
$title
=
implode
(
'.'
,
$numbers
)
.
' '
.
$title
;
}
return
$title
;
}
/**
* General logging to table
* @param string $str1
...
...
move.php
View file @
b1a9b01e
...
...
@@ -182,6 +182,6 @@ if (!$nothing) {
add_to_log
(
$course
->
id
,
'course'
,
'update mod'
,
'../mod/book/view.php?id='
.
$cm
->
id
,
'book '
.
$book
->
id
);
add_to_log
(
$course
->
id
,
'book'
,
'update'
,
'view.php?id='
.
$cm
->
id
,
$book
->
id
,
$cm
->
id
);
book_preload_chapters
(
$book
->
id
);
// fix structure
book_preload_chapters
(
$book
);
// fix structure
redirect
(
'view.php?id='
.
$cm
->
id
.
'&chapterid='
.
$chapter
->
id
);
show.php
View file @
b1a9b01e
...
...
@@ -69,6 +69,6 @@ if (!$chapter->subchapter) {
add_to_log
(
$course
->
id
,
'course'
,
'update mod'
,
'../mod/book/view.php?id='
.
$cm
->
id
,
'book '
.
$book
->
id
);
add_to_log
(
$course
->
id
,
'book'
,
'update'
,
'view.php?id='
.
$cm
->
id
,
$book
->
id
,
$cm
->
id
);
book_preload_chapters
(
$book
->
id
);
// fix structure
book_preload_chapters
(
$book
);
// fix structure
redirect
(
'view.php?id='
.
$cm
->
id
.
'&chapterid='
.
$chapter
->
id
);
view.php
View file @
b1a9b01e
...
...
@@ -68,7 +68,7 @@ if ($allowedit) {
}
/// read chapters
$chapters
=
book_preload_chapters
(
$book
->
id
);
$chapters
=
book_preload_chapters
(
$book
);
if
(
$allowedit
and
!
$chapters
)
{
redirect
(
'edit.php?cmid='
.
$cm
->
id
);
//no chapters - add new one
...
...
@@ -160,9 +160,6 @@ if ($nextid) {
$chnavigation
.
=
'<a title="'
.
get_string
(
'navexit'
,
'book'
)
.
'" href="../../course/view.php?id='
.
$course
->
id
.
'#section-'
.
$sec
.
'"><img src="'
.
$OUTPUT
->
pix_url
(
'nav_exit'
,
'mod_book'
)
.
'" class="bigicon" alt="'
.
get_string
(
'navexit'
,
'book'
)
.
'" /></a>'
;
}
// prepare $toc and $currtitle, $currsubtitle
list
(
$toc
,
$currtitle
,
$currsubtitle
,
$titles
)
=
book_get_toc
(
$chapters
,
$chapter
,
$book
,
$cm
,
$edit
,
0
);
// =====================================================
// Book display HTML code
// =====================================================
...
...
@@ -173,11 +170,15 @@ echo '<div class="booknav">'.$chnavigation.'</div>';
// chapter itself
echo
$OUTPUT
->
box_start
(
'generalbox book_content'
);
if
(
!
$book
->
customtitles
)
{
if
(
!
$chapter
->
subchapter
)
{
echo
'<p class="book_chapter_title">'
.
$currtitle
.
'</p>'
;
}
else
{
echo
'<p class="book_chapter_title">'
.
$currtitle
.
'<br />'
.
$currsubtitle
.
'</p>'
;
}
$hidden
=
$chapter
->
hidden
?
'dimmed_text'
:
''
;
if
(
!
$chapter
->
subchapter
)
{
$currtitle
=
book_get_chapter_title
(
$chapter
->
id
,
$chapters
,
$book
,
$context
);
echo
'<p class="book_chapter_title '
.
$hidden
.
'">'
.
$currtitle
.
'</p>'
;
}
else
{
$currtitle
=
book_get_chapter_title
(
$chapters
[
$chapter
->
id
]
->
parent
,
$chapters
,
$book
,
$context
);
$currsubtitle
=
book_get_chapter_title
(
$chapter
->
id
,
$chapters
,
$book
,
$context
);
echo
'<p class="book_chapter_title '
.
$hidden
.
'">'
.
$currtitle
.
'<br />'
.
$currsubtitle
.
'</p>'
;
}
}
$chaptertext
=
file_rewrite_pluginfile_urls
(
$chapter
->
content
,
'pluginfile.php'
,
$context
->
id
,
'mod_book'
,
'chapter'
,
$chapter
->
id
);
echo
format_text
(
$chaptertext
,
$chapter
->
contentformat
,
array
(
'noclean'
=>
true
,
'context'
=>
$context
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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