Now the tests are working another time (I had to modify some earlier tests, because...
[breadcrumbs.git] / src / lib / Bcd / Commands / AntNestGetDetailCommand.pm
blob99b23e296e669da6272548e69b3b7686f50b5577
1 package Bcd::Commands::AntNestGetDetailCommand;
3 # This file is part of the breadcrumbs daemon (bcd).
4 # Copyright (C) 2007 Pasqualino Ferrentino
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
23 use strict;
24 use warnings;
25 use threads;
26 use threads::shared;
28 use base qw/ Bcd::Commands::SimpleCommand /;
30 use constant NAME => "an.get_detail";
32 sub get_name{
33 return NAME;
36 sub _exec{
37 #empty for now
39 my ($self, $stash) = @_;
41 my $post_code = $self->{ant_nest};
42 if ( ! Bcd::Data::PostCode::is_valid_post_code_with_sub($post_code)){
43 $self->{"exit_code"} = Bcd::Errors::ErrorCodes::BEC_INVALID_POST_CODE;
44 return;
47 #ok, now I should simply get the details for this ant nest
48 my $res = Bcd::Data::AntNests->get_ant_nest_detail($stash, $post_code);
50 if ( ! defined($res)){
51 $self->{"exit_code"} = Bcd::Errors::ErrorCodes::BEC_NO_ANT_NEST_IN_THIS_CODE;
52 return;
55 my $res2 = &share({});
57 $res2->{id} = $res->[0];
58 $res2->{name} = $res->[3];
60 #$res2->{hq} = $res->[5];
61 #$res2->{opening_hours} = $res->[6];
63 #ok, now let's see the number of ants...
64 $res2->{num_of_ants} = Bcd::Data::Users->get_ant_count_from_ant_nest($stash, $post_code);
66 my $boss = Bcd::Data::Users->get_boss_nick_name_arr($stash, $post_code);
67 $res2->{boss_id} = $boss->[0];
68 $res2->{boss_first_name} = $boss->[2];
69 $res2->{boss_last_name} = $boss->[3];
70 $res2->{boss_nick} = $boss->[1];
72 my $treasurer = Bcd::Data::Users->get_tresaurer_of_this_ant_nest($stash, $post_code);
74 $res2->{treasurer_id} = $treasurer->{id};
75 $res2->{treasurer_nick} = $treasurer->{nick};
76 #$res2->{GDP} = "20000";
78 $self->{output} = $res2;
79 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_OK;
80 return;
83 #this command should simply try to get the ant nests near a certain
84 #post code.
85 sub new{
86 my $class = shift;
87 my $self = $class->SUPER::new(@_);
88 bless ($self, $class);
90 push (@{$self->{"parameters"}}, "ant_nest");
92 return $self;
95 # sub get_output{
96 # my $self = shift;
97 # my @output;
99 # $self->_add_exit_code(\@output);
101 # if ( $self->{exit_code} == Bcd::Errors::ErrorCodes::BEC_OK){
102 # $self->_add_object($self->{output}, "ant_nest", \@output);
104 # return \@output;
107 sub _add_your_specific_output{
108 my ($self, $output) = @_;
109 $self->_add_object($self->{output}, "ant_nest", $output);