diff --git a/calendar/classes/action_factory.php b/calendar/classes/action_factory.php index 11cbb89b460..0914c00a999 100644 --- a/calendar/classes/action_factory.php +++ b/calendar/classes/action_factory.php @@ -36,7 +36,7 @@ use core_calendar\local\event\value_objects\action; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class action_factory implements action_factory_interface { - public function create_instance($name, \moodle_url $url, $itemcount ) { - return new action ($name, $url, $itemcount); + public function create_instance($name, \moodle_url $url, $itemcount, $actionable) { + return new action ($name, $url, $itemcount, $actionable); } } diff --git a/calendar/classes/local/event/mappers/event_mapper.php b/calendar/classes/local/event/mappers/event_mapper.php index 371aa888f94..e72edc81d8a 100644 --- a/calendar/classes/local/event/mappers/event_mapper.php +++ b/calendar/classes/local/event/mappers/event_mapper.php @@ -86,26 +86,27 @@ class event_mapper implements event_mapper_interface { $timeduration = $event->get_times()->get_end_time()->getTimestamp() - $event->get_times()->get_start_time()->getTimestamp(); return new event((object) [ - 'id' => $event->get_id(), - 'name' => $event->get_name(), - 'description' => $event->get_description()->get_value(), - 'format' => $event->get_description()->get_format(), - 'courseid' => $event->get_course() ? $event->get_course()->get_id() : null, - 'groupid' => $event->get_group() ? $event->get_group()->get_id() : null, - 'userid' => $event->get_user() ? $event->get_user()->get_id() : null, - 'repeatid' => $event->get_repeats()->get_id(), - 'modulename' => $event->get_course_module()->get('modname'), - 'instance' => $event->get_course_module()->get('instance'), - 'eventtype' => $event->get_type(), - 'timestart' => $event->get_times()->get_start_time()->getTimestamp(), - 'timeduration' => $timeduration, - 'timesort' => $event->get_times()->get_sort_time()->getTimestamp(), - 'visible' => $event->is_visible() ? 1 : 0, - 'timemodified' => $event->get_times()->get_modified_time()->getTimestamp(), - 'subscriptionid' => $event->get_subscription() ? $event->get_subscription()->get_id() : null, - 'actionname' => $action ? $action->get_name() : null, - 'actionurl' => $action ? $action->get_url() : null, - 'actionnum' => $action ? $action->get_item_count() : null + 'id' => $event->get_id(), + 'name' => $event->get_name(), + 'description' => $event->get_description()->get_value(), + 'format' => $event->get_description()->get_format(), + 'courseid' => $event->get_course() ? $event->get_course()->get_id() : null, + 'groupid' => $event->get_group() ? $event->get_group()->get_id() : null, + 'userid' => $event->get_user() ? $event->get_user()->get_id() : null, + 'repeatid' => $event->get_repeats()->get_id(), + 'modulename' => $event->get_course_module()->get('modname'), + 'instance' => $event->get_course_module()->get('instance'), + 'eventtype' => $event->get_type(), + 'timestart' => $event->get_times()->get_start_time()->getTimestamp(), + 'timeduration' => $timeduration, + 'timesort' => $event->get_times()->get_sort_time()->getTimestamp(), + 'visible' => $event->is_visible() ? 1 : 0, + 'timemodified' => $event->get_times()->get_modified_time()->getTimestamp(), + 'subscriptionid' => $event->get_subscription() ? $event->get_subscription()->get_id() : null, + 'actionname' => $action ? $action->get_name() : null, + 'actionurl' => $action ? $action->get_url() : null, + 'actionnum' => $action ? $action->get_item_count() : null, + 'actionactionable' => $action ? $action->is_actionable() : null ]); } } diff --git a/calendar/classes/local/event/value_objects/action.php b/calendar/classes/local/event/value_objects/action.php index 129fd5e4b55..1b94aa89607 100644 --- a/calendar/classes/local/event/value_objects/action.php +++ b/calendar/classes/local/event/value_objects/action.php @@ -50,21 +50,29 @@ class action implements action_interface { */ protected $itemcount; + /** + * @var bool $actionable Whether or not the event is currently actionable. + */ + protected $actionable; + /** * Constructor. * - * @param string $name The action's name. - * @param \moodle_url $url The action's URL. - * @param int $itemcount How many items there are to action. + * @param string $name The action's name. + * @param \moodle_url $url The action's URL. + * @param int $itemcount How many items there are to action. + * @param bool $actionable Whether or not the event is currently actionable. */ public function __construct( $name, \moodle_url $url, - $itemcount = null + $itemcount, + $actionable ) { $this->name = $name; $this->url = $url; $this->itemcount = $itemcount; + $this->actionable = $actionable; } public function get_name() { @@ -78,4 +86,8 @@ class action implements action_interface { public function get_item_count() { return $this->itemcount; } + + public function is_actionable() { + return $this->actionable; + } } diff --git a/calendar/classes/local/interfaces/action_factory_interface.php b/calendar/classes/local/interfaces/action_factory_interface.php index a6bcf368bb5..a5e2f5b9913 100644 --- a/calendar/classes/local/interfaces/action_factory_interface.php +++ b/calendar/classes/local/interfaces/action_factory_interface.php @@ -30,10 +30,11 @@ interface action_factory_interface { /** * Creates an instance of an action. * - * @param string $name The action's name. - * @param \moodle_url $url The action's URL. - * @param int $itemcount The number of items needing action. + * @param string $name The action's name. + * @param \moodle_url $url The action's URL. + * @param int $itemcount The number of items needing action. + * @param bool $actionable The action's actionability. * @return \core_calendar\local\interfaces\action_interface The action. */ - public function create_instance($name, \moodle_url $url, $itemcount); + public function create_instance($name, \moodle_url $url, $itemcount, $actionable); } diff --git a/calendar/classes/local/interfaces/action_interface.php b/calendar/classes/local/interfaces/action_interface.php index a1d1c2d550e..190d27e6b0f 100644 --- a/calendar/classes/local/interfaces/action_interface.php +++ b/calendar/classes/local/interfaces/action_interface.php @@ -53,4 +53,11 @@ interface action_interface { * @return int */ public function get_item_count(); + + /** + * Get the actions actionability. + * + * @return bool + */ + public function is_actionable(); } diff --git a/calendar/tests/action_event_factory_test.php b/calendar/tests/action_event_factory_test.php index bd3fe974362..8f4e2c28868 100644 --- a/calendar/tests/action_event_factory_test.php +++ b/calendar/tests/action_event_factory_test.php @@ -46,7 +46,8 @@ class core_calendar_action_event_factory_testcase extends advanced_testcase { new action( 'Test', new \moodle_url('http://example.com'), - 1729 + 1729, + true ) ); diff --git a/calendar/tests/action_event_test.php b/calendar/tests/action_event_test.php index b8d63ebd470..e90ebdb2ae2 100644 --- a/calendar/tests/action_event_test.php +++ b/calendar/tests/action_event_test.php @@ -68,7 +68,8 @@ class core_calendar_action_event_testcase extends advanced_testcase { 'action' => new action( 'action 1', new moodle_url('http://example.com'), - 2 + 2, + true ) ] ], @@ -78,7 +79,8 @@ class core_calendar_action_event_testcase extends advanced_testcase { 'action' => new action( 'action 2', new moodle_url('http://example.com'), - 5 + 5, + false ) ] ], diff --git a/calendar/tests/action_factory_test.php b/calendar/tests/action_factory_test.php index 5bd64482a77..760a4642dc1 100644 --- a/calendar/tests/action_factory_test.php +++ b/calendar/tests/action_factory_test.php @@ -42,7 +42,8 @@ class core_calendar_action_factory_test extends advanced_testcase { $instance = $factory->create_instance( 'test', new \moodle_url('http://example.com'), - 1729 + 1729, + true ); $this->assertInstanceOf(action_interface::class, $instance); diff --git a/calendar/tests/action_test.php b/calendar/tests/action_test.php index dba4a4d36e6..cc4dd6a3ccd 100644 --- a/calendar/tests/action_test.php +++ b/calendar/tests/action_test.php @@ -43,11 +43,16 @@ class core_calendar_action_testcase extends advanced_testcase { $action = new action( $constructorparams['name'], $constructorparams['url'], - $constructorparams['item_count'] + $constructorparams['item_count'], + $constructorparams['actionable'] ); foreach ($constructorparams as $name => $value) { - $this->assertEquals($action->{'get_' . $name}(), $value); + if ($name == 'actionable') { + $this->assertEquals($action->is_actionable(), $value); + } else { + $this->assertEquals($action->{'get_' . $name}(), $value); + } } } @@ -60,14 +65,16 @@ class core_calendar_action_testcase extends advanced_testcase { 'constructorparams' => [ 'name' => 'Hello', 'url' => new moodle_url('http://example.com'), - 'item_count' => 1 + 'item_count' => 1, + 'actionable' => true ] ], 'Dataset 2' => [ 'constructorparams' => [ 'name' => 'Goodbye', 'url' => new moodle_url('http://example.com'), - 'item_count' => 2 + 'item_count' => 2, + 'actionable' => false ] ] ]; diff --git a/calendar/tests/event_mapper_test.php b/calendar/tests/event_mapper_test.php index 21b173dc5b7..91742dc24bc 100644 --- a/calendar/tests/event_mapper_test.php +++ b/calendar/tests/event_mapper_test.php @@ -86,6 +86,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase { $this->assertEquals($legacyevent->actionname, 'test action'); $this->assertInstanceOf(\moodle_url::class, $legacyevent->actionurl); $this->assertEquals($legacyevent->actionnum, 1729); + $this->assertEquals($legacyevent->actionactionable, $event->get_action()->is_actionable()); } /** @@ -193,7 +194,8 @@ class event_mapper_test_action_event implements action_event_interface { return new action( 'test action', new \moodle_url('http://example.com'), - 1729 + 1729, + true ); } } diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 19f34f1c641..ae6d0c50f35 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -1715,6 +1715,7 @@ function mod_assign_core_calendar_provide_event_action( return $factory->create_instance( 'chef', new \moodle_url('http://example.com'), - 3 + 3, + true ); }