# setup
includeLibs.tx_rnbase_controller = EXT:rn_base/class.tx_rnbase_controller.php


plugin.tx_t3sportstats                = USER
plugin.tx_t3sportstats.flexform       = flexform_main.xml
plugin.tx_t3sportstats.toUserInt      = 1
plugin.tx_t3sportstats.userFunc       = tx_rnbase_controller->main
plugin.tx_t3sportstats.defaultAction  = System25\T3sports\Action\PlayerStats
plugin.tx_t3sportstats.qualifier      = cfc_league_fe
plugin.tx_t3sportstats.templatePath   = EXT:t3sportstats/templates
plugin.tx_t3sportstats.locallangFilename = EXT:t3sportstats/Resources/Private/Language/locallang.xml


tt_content.list.20.tx_t3sportstats    =< plugin.tx_t3sportstats

lib.t3sports.statsData {
  pagebrowser =< lib.t3sports.pagebrowser
  roll.value = 1
  totalline.startValue = 1

  player =< lib.t3sports.profile
  coach =< lib.t3sports.profile
  referee =< lib.t3sports.profile
  competition =< lib.t3sports.competition
  club =< lib.t3sports.club
  team =< lib.t3sports.team
  goals.ifEmpty = -
  goals_per_match {
    wrap = (|)
  	number_format.decimal = 2
    # Auch an ganze Zahlen Nachkommastellen anfügen
    number_format.dontCheckFloat = 1
    ifEmpty = -
  }
  goals_after_minutes.number_format.decimal = 0
  goals_after_minutes.number_format.dontCheckFloat = 1
  goalshome.ifEmpty = -
  goalsaway.ifEmpty = -
  goalsown.ifEmpty = -
  goalshead.ifEmpty = -
  goalshead_per_match =< lib.t3sports.statsData.goals_per_match
  goalspenalty.ifEmpty = -
  goalsjoker.ifEmpty = -
  goalsfreekick.ifEmpty = -
  assists.ifEmpty = -
  assists_per_match =< lib.t3sports.statsData.goals_per_match
  cardyellow.ifEmpty = -
  cardyr.ifEmpty = -
  cardred.ifEmpty = -
  changein.ifEmpty = -
  changeout.ifEmpty = -
  dchl = CASE
  dchl {
    key.field = hlTeam
    1 = TEXT
    1.value = font-weight:bold
  }
  links{
    played {
      pid = {$plugin.tx_t3sportstats.statsmatchtablepage}
      useKeepVars = 1
      useKeepVars.add = cfc_league_fe::statstype=default
    }
    goals < .played
#    goals.useKeepVars.add = cfc_league_fe::statstype=default
  }
}

lib.t3sports.statsFilter {
  filter = System25\T3sports\Filter\PlayerStatsFilter
  options.what = player
  options.forcewrapper = 1
  options.groupby = PLAYERSTAT.player
  columns = played,win,draw,loose,cardyellow,cardyr,cardred,playtime,goals,assists,goalshome,goalsaway,goalshead,goalsjoker,goalsown,goalspenalty,goalsfreekick,changein,changeout,captain
  data =< lib.t3sports.statsData
}
lib.t3sports.statsPlayerFilter < lib.t3sports.statsFilter
lib.t3sports.statsPlayerFilter {
  filter = System25\T3sports\Filter\PlayerStatsFilter
  options.what = player
  options.groupby = PLAYERSTAT.player
  markerClass = System25\T3sports\Marker\PlayerStatsMarker
  filterType = player
}

