MDL-63280 core_message: Create conversation area

This commit is contained in:
cescobedo
2018-10-25 12:20:00 +08:00
committed by Mark Nelson
parent daf0b4f08b
commit 55fda006e3
4 changed files with 113 additions and 2 deletions
+36
View File
@@ -1975,4 +1975,40 @@ class api {
return $DB->count_records('message_conversation_members', ['conversationid' => $convid]);
}
/**
* Create message conversation 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
* @param int $enabled Allow enabled or disabled the conversation area
* @param string $name The main name of the area
* @return \stdClass
*/
public static function create_conversation_area(string $component,
string $itemtype,
int $itemid,
int $contextid,
int $enabled = 0,
string $name) {
global $DB;
// Create a conversation.
$conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_GROUP, array(), $name);
// Create a conversation area.
$conversationarea = new \stdClass;
$conversationarea->conversationid = $conversation->id;
$conversationarea->component = !empty($component) ? $component : '';
$conversationarea->itemtype = $itemtype;
$conversationarea->itemid = $itemid;
$conversationarea->contextid = $contextid;
$conversationarea->enabled = $enabled;
$conversationarea->timecreated = time();
$conversationarea->timemodified = $conversationarea->timecreated;
$conversationarea->id = $DB->insert_record('message_conversation_area', $conversationarea);
return $conversationarea;
}
}