convert feature collateral to JSON

This commit is contained in:
Colin Kuskie 2008-05-05 17:50:26 +00:00
parent 52d29d90e4
commit d7c6507c8b
3 changed files with 69 additions and 69 deletions

View file

@ -699,6 +699,7 @@ EOSQL1
my $accessorySth = $session->db->read('select accessoryAssetId from Product_accessory where assetId=? order by sequenceNumber'); my $accessorySth = $session->db->read('select accessoryAssetId from Product_accessory where assetId=? order by sequenceNumber');
my $relatedSth = $session->db->read('select relatedAssetId from Product_related where assetId=? order by sequenceNumber'); my $relatedSth = $session->db->read('select relatedAssetId from Product_related where assetId=? order by sequenceNumber');
my $specificationSth = $session->db->read('select name, value, units from Product_specification where assetId=? order by sequenceNumber'); my $specificationSth = $session->db->read('select name, value, units from Product_specification where assetId=? order by sequenceNumber');
my $featureSth = $session->db->read('select feature from Product_feature where assetId=? order by sequenceNumber');
while (my ($assetId) = $assetSth->array) { while (my ($assetId) = $assetSth->array) {
##For each assetId, get each type of collateral ##For each assetId, get each type of collateral
##Convert the data to JSON and store it in Product with setCollateral (update) ##Convert the data to JSON and store it in Product with setCollateral (update)
@ -731,15 +732,24 @@ EOSQL1
my $specJson = to_json(\@specification); my $specJson = to_json(\@specification);
$session->db->write('update Product set specificationJSON=? where assetId=?',[$specJson, $assetId]); $session->db->write('update Product set specificationJSON=? where assetId=?',[$specJson, $assetId]);
##Feature
$featureSth->execute([$assetId]);
my @features = ();
while (my $feature = $featureSth->hashRef()) {
push @features, $feature;
}
my $specJson = to_json(\@features);
$session->db->write('update Product set featureJSON=? where assetId=?',[$specJson, $assetId]);
} }
$assetSth->finish; $assetSth->finish;
##Drop collateral tables ##Drop collateral tables
$session->db->write('drop table Product_accessory'); $session->db->write('drop table Product_accessory');
#$session->db->write('drop table Product_benefit'); #$session->db->write('drop table Product_benefit');
#$session->db->write('drop table Product_feature'); $session->db->write('drop table Product_feature');
$session->db->write('drop table Product_related'); $session->db->write('drop table Product_related');
#$session->db->write('drop table Product_specification'); $session->db->write('drop table Product_specification');
## Remove productNumber from Product; ## Remove productNumber from Product;
$session->db->write('alter table Product drop column productNumber'); $session->db->write('alter table Product drop column productNumber');

View file

