mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Merge branch 'MDL-63280_master' of git://github.com/markn86/moodle
This commit is contained in:
commit
56076d5991
@ -66,6 +66,12 @@ class group_form extends moodleform {
|
||||
$mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group');
|
||||
$mform->setType('enrolmentkey', PARAM_RAW);
|
||||
|
||||
// Group conversation messaging.
|
||||
if (\core_message\api::can_create_group_conversation($USER->id, $coursecontext)) {
|
||||
$mform->addElement('selectyesno', 'enablemessaging', get_string('enablemessaging', 'group'));
|
||||
$mform->addHelpButton('enablemessaging', 'enablemessaging', 'group');
|
||||
}
|
||||
|
||||
$mform->addElement('static', 'currentpicture', get_string('currentpicture'));
|
||||
|
||||
$mform->addElement('checkbox', 'deletepicture', get_string('delete'));
|
||||
@ -90,13 +96,19 @@ class group_form extends moodleform {
|
||||
* Extend the form definition after the data has been parsed.
|
||||
*/
|
||||
public function definition_after_data() {
|
||||
global $COURSE, $DB;
|
||||
global $COURSE, $DB, $USER;
|
||||
|
||||
$mform = $this->_form;
|
||||
$groupid = $mform->getElementValue('id');
|
||||
$coursecontext = context_course::instance($COURSE->id);
|
||||
|
||||
if ($group = $DB->get_record('groups', array('id' => $groupid))) {
|
||||
|
||||
// If can create group conversation then get if a conversation area exists and it is enabled.
|
||||
if (\core_message\api::can_create_group_conversation($USER->id, $coursecontext)) {
|
||||
if (\core_message\api::is_conversation_area_enabled('core_group', 'groups', $groupid, $coursecontext->id)) {
|
||||
$mform->getElement('enablemessaging')->setSelected(1);
|
||||
}
|
||||
}
|
||||
// Print picture.
|
||||
if (!($pic = print_group_picture($group, $COURSE->id, true, true, false))) {
|
||||
$pic = get_string('none');
|
||||
|
@ -233,7 +233,7 @@ function groups_remove_member($grouporid, $userorid) {
|
||||
* @return id of group or false if error
|
||||
*/
|
||||
function groups_create_group($data, $editform = false, $editoroptions = false) {
|
||||
global $CFG, $DB;
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
//check that courseid exists
|
||||
$course = $DB->get_record('course', array('id' => $data->courseid), '*', MUST_EXIST);
|
||||
@ -275,6 +275,21 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {
|
||||
// Invalidate the grouping cache for the course
|
||||
cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($course->id));
|
||||
|
||||
// Group conversation messaging.
|
||||
if (\core_message\api::can_create_group_conversation($USER->id, $context)) {
|
||||
if (!empty($data->enablemessaging)) {
|
||||
\core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$group->name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_ENABLED,
|
||||
'core_group',
|
||||
'groups',
|
||||
$group->id,
|
||||
$context->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger group event.
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
@ -383,7 +398,7 @@ function groups_update_group_icon($group, $data, $editform) {
|
||||
* @return bool true or exception
|
||||
*/
|
||||
function groups_update_group($data, $editform = false, $editoroptions = false) {
|
||||
global $CFG, $DB;
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
$context = context_course::instance($data->courseid);
|
||||
|
||||
@ -413,6 +428,32 @@ function groups_update_group($data, $editform = false, $editoroptions = false) {
|
||||
groups_update_group_icon($group, $data, $editform);
|
||||
}
|
||||
|
||||
// Group conversation messaging.
|
||||
if (\core_message\api::can_create_group_conversation($USER->id, $context)) {
|
||||
if ($conversation = \core_message\api::get_conversation_by_area('core_group', 'groups', $group->id, $context->id)) {
|
||||
if ($data->enablemessaging && $data->enablemessaging != $conversation->enabled) {
|
||||
\core_message\api::enable_conversation($conversation->id);
|
||||
}
|
||||
if (!$data->enablemessaging && $data->enablemessaging != $conversation->enabled) {
|
||||
\core_message\api::disable_conversation($conversation->id);
|
||||
}
|
||||
\core_message\api::update_conversation_name($conversation->id, $group->name);
|
||||
} else {
|
||||
if (!empty($data->enablemessaging)) {
|
||||
\core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$group->name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_ENABLED,
|
||||
'core_group',
|
||||
'groups',
|
||||
$group->id,
|
||||
$context->id
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger group event.
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
|
@ -528,4 +528,100 @@ class core_group_lib_testcase extends advanced_testcase {
|
||||
}
|
||||
$this->assertEquals(2, $DB->count_records('groups_members', array('groupid' => $group6->id)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test groups_create_group enabling a group conversation.
|
||||
*/
|
||||
public function test_groups_create_group_with_conversation() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$coursecontext1 = context_course::instance($course1->id);
|
||||
|
||||
// Create two groups and only one group with enablemessaging = 1.
|
||||
$group1a = $this->getDataGenerator()->create_group(array('courseid' => $course1->id, 'enablemessaging' => 1));
|
||||
$group1b = $this->getDataGenerator()->create_group(array('courseid' => $course1->id, 'enablemessaging' => 0));
|
||||
|
||||
$conversations = $DB->get_records('message_conversations',
|
||||
[
|
||||
'contextid' => $coursecontext1->id,
|
||||
'component' => 'core_group',
|
||||
'itemtype' => 'groups',
|
||||
'enabled' => \core_message\api::MESSAGE_CONVERSATION_ENABLED
|
||||
]
|
||||
);
|
||||
$this->assertCount(1, $conversations);
|
||||
|
||||
$conversation = reset($conversations);
|
||||
// Check groupid was stored in itemid on conversation area.
|
||||
$this->assertEquals($group1a->id, $conversation->itemid);
|
||||
|
||||
$conversations = $DB->get_records('message_conversations', ['id' => $conversation->id]);
|
||||
$this->assertCount(1, $conversations);
|
||||
|
||||
$conversation = reset($conversations);
|
||||
|
||||
// Check group name was stored in conversation.
|
||||
$this->assertEquals($group1a->name, $conversation->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test groups_update_group enabling and disabling a group conversation.
|
||||
*/
|
||||
public function test_groups_update_group_conversation() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$coursecontext1 = context_course::instance($course1->id);
|
||||
|
||||
// Create two groups and only one group with enablemessaging = 1.
|
||||
$group1a = $this->getDataGenerator()->create_group(array('courseid' => $course1->id, 'enablemessaging' => 1));
|
||||
$group1b = $this->getDataGenerator()->create_group(array('courseid' => $course1->id, 'enablemessaging' => 0));
|
||||
|
||||
$conversations = $DB->get_records('message_conversations',
|
||||
[
|
||||
'contextid' => $coursecontext1->id,
|
||||
'component' => 'core_group',
|
||||
'itemtype' => 'groups',
|
||||
'enabled' => \core_message\api::MESSAGE_CONVERSATION_ENABLED
|
||||
]
|
||||
);
|
||||
$this->assertCount(1, $conversations);
|
||||
|
||||
// Check that the conversation area is created when group messaging is enabled in the course group.
|
||||
$group1b->enablemessaging = 1;
|
||||
groups_update_group($group1b);
|
||||
|
||||
$conversations = $DB->get_records('message_conversations',
|
||||
[
|
||||
'contextid' => $coursecontext1->id,
|
||||
'component' => 'core_group',
|
||||
'itemtype' => 'groups',
|
||||
'enabled' => \core_message\api::MESSAGE_CONVERSATION_ENABLED
|
||||
],
|
||||
'id ASC');
|
||||
$this->assertCount(2, $conversations);
|
||||
|
||||
$conversation1a = array_shift($conversations);
|
||||
$conversation1b = array_shift($conversations);
|
||||
|
||||
$conversation1b = $DB->get_record('message_conversations', ['id' => $conversation1b->id]);
|
||||
|
||||
// Check for group1b that group name was stored in conversation.
|
||||
$this->assertEquals($group1b->name, $conversation1b->name);
|
||||
|
||||
$group1b->enablemessaging = 0;
|
||||
groups_update_group($group1b);
|
||||
$this->assertEquals(0, $DB->get_field("message_conversations", "enabled", ['id' => $conversation1b->id]));
|
||||
|
||||
// Check that the name of the conversation is changed when the name of the course group is updated.
|
||||
$group1b->name = 'New group name';
|
||||
groups_update_group($group1b);
|
||||
$conversation1b = $DB->get_record('message_conversations', ['id' => $conversation1b->id]);
|
||||
$this->assertEquals($group1b->name, $conversation1b->name);
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,8 @@ $string['deleteselectedgroup'] = 'Delete selected group';
|
||||
$string['editgroupingsettings'] = 'Edit grouping settings';
|
||||
$string['editgroupsettings'] = 'Edit group settings';
|
||||
$string['editusersgroupsa'] = 'Edit groups for "{$a}"';
|
||||
$string['enablemessaging'] = 'Group messaging';
|
||||
$string['enablemessaging_help'] = 'If enabled, group members can send messages to the others in their group via the messaging drawer.';
|
||||
$string['enrolmentkey'] = 'Enrolment key';
|
||||
$string['enrolmentkey_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key. If a group enrolment key is specified, then not only will entering that key let the user into the course, but it will also automatically make them a member of this group.
|
||||
|
||||
|
@ -619,14 +619,22 @@
|
||||
<FIELD NAME="type" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
|
||||
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="convhash" TYPE="char" LENGTH="40" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" COMMENT="Defines the Moodle component which the area was added to"/>
|
||||
<FIELD NAME="itemtype" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="contextid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="The context id of the itemid or course of the itemtype was added"/>
|
||||
<FIELD NAME="enabled" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
<KEY NAME="contextid" TYPE="foreign" FIELDS="contextid" REFTABLE="context" REFFIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="type" UNIQUE="false" FIELDS="type"/>
|
||||
<INDEX NAME="convhash" UNIQUE="false" FIELDS="convhash"/>
|
||||
<INDEX NAME="component-itemtype-contextid-itemid" UNIQUE="false" FIELDS="component, itemtype, contextid, itemid"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="message_conversation_members" COMMENT="Stores all members in a conversations">
|
||||
|
@ -2605,5 +2605,52 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2018102200.00);
|
||||
}
|
||||
|
||||
if ($oldversion < 2018102300.02) {
|
||||
// Alter 'message_conversations' table to support groups.
|
||||
$table = new xmldb_table('message_conversations');
|
||||
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'convhash');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('itemtype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'component');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'itemtype');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('contextid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'itemid');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 0, 'contextid');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'enabled');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Add key.
|
||||
$key = new xmldb_key('contextid', XMLDB_KEY_FOREIGN, ['contextid'], 'context', ['id']);
|
||||
$dbman->add_key($table, $key);
|
||||
|
||||
// Add index.
|
||||
$index = new xmldb_index('component-itemtype-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, ['component', 'itemtype',
|
||||
'itemid', 'contextid']);
|
||||
if (!$dbman->index_exists($table, $index)) {
|
||||
$dbman->add_index($table, $index);
|
||||
}
|
||||
|
||||
upgrade_main_savepoint(true, 2018102300.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -73,6 +73,16 @@ class api {
|
||||
*/
|
||||
const MESSAGE_CONVERSATION_TYPE_GROUP = 2;
|
||||
|
||||
/**
|
||||
* The state for an enabled conversation area.
|
||||
*/
|
||||
const MESSAGE_CONVERSATION_ENABLED = 1;
|
||||
|
||||
/**
|
||||
* The state for a disabled conversation area.
|
||||
*/
|
||||
const MESSAGE_CONVERSATION_DISABLED = 0;
|
||||
|
||||
/**
|
||||
* Handles searching for messages in the message area.
|
||||
*
|
||||
@ -1459,10 +1469,18 @@ class api {
|
||||
*
|
||||
* @param int $type The type of conversation
|
||||
* @param int[] $userids The array of users to add to the conversation
|
||||
* @param string $name The name of the conversation
|
||||
* @param string|null $name The name of the conversation
|
||||
* @param int $enabled Determines if the conversation is created enabled or disabled
|
||||
* @param string|null $component Defines the Moodle component which the conversation belongs to, if any
|
||||
* @param string|null $itemtype Defines the type of the component
|
||||
* @param int|null $itemid The id of the component
|
||||
* @param int|null $contextid The id of the context
|
||||
* @return \stdClass
|
||||
*/
|
||||
public static function create_conversation(int $type, array $userids, string $name = null) {
|
||||
public static function create_conversation(int $type, array $userids, string $name = null,
|
||||
int $enabled = self::MESSAGE_CONVERSATION_ENABLED, string $component = null,
|
||||
string $itemtype = null, int $itemid = null, int $contextid = null) {
|
||||
|
||||
global $DB;
|
||||
|
||||
// Sanity check.
|
||||
@ -1479,7 +1497,13 @@ class api {
|
||||
if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) {
|
||||
$conversation->convhash = helper::get_conversation_hash($userids);
|
||||
}
|
||||
$conversation->component = $component;
|
||||
$conversation->itemtype = $itemtype;
|
||||
$conversation->itemid = $itemid;
|
||||
$conversation->contextid = $contextid;
|
||||
$conversation->enabled = $enabled;
|
||||
$conversation->timecreated = time();
|
||||
$conversation->timemodified = $conversation->timecreated;
|
||||
$conversation->id = $DB->insert_record('message_conversations', $conversation);
|
||||
|
||||
// Add users to this conversation.
|
||||
@ -1975,4 +1999,100 @@ class api {
|
||||
|
||||
return $DB->count_records('message_conversation_members', ['conversationid' => $convid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a conversation area is enabled.
|
||||
*
|
||||
* @param string $component Defines the Moodle component which the area was added to.
|
||||
* @param string $itemtype Defines the type of the component.
|
||||
* @param int $itemid The id of the component.
|
||||
* @param int $contextid The id of the context.
|
||||
* @return bool Returns if a conversation area exists and is enabled, false otherwise
|
||||
*/
|
||||
public static function is_conversation_area_enabled(string $component, string $itemtype, int $itemid, int $contextid) : bool {
|
||||
global $DB;
|
||||
|
||||
return $DB->record_exists('message_conversations',
|
||||
[
|
||||
'itemid' => $itemid,
|
||||
'contextid' => $contextid,
|
||||
'component' => $component,
|
||||
'itemtype' => $itemtype,
|
||||
'enabled' => self::MESSAGE_CONVERSATION_ENABLED
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get conversation by area.
|
||||
*
|
||||
* @param string $component Defines the Moodle component which the area was added to.
|
||||
* @param string $itemtype Defines the type of the component.
|
||||
* @param int $itemid The id of the component.
|
||||
* @param int $contextid The id of the context.
|
||||
* @return \stdClass
|
||||
*/
|
||||
public static function get_conversation_by_area(string $component, string $itemtype, int $itemid, int $contextid) {
|
||||
global $DB;
|
||||
|
||||
return $DB->get_record('message_conversations',
|
||||
[
|
||||
'itemid' => $itemid,
|
||||
'contextid' => $contextid,
|
||||
'component' => $component,
|
||||
'itemtype' => $itemtype
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a conversation.
|
||||
*
|
||||
* @param int $conversationid The id of the conversation.
|
||||
* @return void
|
||||
*/
|
||||
public static function enable_conversation(int $conversationid) {
|
||||
global $DB;
|
||||
|
||||
$conversation = new \stdClass();
|
||||
$conversation->id = $conversationid;
|
||||
$conversation->enabled = self::MESSAGE_CONVERSATION_ENABLED;
|
||||
$conversation->timemodified = time();
|
||||
$DB->update_record('message_conversations', $conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a conversation.
|
||||
*
|
||||
* @param int $conversationid The id of the conversation.
|
||||
* @return void
|
||||
*/
|
||||
public static function disable_conversation(int $conversationid) {
|
||||
global $DB;
|
||||
|
||||
$conversation = new \stdClass();
|
||||
$conversation->id = $conversationid;
|
||||
$conversation->enabled = self::MESSAGE_CONVERSATION_DISABLED;
|
||||
$conversation->timemodified = time();
|
||||
$DB->update_record('message_conversations', $conversation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the name of a conversation.
|
||||
*
|
||||
* @param int $conversationid The id of a conversation.
|
||||
* @param string $name The main name of the area
|
||||
* @return void
|
||||
*/
|
||||
public static function update_conversation_name(int $conversationid, string $name) {
|
||||
global $DB;
|
||||
|
||||
if ($conversation = $DB->get_record('message_conversations', array('id' => $conversationid))) {
|
||||
if ($name <> $conversation->name) {
|
||||
$conversation->name = $name;
|
||||
$conversation->timemodified = time();
|
||||
$DB->update_record('message_conversations', $conversation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3263,6 +3263,117 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
|
||||
\core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, [1, 2, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test create message conversation with area.
|
||||
*/
|
||||
public function test_create_conversation_with_area() {
|
||||
$contextid = 111;
|
||||
$itemid = 222;
|
||||
$name = 'Name of conversation';
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_DISABLED,
|
||||
'core_group',
|
||||
'groups',
|
||||
$itemid,
|
||||
$contextid
|
||||
);
|
||||
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_DISABLED, $conversation->enabled);
|
||||
$this->assertEquals('core_group', $conversation->component);
|
||||
$this->assertEquals('groups', $conversation->itemtype);
|
||||
$this->assertEquals($itemid, $conversation->itemid);
|
||||
$this->assertEquals($contextid, $conversation->contextid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_conversation_by_area.
|
||||
*/
|
||||
public function test_get_conversation_by_area() {
|
||||
$contextid = 111;
|
||||
$itemid = 222;
|
||||
$name = 'Name of conversation';
|
||||
$createconversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_DISABLED,
|
||||
'core_group',
|
||||
'groups',
|
||||
$itemid,
|
||||
$contextid
|
||||
);
|
||||
$conversation = \core_message\api::get_conversation_by_area('core_group', 'groups', $itemid, $contextid);
|
||||
|
||||
$this->assertEquals($createconversation->id, $conversation->id);
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_DISABLED, $conversation->enabled);
|
||||
$this->assertEquals('core_group', $conversation->component);
|
||||
$this->assertEquals('groups', $conversation->itemtype);
|
||||
$this->assertEquals($itemid, $conversation->itemid);
|
||||
$this->assertEquals($contextid, $conversation->contextid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test enable_conversation.
|
||||
*/
|
||||
public function test_enable_conversation() {
|
||||
global $DB;
|
||||
|
||||
$name = 'Name of conversation';
|
||||
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_DISABLED
|
||||
);
|
||||
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_DISABLED, $conversation->enabled);
|
||||
\core_message\api::enable_conversation($conversation->id);
|
||||
$conversationenabled = $DB->get_field('message_conversations', 'enabled', ['id' => $conversation->id]);
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_ENABLED, $conversationenabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test disable_conversation.
|
||||
*/
|
||||
public function test_disable_conversation() {
|
||||
global $DB;
|
||||
|
||||
$name = 'Name of conversation';
|
||||
|
||||
$conversation = \core_message\api::create_conversation(
|
||||
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP,
|
||||
[],
|
||||
$name,
|
||||
\core_message\api::MESSAGE_CONVERSATION_ENABLED
|
||||
);
|
||||
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_ENABLED, $conversation->enabled);
|
||||
\core_message\api::disable_conversation($conversation->id);
|
||||
$conversationenabled = $DB->get_field('message_conversations', 'enabled', ['id' => $conversation->id]);
|
||||
$this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_DISABLED, $conversationenabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update_conversation_name.
|
||||
*/
|
||||
public function test_update_conversation_name() {
|
||||
global $DB;
|
||||
|
||||
$conversation = \core_message\api::create_conversation(\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP, []);
|
||||
|
||||
$newname = 'New name of conversation';
|
||||
\core_message\api::update_conversation_name($conversation->id, $newname);
|
||||
|
||||
$this->assertEquals(
|
||||
$newname,
|
||||
$DB->get_field('message_conversations', 'name', ['id' => $conversation->id])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison function for sorting contacts.
|
||||
*
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2018102300.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2018102300.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user