/[A3C]/lib/Strix.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 188 by dpavlin, Tue Jun 17 10:11:46 2008 UTC revision 193 by dpavlin, Tue Jun 17 21:27:31 2008 UTC
# Line 32  Strix Line 32  Strix
32  =cut  =cut
33    
34  our $instance_dbh;  our $instance_dbh;
35    our @instances_active;
36    
37  sub dbh {  sub dbh {
38          my $self = shift;          my $self = shift;
# Line 59  sub dbh { Line 60  sub dbh {
60          $dbh->{pg_enable_utf8} = 1;          $dbh->{pg_enable_utf8} = 1;
61    
62          $instance_dbh->{$instance} = $dbh;          $instance_dbh->{$instance} = $dbh;
63            push @instances_active, $instance;
64    
65            if ( $#instances_active > 5 ) {
66                    my $i = shift @instances_active;
67                    warn "## remove connection to instance $instance\n";
68                    delete( $instance_dbh->{$i} );
69            }
70    
71          warn "## instance_dbh = ",dump( $instance_dbh ) if $debug;          warn "## instance_dbh = ",dump( $instance_dbh ) if $debug;
72    
# Line 175  sub layout { Line 183  sub layout {
183    
184  }  }
185    
186  =head2 sitemap  =head2 sites
187    
188          my $sitemap = $strix->sitemap( $site_id, $uid );          my @sites = $strix->sites;
189    
190  =cut  =cut
191    
192  sub sitemap {  sub sites {
193          my $self = shift;          my $self = shift;
194    
195          my ( $site_id, $uid ) = @_;          my @sites;
         my $sitemap;  
196    
197          my $query = "SELECT *, ( length(ordstr)/3 ) - 1 AS depth FROM site WHERE id = ?";          my $sth = $self->dbh->prepare(
198          $query = "SELECT *, coalesce(( length(ordstr)/3 ) - 1,0) AS depth FROM site ORDER BY ordstr" unless $site_id;          "SELECT *, coalesce(( length(ordstr)/3 ) - 1,0) AS depth FROM site ORDER BY ordstr"
199            );
200          my $sth = $self->dbh->prepare( $query );          $sth->execute;
         if ( $site_id ) {  
                 $sth->execute( $site_id );  
         } else {  
                 $sth->execute;  
         }  
201    
202          while (my $row = $sth->fetchrow_hashref() ) {          while (my $row = $sth->fetchrow_hashref() ) {
203                  warn dump( $row ) if $debug;                  push @sites, $row;
   
                 $sitemap->{ $row->{naziv} } = $self->site_navigation( $site_id, $uid );  
204          }          }
205    
206          return $sitemap;          return @sites;
207  }  }
208    
209  =head2 site_navigation  =head2 site_navigation
# Line 232  sub site_navigation { Line 232  sub site_navigation {
232    
233          while (my $kat = $sth->fetchrow_hashref() ) {          while (my $kat = $sth->fetchrow_hashref() ) {
234                  warn "# kat = ",dump( $kat ) if $debug;                  warn "# kat = ",dump( $kat ) if $debug;
235                  die "no depth" unless $kat->{depth};                  if ( ! $kat->{depth} ) {
236                            Jifty->log->error("depth increased to 1 in ",dump( $kat ));
237                            $kat->{depth} = 1;
238                    }
239    
240                  my $node = { type => 'category' };                  my $node = { type => 'category' };
241                  foreach my $c ( qw/naziv url/ ) {                  foreach my $c ( qw/naziv url/ ) {

Legend:
Removed from v.188  
changed lines
  Added in v.193

  ViewVC Help
Powered by ViewVC 1.1.26