@ -149,6 +149,16 @@ sub definition {
autoGenerate => 0, autoGenerate => 0,
defaultValue => '[]', defaultValue => '[]',
}, },
featureJSON => {
##Collateral data is stored as JSON in here
autoGenerate => 0,
defaultValue => '[]',
},
benefitJSON => {
##Collateral data is stored as JSON in here
autoGenerate => 0,
defaultValue => '[]',
},
); );
push(@{$definition}, { push(@{$definition}, {
assetName=>$i18n->get('assetName'), assetName=>$i18n->get('assetName'),
@ -364,29 +374,6 @@ sub getThumbnailUrl {
return $store->getThumbnailUrl($store->getFiles->[0]); return $store->getThumbnailUrl($store->getFiles->[0]);
} }
#-------------------------------------------------------------------
=head2 indexContent ( )
Indexing product data. See WebGUI::Asset::indexContent() for additonal details.
=cut
sub indexContent {
my $self = shift;
my $indexer = $self->SUPER::indexContent;
my @data = $self->session->db->buildArray("select feature from Product_feature where assetId=".$self->session->db->quote($self->getId));
$indexer->addKeywords(join(" ", @data));
@data = $self->session->db->buildArray("select benefit from Product_benefit where assetId=".$self->session->db->quote($self->getId));
$indexer->addKeywords(join(" ", @data));
@data = ();
foreach my $collateral (@{ $self->getAllCollateral('specificationJSON') }) {
push @data, join(" ", @{ $collateral }{qw/name value units/});
}
$indexer->addKeywords(join(" ", @data));
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 moveCollateralDown ( tableName, index ) =head2 moveCollateralDown ( tableName, index )
@ -480,7 +467,6 @@ sub purge {
} }
$sth->finish; $sth->finish;
$self->session->db->write("delete from Product_benefit where assetId=".$self->session->db->quote($self->getId)); $self->session->db->write("delete from Product_benefit where assetId=".$self->session->db->quote($self->getId));
$self->session->db->write("delete from Product_feature where assetId=".$self->session->db->quote($self->getId));
$self->SUPER::purge(); $self->SUPER::purge();
} }
@ -761,8 +747,7 @@ sub www_deleteBenefitConfirm {
sub www_deleteFeatureConfirm { sub www_deleteFeatureConfirm {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->deleteCollateral("Product_feature","Product_featureId",$self->session->form->process("fid")); $self->deleteCollateral("featureJSON", $self->session->form->process("fid"));
$self->reorderCollateral("Product_feature","Product_featureId");
return ""; return "";
} }
@ -847,25 +832,22 @@ sub www_editFeature {
my $self = shift; my $self = shift;
my $fid = shift || $self->session->form->process("fid"); my $fid = shift || $self->session->form->process("fid");
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my ($data, $f, $features); my $data = $self->getCollateral("featureJSON", $fid);
$data = $self->getCollateral("Product_feature","Product_featureId",$fid);
my $i18n = WebGUI::International->new($self->session,'Asset_Product'); my $i18n = WebGUI::International->new($self->session,'Asset_Product');
$f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
$f->hidden( $f->hidden(
-name => "fid", -name => "fid",
-value => $data->{Product_featureId}, -value => $fid,
); );
$f->hidden( $f->hidden(
-name => "func", -name => "func",
-value => "editFeatureSave", -value => "editFeatureSave",
); );
$features = $self->session->db->buildHashRef("select feature,feature from Product_feature order by feature"); $f->text(
$f->combo(
-name => "feature", -name => "feature",
-options => $features,
-label => $i18n->get(23), -label => $i18n->get(23),
-hoverHelp => $i18n->get('23 description'), -hoverHelp => $i18n->get('23 description'),
-value => [$data->{feature}], -value => $data->{feature},
); );
$f->yesNo( $f->yesNo(
-name => "proceed", -name => "proceed",
@ -880,9 +862,8 @@ sub www_editFeature {
sub www_editFeatureSave { sub www_editFeatureSave {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->setCollateral("Product_feature", "Product_featureId", { $self->setCollateral("featureJSON", $self->session->form->process("fid"), {
Product_featureId => $self->session->form->process("fid"), feature => $self->session->form->process("feature","text")
feature => $self->session->form->process("feature","combo")
}); });
return "" unless($self->session->form->process("proceed")); return "" unless($self->session->form->process("proceed"));
return $self->www_editFeature("new"); return $self->www_editFeature("new");
@ -893,10 +874,11 @@ sub www_editSpecification {
my $self = shift; my $self = shift;
my $sid = shift || $self->session->form->process("sid"); my $sid = shift || $self->session->form->process("sid");
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
my ($data, $f, $hashRef);
my $i18n = WebGUI::International->new($self->session,'Asset_Product'); my $i18n = WebGUI::International->new($self->session,'Asset_Product');
$data = $self->getCollateral("specificationJSON", $sid); my $data = $self->getCollateral("specificationJSON", $sid);
$f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
$f->hidden( $f->hidden(
-name => "sid", -name => "sid",
-value => $sid, -value => $sid,
@ -907,7 +889,6 @@ sub www_editSpecification {
); );
$f->text( $f->text(
-name => "name", -name => "name",
-options => $hashRef,
-label => $i18n->get(26), -label => $i18n->get(26),
-hoverHelp => $i18n->get('26 description'), -hoverHelp => $i18n->get('26 description'),
-value => $data->{name}, -value => $data->{name},
@ -920,7 +901,6 @@ sub www_editSpecification {
); );
$f->text( $f->text(
-name => "units", -name => "units",
-options => $hashRef,
-label => $i18n->get(29), -label => $i18n->get(29),
-hoverHelp => $i18n->get('29 description'), -hoverHelp => $i18n->get('29 description'),
-value => $data->{units}, -value => $data->{units},
@ -939,9 +919,9 @@ sub www_editSpecificationSave {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->setCollateral("specificationJSON", $self->session->form->process("sid"), { $self->setCollateral("specificationJSON", $self->session->form->process("sid"), {
name => $self->session->form->process("name","combo"), name => $self->session->form->process("name", "text"),
value => $self->session->form->process("value","combo"), value => $self->session->form->process("value", "text"),
units => $self->session->form->process("units","combo") units => $self->session->form->process("units", "text")
}); });
return "" unless($self->session->form->process("proceed")); return "" unless($self->session->form->process("proceed"));
@ -1048,7 +1028,7 @@ sub www_moveBenefitUp {
sub www_moveFeatureDown { sub www_moveFeatureDown {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->moveCollateralDown("Product_feature","Product_featureId",$self->session->form->process("fid")); $self->moveCollateralDown("featureJSON", $self->session->form->process("fid"));
return ""; return "";
} }
@ -1056,7 +1036,7 @@ sub www_moveFeatureDown {
sub www_moveFeatureUp { sub www_moveFeatureUp {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit); return $self->session->privilege->insufficient() unless ($self->canEdit);
$self->moveCollateralUp("Product_feature","Product_featureId",$self->session->form->process("fid")); $self->moveCollateralUp("featureJSON", $self->session->form->process("fid"));
return ""; return "";
} }
@ -1150,22 +1130,21 @@ sub view {
$var{image3} = $self->getFileUrl($file); $var{image3} = $self->getFileUrl($file);
} }
#---features #---features
$var{"addFeature.url"} = $self->getUrl('func=editFeature&fid=new'); $var{'addFeature.url'} = $self->getUrl('func=editFeature&fid=new');
$var{"addFeature.label"} = $i18n->get(34); $var{'addFeature.label'} = $i18n->get(34);
$sth = $self->session->db->read("select feature,Product_featureId from Product_feature where assetId=".$self->session->db->quote($self->getId)." order by sequenceNumber"); foreach my $collateral ( @{ $self->getIndexedCollateralData('featureJSON') } ) {
while (%data = $sth->hash) { my $id = $collateral->{collateralIndex};
$segment = $self->session->icon->delete('func=deleteFeatureConfirm&fid='.$data{Product_featureId},$self->get("url"),$i18n->get(3)) $segment = $self->session->icon->delete('func=deleteFeatureConfirm&fid='.$id,$self->get('url'),$i18n->get(3))
.$self->session->icon->edit('func=editFeature&fid='.$data{Product_featureId},$self->get("url")) . $self->session->icon->edit('func=editFeature&fid='.$id,$self->get('url'))
.$self->session->icon->moveUp('func=moveFeatureUp&&fid='.$data{Product_featureId},$self->get("url")) . $self->session->icon->moveUp('func=moveFeatureUp&&fid='.$id,$self->get('url'))
.$self->session->icon->moveDown('func=moveFeatureDown&&fid='.$data{Product_featureId},$self->get("url")); . $self->session->icon->moveDown('func=moveFeatureDown&&fid='.$id,$self->get('url'));
push(@featureloop,{ push(@featureloop,{
"feature.feature"=>$data{feature}, 'feature.feature' => $collateral->{feature},
"feature.controls"=>$segment 'feature.controls' => $segment
}); });
} }
$sth->finish; $var{feature_loop} = \@featureloop;
$var{feature_loop} = \@featureloop;
#---benefits #---benefits
$var{"addBenefit.url"} = $self->getUrl('func=editBenefit&fid=new'); $var{"addBenefit.url"} = $self->getUrl('func=editBenefit&fid=new');
@ -1200,7 +1179,6 @@ sub view {
'specification.label' => $collateral->{name}, 'specification.label' => $collateral->{name},
}); });
} }
$sth->finish;
$var{specification_loop} = \@specificationloop; $var{specification_loop} = \@specificationloop;
#---accessories #---accessories

View file

@ -148,10 +148,22 @@ $products->setCollateral('Product_specification', 'Product_specificationId', {
units => 'Hertz', units => 'Hertz',
}); });
$products->setCollateral('Product_specification', 'Product_specificationId', { my $propertiesf = {
name => 'hue', className => 'WebGUI::Asset::Wobject::Product',
value => '75', url => 'feature_Product',
units => 'lumens', price => 3.33,
title => 'feature Product',
description => 'feature Product',
};
my $productf = $root->addChild($propertiesf);
$productf->setCollateral('Product_feature', 'Product_featureId', {
feature => 'leather interior',
});
$productf->setCollateral('Product_feature', 'Product_featureId', {
feature => '25% less code',
}); });
$tag->commit; $tag->commit;