adding user and asset stat_cat stuff
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 May 2005 19:53:50 +0000 (19:53 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 May 2005 19:53:50 +0000 (19:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@647 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/asset.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg/dbi.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
Open-ILS/src/sql/Postgres/005.schema.actors.sql
Open-ILS/src/sql/Postgres/040.schema.asset.sql

index fb1a68d..b992eb2 100644 (file)
@@ -293,6 +293,16 @@ sub modify_from_fieldmapper {
        actor::org_unit->has_a( ou_type => 'actor::org_unit_type' );
        #actor::org_unit->has_a( address => 'actor::org_address' );
 
+       actor::stat_cat_entry->has_a( stat_cat => 'actor::stat_cat' );
+       actor::stat_cat->has_many( entries => 'actor::stat_cat_entry' );
+       actor::stat_cat_entry_user_map->has_a( stat_cat => 'actor::stat_cat' );
+       actor::stat_cat_entry_user_map->has_a( target_usr => 'actor::user' );
+
+       asset::stat_cat_entry->has_a( stat_cat => 'asset::stat_cat' );
+       asset::stat_cat->has_many( entries => 'asset::stat_cat_entry' );
+       asset::stat_cat_entry_copy_map->has_a( stat_cat => 'asset::stat_cat' );
+       asset::stat_cat_entry_copy_map->has_a( owning_copy => 'asset::copy' );
+
        action::survey_response->has_a( usr => 'actor::user' );
        action::survey_response->has_a( survey => 'action::survey' );
        action::survey_response->has_a( question => 'action::survey_question' );
@@ -304,6 +314,9 @@ sub modify_from_fieldmapper {
 
        asset::copy_note->has_a( owning_copy => 'asset::copy' );
 
+       actor::user->has_many( stat_cat_entries => 'actor::stat_cat_entry_user_map' );
+       asset::copy->has_many( stat_cat_entries => 'asset::stat_cat_entry_copy_map' );
+
        asset::copy->has_a( call_number => 'asset::call_number' );
        asset::copy->has_a( creator => 'actor::user' );
        asset::copy->has_a( editor => 'actor::user' );
index 58f4b00..27c3a6e 100644 (file)
@@ -59,7 +59,7 @@ use base qw/actor/;
 
 __PACKAGE__->table( 'actor_stat_cat_entry' );
 __PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/owner value/ );
+__PACKAGE__->columns( Essential => qw/stat_cat owner value/ );
 
 #-------------------------------------------------------------------------------
 package actor::stat_cat_entry_user_map;
@@ -67,7 +67,7 @@ use base qw/actor/;
 
 __PACKAGE__->table( 'actor_stat_cat_entry_usr_map' );
 __PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/stat_cat stat_cat_entry target_user/ );
+__PACKAGE__->columns( Essential => qw/stat_cat stat_cat_entry target_usr/ );
 
 #-------------------------------------------------------------------------------
 package actor::card;
index 6c4cedf..0a9f79b 100644 (file)
@@ -53,7 +53,7 @@ use base qw/asset/;
 
 __PACKAGE__->table( 'asset_stat_cat_entry' );
 __PACKAGE__->columns( Primary => qw/id/ );
-__PACKAGE__->columns( Essential => qw/owner value/ );
+__PACKAGE__->columns( Essential => qw/stat_cat owner value/ );
 
 #-------------------------------------------------------------------------------
 package asset::stat_cat_entry_copy_map;
index 09c5dde..5081c1c 100644 (file)
        #---------------------------------------------------------------------
        package actor::stat_cat_entry_user_map;
        
-       actor::stat_cat_entry_user_map->table( 'actor.stat_cat_entry_copy_map' );
+       actor::stat_cat_entry_user_map->table( 'actor.stat_cat_entry_usr_map' );
        actor::stat_cat_entry_user_map->sequence( 'actor.stat_cat_entry_usr_map_id_seq' );
        
        #---------------------------------------------------------------------
index fa845ee..2f99cdd 100644 (file)
@@ -272,5 +272,75 @@ __PACKAGE__->register_method(
        stream          => 1,
 );
 
+#XXX Fix stored proc calls
+sub ranged_actor_stat_cat {
+        my $self = shift;
+        my $client = shift;
+        my $ou = ''.shift();
+        
+        return undef unless ($ou);
+        my $s_table = actor::stat_cat->table;
+
+        my $select = <<"        SQL";
+                SELECT  s.*
+                  FROM  $s_table s
+                        JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
+                 ORDER BY name
+        SQL
+
+        my $sth = actor::stat_cat->db_Main->prepare_cached($select);
+        $sth->execute($ou);
+
+        for my $sc ( map { actor::stat_cat->construct($_) } $sth->fetchall_hash ) {
+               my $sc_fm = $sc->to_fieldmapper;
+               $sc_fm->entries(
+                       [ $self->method_lookup( 'open-ils.storage.ranged.fleshed.actor.stat_cat_entry.search.stat_cat' )->run($ou,$sc->id) ]
+               );
+               $client->respond( $sc_fm );
+       }
+
+        return undef;
+}
+__PACKAGE__->register_method(
+        api_name        => 'open-ils.storage.ranged.fleshed.actor.stat_cat.all',
+        api_level       => 1,
+        stream          => 1,
+        method          => 'ranged_actor_stat_cat',
+);
+
+#XXX Fix stored proc calls
+sub ranged_actor_stat_cat_entry {
+        my $self = shift;
+        my $client = shift;
+        my $ou = ''.shift();
+        my $sc = ''.shift();
+        
+        return undef unless ($ou);
+        my $s_table = actor::stat_cat_entry->table;
+
+        my $select = <<"        SQL";
+                SELECT  s.*
+                  FROM  $s_table s
+                        JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
+                 WHERE stat_cat = ?
+                 ORDER BY name
+        SQL
+
+        my $sth = actor::stat_cat->db_Main->prepare_cached($select);
+        $sth->execute($ou,$sc);
+
+        for my $sce ( map { actor::stat_cat_entry->construct($_) } $sth->fetchall_hash ) {
+               $client->respond( $sce->to_fieldmapper );
+       }
+
+        return undef;
+}
+__PACKAGE__->register_method(
+        api_name        => 'open-ils.storage.ranged.fleshed.actor.stat_cat_entry.search.stat_cat',
+        api_level       => 1,
+        stream          => 1,
+        method          => 'ranged_actor_stat_cat_entry',
+);
+
 
 1;
index c79cb23..0924186 100644 (file)
@@ -95,9 +95,10 @@ CREATE TABLE actor.stat_cat (
 );
 
 CREATE TABLE actor.stat_cat_entry (
-       id      SERIAL  PRIMARY KEY,
-       owner   INT     NOT NULL, -- actor.org_unit.id
-       value   TEXT    NOT NULL,
+       id              SERIAL  PRIMARY KEY,
+       stat_cat        INT     NOT NULL REFERENCES actor.stat_cat (id) ON DELETE CASCADE,
+       owner           INT     NOT NULL REFERENCES actor.org_unit (id) ON DELETE CASCADE,
+       value           TEXT    NOT NULL,
        CONSTRAINT sce_once_per_owner UNIQUE (owner,value)
 );
 
index 4276c78..b69f08b 100644 (file)
@@ -84,7 +84,8 @@ CREATE TABLE asset.stat_cat (
 
 CREATE TABLE asset.stat_cat_entry (
        id              SERIAL  PRIMARY KEY,
-       owner           INT     NOT NULL, -- actor.org_unit.id
+        stat_cat        INT     NOT NULL REFERENCES actor.stat_cat (id) ON DELETE CASCADE,
+       owner           INT     NOT NULL REFERENCES actor.org_unit.id (id) ON DELETE CASCADE,
        value           TEXT    NOT NULL,
        CONSTRAINT sce_once_per_owner UNIQUE (owner,value)
 );