Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.

Commit

Permalink
Add UserPref
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Mar 23, 2010
1 parent ef354ba commit 1275fd9
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/App/Prong/ImportModule.pm
Expand Up @@ -65,6 +65,11 @@ sub create_module {
my $module = $schema->resultset('Module')->create( \%args );

$self->create_module_prefs( $module, $schema, $xml->findnodes('/Module/ModulePrefs' ) );

foreach my $userpref ($xml->findnodes('/Module/UserPref')) {
$self->create_module_userpref( $module, $schema, $userpref );
}

foreach my $content ($xml->findnodes('/Module/Content')) {
$self->create_module_content( $module, $schema, $content );
}
Expand Down Expand Up @@ -118,6 +123,21 @@ sub _get_module_prefs {
return %attrs;
}

sub create_module_userpref {
my ($self, $module, $schema, $xml) = @_;

my %attrs = (
name => $xml->findvalue('@name'),
data_type => $xml->findvalue('@datatype') || undef,
);

foreach my $attr qw(display_name default_alue) {
my $value = $xml->findvalue("\@$attr");
$attrs{ $attr } = $value if defined $value && length $value;
}
$module->create_related('userprefs', \%attrs );
}

sub create_module_content {
my ($self, $module, $schema, $xml) = @_;

Expand Down
2 changes: 2 additions & 0 deletions lib/Prong/Schema/Result/Module.pm
Expand Up @@ -83,5 +83,7 @@ __PACKAGE__->has_many( features =>
'Prong::Schema::Result::ModuleFeature' => 'module_id' );
__PACKAGE__->has_many( preloads =>
'Prong::Schema::Result::ModulePreload' => 'module_id' );
__PACKAGE__->has_many( userprefs =>
'Prong::Schema::Result::ModuleUserPref' => 'module_id' );

1;
65 changes: 65 additions & 0 deletions lib/Prong/Schema/Result/ModuleUserPref.pm
@@ -0,0 +1,65 @@
package Prong::Schema::Result::ModuleUserPref;
use strict;
use warnings;
use base qw(Prong::Schema::Result);

__PACKAGE__->load_components( qw(TimeStamp Core) );
__PACKAGE__->table( 'prong_module_userpref' );
__PACKAGE__->add_columns(
id => {
data_type => 'CHAR',
size => 36,
is_nullable => 0,
dynamic_default_on_create => 'uuid',
},
module_id => {
data_type => 'CHAR',
size => 36,
is_nullable => 0,
},
name => {
data_type => 'CHAR',
size => 64,
is_nullable => 0,
},
data_type => {
data_type => 'CHAR',
size => 32,
default_value => "string",
is_nullable => 0,
},
display_name => {
data_type => 'CHAR',
size => 32,
is_nullable => 0,
},
default_value => {
data_type => 'CHAR',
size => 256,
is_nullable => 1,
},
is_required => {
data_type => 'TINYINT',
default_value => 0,
is_nullable => 0,
},
content => {
data_type => 'TEXT',
is_nullable => 0,
},
created_on => {
data_type => 'DATETIME',
is_nullable => 0,
set_on_create => 1,
},
modified_on => {
data_type => 'TIMESTAMP',
is_nullable => 0,
set_on_create => 1,
set_on_update => 1,
},
);
__PACKAGE__->set_primary_key( 'id' );
__PACKAGE__->belongs_to( module => 'Prong::Schema::Result::Module' => 'module_id' );

1;

0 comments on commit 1275fd9

Please sign in to comment.