diff --git a/course/classes/local/entity/content_item.php b/course/classes/local/entity/content_item.php new file mode 100644 index 00000000000..b6554936599 --- /dev/null +++ b/course/classes/local/entity/content_item.php @@ -0,0 +1,154 @@ +. + +/** + * Contains the content_item class. + * + * @package core + * @subpackage course + * @copyright 2020 Jake Dallimore + * @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 + * @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; + } +} diff --git a/course/tests/content_item_test.php b/course/tests/content_item_test.php new file mode 100644 index 00000000000..ec067475761 --- /dev/null +++ b/course/tests/content_item_test.php @@ -0,0 +1,59 @@ +. + +/** + * Contains tests for the \core_course\local\entity\content_item class. + * + * @package core + * @subpackage course + * @copyright 2020 Jake Dallimore + * @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 + * @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'), '', + '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('', $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()); + } +}