1package Netdot::Model::Site;
2
3use base 'Netdot::Model';
4use warnings;
5use strict;
6
7# Make sure to return 1
81;
9
10=head1 NAME
11
12Netdot::Model::Site
13
14=head1 CLASS METHODS
15=cut
16
17=head2 search_with_backbones
18
19=cut
20
21__PACKAGE__->set_sql(with_backbones => qq{
22SELECT   site.id
23FROM     site, closet, room, floor, backbonecable
24WHERE    (backbonecable.start_closet=closet.id OR backbonecable.end_closet=closet.id)
25  AND    ((closet.room=room.id AND room.floor=floor.id) AND floor.site=site.id)
26GROUP BY site.id, site.name
27ORDER BY site.name
28});
29
30=head2 search_with_closets
31
32=cut
33
34__PACKAGE__->set_sql(with_closets => qq{
35SELECT   site.id
36FROM     site, closet, room, floor
37WHERE    (closet.room=room.id AND room.floor=floor.id) AND floor.site=site.id
38GROUP BY site.id, site.name
39ORDER BY site.name
40});
41
42=head1 INSTANCE METHODS
43=cut
44
45############################################################################
46
47=head2 rooms - Get list of rooms
48
49  Arguments:
50    None
51  Returns:
52    Array of Room objects
53  Examples:
54    my @rooms = $site->rooms;
55
56=cut
57
58sub rooms {
59    my ($self) = @_;
60
61    my @rooms;
62    foreach my $floor ( $self->floors ){
63	push @rooms, $floor->rooms;
64    }
65    return @rooms;
66}
67
68#############################################################################
69
70=head2 closets - Get list of closets
71
72  Arguments:
73    None
74  Returns:
75    Array of Closet objects
76  Examples:
77    my @closets = $site->closets;
78
79=cut
80
81sub closets {
82    my ($self) = @_;
83    my @closets;
84    foreach my $room ( $self->rooms ){
85	if ( $room->closets ){
86	    push @closets, $room->closets;
87	}
88    }
89    return @closets;
90}
91
92##################################################################
93
94=head2 get_label - Override get_label method
95
96    Appends site number if available
97
98  Arguments:
99    None
100  Returns:
101    string
102  Examples:
103    print $site->get_label();
104
105=cut
106
107sub get_label {
108    my $self = shift;
109    $self->isa_object_method('get_label');
110    my $lbl = $self->name;
111    if ( my $aliases = $self->aliases ){
112	$lbl .= " ($aliases)";
113    }
114    if ( my $number = $self->number ){
115	$lbl .= " ($number)";
116    }
117    return $lbl;
118}
119
120=head1 AUTHOR
121
122Carlos Vicente, C<< <cvicente at ns.uoregon.edu> >>
123
124=head1 COPYRIGHT & LICENSE
125
126Copyright 2012 University of Oregon, all rights reserved.
127
128This program is free software; you can redistribute it and/or modify
129it under the terms of the GNU General Public License as published by
130the Free Software Foundation; either version 2 of the License, or
131(at your option) any later version.
132
133This program is distributed in the hope that it will be useful, but
134WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
135or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
136License for more details.
137
138You should have received a copy of the GNU General Public License
139along with this program; if not, write to the Free Software Foundation,
140Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
141
142=cut
143
1441;
145