=head2 base Chain base for getting the club ID and checking it. Matches /clubs/* =cut sub base :Chained("/") :PathPart("clubs") :CaptureArgs(1) { my ( $self, $c, $id_or_key ) = @_; # Load the messages $c->load_status_msgs; my $club = $c->model("DB::Club")->find_id_or_url_key( $id_or_key ); if ( defined($club) ) { # Club found, stash it, then stash the name / view URL in the breadcrumbs section of our stash $c->stash({ club => $club, breadcrumbs => { object => { label => $club->full_name, link => $c->uri_for_action("/clubs/view", [$club->url_key]), }, }, }); } else { # 404 $c->detach( "TopTable::Controller::Root", "default" ); return; } } =head2 view Chained to the base class; all this does is check we're authorised to view clubs, then the more relevant funcionality is in methods chained from this. =cut sub view :Chained("base") :PathPart("") :CaptureArgs(0) { my ( $self, $c ) = @_; # Check that we are authorised to view clubs $c->forward( "TopTable::Controller::Users", "check_authorisation", ["club_view", "view clubs", 1] ); $c->forward( "TopTable::Controller::Users", "check_authorisation", [ [ qw( club_edit club_delete team_view team_create ) ], "edit clubs", 0] ); } =head2 Get and stash the current season (or last complete one if it doesn't exist) for the team view page. End of chain for /clubs/* =cut =head2 Get and stash the current season (or last complete one if it doesn't exist) for the team view page. End of chain for /clubs/* =cut sub view_current_season :Chained("view") :PathPart("") :Args(0) { my ( $self, $c ) = @_; my $club = $c->stash->{club}; # Try to find the current season (or the last completed season if there is no current season) my $season = $c->model("DB::Season")->get_current; # More season stuff # Finalise the view routine $c->detach("view_finalise"); } =head2 view_specific_season View a club only with teams for a specific season. Matches /clubs/*/seasons/* (End of chain) =cut sub view_specific_season :Chained("view") :PathPart("seasons") :Args(1) { my ( $self, $c, $season_id_or_url_key ) = @_; my $club = $c->stash->{club}; # Validate the passed season ID my $season = $c->model("DB::Season")->find_id_or_url_key( $season_id_or_url_key ); if ( defined($season) ) { # More season stuff # Append the season on to the object for breadcrumbs - this is for using in sprintf for our text labels $c->stash->{breadcrumbs}{replace_text} = $season->name; } # Finalise the view routine $c->detach("view_finalise"); } sub view_finalise :Private { # Irrelevant to this }