MDL-63280 core_message: added constants for enabled/disabled
authorMark Nelson <markn@moodle.com>
Wed, 24 Oct 2018 09:28:06 +0000 (17:28 +0800)
committerMark Nelson <markn@moodle.com>
Thu, 25 Oct 2018 09:51:34 +0000 (17:51 +0800)
group/lib.php
group/tests/lib_test.php
message/classes/api.php
message/tests/api_test.php

index e06ea2a..8574a53 100644 (file)
@@ -278,7 +278,8 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {
     // Group conversation messaging.
     if (\core_message\api::can_create_group_conversation($USER->id, $context)) {
         if (!empty($data->enablemessaging)) {
-            \core_message\api::create_conversation_area('core_group', 'groups', $group->id, $context->id, $group->name, 1);
+            \core_message\api::create_conversation_area('core_group', 'groups', $group->id, $group->name, $context->id,
+                \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED);
         }
     }
 
@@ -432,7 +433,8 @@ function groups_update_group($data, $editform = false, $editoroptions = false) {
             \core_message\api::update_conversation_name($conversationarea->conversationid, $group->name);
         } else {
             if (!empty($data->enablemessaging)) {
-                \core_message\api::create_conversation_area('core_group', 'groups', $group->id, $context->id, $group->name, 1);
+                \core_message\api::create_conversation_area('core_group', 'groups', $group->id, $group->name,
+                    \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED);
             }
         }
     }
index b141b68..01ad486 100644 (file)
@@ -549,7 +549,7 @@ class core_group_lib_testcase extends advanced_testcase {
                 'contextid' => $coursecontext1->id,
                 'component' => 'core_group',
                 'itemtype' => 'groups',
-                'enabled' => 1
+                'enabled' => \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED
             ]
         );
         $this->assertCount(1, $conversationareas);
@@ -587,7 +587,7 @@ class core_group_lib_testcase extends advanced_testcase {
                 'contextid' => $coursecontext1->id,
                 'component' => 'core_group',
                 'itemtype' => 'groups',
-                'enabled' => 1
+                'enabled' => \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED
             ]
         );
         $this->assertCount(1, $conversationareas);
@@ -601,7 +601,7 @@ class core_group_lib_testcase extends advanced_testcase {
                 'contextid' => $coursecontext1->id,
                 'component' => 'core_group',
                 'itemtype' => 'groups',
-                'enabled' => 1
+                'enabled' => \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED
             ],
         'id ASC');
         $this->assertCount(2, $conversationareas);
index b29bde3..5aff397 100644 (file)
@@ -73,6 +73,16 @@ class api {
      */
     const MESSAGE_CONVERSATION_TYPE_GROUP = 2;
 
+    /**
+     * The state for an enabled conversation area.
+     */
+    const MESSAGE_CONVERSATION_AREA_ENABLED = 1;
+
+    /**
+     * The state for a disabled conversation area.
+     */
+    const MESSAGE_CONVERSATION_AREA_DISABLED = 0;
+
     /**
      * Handles searching for messages in the message area.
      *
@@ -1988,7 +1998,7 @@ class api {
      * @return \stdClass
      */
     public static function create_conversation_area(string $component, string $itemtype, int $itemid, int $contextid, string $name,
-            int $enabled = 0) {
+            int $enabled = self::MESSAGE_CONVERSATION_AREA_DISABLED) {
         global $DB;
 
         // Create a conversation.
@@ -2027,7 +2037,7 @@ class api {
                 'contextid' => $contextid,
                 'component' => $component,
                 'itemtype' => $itemtype,
-                'enabled' => 1
+                'enabled' => self::MESSAGE_CONVERSATION_AREA_ENABLED
             ]
         );
     }
@@ -2065,7 +2075,7 @@ class api {
 
         $conversationarea = new \stdClass();
         $conversationarea->id = $conversationareaid;
-        $conversationarea->enabled = 1;
+        $conversationarea->enabled = self::MESSAGE_CONVERSATION_AREA_ENABLED;
         $conversationarea->timemodified = time();
         $DB->update_record('message_conversation_area', $conversationarea);
     }
@@ -2081,7 +2091,7 @@ class api {
 
         $conversationarea = new \stdClass();
         $conversationarea->id = $conversationareaid;
-        $conversationarea->enabled = 0;
+        $conversationarea->enabled = self::MESSAGE_CONVERSATION_AREA_DISABLED;
         $conversationarea->timemodified = time();
         $DB->update_record('message_conversation_area', $conversationarea);
     }
index da8525b..6ba1fdf 100644 (file)
@@ -3271,13 +3271,13 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $contextid = 111;
         $itemid = 222;
         $name = 'Name of conversation';
-        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name, 0);
+        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name);
 
         $this->assertEquals($itemid, $conversationarea->itemid);
         $this->assertEquals($contextid, $conversationarea->contextid);
         $this->assertEquals('core_group', $conversationarea->component);
         $this->assertEquals('groups', $conversationarea->itemtype);
-        $this->assertEquals(0, $conversationarea->enabled);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_AREA_DISABLED, $conversationarea->enabled);
     }
 
     /**
@@ -3287,14 +3287,15 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $contextid = 111;
         $itemid = 222;
         $name = 'Name of conversation';
-        \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name, 1);
+        \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name,
+            \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED);
         $conversationarea = \core_message\api::get_conversation_area('core_group', 'groups', $itemid, $contextid);
 
         $this->assertEquals($itemid, $conversationarea->itemid);
         $this->assertEquals($contextid, $conversationarea->contextid);
         $this->assertEquals('core_group', $conversationarea->component);
         $this->assertEquals('groups', $conversationarea->itemtype);
-        $this->assertEquals(1, $conversationarea->enabled);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED, $conversationarea->enabled);
     }
 
     /**
@@ -3306,10 +3307,11 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $contextid = 111;
         $itemid = 222;
         $name = 'Name of conversation';
-        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name, 0);
+
+        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name);
         \core_message\api::enable_conversation_area($conversationarea->id);
         $conversationareaenabled = $DB->get_field('message_conversation_area', 'enabled', ['id' => $conversationarea->id]);
-        $this->assertEquals(1, $conversationareaenabled);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED, $conversationareaenabled);
     }
 
     /**
@@ -3321,11 +3323,13 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $contextid = 111;
         $itemid = 222;
         $name = 'Name of conversation';
-        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name, 1);
-        $this->assertEquals(1, $conversationarea->enabled);
+
+        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name,
+            \core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_AREA_ENABLED, $conversationarea->enabled);
         \core_message\api::disable_conversation_area($conversationarea->id);
         $conversationareaenabled = $DB->get_field('message_conversation_area', 'enabled', ['id' => $conversationarea->id]);
-        $this->assertEquals(0, $conversationareaenabled);
+        $this->assertEquals(\core_message\api::MESSAGE_CONVERSATION_AREA_DISABLED, $conversationareaenabled);
     }
     /**
      * Test update_conversation_name.
@@ -3336,7 +3340,8 @@ class core_message_api_testcase extends core_message_messagelib_testcase {
         $contextid = 111;
         $itemid = 222;
         $name = 'Name of conversation';
-        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name, 1);
+
+        $conversationarea = \core_message\api::create_conversation_area('core_group', 'groups', $itemid, $contextid, $name);
 
         $newname = 'New name of conversation';
         \core_message\api::update_conversation_name($conversationarea->conversationid, $newname);