MDL-63280 core: minor changes after review

- Fixed reference to non-existent column 'timeread'.
- Fixed alignment issues.
- Fixed inconsistencies between upgrade.php and install.xml.
- Cleaned unit tests of unnecessary DB calls.
- Renamed 'get_does_conversation_area_enabled' to
  'is_conversation_area_enabled' and moved to api.php.
- Replaced "$mform->elementExists('enablemessaging')"
  check with a capability check.
- Removed the change of [] to array() in unrelated to upgrade code.
- Updated conversation 'timemodified' field when updating name.
- Bumped version based on latest master.
This commit is contained in:
Mark Nelson
2018-10-25 17:51:04 +08:00
parent e7f467143f
commit f0e137c539
9 changed files with 137 additions and 243 deletions
+40 -18
View File
@@ -1983,24 +1983,21 @@ class api {
* @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
* @param int $enabled Enable or disable the conversation area
* @return \stdClass
*/
public static function create_conversation_area(string $component,
string $itemtype,
int $itemid,
int $contextid,
int $enabled = 0,
string $name) {
public static function create_conversation_area(string $component, string $itemtype, int $itemid, int $contextid, string $name,
int $enabled = 0) {
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->component = $component;
$conversationarea->itemtype = $itemtype;
$conversationarea->itemid = $itemid;
$conversationarea->contextid = $contextid;
@@ -2012,6 +2009,29 @@ class api {
return $conversationarea;
}
/**
* 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_conversation_area',
[
'itemid' => $itemid,
'contextid' => $contextid,
'component' => $component,
'itemtype' => $itemtype,
'enabled' => 1
]
);
}
/**
* Get conversation area.
*
@@ -2021,16 +2041,17 @@ class api {
* @param int $contextid The id of the context.
* @return object message_conversation_area.
*/
public static function get_conversation_area(string $component,
string $itemtype,
int $itemid,
int $contextid) {
public static function get_conversation_area(string $component, string $itemtype, int $itemid, int $contextid) {
global $DB;
return $DB->get_record('message_conversation_area', ['itemid' => $itemid,
'contextid' => $contextid,
'component' => $component,
'itemtype' => $itemtype]);
return $DB->get_record('message_conversation_area',
[
'itemid' => $itemid,
'contextid' => $contextid,
'component' => $component,
'itemtype' => $itemtype
]
);
}
/**
@@ -2045,7 +2066,7 @@ class api {
$conversationarea = new \stdClass();
$conversationarea->id = $conversationareaid;
$conversationarea->enabled = 1;
$conversationarea->timeread = time();
$conversationarea->timemodified = time();
$DB->update_record('message_conversation_area', $conversationarea);
}
@@ -2061,7 +2082,7 @@ class api {
$conversationarea = new \stdClass();
$conversationarea->id = $conversationareaid;
$conversationarea->enabled = 0;
$conversationarea->timeread = time();
$conversationarea->timemodified = time();
$DB->update_record('message_conversation_area', $conversationarea);
}
@@ -2078,6 +2099,7 @@ class api {
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);
}
}