Parley::Controller::Admin - Catalyst Controller


Parley documentation Contained in the Parley distribution.

Index


Code Index:

NAME

Top

Parley::Controller::Admin - Catalyst Controller

DESCRIPTION

Top

Catalyst Controller.

METHODS

Top

index

AUTHOR

Top

Chisel Wright <chiselwright@users.berlios.de>

LICENSE

Top

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


Parley documentation Contained in the Parley distribution.

package Parley::Controller::Admin;
# vim: ts=8 sts=4 et sw=4 sr sta
use strict;
use warnings;

use Parley::Version;  our $VERSION = $Parley::VERSION;
use base 'Catalyst::Controller';

sub index : Private {
    my ( $self, $c ) = @_;

    $c->response->body('Matched Parley::Controller::Admin in Admin.');
}

sub auto : Private {
    my ($self, $c) = @_;
    $c->log->debug( 'Admin::auto()' );

    # if we're not a moderator, bounce back to where we came from
    if (not $c->stash->{moderator}) {
        $c->log->debug( 'not a moderator' );
        $c->response->redirect( $c->request->referer() );
        return 0;
    }

    # succeed
    $c->log->debug( 'a moderator' );
    return 1;
}

sub lock :Local {
    my ($self, $c) = @_;

    # the 'lock' parameter tells us if we're adding or removing a lock
    # if it's not specified, default action os to ADD a lock
    my $locked = $c->request->param('lock');
    if (not defined $locked) {
        $locked = 1;
    }
    $c->log->debug( qq{lock: $locked} );

    # we should already have the thread we're locking, but let's check anyway
    if (not defined $c->_current_thread()) {
        $c->stash->{error}{message} = $c->localize(q{ADMIN SPECIFY LOCK THREAD});
        $c->log->error( $c->localize(q{ADMIN SPECIFY LOCK THREAD}) );
        return;
    }

    # update the lock status
    $c->_current_thread()->locked( $locked );
    $c->_current_thread()->update();

    # go back to where we came from
    $c->response->redirect( $c->request->referer() );
    return;
}

sub sticky :Local {
    my ($self, $c) = @_;

    # the 'sticky' parameter tells us if we're adding or removing a sticky
    # if it's not specified, default action os to ADD a sticky
    my $sticky = $c->request->param('sticky');
    if (not defined $sticky) {
        $sticky = 1;
    }
    $c->log->debug( qq{sticky: $sticky} );

    # we should already have the thread we're sticking, but let's check anyway
    if (not defined $c->_current_thread()) {
        $c->stash->{error}{message}
            = $c->localize(q{ADMIN SPECIFY STICK THREAD});
        $c->log->error( $c->localize(q{ADMIN SPECIFY STICK THREAD}) );
        return;
    }

    # update the stick status
    $c->_current_thread()->sticky( $sticky );
    $c->_current_thread()->update();

    # go back to where we came from
    $c->response->redirect( $c->request->referer() );
    return;
}

1;