lib.t3sports.statsCoachFilter < lib.t3sports.statsFilter
lib.t3sports.statsCoachFilter {
  filter = System25\T3sports\Filter\CoachStatsFilter
  options.what = coach
  options.groupby = COACHSTAT.coach
  columns = played,win,draw,loose,cardyellow,cardyr,cardred,goals,goalshome,goalsaway,goalsjoker,changeout
  markerClass = System25\T3sports\Marker\CoachStatsMarker
  filterType = coach
  data.links.played.useKeepVars.add = cfc_league_fe::statstype=defaultCoach
  data.links.goals.useKeepVars.add = cfc_league_fe::statstype=defaultCoach
}
lib.t3sports.statsRefereeFilter < lib.t3sports.statsFilter
lib.t3sports.statsRefereeFilter {
  filter = System25\T3sports\Filter\RefereeStatsFilter
  options.what = referee
  options.groupby = REFEREESTAT.referee
  columns (
    played,mainref,assist,win,draw,loose,
    cardyellow,cardyr,cardred,
    cardyellowown,cardyrown,cardredown,
    cardyellowagainst,cardyragainst,cardredagainst,
    goalspenalty,goalspenaltyown,goalspenaltyagainst,penalty,penaltyown,penaltyagainst
  )
  markerClass = System25\T3sports\Marker\RefereeStatsMarker
  filterType = referee
  data.links.played.useKeepVars.add = cfc_league_fe::statstype=defaultRef
  data.links.goals.useKeepVars.add = cfc_league_fe::statstype=defaultRef
}

# Ab hier Konfiguration der einzelnen Views 
plugin.tx_t3sportstats {
  scopeTemplate = {$plugin.tx_cfcleaguefe_competition.scopeTemplate}
  playerstatsTemplate = {$plugin.tx_t3sportstats.playerstatsTemplate}
  coachstatsTemplate = {$plugin.tx_t3sportstats.coachstatsTemplate}
  refereestatsTemplate = {$plugin.tx_t3sportstats.refereestatsTemplate}
  dbstatsTemplate = {$plugin.tx_t3sportstats.dbstatsTemplate}

  scopeSelection =< plugin.tx_cfcleaguefe_competition.scopeSelection
  playerstats {
    default =< lib.t3sports.statsPlayerFilter
    default.options.orderby.PLAYER.LAST_NAME = asc
    scorerlist =< lib.t3sports.statsPlayerFilter
    scorerlist {
      options.orderby.CUSTOM = goals desc
    	options.having = sum(goals) > 0
      data =< lib.t3sports.statsData
    }
    assistlist =< lib.t3sports.statsPlayerFilter
    assistlist {
      options.orderby.CUSTOM = assists desc
    	options.having = sum(assists) > 0
      data =< lib.t3sports.statsData
    }
  }
  coachstats {
    default =< lib.t3sports.statsCoachFilter
    default.options.orderby.COACH.LAST_NAME = asc
  }
  refereestats {
    default =< lib.t3sports.statsRefereeFilter
    default.fields.REFEREESTAT.ISHOME.OP_EQ_INT = 1
    default.options.orderby.REFEREE.LAST_NAME = asc
  }
  dbstats {
    tables = tx_cfcleague_games,tx_cfcleague_profiles,tx_cfcleague_teams,tx_cfcleague_club, tx_cfcleague_match_notes
  }
}

# Register freekick goal
lib.t3sports.matchreport.tickerType.cObject.13 < lib.t3sports.matchreport.tickerType.cObject.10


plugin.tx_cfcleaguefe_report {
  profileview.profile.stats {
    # Define a new statistics
    league =< lib.t3sports.statsPlayerFilter
    league {
      # Use matches from leagues only
      fields.COMPETITION.TYPE.OP_EQ_INT = 1
      # Use obligate matches only
      fields.COMPETITION.OBLIGATION.OP_EQ_INT = 1
    }
    referee =< lib.t3sports.statsRefereeFilter
    referee {
      # For common stats use home matches only
      fields.REFEREESTAT.ISHOME.OP_EQ_INT = 1
      # Use matches from leagues only
      fields.COMPETITION.TYPE.OP_EQ_INT = 1
      # Use obligate matches only
      fields.COMPETITION.OBLIGATION.OP_EQ_INT = 1
    }
  }
}
plugin.tx_cfcleaguefe_competition {
  matchtable.filter.stats {
    default =< lib.t3sports.statsPlayerFilter
    defaultCoach =< lib.t3sports.statsCoachFilter
    defaultRef =< lib.t3sports.statsRefereeFilter
  }
}
