--- lib/Strix.pm 2008/06/15 23:19:02 167 +++ lib/Strix.pm 2008/06/15 23:59:51 168 @@ -3,10 +3,14 @@ use strict; use warnings; -use base qw/Jifty::Object/; +use base qw(Jifty::Object Class::Accessor::Fast); +__PACKAGE__->mk_accessors( qw(site) ); use DBI; use Data::Dump qw/dump/; +use Carp qw/confess/; + +our $debug = 0; =head1 NAME @@ -14,16 +18,22 @@ =head1 METHODS +=head2 new + + my $strix = Strix->new({ site => 'os-test0604-zg' }); + =head2 dbh - my $dbh = Strix->dbh( $site_name ); + my $dbh = Strix->dbh( $site_name ); + + my $dbh = $strix->dbh; =cut sub dbh { my $self = shift; - my $site = shift or die "no site?"; + my $site = shift || $self->site || confess "no site"; my $config = Jifty->config->app('strix') or die "need strix config"; my $database = $config->{database} or die "no strix.database in config"; @@ -42,4 +52,104 @@ return $dbh; } +=head2 category + + my $category = Strix->category( $url ); + +=cut + +sub category { + my $self = shift; + + my $url = shift || confess "no url"; + + # sysinc/profiles.php + my $sth = $self->dbh->prepare(qq{ + SELECT kategorija.*, lang.langid, lang.locale, template.tfilename, template.tflags, site.naziv as sitename, site.admin_mail, site.address, site.root as site_root, getPathFromNav(kategorija.id) as path, site.ordstr as site_ordstr FROM kategorija, template, site, lang WHERE kategorija.url = ? AND kategorija.template_id = template.id AND kategorija.site_id = site.id AND lang.id = kategorija.lang + }); + $sth->execute($url); + + my $category = $sth->fetchrow_hashref() or die "can't fetch category $url"; + return $category; +} + +=head2 layout + + my $layout = $strix->layout( $url ); + +=cut + +sub layout { + my $self = shift; + + my $url = shift || confess "no url"; + + my $dbh = $self->dbh; + my $category = $self->category( $url ); + + my $sth = $dbh->prepare(qq{ + SELECT template.tfilename, template.tflags FROM template WHERE id = ? + }); + $sth->execute( $category->{template_id} ); + + my $template = $sth->fetchrow_hashref() or die "can't fetch template"; + + warn "template = ",dump( $template ) if $debug; + + my $page; + warn "### free layout...\n" if $debug; + + # index.php + $sth = $dbh->prepare(qq{ + SELECT layout_id, module_id, pozicija, module_args, name, fname, notitle, class_name + FROM pre_layout, modules + WHERE id=module_id AND ? = template_id AND redoslijed >= 0 + ORDER BY redoslijed DESC + }); + $sth->execute( $category->{template_id} ); + + while (my $row = $sth->fetchrow_hashref() ) { + warn dump( $row ) if $debug; + push @{ $page->{free} }, { $row->{name} => $row->{module_args} }; + } + + warn "### pre layout...\n" if $debug; + + $sth = $dbh->prepare(qq{ + SELECT + l.id as layout_id, l.user_id, l.kategorija_id, l.module_id, l.pozicija, l.redoslijed, l.module_args, l.state, l.notitle, + m.name, m.fname, m.hidden, m.nocache, m.pos, m.class_name, + acl_module.acl_register_id + FROM layout as l, modules as m LEFT JOIN acl_module ON (acl_module.modules_id = m.id) + WHERE l.user_id=? + AND l.kategorija_id=? + AND m.id=l.module_id + ORDER BY pozicija,redoslijed DESC + }); + $sth->execute( 1, $category->{id} ); + + while (my $row = $sth->fetchrow_hashref() ) { + warn dump( $row ) if $debug; + push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => $row->{module_args} }; + } + + warn "### post layout...\n" if $debug; + + $sth = $dbh->prepare(qq{ + SELECT layout_id, module_id, pozicija, module_args, name, notitle + FROM pre_layout, modules + WHERE id=module_id AND ? = template_id AND redoslijed < 0 + ORDER BY redoslijed DESC + }); + $sth->execute( $category->{template_id} ); + + while (my $row = $sth->fetchrow_hashref() ) { + warn dump( $row ) if $debug; + push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => $row->{module_args} }; + } + + return $page; + +} + 1;