Rapi-Blog

 view release on metacpan or  search on metacpan

lib/Rapi/Blog/DB/Result/Post.pm  view on Meta::CPAN

  "title",
  {
    data_type => "varchar",
    default_value => \"null",
    is_nullable => 1,
    size => 255,
  },
  "image",
  {
    data_type => "varchar",
    default_value => \"null",
    is_nullable => 1,
    size => 255,
  },
  "ts",
  { data_type => "datetime", is_nullable => 0 },
  "create_ts",
  { data_type => "datetime", is_nullable => 0 },
  "update_ts",
  { data_type => "datetime", is_nullable => 0 },
  "author_id",
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
  "creator_id",
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
  "updater_id",
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
  "section_id",
  {
    data_type      => "integer",
    default_value  => \"null",
    is_foreign_key => 1,
    is_nullable    => 1,
  },
  "published",
  { data_type => "boolean", default_value => 0, is_nullable => 0 },
  "publish_ts",
  { data_type => "datetime", default_value => \"null", is_nullable => 1 },
  "size",
  { data_type => "integer", default_value => \"null", is_nullable => 1 },
  "tag_names",
  { data_type => "text", default_value => \"null", is_nullable => 1 },
  "custom_summary",
  { data_type => "text", default_value => \"null", is_nullable => 1 },
  "summary",
  { data_type => "text", default_value => \"null", is_nullable => 1 },
  "body",
  { data_type => "text", default_value => "", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("name_unique", ["name"]);
__PACKAGE__->belongs_to(
  "author",
  "Rapi::Blog::DB::Result::User",
  { id => "author_id" },
  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "CASCADE" },
);
__PACKAGE__->has_many(
  "comments",
  "Rapi::Blog::DB::Result::Comment",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
  "creator",
  "Rapi::Blog::DB::Result::User",
  { id => "creator_id" },
  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "CASCADE" },
);
__PACKAGE__->has_many(
  "hits",
  "Rapi::Blog::DB::Result::Hit",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
  "post_categories",
  "Rapi::Blog::DB::Result::PostCategory",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
  "post_tags",
  "Rapi::Blog::DB::Result::PostTag",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
  "section",
  "Rapi::Blog::DB::Result::Section",
  { id => "section_id" },
  {
    is_deferrable => 0,
    join_type     => "LEFT",
    on_delete     => "SET DEFAULT",
    on_update     => "CASCADE",
  },
);
__PACKAGE__->has_many(
  "trk_section_posts",
  "Rapi::Blog::DB::Result::TrkSectionPost",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->belongs_to(
  "updater",
  "Rapi::Blog::DB::Result::User",
  { id => "updater_id" },
  { is_deferrable => 0, on_delete => "RESTRICT", on_update => "CASCADE" },
);


# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-10-04 18:42:02
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EgoroG32J0nSECxuTHx0yQ

__PACKAGE__->load_components('+RapidApp::DBIC::Component::TableSpec');
__PACKAGE__->TableSpec_m2m( categories => "post_categories", 'category_name');
__PACKAGE__->apply_TableSpec;

__PACKAGE__->load_components('+Rapi::Blog::DB::Component::SafeResult');

__PACKAGE__->has_many(
  "direct_comments",
  "Rapi::Blog::DB::Result::Comment",
  { "foreign.post_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0, where => { parent_id => undef } },
);

__PACKAGE__->many_to_many( 'tags', 'post_tags', 'tag_name' );

use RapidApp::Util ':all';
use Rapi::Blog::Util;
use HTML::Strip;

sub schema { (shift)->result_source->schema }
# This relies on us having been loaded via RapidApp::Util::Role::ModelDBIC
sub parent_app_class { (shift)->schema->_ra_catalyst_origin_model->app_class }
sub Access { (shift)->parent_app_class->template_controller->Access }

sub public_url_path {
  my $self = shift;
  return undef unless $self->Access->default_view_path;
  $self->{_public_url_path} //= do {
    my $pfx = '';
    if(my $c = RapidApp->active_request_context) { $pfx = $c->mount_url || ''; }
    my $path = join('',$pfx,'/',$self->Access->default_view_path);
    $path =~ s/\/?$/\//; # make sure there is a trailing '/';
    $path
  }
}

sub public_url {
  my $self = shift;
  my $path = $self->public_url_path or return undef;
 return join('',$path,$self->name)
}

sub preview_url_path {
  my $self = shift;
  return undef unless $self->Access->preview_path;
  $self->{_preview_url_path} //= do {
    my $pfx = '';
    if(my $c = RapidApp->active_request_context) { $pfx = $c->mount_url || ''; }
    my $path = join('',$pfx,'/',$self->Access->preview_path);
    $path =~ s/\/?$/\//; # make sure there is a trailing '/';
    $path
  }
}

sub preview_url {
  my $self = shift;
  my $path = $self->preview_url_path or return undef;
 return join('',$path,$self->name)
}

sub open_url_path {
  my $self = shift;
  my $mode = shift;
  my $app = $self->parent_app_class;
  my $pfx = '';
  if(my $c = RapidApp->active_request_context) { $pfx = $c->mount_url || ''; }
  if($mode) {
    $mode = lc($mode);
    die "open_url_path(): bad argument '$mode' -- must be undef, 'direct' or 'navable'"
      unless ($mode eq 'direct' or $mode eq 'navable');
    return join('',$pfx,'/rapidapp/module/',$mode,$self->getRestPath)



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