AxKit-App-TABOO

 view release on metacpan or  search on metacpan

lib/AxKit/App/TABOO/Provider/Classification.pm  view on Meta::CPAN

sub process {
  my $self = shift;
  $self->{foundcats} = AxKit::App::TABOO::Data::Plurals::Categories->new();
  foreach my $catname (@{$self->{cats}}) {
    my $category = AxKit::App::TABOO::Data::Category->new();
    unless ($category->load(limit => {catname => $catname})) {
      $self->{exists} = 0;
      $self->{catnotfound} = $catname;
      last;
    } else {
      $self->{foundcats}->Push($category);
      $self->{exists} = 1;
    }
  }
  if ($self->{exists}) {
    $self->{articles} = AxKit::App::TABOO::Data::Plurals::Articles->new();
    $self->{stories} = AxKit::App::TABOO::Data::Plurals::Stories->new();
    unless ($self->{articles}->incat(@{$self->{cats}})) {
      $self->{articles} = undef;
      unless ($self->{stories}->exists(primcat => @{$self->{cats}})) { 
	$self->{exists} = 0;
      }
    }
  }
  return $self->{exists};
}

sub exists {
  my $self = shift;
  if ($self->{exists}) {
    return 1;
  } else {
    return 0;
  }
  # Thanks, Kip! :-)
}


sub key {
  my $self = shift;
  return $self->{uri} . "/" . AxKit::App::TABOO::loggedin($self->{session});
}


sub mtime {
  my $self=shift;
  return time();
}


sub get_fh {
  throw Apache::AxKit::Exception::IO(
	      -text => "No fh for Classification Provider");
}

sub get_dom {
  my $self = shift;
  unless ($self->{dom}) {
    unless ($self->{exists}) {
      throw Apache::AxKit::Exception::Retval(
					     return_code => 404,
					     -text => "Category " . $self->{catnotfound} . " was not found");
    }
#    warn "ANT: " . Dumper($self);
    my $authlevel = AxKit::App::TABOO::authlevel($self->{session});
    if (scalar(@{$self->{cats}}) == 1) {
      my %limit;
      if (! defined($authlevel)
	  || ($authlevel < 4)) {
	$limit{'editorok'} = 1;
      } elsif ($self->{editor}) {
	$limit{'editorok'} = 0;
      }
      $limit{'primcat'} = ${$self->{cats}}[0];
      
      $self->{stories}->load(what => 'storyname,sectionid,primcat,editorok,title,submitterid,timestamp',
			     limit => \%limit, 
			     orderby => 'timestamp DESC');
      $self->{stories}->addcatinfo;
      $self->{stories}->adduserinfo;
    } else {
      $self->{stories} = undef;
    }
    my $doc = XML::LibXML::Document->new();
    my $rootel = $doc->createElement('taboo');
    $rootel->setAttribute('type', 'catlists');
    $rootel->setAttribute('origin', 'Classification');
    $doc->setDocumentElement($rootel);
    if ($self->{stories}) {
      $self->{stories}->write_xml($doc, $rootel);
    }
    $self->{foundcats}->write_xml($doc, $rootel);
    my $anyarticles = 0;
    if($self->{articles}) {
      my %limit;
      if (! defined($authlevel)
	  || ($authlevel < 4)) {
	$limit{'editorok'} = 1;
	$limit{'authorok'} = 1;
      }
      if ($self->{articles}->load(limit => \%limit)) {
	$anyarticles = 1;
      }
      $self->{articles}->addcatinfo;
      $self->{articles}->adduserinfo;
      $self->{articles}->addformatinfo;
      $self->{articles}->write_xml($doc, $rootel);
    }
#    warn Dumper($self->{stories});
#    warn Dumper($self->{articles});
    
    unless (($anyarticles) || (defined($self->{stories}))) {
      if (defined($authlevel)) {
	throw Apache::AxKit::Exception::Retval(
					       return_code => 403,
					       -text => "Articles or stories exist, but are only accessible to editors.");
      } else {
	throw Apache::AxKit::Exception::Retval(
					       return_code => 401,
					       -text => "Articles or stories exist, but are only accessible to editors, you have to log in as one.");
      }



( run in 0.641 second using v1.01-cache-2.11-cpan-39bf76dae61 )