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
7f6e3eef
Commit
7f6e3eef
authored
Oct 01, 2013
by
Frederic Massart
Browse files
MDL-40060 mod_book: Replace add_to_log with events
parent
7abaa052
Changes
26
Hide whitespace changes
Inline
Side-by-side
mod/book/classes/event/chapter_created.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book chapter created event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book chapter created event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
chapter_created
extends
\
core\event\base
{
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"The chapter
$this->objectid
of the book
$this->context
->instanceid has been created."
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
array
(
$this
->
courseid
,
'book'
,
'add chapter'
,
'view.php?id='
.
$this
->
context
->
instanceid
.
'&chapterid='
.
$this
->
objectid
,
$this
->
objectid
,
$this
->
context
->
instanceid
);
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_chapter_created'
,
'mod_book'
);
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/view.php'
,
array
(
'id'
=>
$this
->
context
->
instanceid
,
'chapterid'
=>
$this
->
objectid
));
}
/**
* Init method.
*
* @return void
*/
protected
function
init
()
{
$this
->
data
[
'crud'
]
=
'c'
;
$this
->
data
[
'level'
]
=
self
::
LEVEL_TEACHING
;
$this
->
data
[
'objecttable'
]
=
'book_chapters'
;
}
}
mod/book/classes/event/chapter_deleted.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book chapter deleted event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book chapter deleted event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
chapter_deleted
extends
\
core\event\base
{
/**
* Legacy log data.
*
* @var array
*/
protected
$legacylogdata
;
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"The chapter
$this->objectid
of the book
$this->context
->instanceid has been deleted."
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
$this
->
legacylogdata
;
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_chapter_deleted'
,
'mod_book'
);
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/view.php'
,
array
(
'id'
=>
$this
->
context
->
instanceid
));
}
/**
* Init method.
*
* @return void
*/
protected
function
init
()
{
$this
->
data
[
'crud'
]
=
'd'
;
$this
->
data
[
'level'
]
=
self
::
LEVEL_TEACHING
;
$this
->
data
[
'objecttable'
]
=
'book_chapters'
;
}
/**
* Set the legacy event log data.
*
* @return array|null
*/
public
function
set_legacy_logdata
(
$legacydata
)
{
$this
->
legacylogdata
=
$legacydata
;
}
}
mod/book/classes/event/chapter_updated.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book chapter updated event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book chapter updated event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
chapter_updated
extends
\
core\event\base
{
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"The chapter
$this->objectid
of the book
$this->context
->instanceid has been updated."
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
array
(
$this
->
courseid
,
'book'
,
'update chapter'
,
'view.php?id='
.
$this
->
context
->
instanceid
.
'&chapterid='
.
$this
->
objectid
,
$this
->
objectid
,
$this
->
context
->
instanceid
);
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_chapter_updated'
,
'mod_book'
);
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/view.php'
,
array
(
'id'
=>
$this
->
context
->
instanceid
,
'chapterid'
=>
$this
->
objectid
));
}
/**
* Init method.
*
* @return void
*/
protected
function
init
()
{
$this
->
data
[
'crud'
]
=
'u'
;
$this
->
data
[
'level'
]
=
self
::
LEVEL_TEACHING
;
$this
->
data
[
'objecttable'
]
=
'book_chapters'
;
}
}
mod/book/classes/event/chapter_viewed.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book chapter viewed event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book chapter viewed event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
chapter_viewed
extends
\
core\event\content_viewed
{
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"The user
$this->userid
has viewed the chapter
$this->objectid
of book module
$this->context
->instanceid"
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
array
(
$this
->
courseid
,
'book'
,
'view chapter'
,
'view.php?id='
.
$this
->
context
->
instanceid
.
'&chapterid='
.
$this
->
objectid
,
$this
->
objectid
,
$this
->
context
->
instanceid
);
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_chapter_viewed'
,
'mod_book'
);
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/view.php'
,
array
(
'id'
=>
$this
->
context
->
instanceid
,
'chapterid'
=>
$this
->
objectid
));
}
/**
* Init method.
*
* @return void
*/
protected
function
init
()
{
$this
->
data
[
'crud'
]
=
'r'
;
$this
->
data
[
'level'
]
=
self
::
LEVEL_PARTICIPATING
;
$this
->
data
[
'objecttable'
]
=
'book_chapters'
;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected
function
validate_data
()
{
// Hack to please the parent class. 'view chapter' was the key used in old add_to_log().
$this
->
data
[
'other'
][
'content'
]
=
'view chapter'
;
parent
::
validate_data
();
}
}
mod/book/classes/event/course_module_viewed.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book course module viewed event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book course module viewed event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
course_module_viewed
extends
\
core\event\content_viewed
{
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"The user
$this->userid
has viewed the book
$this->objectid
."
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
array
(
$this
->
courseid
,
'book'
,
'view'
,
'view.php?id='
.
$this
->
context
->
instanceid
,
$this
->
objectid
,
$this
->
context
->
instanceid
);
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_course_module_viewed'
,
'mod_book'
);
}
/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/view.php'
,
array
(
'id'
=>
$this
->
context
->
instanceid
));
}
/**
* Init method.
*
* @return void
*/
protected
function
init
()
{
$this
->
data
[
'crud'
]
=
'r'
;
$this
->
data
[
'level'
]
=
self
::
LEVEL_PARTICIPATING
;
$this
->
data
[
'objecttable'
]
=
'book'
;
}
/**
* Custom validation.
*
* @throws \coding_exception
* @return void
*/
protected
function
validate_data
()
{
// Hack to please the parent class. 'view' was the key used in old add_to_log().
$this
->
data
[
'other'
][
'content'
]
=
'view'
;
parent
::
validate_data
();
}
}
mod/book/classes/event/instances_list_viewed.php
0 → 100644
View file @
7f6e3eef
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* mod_book instances list viewed event.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace
mod_book\event
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
/**
* mod_book instances list viewed event class.
*
* @package mod_book
* @copyright 2013 Frédéric Massart
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class
instances_list_viewed
extends
\
core\event\course_module_instances_list_viewed
{
/**
* Returns description of what happened.
*
* @return string
*/
public
function
get_description
()
{
return
"User
$this->userid
viewed the list of book activities in the course
$this->courseid
."
;
}
/**
* Return the legacy event log data.
*
* @return array|null
*/
protected
function
get_legacy_logdata
()
{
return
array
(
$this
->
courseid
,
'book'
,
'view all'
,
'index.php?id='
.
$this
->
courseid
,
''
);
}
/**
* Return localised event name.
*
* @return string
*/
public
static
function
get_name
()
{
return
get_string
(
'event_instances_list_viewed'
,
'mod_book'
);
}
/**
* Get URL related to the action
*
* @return \moodle_url
*/
public
function
get_url
()
{
return
new
\
moodle_url
(
'/mod/book/index.php'
,
array
(
'id'
=>
$this
->
courseid
));
}
}
mod/book/delete.php
View file @
7f6e3eef
...
...
@@ -52,7 +52,7 @@ $PAGE->set_heading($course->fullname);
if
(
$confirm
)
{
// the operation was confirmed.
$fs
=
get_file_storage
();
if
(
!
$chapter
->
subchapter
)
{
// Delete all its sub-chapters if any
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
),
'pagenum'
,
'id, subchapter'
);
$chapters
=
$DB
->
get_records
et
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
),
'pagenum'
);
$found
=
false
;
foreach
(
$chapters
as
$ch
)
{
if
(
$ch
->
id
==
$chapter
->
id
)
{
...
...
@@ -60,16 +60,32 @@ if ($confirm) { // the operation was confirmed.
}
else
if
(
$found
and
$ch
->
subchapter
)
{
$fs
->
delete_area_files
(
$context
->
id
,
'mod_book'
,
'chapter'
,
$ch
->
id
);
$DB
->
delete_records
(
'book_chapters'
,
array
(
'id'
=>
$ch
->
id
));
$params
=
array
(
'context'
=>
$context
,
'objectid'
=>
$ch
->
id
);
$event
=
\
mod_book\event\chapter_deleted
::
create
(
$params
);
$event
->
add_record_snapshot
(
'book_chapters'
,
$ch
);
$event
->
trigger
();
}
else
if
(
$found
)
{
break
;
}
}
$chapters
->
close
();
}
$fs
->
delete_area_files
(
$context
->
id
,
'mod_book'
,
'chapter'
,
$chapter
->
id
);
$DB
->
delete_records
(
'book_chapters'
,
array
(
'id'
=>
$chapter
->
id
));
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
);
$params
=
array
(
'context'
=>
$context
,
'objectid'
=>
$chapter
->
id
);
$event
=
\
mod_book\event\chapter_deleted
::
create
(
$params
);
$event
->
add_record_snapshot
(
'book_chapters'
,
$chapter
);
$event
->
set_legacy_logdata
(
array
(
$course
->
id
,
'book'
,
'update'
,
'view.php?id='
.
$cm
->
id
,
$book
->
id
,
$cm
->
id
));
$event
->
trigger
();
book_preload_chapters
(
$book
);
// Fix structure.
$DB
->
set_field
(
'book'
,
'revision'
,
$book
->
revision
+
1
,
array
(
'id'
=>
$book
->
id
));
...
...
mod/book/edit.php
View file @
7f6e3eef
...
...
@@ -76,7 +76,13 @@ if ($mform->is_cancelled()) {
$DB
->
set_field
(
'book'
,
'revision'
,
$book
->
revision
+
1
,
array
(
'id'
=>
$book
->
id
));
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 chapter'
,
'view.php?id='
.
$cm
->
id
.
'&chapterid='
.
$data
->
id
,
$data
->
id
,
$cm
->
id
);
$params
=
array
(
'context'
=>
$context
,
'objectid'
=>
$data
->
id
);
$event
=
\
mod_book\event\chapter_updated
::
create
(
$params
);
$event
->
add_record_snapshot
(
'book_chapters'
,
$data
);
$event
->
trigger
();
}
else
{
// adding new chapter
...
...
@@ -102,7 +108,13 @@ if ($mform->is_cancelled()) {
$DB
->
set_field
(
'book'
,
'revision'
,
$book
->
revision
+
1
,
array
(
'id'
=>
$book
->
id
));
add_to_log
(
$course
->
id
,
'course'
,
'update mod'
,
'../mod/book/view.php?id='
.
$cm
->
id
,
'book '
.
$book
->
id
);
add_to_log
(
$course
->
id
,
'book'
,
'add chapter'
,
'view.php?id='
.
$cm
->
id
.
'&chapterid='
.
$data
->
id
,
$data
->
id
,
$cm
->
id
);
$params
=
array
(
'context'
=>
$context
,
'objectid'
=>
$data
->
id
);
$event
=
\
mod_book\event\chapter_created
::
create
(
$params
);
$event
->
add_record_snapshot
(
'book_chapters'
,
$data
);