original_string: public static function get_conversation_messages(int $userid, int $convid, int $timedeleted = 0, int $limitfrom = 0,
                                                       int $limitnum = 0, string $sort = 'timecreated ASC', int $timefrom = 0,
                                                       int $timeto = 0) : array {
          global $DB;
  
          $sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
                         m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
                         mc.contextid, muaread.timecreated AS timeread
                    FROM {message_conversations} mc
              INNER JOIN {messages} m
                      ON m.conversationid = mc.id
               LEFT JOIN {message_user_actions} muaread
                      ON (muaread.messageid = m.id
                     AND muaread.userid = :userid1
                     AND muaread.action = :readaction)";
          $params = ['userid1' => $userid, 'readaction' => api::MESSAGE_ACTION_READ, 'convid' => $convid];
  
          if (empty($timedeleted)) {
              $sql .= " LEFT JOIN {message_user_actions} mua
                               ON (mua.messageid = m.id
                              AND mua.userid = :userid2
                              AND mua.action = :deleteaction
                              AND mua.timecreated is NOT NULL)";
          } else {
              $sql .= " INNER JOIN {message_user_actions} mua
                                ON (mua.messageid = m.id
                               AND mua.userid = :userid2
                               AND mua.action = :deleteaction
                               AND mua.timecreated = :timedeleted)";
              $params['timedeleted'] = $timedeleted;
          }
  
          $params['userid2'] = $userid;
          $params['deleteaction'] = api::MESSAGE_ACTION_DELETED;
  
          $sql .= " WHERE mc.id = :convid";
  
          if (!empty($timefrom)) {
              $sql .= " AND m.timecreated >= :timefrom";
              $params['timefrom'] = $timefrom;
          }
  
          if (!empty($timeto)) {
              $sql .= " AND m.timecreated <= :timeto";
              $params['timeto'] = $timeto;
          }
  
          if (empty($timedeleted)) {
              $sql .= " AND mua.id is NULL";
          }
  
          $sql .= " ORDER BY m.$sort";
  
          $messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
  
          return $messages;
      }
code: public static function get_conversation_messages(int $userid, int $convid, int $timedeleted = 0, int $limitfrom = 0,
                                                       int $limitnum = 0, string $sort = 'timecreated ASC', int $timefrom = 0,
                                                       int $timeto = 0) : array {
          global $DB;
  
          $sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
                         m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
                         mc.contextid, muaread.timecreated AS timeread
                    FROM {message_conversations} mc
              INNER JOIN {messages} m
                      ON m.conversationid = mc.id
               LEFT JOIN {message_user_actions} muaread
                      ON (muaread.messageid = m.id
                     AND muaread.userid = :userid1
                     AND muaread.action = :readaction)";
          $params = ['userid1' => $userid, 'readaction' => api::MESSAGE_ACTION_READ, 'convid' => $convid];
  
          if (empty($timedeleted)) {
              $sql .= " LEFT JOIN {message_user_actions} mua
                               ON (mua.messageid = m.id
                              AND mua.userid = :userid2
                              AND mua.action = :deleteaction
                              AND mua.timecreated is NOT NULL)";
          } else {
              $sql .= " INNER JOIN {message_user_actions} mua
                                ON (mua.messageid = m.id
                               AND mua.userid = :userid2
                               AND mua.action = :deleteaction
                               AND mua.timecreated = :timedeleted)";
              $params['timedeleted'] = $timedeleted;
          }
  
          $params['userid2'] = $userid;
          $params['deleteaction'] = api::MESSAGE_ACTION_DELETED;
  
          $sql .= " WHERE mc.id = :convid";
  
          if (!empty($timefrom)) {
              $sql .= " AND m.timecreated >= :timefrom";
              $params['timefrom'] = $timefrom;
          }
  
          if (!empty($timeto)) {
              $sql .= " AND m.timecreated <= :timeto";
              $params['timeto'] = $timeto;
          }
  
          if (empty($timedeleted)) {
              $sql .= " AND mua.id is NULL";
          }
  
          $sql .= " ORDER BY m.$sort";
  
          $messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
  
          return $messages;
      }
code_tokens: public static function get_conversation_messages ( int $ userid , int $ convid , int $ timedeleted = 0 , int $ limitfrom = 0 , int $ limitnum = 0 , string $ sort = 'timecreated ASC' , int $ timefrom = 0 , int $ timeto = 0 ) : array { global $ DB ; $ sql = "SELECT m.id, m.useridfrom, m.subject, m.fullmessage, m.fullmessagehtml,
                         m.fullmessageformat, m.fullmessagetrust, m.smallmessage, m.timecreated,
                         mc.contextid, muaread.timecreated AS timeread
                    FROM {message_conversations} mc
              INNER JOIN {messages} m
                      ON m.conversationid = mc.id
               LEFT JOIN {message_user_actions} muaread
                      ON (muaread.messageid = m.id
                     AND muaread.userid = :userid1
                     AND muaread.action = :readaction)" ; $ params = [ 'userid1' => $ userid , 'readaction' => api :: MESSAGE_ACTION_READ , 'convid' => $ convid ] ; if ( empty ( $ timedeleted ) ) { $ sql .= " LEFT JOIN {message_user_actions} mua
                               ON (mua.messageid = m.id
                              AND mua.userid = :userid2
                              AND mua.action = :deleteaction
                              AND mua.timecreated is NOT NULL)" ; } else { $ sql .= " INNER JOIN {message_user_actions} mua
                                ON (mua.messageid = m.id
                               AND mua.userid = :userid2
                               AND mua.action = :deleteaction
                               AND mua.timecreated = :timedeleted)" ; $ params [ 'timedeleted' ] = $ timedeleted ; } $ params [ 'userid2' ] = $ userid ; $ params [ 'deleteaction' ] = api :: MESSAGE_ACTION_DELETED ; $ sql .= " WHERE mc.id = :convid" ; if ( ! empty ( $ timefrom ) ) { $ sql .= " AND m.timecreated >= :timefrom" ; $ params [ 'timefrom' ] = $ timefrom ; } if ( ! empty ( $ timeto ) ) { $ sql .= " AND m.timecreated <= :timeto" ; $ params [ 'timeto' ] = $ timeto ; } if ( empty ( $ timedeleted ) ) { $ sql .= " AND mua.id is NULL" ; } $ sql .= " ORDER BY m.$sort" ; $ messages = $ DB -> get_records_sql ( $ sql , $ params , $ limitfrom , $ limitnum ) ; return $ messages ; }
docstring: Helper function to retrieve conversation messages.
  
  @param  int $userid The current user.
  @param  int $convid The conversation identifier.
  @param  int $timedeleted The time the message was deleted
  @param  int $limitfrom Return a subset of records, starting at this point (optional).
  @param  int $limitnum Return a subset comprising this many records in total (optional, required if $limitfrom is set).
  @param  string $sort The column name to order by including optionally direction.
  @param  int $timefrom The time from the message being sent.
  @param  int $timeto The time up until the message being sent.
  @return array of messages
docstring_tokens: Helper function to retrieve conversation messages .