mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
MDL-67585 core_course: add the content_item class
Objects of this class represent items able to be added to a course, including modules and submodules.
This commit is contained in:
parent
a21ba663fd
commit
dd8048e350
course
154
course/classes/local/entity/content_item.php
Normal file
154
course/classes/local/entity/content_item.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Contains the content_item class.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
* @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace core_course\local\entity;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The content_item class.
|
||||
*
|
||||
* @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class content_item {
|
||||
/** @var int $id the id. */
|
||||
private $id;
|
||||
|
||||
/** @var string $name the name. */
|
||||
private $name;
|
||||
|
||||
/** @var string $title the title. */
|
||||
private $title;
|
||||
|
||||
/** @var \moodle_url $link the url for the content item's setup page (usually mod/edit.php). */
|
||||
private $link;
|
||||
|
||||
/** @var string $icon an html string containing the icon for this item. */
|
||||
private $icon;
|
||||
|
||||
/** @var string $help the description/help text for this content item. */
|
||||
private $help;
|
||||
|
||||
/** @var int $achetype a module archetype, e.g. MOD_ARCHETYPE_RESOURCE, MOD_ARCHETYPE_OTHER. */
|
||||
private $archetype;
|
||||
|
||||
/** @var string $componentname the name of the component from which this content item originates. */
|
||||
private $componentname;
|
||||
|
||||
/**
|
||||
* The content_item constructor.
|
||||
*
|
||||
* @param int $id Id number.
|
||||
* @param string $name Name of the item, not human readable.
|
||||
* @param string $title Human readable title for the item.
|
||||
* @param \moodle_url $link The URL to the creation page, with any item specific params
|
||||
* @param string $icon HTML containing the icon for the item
|
||||
* @param string $help The description of the item.
|
||||
* @param int $archetype the archetype for the content item (see MOD_ARCHETYPE_X definitions in lib/moodlelib.php).
|
||||
* @param string $componentname the name of the component/plugin with which this content item is associated.
|
||||
*/
|
||||
public function __construct(int $id, string $name, string $title, \moodle_url $link, string $icon, string $help,
|
||||
int $archetype, string $componentname) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->title = $title;
|
||||
$this->link = $link;
|
||||
$this->icon = $icon;
|
||||
$this->help = $help;
|
||||
$this->archetype = $archetype;
|
||||
$this->componentname = $componentname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the component with which this content item is associated.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_component_name(): string {
|
||||
return $this->componentname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the help description of this item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_help(): string {
|
||||
return $this->help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the archetype of this item.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_archetype(): int {
|
||||
return $this->archetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of this item.
|
||||
* @return int
|
||||
*/
|
||||
public function get_id(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the human readable title of this item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title(): string {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the link to the creation page of this item.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_link(): \moodle_url {
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon html for this item.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_icon(): string {
|
||||
return $this->icon;
|
||||
}
|
||||
}
|
59
course/tests/content_item_test.php
Normal file
59
course/tests/content_item_test.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Contains tests for the \core_course\local\entity\content_item class.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
* @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tests\core_course;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_course\local\entity\content_item;
|
||||
|
||||
/**
|
||||
* Tests for the \core_course\local\entity\content_item class.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
* @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class content_item_testcase extends \advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the content_item class.
|
||||
*/
|
||||
public function test_content_item() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$contentitem = new content_item(22, 'Item name', 'Item title', new \moodle_url('mod_edit.php'), '<img src="test">',
|
||||
'Description of the module', MOD_ARCHETYPE_RESOURCE, 'mod_page');
|
||||
|
||||
$this->assertEquals(22, $contentitem->get_id());
|
||||
$this->assertEquals('Item name', $contentitem->get_name());
|
||||
$this->assertEquals('Item title', $contentitem->get_title());
|
||||
$this->assertEquals(new \moodle_url('mod_edit.php'), $contentitem->get_link());
|
||||
$this->assertEquals('<img src="test">', $contentitem->get_icon());
|
||||
$this->assertEquals('Description of the module', $contentitem->get_help());
|
||||
$this->assertEquals(MOD_ARCHETYPE_RESOURCE, $contentitem->get_archetype());
|
||||
$this->assertEquals('mod_page', $contentitem->get_component_name());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user