Merge branch 'MDL-55869_m32v1' of https://github.com/sbourget/moodle

This commit is contained in:
David Monllao 2016-11-18 09:16:06 +08:00
commit aab30ea828
2 changed files with 78 additions and 18 deletions

View File

@ -113,20 +113,21 @@ function chat_add_instance($chat) {
$returnid = $DB->insert_record("chat", $chat);
$event = new stdClass();
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->courseid = $chat->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'chat';
$event->instance = $returnid;
$event->eventtype = 'chattime';
$event->timestart = $chat->chattime;
$event->timeduration = 0;
calendar_event::create($event);
if ($chat->schedule > 0) {
$event = new stdClass();
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->courseid = $chat->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'chat';
$event->instance = $returnid;
$event->eventtype = 'chattime';
$event->timestart = $chat->chattime;
$event->timeduration = 0;
calendar_event::create($event);
}
return $returnid;
}
@ -151,12 +152,35 @@ function chat_update_instance($chat) {
if ($event->id = $DB->get_field('event', 'id', array('modulename' => 'chat', 'instance' => $chat->id))) {
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->timestart = $chat->chattime;
if ($chat->schedule > 0) {
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->timestart = $chat->chattime;
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
} else {
// Do not publish this event, so delete it.
$calendarevent = calendar_event::load($event->id);
$calendarevent->delete();
}
} else {
// No event, do we need to create one?
if ($chat->schedule > 0) {
$event = new stdClass();
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->courseid = $chat->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'chat';
$event->instance = $chat->id;
$event->eventtype = 'chattime';
$event->timestart = $chat->chattime;
$event->timeduration = 0;
calendar_event::create($event);
}
}
return true;

View File

@ -0,0 +1,36 @@
@mod @mod_chat
Feature: Chat calendar entries
In order to notify students of upcoming chat sessons
As a teacher
I need to create a chat activity and publish the event times
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Tina | Teacher1 | teacher1@example.com |
| student1 | Sam | Student1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
Scenario: Create a chat activity and do not publish the start date to the calendar
Given the following "activities" exist:
| activity | name | intro | course | idnumber | schedule |
| chat | Test chat name | Test chat description | C1 | chat1 | 0 |
And I log in as "teacher1"
And I follow "Course 1"
When I navigate to "Calendar" node in "Site pages"
Then I should not see "Test chat name"
Scenario: Create a chat activity and publish the start date to the calendar
Given the following "activities" exist:
| activity | name | intro | course | idnumber | schedule |
| chat | Test chat name | Test chat description | C1 | chat1 | 1 |
And I log in as "teacher1"
And I follow "Course 1"
When I navigate to "Calendar" node in "Site pages"
Then I should see "Test chat name"