Skip to content

Commit

Permalink
MED-99: Implement content added event
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 8, 2024
1 parent db77fb1 commit 219d061
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 4 deletions.
60 changes: 59 additions & 1 deletion classes/event/resource_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace tool_mediatime\event;

use core\event\base;

/**
* The resource_created event class.
*
Expand All @@ -24,7 +26,63 @@
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_created extends core_event\base {
class resource_created extends base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.

/**
* Initialise the event.
*/
protected function init() {
$this->data['objecttable'] = 'tool_mediatime';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['crud'] = 'c';
}

/**
* Returns event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_resource_created', 'tool_mediatime');
}

/**
* Get the event description.
*
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' created a mediatime resource with id '{$this->objectid}'.";
}

/**
* Get URL related to the action.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/admin/tool/mediatime/index.php', [
'id' => $this->objectid,
]);
}

/**
* Get the object ID mapping.
*
* @return array
*/
public static function get_objectid_mapping() {
return array('db' => 'tool_mediatime', 'restore' => \core\event\base::NOT_MAPPED);
}

/**
* No mapping required for this event because this event is not backed up.
*
* @return bool
*/
public static function get_other_mapping() {
return false;
}
}
1 change: 1 addition & 0 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

$string['pluginname'] = 'Media Time';
$string['addnewcontent'] = 'Add new content';
$string['event_resource_created'] = 'Resource created';
$string['library'] = 'Library';
$string['keyword'] = 'Keyword';
$string['mediatime:create'] = 'Create media in library';
Expand Down
14 changes: 11 additions & 3 deletions source/streamio/classes/event/resource_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace mediatimesrc_streamio\event;

use core\event\base;

/**
* The resource_created event class.
*
Expand All @@ -24,7 +26,13 @@
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_created extends core_event\base {

// For more information about the Events API please visit {@link https://docs.moodle.org/dev/Events_API}.
class resource_created extends \tool_mediatime\event\resource_created {
/**
* Returns event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_resource_created', 'mediatimesrc_streamio');
}
}
10 changes: 10 additions & 0 deletions source/streamio/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function __construct($record = null) {
json_decode($tags)
);
}
$event = \mediatimesrc_streamio\event\resource_created::create([
'contextid' => SYSCONTEXTID,
'objectid' => $id,
]);
$event->trigger();
$redirect = new moodle_url('/admin/tool/mediatime/index.php', ['id' => $id]);
redirect($redirect);
}
Expand Down Expand Up @@ -122,6 +127,11 @@ public function __construct($record = null) {
$data->content = json_encode($video);
$data->timecreated = $data->timemodified;
$data->edit = $DB->insert_record('tool_mediatime', $data);
$event = \mediatimesrc_streamio\event\resource_created::create([
'contextid' => SYSCONTEXTID,
'objectid' => $data->edit,
]);
$event->trigger();
} else {
$data->id = $data->edit;
if (has_capability('mediatimesrc/streamio:upload', context_system::instance())) {
Expand Down
1 change: 1 addition & 0 deletions source/streamio/lang/en/mediatimesrc_streamio.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'Streamio';
$string['event_resource_created'] = 'Streamio resource created';
$string['password'] = 'Password';
$string['password_help'] = 'Streamio password for administrative access';
$string['selectexistingfile'] = 'Select existing file';
Expand Down
38 changes: 38 additions & 0 deletions source/videotime/classes/event/resource_created.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.

namespace mediatimesrc_videotime\event;

use core\event\base;

/**
* The resource_created event class.
*
* @package mediatimesrc_videotime
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_created extends \tool_mediatime\event\resource_created {
/**
* Returns event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_resource_created', 'mediatimesrc_videotime');
}
}
5 changes: 5 additions & 0 deletions source/videotime/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public function __construct($record = null) {
$data->timecreated = $data->timemodified;
$data->content = json_encode($data);
$data->edit = $DB->insert_record('tool_mediatime', $data);
$event = \mediatimesrc_videotime\event\resource_created::create([
'contextid' => SYSCONTEXTID,
'objectid' => $data->edit,
]);
$event->trigger();
} else {
$data->id = $data->edit;
$data->content = json_encode($data);
Expand Down
1 change: 1 addition & 0 deletions source/videotime/lang/en/mediatimesrc_videotime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'Video Time resource';
$string['event_resource_created'] = 'Video Time resource created';
$string['posterimage'] = 'Poster image';
$string['posterimage_help'] = 'Select an image to displayed before the video is played or as a thumbnail image.';
$string['maxbytes'] = 'Maximum size of file uploads';
Expand Down

0 comments on commit 219d061

Please sign in to comment.