MDL-76849 qtype_truefalse: Include question number in answer fields
[moodle.git] / message / classes / time_last_message_between_users.php
blob8f7e99a05e6f09434bc1fe8cbddcc73a6a17413a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Cache data source for the time of the last message between users.
20 * @package core_message
21 * @category cache
22 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 namespace core_message;
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Cache data source for the time of the last message in a conversation.
33 * @package core_message
34 * @category cache
35 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class time_last_message_between_users implements \cache_data_source {
40 /** @var time_last_message_between_users the singleton instance of this class. */
41 protected static $instance = null;
43 /**
44 * Returns an instance of the data source class that the cache can use for loading data using the other methods
45 * specified by the cache_data_source interface.
47 * @param \cache_definition $definition
48 * @return object
50 public static function get_instance_for_cache(\cache_definition $definition) {
51 if (is_null(self::$instance)) {
52 self::$instance = new time_last_message_between_users();
54 return self::$instance;
57 /**
58 * Loads the data for the key provided ready formatted for caching.
60 * @param string|int $key The key to load.
61 * @return mixed What ever data should be returned, or false if it can't be loaded.
63 public function load_for_cache($key) {
64 $message = api::get_most_recent_conversation_message($key);
66 if ($message) {
67 return $message->timecreated;
68 } else {
69 return null;
73 /**
74 * Loads several keys for the cache.
76 * @param array $keys An array of keys each of which will be string|int.
77 * @return array An array of matching data items.
79 public function load_many_for_cache(array $keys) {
80 $results = [];
82 foreach ($keys as $key) {
83 $results[] = $this->load_for_cache($key);
86 return $results;