MDL-56994 course: New method to check if format supports news forum
This commit is contained in:
@@ -1139,6 +1139,26 @@ abstract class format_base {
|
||||
return $startdate + $courseduration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the course format supports the creation of the Announcements forum.
|
||||
*
|
||||
* For course format plugin developers, please override this to return true if you want the Announcements forum
|
||||
* to be created upon course creation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_news() {
|
||||
// For backwards compatibility, check if default blocks include the news_items block.
|
||||
$defaultblocks = $this->get_default_blocks();
|
||||
foreach ($defaultblocks as $blocks) {
|
||||
if (in_array('news_items', $blocks)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Return false by default.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start date value from the course settings page form.
|
||||
*
|
||||
|
||||
@@ -401,6 +401,15 @@ class format_topics extends format_base {
|
||||
}
|
||||
return parent::inplace_editable_render_section_name($section, $linkifneeded, $editable, $edithint, $editlabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the course format supports the creation of a news forum.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_news() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,9 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
|
||||
* Course formats can overwrite get_default_course_enddate function to set the default course end date for new courses.
|
||||
format_base::get_default_course_enddate uses the new "Course duration" site setting to calculate the default course end date
|
||||
from the default course start date.
|
||||
* New method format_base::supports_news() which is used to determine whether an Announcements forum will be automatically created on
|
||||
course creation. For course format plugin developers, please override format_base::supports_news() to return true if you want the
|
||||
Announcements forum to be created upon course creation and remove the block names defined in format_base::get_default_blocks().
|
||||
|
||||
=== 3.1 ===
|
||||
* Course format may use the inplace_editable template to allow quick editing of section names, see
|
||||
|
||||
@@ -488,6 +488,15 @@ class format_weeks extends format_base {
|
||||
$dates = $this->get_section_dates(intval($numsections), $startdate);
|
||||
return $dates->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the course format supports the creation of a news forum.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function supports_news() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -101,4 +101,66 @@ class core_course_courseformat_testcase extends advanced_testcase {
|
||||
$this->assertFalse($modinfoteacher->get_cm($assign1->cmid)->available);
|
||||
$this->assertTrue($modinfoteacher->get_cm($assign1->cmid)->uservisible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for supports_news() with a course format plugin that doesn't define 'news_items' in default blocks.
|
||||
*/
|
||||
public function test_supports_news() {
|
||||
$this->resetAfterTest();
|
||||
$format = course_get_format((object)['format' => 'testformat']);
|
||||
$this->assertFalse($format->supports_news());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for supports_news() for old course format plugins that defines 'news_items' in default blocks.
|
||||
*/
|
||||
public function test_supports_news_legacy() {
|
||||
$this->resetAfterTest();
|
||||
$format = course_get_format((object)['format' => 'testlegacy']);
|
||||
$this->assertTrue($format->supports_news());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class format_testformat.
|
||||
*
|
||||
* A test class that simulates a course format that doesn't define 'news_items' in default blocks.
|
||||
*
|
||||
* @copyright 2016 Jun Pataleta <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class format_testformat extends format_base {
|
||||
/**
|
||||
* Returns the list of blocks to be automatically added for the newly created course.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_default_blocks() {
|
||||
return [
|
||||
BLOCK_POS_RIGHT => [],
|
||||
BLOCK_POS_LEFT => []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class format_testlegacy.
|
||||
*
|
||||
* A test class that simulates old course formats that define 'news_items' in default blocks.
|
||||
*
|
||||
* @copyright 2016 Jun Pataleta <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class format_testlegacy extends format_base {
|
||||
/**
|
||||
* Returns the list of blocks to be automatically added for the newly created course.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_default_blocks() {
|
||||
return [
|
||||
BLOCK_POS_RIGHT => ['news_items'],
|
||||
BLOCK_POS_LEFT => []
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user