original_string: public static function get_records_by_contextlevel($contextlevel = null, $status = false, $sort = 'timecreated',
                                                         $offset = 0, $limit = 0) {
          global $DB;
  
          $sql = "SELECT expiredctx.*
                    FROM {" . self::TABLE . "} expiredctx
                    JOIN {context} ctx
                      ON ctx.id = expiredctx.contextid";
          $params = [];
          $conditions = [];
  
          if (!empty($contextlevel)) {
              $conditions[] = "ctx.contextlevel = :contextlevel";
              $params['contextlevel'] = intval($contextlevel);
          }
  
          if ($status !== false) {
              $conditions[] = "expiredctx.status = :status";
              $params['status'] = intval($status);
          }
  
          if (!empty($conditions)) {
              $sql .= ' WHERE ' . implode(' AND ', $conditions);
          }
          $sql .= " ORDER BY expiredctx.{$sort}";
  
          $records = $DB->get_records_sql($sql, $params, $offset, $limit);
  
          // We return class instances.
          $instances = array();
          foreach ($records as $key => $record) {
              $instances[$key] = new static(0, $record);
          }
  
          return $instances;
      }
code: public static function get_records_by_contextlevel($contextlevel = null, $status = false, $sort = 'timecreated',
                                                         $offset = 0, $limit = 0) {
          global $DB;
  
          $sql = "SELECT expiredctx.*
                    FROM {" . self::TABLE . "} expiredctx
                    JOIN {context} ctx
                      ON ctx.id = expiredctx.contextid";
          $params = [];
          $conditions = [];
  
          if (!empty($contextlevel)) {
              $conditions[] = "ctx.contextlevel = :contextlevel";
              $params['contextlevel'] = intval($contextlevel);
          }
  
          if ($status !== false) {
              $conditions[] = "expiredctx.status = :status";
              $params['status'] = intval($status);
          }
  
          if (!empty($conditions)) {
              $sql .= ' WHERE ' . implode(' AND ', $conditions);
          }
          $sql .= " ORDER BY expiredctx.{$sort}";
  
          $records = $DB->get_records_sql($sql, $params, $offset, $limit);
  
          // We return class instances.
          $instances = array();
          foreach ($records as $key => $record) {
              $instances[$key] = new static(0, $record);
          }
  
          return $instances;
      }
code_tokens: public static function get_records_by_contextlevel ( $ contextlevel = null , $ status = false , $ sort = 'timecreated' , $ offset = 0 , $ limit = 0 ) { global $ DB ; $ sql = "SELECT expiredctx.*
                    FROM {" . self :: TABLE . "} expiredctx
                    JOIN {context} ctx
                      ON ctx.id = expiredctx.contextid" ; $ params = [ ] ; $ conditions = [ ] ; if ( ! empty ( $ contextlevel ) ) { $ conditions [ ] = "ctx.contextlevel = :contextlevel" ; $ params [ 'contextlevel' ] = intval ( $ contextlevel ) ; } if ( $ status !== false ) { $ conditions [ ] = "expiredctx.status = :status" ; $ params [ 'status' ] = intval ( $ status ) ; } if ( ! empty ( $ conditions ) ) { $ sql .= ' WHERE ' . implode ( ' AND ' , $ conditions ) ; } $ sql .= " ORDER BY expiredctx.{$sort}" ; $ records = $ DB -> get_records_sql ( $ sql , $ params , $ offset , $ limit ) ; // We return class instances. $ instances = array ( ) ; foreach ( $ records as $ key => $ record ) { $ instances [ $ key ] = new static ( 0 , $ record ) ; } return $ instances ; }
docstring: Returns expired_contexts instances that match the provided level and status.
  
  @param int $contextlevel The context level filter criterion.
  @param bool $status The expired context record's status.
  @param string $sort The sort column. Must match the column name in {tool_dataprivacy_ctxexpired} table
  @param int $offset The query offset.
  @param int $limit The query limit.
  @return expired_context[]
  @throws dml_exception
docstring_tokens: Returns expired_contexts instances that match the provided level and status .