MDL-57730 core_calendar: Action interface aware of actionability
We need a way to decide whether an action can currently be completed (e.g., an assignment where submissions are not yet open can not be actioned, even though it may be displayed on the upcomming events list). To do this, the action interface now contains an is_actionable method. Part of MDL-55611 epic.
This commit is contained in:
committed by
Damyon Wiese
parent
42ec9f0d63
commit
aa457b7dee
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -53,4 +53,11 @@ interface action_interface {
|
||||
* @return int
|
||||
*/
|
||||
public function get_item_count();
|
||||
|
||||
/**
|
||||
* Get the actions actionability.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_actionable();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
]
|
||||
],
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user