2 package CXGN
::Stock
::Catalog
;
7 extends
'CXGN::JSONProp';
9 # a list of representative images, given as image_ids
10 has
'images' => ( isa
=> 'Maybe[ArrayRef]', is
=> 'rw' );
12 # list of hashrefs like { stock_center => { name => ..., count_available => ..., delivery_time => } }
13 has
'order_source' => ( isa
=> 'Maybe[ArrayRef]', is
=> 'rw');
15 # item type such as single accession or a set of 10 accessions
16 has
'item_type' => ( isa
=> 'Str', is
=> 'rw');
18 # material type such as seed or plant
19 has
'material_type' => ( isa
=> 'Str', is
=> 'rw');
21 # center that generates clones or seed
22 has
'material_source' => ( isa
=> 'Maybe[Str]', is
=> 'rw');
24 has
'category' => ( isa
=> 'Str', is
=> 'rw' );
26 has
'species' => ( isa
=> 'Str', is
=> 'rw' );
28 has
'variety' => ( isa
=> 'Maybe[Str]', is
=> 'rw' );
30 has
'breeding_program' => ( isa
=> 'Int', is
=> 'rw');
32 has
'additional_info' => ( isa
=> 'Maybe[Str]', is
=> 'rw' );
34 has
'contact_person_id' => ( isa
=> 'Int', is
=> 'rw') ;
36 has
'availability' => ( isa
=> 'Maybe[Str]', is
=> 'rw');
38 # a general human readable description of the stock
39 #has 'description' => ( isa => 'Str', is => 'rw' );
41 # availability status: in_stock, delayed, currently_unavailable ...
42 #has 'availability' => ( isa => 'Str', is => 'rw' );
49 $self->prop_table('stockprop');
50 $self->prop_namespace('Stock::Stockprop');
51 $self->prop_primary_key('stockprop_id');
52 $self->prop_type('stock_catalog_json');
53 $self->cv_name('stock_property');
54 $self->allowed_fields( [ qw
| item_type species variety material_type category material_source additional_info breeding_program availability contact_person_id images
| ] );
55 $self->parent_table('stock');
56 $self->parent_primary_key('stock_id');
61 sub get_catalog_items
{
63 my $schema = $self->bcs_schema();
64 my $type = $self->prop_type();
65 my $type_id = $self->_prop_type_id();
66 my $key_ref = $self->allowed_fields();
67 my @fields = @
$key_ref;
69 my $catalog_rs = $schema->resultset("Stock::Stockprop")->search({type_id
=> $type_id }, { order_by
=> {-asc
=> 'stock_id'} });
71 while (my $r = $catalog_rs->next()){
73 my $catalog_stock_id = $r->stock_id();
74 push @each_row, $catalog_stock_id;
75 my $item_detail_json = $r->value();
76 my $detail_hash = JSON
::Any
->jsonToObj($item_detail_json);
77 foreach my $field (@fields){
78 push @each_row, $detail_hash->{$field};
80 push @catalog_list, [@each_row];
82 # print STDERR "CATALOG LIST =".Dumper(\@catalog_list)."\n";
84 return \
@catalog_list;
88 sub get_item_details
{
91 my $schema = $self->bcs_schema();
92 my $item_id = $self->parent_id();
93 my $type = $self->prop_type();
94 my $type_id = $self->_prop_type_id();
95 my $key_ref = $self->allowed_fields();
96 my @fields = @
$key_ref;
98 my $item_details_rs = $schema->resultset("Stock::Stockprop")->find({stock_id
=> $item_id, type_id
=> $type_id});
99 my $details_json = $item_details_rs->value();
100 my $detail_hash = JSON
::Any
->jsonToObj($details_json);
101 foreach my $field (@fields){
102 push @item_details, $detail_hash->{$field};
105 return \
@item_details;