diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 8ab269c07..9ba704f1b 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -449,6 +449,23 @@ sub setRatings { =head2 view ( hasRated ) +Updates the score of a MatrixListing. + +=cut + +sub updateScore { + my $self = shift; + my $score = $self->session->db->quickScalar("select sum(value) from MatrixListing_attribute + left join Matrix_attribute using(attributeId) + where matrixListingId = ? and fieldType = 'MatrixCompare'",[$self->getId]); + $self->update({score => $score}); + return undef; +} + +#------------------------------------------------------------------- + +=head2 view ( hasRated ) + method called by the container www_view method. =head3 hasRated diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index da641c354..54a0dfb8b 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -201,6 +201,17 @@ sub deleteAttribute { my $attributeId = shift; $self->deleteCollateral("Matrix_attribute","attributeId",$attributeId); + $self->session->db->write("delete from MatrixListing_attribute where attributeId=? and matrixId=?", + [$attributeId,$self->getId]); + + # recalculate scores for MatrixListings + my @listings = @{ $self->getLineage(['descendants'], { + includeOnlyClasses => ['WebGUI::Asset::MatrixListing'], + returnObjects => 1, + }) }; + foreach my $listing (@listings){ + $listing->updateScore; + } return undef; }