Skip to content

Commit

Permalink
MED-101: Add remove resource functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thies committed Apr 11, 2024
1 parent 219d061 commit 175b044
Show file tree
Hide file tree
Showing 21 changed files with 609 additions and 8 deletions.
87 changes: 87 additions & 0 deletions classes/event/resource_deleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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 tool_mediatime\event;

use core\event\base;

/**
* The resource_deleted event class.
*
* @package tool_mediatime
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_deleted 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'] = 'd';
}

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

/**
* Get the event description.
*
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' deleted 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', [
]);
}

/**
* 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;
}
}
88 changes: 88 additions & 0 deletions classes/event/resource_updated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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 tool_mediatime\event;

use core\event\base;

/**
* The resource_updated event class.
*
* @package tool_mediatime
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_updated 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'] = 'u';
}

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

/**
* Get the event description.
*
* @return string
*/
public function get_description() {
return "The user with id '{$this->userid}' deleted 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;
}
}
51 changes: 51 additions & 0 deletions classes/form/delete_resource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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/>.

/**
* Media Time media edit form
*
* @package tool_mediatime
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_mediatime\form;

use context_system;
use moodleform;

/**
* Media Time media edit form
*
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delete_resource extends moodleform {

/**
* Definition
*/
public function definition() {
$mform = $this->_form;
require_capability('tool/mediatime:manage', context_system::instance());

$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);

$mform->addElement('hidden', 'source');
$mform->setType('source', PARAM_TEXT);
}
}
2 changes: 2 additions & 0 deletions classes/media_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ public function export_for_template(renderer_base $output): array {
foreach ($this->media as $record) {
$resource = new output\media_resource($record);
$url = new moodle_url('/admin/tool/mediatime/index.php', ['id' => $record->id]);
$removeurl = new moodle_url('/admin/tool/mediatime/index.php', ['delete' => $record->id]);
$media[] = [
'imageurl' => $resource->image_url($output),
'tags' => $resource->tags($output),
'url' => $url->out(),
'content' => $record->content,
'removeurl' => $removeurl->out(),
];
}

Expand Down
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@

$source = optional_param('source', '', PARAM_ALPHANUMEXT);
$id = optional_param('id', null, PARAM_INT);
$delete = optional_param('delete', null, PARAM_INT);
$edit = optional_param('edit', null, PARAM_INT);

admin_externalpage_setup('mediatimelibrary');

$PAGE->set_heading(get_string('pluginname', 'tool_mediatime'));
if ($id) {
$record = $DB->get_record('tool_mediatime', ['id' => $id]);
} else if ($delete) {
$record = $DB->get_record('tool_mediatime', ['id' => $delete]);
} else if ($edit) {
$record = $DB->get_record('tool_mediatime', ['id' => $edit]);
} else {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/tool_mediatime.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
$string['pluginname'] = 'Media Time';
$string['addnewcontent'] = 'Add new content';
$string['event_resource_created'] = 'Resource created';
$string['event_resource_deleted'] = 'Resource deleted';
$string['event_resource_updated'] = 'Resource updated';
$string['filelinks'] = 'File links';
$string['library'] = 'Library';
$string['keyword'] = 'Keyword';
$string['mediatime:create'] = 'Create media in library';
Expand Down
38 changes: 38 additions & 0 deletions source/streamio/classes/event/resource_deleted.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_streamio\event;

use core\event\base;

/**
* The resource_deleted event class.
*
* @package mediatimesrc_streamio
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_deleted extends \tool_mediatime\event\resource_deleted {
/**
* Returns event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_resource_deleted', 'mediatimesrc_streamio');
}
}
38 changes: 38 additions & 0 deletions source/streamio/classes/event/resource_updated.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_streamio\event;

use core\event\base;

/**
* The resource_updated event class.
*
* @package mediatimesrc_streamio
* @category event
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resource_updated extends \tool_mediatime\event\resource_updated {
/**
* Returns event name.
*
* @return string
*/
public static function get_name() {
return get_string('event_resource_updated', 'mediatimesrc_streamio');
}
}
Loading

0 comments on commit 175b044

Please sign in to comment.