original_string: function get_comments($page) {
          global $DB;
  
          if ($page == 0) {
              $start = 0;
          } else {
              $start = $page * $this->perpage;
          }
          $comments = array();
  
          $usernamefields = get_all_user_name_fields(true, 'u');
          $sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated
                    FROM {comments} c
                    JOIN {user} u
                         ON u.id=c.userid
                ORDER BY c.timecreated ASC";
          $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage);
          $formatoptions = array('overflowdiv' => true, 'blanktarget' => true);
          foreach ($rs as $item) {
              // Set calculated fields
              $item->fullname = fullname($item);
              $item->time = userdate($item->timecreated);
              $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
              // Unset fields not related to the comment
              foreach (get_all_user_name_fields() as $namefield) {
                  unset($item->$namefield);
              }
              unset($item->timecreated);
              // Record the comment
              $comments[] = $item;
          }
          $rs->close();
  
          return $comments;
      }
code: function get_comments($page) {
          global $DB;
  
          if ($page == 0) {
              $start = 0;
          } else {
              $start = $page * $this->perpage;
          }
          $comments = array();
  
          $usernamefields = get_all_user_name_fields(true, 'u');
          $sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated
                    FROM {comments} c
                    JOIN {user} u
                         ON u.id=c.userid
                ORDER BY c.timecreated ASC";
          $rs = $DB->get_recordset_sql($sql, null, $start, $this->perpage);
          $formatoptions = array('overflowdiv' => true, 'blanktarget' => true);
          foreach ($rs as $item) {
              // Set calculated fields
              $item->fullname = fullname($item);
              $item->time = userdate($item->timecreated);
              $item->content = format_text($item->content, FORMAT_MOODLE, $formatoptions);
              // Unset fields not related to the comment
              foreach (get_all_user_name_fields() as $namefield) {
                  unset($item->$namefield);
              }
              unset($item->timecreated);
              // Record the comment
              $comments[] = $item;
          }
          $rs->close();
  
          return $comments;
      }
code_tokens: function get_comments ( $ page ) { global $ DB ; if ( $ page == 0 ) { $ start = 0 ; } else { $ start = $ page * $ this -> perpage ; } $ comments = array ( ) ; $ usernamefields = get_all_user_name_fields ( true , 'u' ) ; $ sql = "SELECT c.id, c.contextid, c.itemid, c.component, c.commentarea, c.userid, c.content, $usernamefields, c.timecreated
                    FROM {comments} c
                    JOIN {user} u
                         ON u.id=c.userid
                ORDER BY c.timecreated ASC" ; $ rs = $ DB -> get_recordset_sql ( $ sql , null , $ start , $ this -> perpage ) ; $ formatoptions = array ( 'overflowdiv' => true , 'blanktarget' => true ) ; foreach ( $ rs as $ item ) { // Set calculated fields $ item -> fullname = fullname ( $ item ) ; $ item -> time = userdate ( $ item -> timecreated ) ; $ item -> content = format_text ( $ item -> content , FORMAT_MOODLE , $ formatoptions ) ; // Unset fields not related to the comment foreach ( get_all_user_name_fields ( ) as $ namefield ) { unset ( $ item -> $ namefield ) ; } unset ( $ item -> timecreated ) ; // Record the comment $ comments [ ] = $ item ; } $ rs -> close ( ) ; return $ comments ; }
docstring: Return comments by pages
  
  @global moodle_database $DB
  @param int $page
  @return array An array of comments
docstring_tokens: Return comments by pages