original_string: public static function get_all_models($enabled = false, $trained = false, $predictioncontext = false) {
          global $DB;
  
          $params = array();
  
          $sql = "SELECT am.* FROM {analytics_models} am";
  
          if ($enabled || $trained || $predictioncontext) {
              $conditions = [];
              if ($enabled) {
                  $conditions[] = 'am.enabled = :enabled';
                  $params['enabled'] = 1;
              }
              if ($trained) {
                  $conditions[] = 'am.trained = :trained';
                  $params['trained'] = 1;
              }
              if ($predictioncontext) {
                  $conditions[] = "EXISTS (SELECT 'x'
                                             FROM {analytics_predictions} ap
                                            WHERE ap.modelid = am.id AND ap.contextid = :contextid)";
                  $params['contextid'] = $predictioncontext->id;
              }
              $sql .= ' WHERE ' . implode(' AND ', $conditions);
          }
          $sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC';
  
          $modelobjs = $DB->get_records_sql($sql, $params);
  
          $models = array();
          foreach ($modelobjs as $modelobj) {
              $model = new \core_analytics\model($modelobj);
              if ($model->is_available()) {
                  $models[$modelobj->id] = $model;
              }
          }
          return $models;
      }
code: public static function get_all_models($enabled = false, $trained = false, $predictioncontext = false) {
          global $DB;
  
          $params = array();
  
          $sql = "SELECT am.* FROM {analytics_models} am";
  
          if ($enabled || $trained || $predictioncontext) {
              $conditions = [];
              if ($enabled) {
                  $conditions[] = 'am.enabled = :enabled';
                  $params['enabled'] = 1;
              }
              if ($trained) {
                  $conditions[] = 'am.trained = :trained';
                  $params['trained'] = 1;
              }
              if ($predictioncontext) {
                  $conditions[] = "EXISTS (SELECT 'x'
                                             FROM {analytics_predictions} ap
                                            WHERE ap.modelid = am.id AND ap.contextid = :contextid)";
                  $params['contextid'] = $predictioncontext->id;
              }
              $sql .= ' WHERE ' . implode(' AND ', $conditions);
          }
          $sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC';
  
          $modelobjs = $DB->get_records_sql($sql, $params);
  
          $models = array();
          foreach ($modelobjs as $modelobj) {
              $model = new \core_analytics\model($modelobj);
              if ($model->is_available()) {
                  $models[$modelobj->id] = $model;
              }
          }
          return $models;
      }
code_tokens: public static function get_all_models ( $ enabled = false , $ trained = false , $ predictioncontext = false ) { global $ DB ; $ params = array ( ) ; $ sql = "SELECT am.* FROM {analytics_models} am" ; if ( $ enabled || $ trained || $ predictioncontext ) { $ conditions = [ ] ; if ( $ enabled ) { $ conditions [ ] = 'am.enabled = :enabled' ; $ params [ 'enabled' ] = 1 ; } if ( $ trained ) { $ conditions [ ] = 'am.trained = :trained' ; $ params [ 'trained' ] = 1 ; } if ( $ predictioncontext ) { $ conditions [ ] = "EXISTS (SELECT 'x'
                                             FROM {analytics_predictions} ap
                                            WHERE ap.modelid = am.id AND ap.contextid = :contextid)" ; $ params [ 'contextid' ] = $ predictioncontext -> id ; } $ sql .= ' WHERE ' . implode ( ' AND ' , $ conditions ) ; } $ sql .= ' ORDER BY am.enabled DESC, am.timemodified DESC' ; $ modelobjs = $ DB -> get_records_sql ( $ sql , $ params ) ; $ models = array ( ) ; foreach ( $ modelobjs as $ modelobj ) { $ model = new \ core_analytics \ model ( $ modelobj ) ; if ( $ model -> is_available ( ) ) { $ models [ $ modelobj -> id ] = $ model ; } } return $ models ; }
docstring: Returns all system models that match the provided filters.
  
  @param bool $enabled
  @param bool $trained
  @param \context|false $predictioncontext
  @return \core_analytics\model[]
docstring_tokens: Returns all system models that match the provided filters .