From 22f5565351608e8e32f21c0e9733998c538f9051 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Mon, 20 Oct 2008 16:17:27 +0000 Subject: [PATCH] initial import of Matrix v2 files into Matrix branch --- lib/WebGUI/Asset/MatrixListing.pm | 420 ++++ lib/WebGUI/Asset/Wobject/Matrix.pm | 1918 ++++++----------- lib/WebGUI/Form/MatrixCompare.pm | 156 ++ lib/WebGUI/Form/MatrixFieldType.pm | 153 ++ lib/WebGUI/i18n/English/Asset_Matrix.pm | 392 ++-- .../i18n/English/Asset_MatrixListing.pm | 103 + lib/WebGUI/i18n/English/Form_MatrixCompare.pm | 32 + lib/WebGUI/i18n/English/WebGUI.pm | 12 + t/Asset/MatrixListing.t | 63 + t/Asset/Wobject/Matrix.t | 98 + 10 files changed, 1860 insertions(+), 1487 deletions(-) create mode 100644 lib/WebGUI/Asset/MatrixListing.pm create mode 100644 lib/WebGUI/Form/MatrixCompare.pm create mode 100644 lib/WebGUI/Form/MatrixFieldType.pm create mode 100644 lib/WebGUI/i18n/English/Asset_MatrixListing.pm create mode 100644 lib/WebGUI/i18n/English/Form_MatrixCompare.pm create mode 100644 t/Asset/MatrixListing.t create mode 100644 t/Asset/Wobject/Matrix.t diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm new file mode 100644 index 000000000..8f92a93d6 --- /dev/null +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -0,0 +1,420 @@ +package WebGUI::Asset::MatrixListing; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use Tie::IxHash; +use base 'WebGUI::Asset'; +use WebGUI::Utility; + + + +=head1 NAME + +Package WebGUI::Asset::MatrixListing + +=head1 DESCRIPTION + +Describe your New Asset's functionality and features here. + +=head1 SYNOPSIS + +use WebGUI::Asset::MatrixListing; + + +=head1 METHODS + +These methods are available from this class: + +=cut + + + +#------------------------------------------------------------------- + +=head2 addRevision + + This method exists for demonstration purposes only. The superclass + handles revisions to MatrixListing Assets. + +=cut + +sub addRevision { + my $self = shift; + my $newSelf = $self->SUPER::addRevision(@_); + return $newSelf; +} + +#------------------------------------------------------------------- + +=head2 definition ( session, definition ) + +defines asset properties for MatrixListing instances. + +=head3 session + +=head3 definition + +A hash reference passed in from a subclass definition. + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift; + my %properties; + tie %properties, 'Tie::IxHash'; + my $i18n = WebGUI::International->new($session, "Asset_MatrixListing"); + %properties = ( + templateId => { + tab =>"display", + fieldType =>"template", + defaultValue =>'MatrixListingTmpl00001', + noFormPost =>0, + namespace =>"MatrixListing", + hoverHelp =>$i18n->get('template description'), + label =>$i18n->get('template label') + }, + screenshots => { + tab =>"properties", + fieldType =>"image", + defaultValue =>undef, + label =>$i18n->get("screenshots label"), + hoverHelp =>$i18n->get("screenshots description") + }, + description => { + tab =>"properties", + fieldType =>"HTMLArea", + defaultValue =>undef, + label =>$i18n->get("description label"), + hoverHelp =>$i18n->get("description description") + }, + version => { + tab =>"properties", + fieldType =>"text", + defaultValue =>undef, + label =>$i18n->get("version label"), + hoverHelp =>$i18n->get("version description") + }, + views => { + defaultValue =>0, + autoGenerate =>0, + noFormPost =>1, + }, + compares => { + defaultValue =>0, + autoGenerate =>0, + noFormPost =>1, + }, + clicks => { + defaultValue =>0, + autoGenerate =>0, + noFormPost =>1, + }, + viewsLastIp => { + defaultValue =>undef, + autoGenerate =>0, + noFormPost =>1, + }, + comparesLastIp => { + defaultValue =>undef, + autoGenerate =>0, + noFormPost =>1, + }, + clicksLastIp => { + defaultValue =>undef, + autoGenerate =>0, + noFormPost =>1, + }, + maintainer => { + tab =>"properties", + fieldType =>"user", + defaultValue =>$session->user->userId, + label =>$i18n->get("maintainer label"), + hoverHelp =>$i18n->get("maintainer description") + }, + manufacturerName => { + tab =>"properties", + fieldType =>"text", + defaultValue =>undef, + label =>$i18n->get("manufacturerName label"), + hoverHelp =>$i18n->get("manufacturerName description") + }, + manufacturerURL => { + tab =>"properties", + fieldType =>"url", + defaultValue =>undef, + label =>$i18n->get("manufacturerURL label"), + hoverHelp =>$i18n->get("manufacturerURL description") + }, + productURL => { + tab =>"properties", + fieldType =>"url", + defaultValue =>undef, + label =>$i18n->get("productURL label"), + hoverHelp =>$i18n->get("productURL description") + }, + lastUpdated => { + defaultValue =>time(), + autoGenerate =>0, + noFormPost =>1, + }, + ); + push(@{$definition}, { + assetName=>$i18n->get('assetName'), + icon=>'MatrixListing.gif', + autoGenerateForms=>1, + tableName=>'MatrixListing', + className=>'WebGUI::Asset::MatrixListing', + properties=>\%properties + }); + return $class->SUPER::definition($session, $definition); +} + + +#------------------------------------------------------------------- + +=head2 duplicate + + This method exists for demonstration purposes only. The superclass + handles duplicating MatrixListing Assets. This method will be called + whenever a copy action is executed + +=cut + +sub duplicate { + my $self = shift; + my $newAsset = $self->SUPER::duplicate(@_); + return $newAsset; +} + +#------------------------------------------------------------------- + +=head2 getAutoCommitWorkflowId + +Gets the WebGUI::VersionTag workflow to use to automatically commit MatrixListings. +By specifying this method, you activate this feature. + +=cut + +sub getAutoCommitWorkflowId { + my $self = shift; + return $self->getParent->get("submissionApprovalWorkflowId"); +} + +#------------------------------------------------------------------- + +=head2 indexContent ( ) + +Making private. See WebGUI::Asset::indexContent() for additonal details. + +=cut + +sub indexContent { + my $self = shift; + my $indexer = $self->SUPER::indexContent; + $indexer->setIsPublic(0); +} + + +#------------------------------------------------------------------- + +=head2 prepareView ( ) + +See WebGUI::Asset::prepareView() for details. + +=cut + +sub prepareView { + my $self = shift; + $self->SUPER::prepareView(); + my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); + $template->prepare; + $self->{_viewTemplate} = $template; +} + + +#------------------------------------------------------------------- + +=head2 processPropertiesFromFormPost ( ) + +Used to process properties from the form posted. Do custom things with +noFormPost fields here, or do whatever you want. This method is called +when /yourAssetUrl?func=editSave is requested/posted. + +=cut + +sub processPropertiesFromFormPost { + my $self = shift; + $self->SUPER::processPropertiesFromFormPost; + $self->requestAutoCommit; +} + + +#------------------------------------------------------------------- + +=head2 purge ( ) + +This method is called when data is purged by the system. +removes collateral data associated with a MatrixListing when the system +purges it's data. + +=cut + +sub purge { + my $self = shift; + return $self->SUPER::purge; +} + +#------------------------------------------------------------------- + +=head2 purgeRevision ( ) + +This method is called when data is purged by the system. + +=cut + +sub purgeRevision { + my $self = shift; + return $self->SUPER::purgeRevision; +} + +#------------------------------------------------------------------- +=head2 view ( ) + +method called by the container www_view method. + +=cut + +sub view { + my $self = shift; + my $var = $self->get; # $var is a hash reference. + $var->{controls} = $self->getToolbar; + $var->{fileUrl} = $self->getFileUrl; + $var->{fileIcon} = $self->getFileIconUrl; + return $self->processTemplate($var,undef, $self->{_viewTemplate}); +} + + +#------------------------------------------------------------------- + +=head2 www_edit ( ) + +Web facing method which is the default edit page + +=cut + +sub www_edit { + my $self = shift; + + return $self->session->privilege->noAccess() unless $self->getParent->canAddMatrixListing(); + + my $i18n = WebGUI::International->new($self->session, "Asset_MatrixListing"); + return $self->session->privilege->insufficient() unless $self->canEdit; + return $self->session->privilege->locked() unless $self->canEditIfLocked; + return $self->getAdminConsole->render($self->getEditForm->print,$i18n->get('edit matrix listing title')); +} + +#------------------------------------------------------------------- + +=head2 www_view ( ) + +Web facing method which is the default view page. This method does a +302 redirect to the "showPage" file in the storage location. + +=cut + +sub www_view { + my $self = shift; + return $self->session->privilege->noAccess() unless $self->canView; + if ($self->session->var->isAdminOn) { + return $self->getContainer->www_view; + } + $self->session->http->setRedirect($self->getFileUrl($self->getValue("showPage"))); + return undef; +} + +#------------------------------------------------------------------- +# Everything below here is to make it easier to install your custom +# asset, but has nothing to do with assets in general +#------------------------------------------------------------------- +# cd /data/WebGUI/lib +# perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf [ /path/to/WebGUI ] +# - or - +# perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf [ /path/to/WebGUI ] +#------------------------------------------------------------------- + + +use base 'Exporter'; +our @EXPORT = qw(install uninstall); +use WebGUI::Session; + +#------------------------------------------------------------------- +sub install { + my $config = $ARGV[0]; + my $home = $ARGV[1] || "/data/WebGUI"; + die "usage: perl -MWebGUI::Asset::MatrixListing -e install www.example.com.conf\n" unless ($home && $config); + print "Installing asset.\n"; + my $session = WebGUI::Session->open($home, $config); + $session->config->addToArray("assets","WebGUI::Asset::MatrixListing"); + $session->db->write("create table MatrixListing ( + assetId varchar(22) binary not null, + revisionDate bigint not null, + title varchar(255), + screenshots varchar(22), + description text, + version varchar(255), + views int(11), + compares int(11), + clicks int(11), + viewsLastIp varchar(255), + comparesLastIp varchar(255), + clicksLastIp varchar(255), + lastUpdated int(11), + maintainer varchar(22), + manufacturerName varchar(255), + manufacturerURL varchar(255), + productURL varchar(255), + primary key (assetId, revisionDate) + )"); + $session->var->end; + $session->close; + print "Done. Please restart Apache.\n"; +} + +#------------------------------------------------------------------- +sub uninstall { + my $config = $ARGV[0]; + my $home = $ARGV[1] || "/data/WebGUI"; + die "usage: perl -MWebGUI::Asset::MatrixListing -e uninstall www.example.com.conf\n" unless ($home && $config); + print "Uninstalling asset.\n"; + my $session = WebGUI::Session->open($home, $config); + $session->config->deleteFromArray("assets","WebGUI::Asset::MatrixListing"); + my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::MatrixListing'"); + while (my ($id) = $rs->array) { + my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::MatrixListing"); + $asset->purge if defined $asset; + } + $session->db->write("drop table MatrixListing"); + $session->var->end; + $session->close; + print "Done. Please restart Apache.\n"; +} + + +1; + +#vim:ft=perl diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 8c4120e2c..b71ad07b2 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -1,183 +1,334 @@ package WebGUI::Asset::Wobject::Matrix; - + +$VERSION = "2.0.0"; + +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2008 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + use strict; +use warnings; use Tie::IxHash; -use WebGUI::Form; -use WebGUI::HTMLForm; -use WebGUI::Cache; -use WebGUI::Mail::Send; -use WebGUI::SQL; -use WebGUI::Storage::Image; -use WebGUI::User; +use WebGUI::International; use WebGUI::Utility; -use WebGUI::Inbox; -use WebGUI::Asset::Wobject; -use WebGUI::Asset::Wobject::Collaboration; +use base 'WebGUI::Asset::Wobject'; + +#---------------------------------------------------------------------------- + +=head2 canAddMatrixListing ( ) + +Returns true if able to add MatrixListings. + + Checks to make sure that the + Calendar has been committed at least once. Checks to make sure that + the user is in the appropriate group (either the group that can edit + the calendar, or the group that can edit events in the calendar). + +=cut + +sub canAddMatrixListing { + my $self = shift; + + return 1; +=cut + my $userId = shift; + + my $user = $userId + ? WebGUI::User->new( $self->session, $userId ) + : $self->session->user + ; + + return 1 if ( + $user->isInGroup( $self->get("groupIdEventEdit") ) + ); +=cut +} - -our @ISA = qw(WebGUI::Asset::Wobject); - #------------------------------------------------------------------- + +=head2 definition ( ) + +defines wobject properties for Matrix instances. + +=cut + sub definition { - my $class = shift; + my $class = shift; my $session = shift; - my $definition = shift; - my $i18n = WebGUI::International->new($session,"Asset_Matrix"); - push(@{$definition}, { - icon=>'matrix.gif', - tableName=>'Matrix', - className=>'WebGUI::Asset::Wobject::Matrix', + my $definition = shift; + my $i18n = WebGUI::International->new($session, 'Asset_Matrix'); + + my %properties; + tie %properties, 'Tie::IxHash'; + %properties = ( + templateId =>{ + fieldType =>"template", + defaultValue =>'matrixtmpl000000000001', + tab =>"display", + #www_editSave will ignore anyone's attempts to update this field if this is set to 1 + noFormPost =>0, + #This is an option specific to the template fieldType. + namespace =>"Matrix", + hoverHelp =>$i18n->get('template description'), + label =>$i18n->get('template label'), + }, + searchTemplateId=>{ + defaultValue =>"matrixtmpl000000000005", + fieldType =>"template", + tab =>"display", + namespace =>"Matrix/Search", + hoverHelp =>$i18n->get('search template description'), + label =>$i18n->get('search template label'), + }, + detailTemplateId=>{ + defaultValue =>"matrixtmpl000000000003", + fieldType =>"template", + tab =>"display", + namespace =>"Matrix/Detail", + hoverHelp =>$i18n->get('detail template description'), + label =>$i18n->get('detail template label'), + }, + ratingDetailTemplateId=>{ + defaultValue =>"matrixtmpl000000000004", + fieldType =>"template", + tab =>"display", + namespace =>"Matrix/RatingDetail", + hoverHelp =>$i18n->get('rating detail template description'), + label =>$i18n->get('rating detail template label'), + }, + compareTemplateId=>{ + defaultValue =>"matrixtmpl000000000002", + fieldType =>"template", + tab =>"display", + namespace =>"Matrix/Compare", + hoverHelp =>$i18n->get('compare template description'), + label =>$i18n->get('compare template label'), + }, + defaultSort=>{ + fieldType =>"selectBox", + tab =>"display", + options =>{ + score => $i18n->get('sort by score label'), + alphaNumeric => $i18n->get('sort alpha numeric label'), + assetRank => $i18n->get('sort by asset rank label'), + lastUpdated => $i18n->get('sort by last updated label'), + }, + defaultValue =>"score", + hoverHelp =>$i18n->get('default sort description'), + label =>$i18n->get('default sort label'), + }, + compareColorNo=>{ + fieldType =>"color", + tab =>"display", + defaultValue =>"#ffaaaa", + hoverHelp =>$i18n->get('compare color no description'), + label =>$i18n->get('compare color no label'), + }, + compareColorLimited=>{ + fieldType =>"color", + tab =>"display", + defaultValue =>"#ffffaa", + hoverHelp =>$i18n->get('compare color limited description'), + label =>$i18n->get('compare color limited label'), + }, + compareColorCostsExtra=>{ + fieldType =>"color", + tab =>"display", + defaultValue =>"#ffffaa", + hoverHelp =>$i18n->get('compare color costs extra description'), + label =>$i18n->get('compare color costs extra label'), + }, + compareColorFreeAddOn=>{ + fieldType =>"color", + tab =>"display", + defaultValue =>"#ffffaa", + hoverHelp =>$i18n->get('compare color free add on description'), + label =>$i18n->get('compare color free add on label'), + }, + compareColorYes=>{ + fieldType =>"color", + tab =>"display", + defaultValue =>"#aaffaa", + hoverHelp =>$i18n->get('compare color yes description'), + label =>$i18n->get('compare color yes label'), + }, + categories=>{ + fieldType =>"textarea", + tab =>"properties", + defaultValue =>$i18n->get('categories default value'), + hoverHelp =>$i18n->get('categories description'), + label =>$i18n->get('categories label'), + subtext =>$i18n->get('categories subtext'), + }, + maxComparisons=>{ + fieldType =>"integer", + tab =>"properties", + defaultValue =>25, + hoverHelp =>$i18n->get('max comparisons description'), + label =>$i18n->get('max comparisons label'), + }, + maxComparisonsPrivileged=>{ + fieldType =>"integer", + tab =>"properties", + defaultValue =>10, + hoverHelp =>$i18n->get('max comparisons privileged description'), + label =>$i18n->get('max comparisons privileged label'), + }, + submissionApprovalWorkflowId=>{ + fieldType =>"workflow", + tab =>"security", + type =>'WebGUI::VersionTag', + defaultValue =>"pbworkflow000000000003", + hoverHelp =>$i18n->get('submission approval workflow description'), + label =>$i18n->get('submission approval workflow label'), + }, + ratingsDuration=>{ + fieldType =>"interval", + tab =>"properties", + defaultValue =>7776000, # 3 months 3*30*24*60*60 + hoverHelp =>$i18n->get('ratings duration description'), + label =>$i18n->get('ratings duration label'), + }, + ); + push(@{$definition}, { assetName=>$i18n->get('assetName'), - properties=>{ - visitorCacheTimeout => { - tab => "display", - fieldType => "interval", - defaultValue => 3600, - uiLevel => 8, - label => $i18n->get("visitor cache timeout"), - hoverHelp => $i18n->get("visitor cache timeout help") - }, - categories=>{ - defaultValue=>"Features\nBenefits", - fieldType=>"textarea" - }, - maxComparisons=>{ - defaultValue=>10, - fieldName=>"integer" - }, - templateId=>{ - defaultValue=>"matrixtmpl000000000001", - fieldType=>"template" - }, - searchTemplateId=>{ - defaultValue=>"matrixtmpl000000000005", - fieldType=>"template" - }, - detailTemplateId=>{ - defaultValue=>"matrixtmpl000000000003", - fieldType=>"template" - }, - ratingDetailTemplateId=>{ - defaultValue=>"matrixtmpl000000000004", - fieldType=>"template" - }, - compareTemplateId=>{ - defaultValue=>"matrixtmpl000000000002", - fieldType=>"template" - }, - privilegedGroup=>{ - defaultValue=>'2', - fieldType=>"group", - }, - groupToRate=>{ - defaultValue=>'2', - fieldType=>"group", - }, - groupToAdd=>{ - defaultValue=>'2', - fieldType=>"group", - }, - maxComparisonsPrivileged=>{ - defaultValue=>10, - fieldType=>"integer", - }, - ratingTimeout=>{ - defaultValue=>60*60*24*365, - fieldType=>"interval" - }, - ratingTimeoutPrivileged=>{ - defaultValue=>60*60*24*365, - fieldType=>"interval" - } - } - }); - return $class->SUPER::definition($session, $definition); + icon=>'matrix.gif', + autoGenerateForms=>1, + tableName=>'Matrix', + className=>'WebGUI::Asset::Wobject::Matrix', + properties=>\%properties + }); + return $class->SUPER::definition($session, $definition); } #------------------------------------------------------------------- + +=head2 deleteAttribute ( attributeId ) + +Deletes an attribute and listing data for this attribute from Collateral. + +=head3 attributeId + +The id of the attribute that should be deleted. + +=cut + +sub deleteAttribute { + + my $self = shift; + my $attributeId = shift; + + $self->deleteCollateral("Matrix_attribute","attributeId",$attributeId); + #TODO: delete listing data, $self->deleteCollateral("Matrix_listingData","attributeId",$attributeId); + + return undef; +} + +#------------------------------------------------------------------- + +=head2 duplicate ( ) + +duplicates a Matrix. + +=cut + sub duplicate { - # Buggo: how do we duplicate these? - return undef; -} - -#------------------------------------------------------------------- -# Too much data to keep track of modification dates, always assume new data -sub getContentLastModified { - return time(); -} - -#------------------------------------------------------------------- -sub formatURL { my $self = shift; - my $func = shift; - my $listingId = shift; - my $url = $self->getUrl("func=".$func.";listingId=".$listingId); - return $url; + my $newAsset = $self->SUPER::duplicate(@_); + return $newAsset; } +#------------------------------------------------------------------- + +=head2 editAttributeSave ( attributeProperties ) + +Saves an attribute. + +=head3 attributeProperties + +A hashref containing the properties of the attribute. + +=cut + +sub editAttributeSave { + my $self = shift; + my $attributeProperties = shift; + my $session = $self->session; + my $form = $session->form; + + return $session->privilege->insufficient() unless $self->canEdit; + + my $attributeId = $self->setCollateral("Matrix_attribute","attributeId",$attributeProperties,0,1); + + return $attributeId; +} #------------------------------------------------------------------- + +=head2 getAttribute ( attributeId ) + +Returns a hash reference of the properties of an attribute. + +=head3 attributeId + +The unique id of an attribute. + +=cut + +sub getAttribute { + my ($self, $attributeId) = @_; + return $self->session->db->quickHashRef("select * from Matrix_attribute where attributeId=?",[$attributeId]); +} + +#------------------------------------------------------------------- + +=head2 getCategories ( ) + +Returns the categories for this Matrix as a hashref. + +=cut + sub getCategories { - my $self = shift; - my $cat = $self->getValue("categories"); - $cat =~ s/\r//g; - chomp($cat); - my @categories = split(/\n/,$cat); - return @categories; -} + my $self = shift; + my %categories; + tie %categories, 'Tie::IxHash'; + my $categories = $self->getValue("categories"); + $categories =~ s/\r//g; + chomp($categories); + my @categories = split(/\n/,$categories); + foreach my $category (@categories) { + $categories{$category} = $category; + } + return \%categories; -#------------------------------------------------------------------- -sub getCompareForm { - my $self = shift; - my @ids = @_; - my $form = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl}) - .WebGUI::Form::submit($self->session, { - value=>"compare" - }) - ."
" - ."
" - .WebGUI::Form::hidden($self->session, { - name=>"func", - value=>"compare" - }) - .WebGUI::Form::checkList($self->session, { - name=>"listingId", - vertical=>1, - value=>\@ids, - options=>$self->session->db->buildHashRef("select listingId, concat('getUrl("func=viewDetail").";listingId=',listingId,'\\\">', productName,'') from Matrix_listing - where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by productName") - }) - ."
" - .WebGUI::Form::submit($self->session,{ - value=>"compare" - }) - .WebGUI::Form::formFooter($self->session); - return $form; } #------------------------------------------------------------------- -sub hasRated { - my $self = shift; - my $listingId = shift; - return 1 unless ($self->session->user->isInGroup($self->get("groupToRate"))); - my $ratingTimeout = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("ratingTimeoutPrivileged") : $self->get("ratingTimeout"); - my ($hasRated) = $self->session->db->quickArray("select count(*) from Matrix_rating where - ((userId=".$self->session->db->quote($self->session->user->userId)." and userId<>'1') or (userId='1' and ipAddress=".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR")).")) and - listingId=".$self->session->db->quote($listingId)." and timeStamp>".($self->session->datetime->time()-$ratingTimeout)); - return $hasRated; -} -#------------------------------------------------------------------- -sub incrementCounter { +=head2 getEditForm ( ) + +returns the tabform object that will be used in generating the edit page for Matrix. + +=cut + +sub getEditForm { my $self = shift; - my $listingId = shift; - my $counter = shift; - my ($lastIp) = $self->session->db->quickArray("select ".$counter."LastIp from Matrix_listing where listingId = ".$self->session->db->quote($listingId)); - unless ($lastIp eq $self->session->env->get("HTTP_X_FORWARDED_FOR")) { - $self->session->db->write("update Matrix_listing set $counter=$counter+1, ".$counter."LastIp=".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR"))." where listingId=".$self->session->db->quote($listingId)); - } + my $tabform = $self->SUPER::getEditForm(); +=cut + $tabform->getTab("display")->template( + -value=>$self->getValue("templateId"), + -label=>WebGUI::International::get("template_label","Asset_Matrix"), + -namespace=>"Matrix" + ); +=cut + return $tabform; } #------------------------------------------------------------------- @@ -192,1185 +343,350 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare($self->getMetaDataAsTemplateVariables); + $template->prepare; $self->{_viewTemplate} = $template; } #------------------------------------------------------------------- + +=head2 purge ( ) + +removes collateral data associated with a Matrix when the system +purges it's data. + +=cut + sub purge { - my $self = shift; - $self->session->db->write("delete from Matrix_listing where assetId=".$self->session->db->quote($self->getId)); - $self->session->db->write("delete from Matrix_listingData where assetId=".$self->session->db->quote($self->getId)); - $self->session->db->write("delete from Matrix_field where assetId=".$self->session->db->quote($self->getId)); - $self->session->db->write("delete from Matrix_rating where assetId=".$self->session->db->quote($self->getId)); - $self->session->db->write("delete from Matrix_ratingSummary where assetId=".$self->session->db->quote($self->getId)); - $self->SUPER::purge; + my $self = shift; + #purge your wobject-specific data here. This does not include fields + # you create for your Matrix asset/wobject table. + return $self->SUPER::purge; } #------------------------------------------------------------------- -=head2 purgeCache ( ) +=head2 view ( ) -See WebGUI::Asset::purgeCache() for details. +method called by the www_view method. Returns a processed template +to be displayed within the page style. =cut -sub purgeCache { - my $self = shift; - WebGUI::Cache->new($self->session,"view_".$self->getId)->delete; - $self->SUPER::purgeCache; -} - -#------------------------------------------------------------------- -sub setRatings { - my $self = shift; - my $listingId = shift; - my $ratings = shift; - foreach my $category ($self->getCategories) { - if ($ratings->{$category}) { - $self->session->db->write("insert into Matrix_rating (userId, category, rating, timeStamp, listingId,ipAddress, assetId) values ( - ".$self->session->db->quote($self->session->user->userId).", ".$self->session->db->quote($category).", ".$self->session->db->quote($ratings->{$category}).", ".$self->session->datetime->time() - .", ".$self->session->db->quote($listingId).", ".$self->session->db->quote($self->session->env->get("HTTP_X_FORWARDED_FOR")).",".$self->session->db->quote($self->getId).")"); - } - my $sql = "from Matrix_rating where listingId=".$self->session->db->quote($listingId)." and category=".$self->session->db->quote($category); - my ($sum) = $self->session->db->quickArray("select sum(rating) $sql"); - my ($count) = $self->session->db->quickArray("select count(*) $sql"); - my $half = round($count/2); - my $mean = $sum / ($count || 1); - my ($median) = $self->session->db->quickArray("select rating $sql limit $half,$half"); - $self->session->db->write("replace into Matrix_ratingSummary (listingId, category, meanValue, medianValue, countValue,assetId) values ( - ".$self->session->db->quote($listingId).", ".$self->session->db->quote($category).", $mean, ".$self->session->db->quote($median).", $count, ".$self->session->db->quote($self->getId).")"); - } -} - -#------------------------------------------------------------------- -sub www_approveListing { - my $self = shift; - return $self->session->privilege->insufficient() unless($self->canEdit); - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - $self->session->db->write("update Matrix_listing set status='approved' where listingId=".$self->session->db->quote($self->session->form->process("listingId"))); - my $inbox = WebGUI::Inbox->new($self->session); - $inbox->addMessage({ - subject=>"New Listing Approved", - message=>"Your new listing, ".$listing->{productName}.", has been approved.", - status=>'completed', - userId=>$listing->{maintainerId} - }); - my $message = $inbox->getMessage($listing->{approvalMessageId}); - if (defined $message) { - $message->setCompleted; - } - return $self->www_viewDetail; -} - - -#------------------------------------------------------------------- -sub www_click { - my $self = shift; - $self->incrementCounter($self->session->form->process("listingId"),"clicks"); - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - if ($self->session->form->process("m")) { - $self->session->http->setRedirect($listing->{manufacturerUrl}); - } - else { - $self->session->http->setRedirect($listing->{productUrl}); - } - return undef; -} - - -#------------------------------------------------------------------- -sub www_compare { - my $self = shift; - my @cmsList = @_; - unless (scalar(@cmsList)) { - @cmsList = $self->session->form->checkList("listingId"); - } - my ($style, $url) = ($self->session->style, $self->session->url); - my ( %var, @prodcol, @datecol); - my $max = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("maxComparisonsPrivileged") : $self->get("maxComparisons"); - $var{isTooMany} = (scalar(@cmsList)>$max); - $var{isTooFew} = (scalar(@cmsList)<2); - $var{'compare.form'} = $self->getCompareForm(@cmsList); - $var{'isLoggedIn'} = ($self->session->user->isRegistered); - if ($var{isTooMany} || $var{isTooFew}) { - return $self->processStyle($self->processTemplate(\%var,$self->get("compareTemplateId"))); - } - foreach my $cms (@cmsList) { - $self->incrementCounter($cms,"compares"); - my $data = $self->session->db->quickHashRef("select listingId, productName, versionNumber, lastUpdated - from Matrix_listing where listingId=".$self->session->db->quote($cms)); - push(@prodcol, { - name=>$data->{productName} || "__untitled__", - version=>$data->{versionNumber}, - url=>$self->formatURL("viewDetail",$cms) - }); - push(@datecol, { - lastUpdated=>$self->session->datetime->epochToHuman($data->{lastUpdated},"%z") - }); - } - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - my %goodBad = ( - "No" => $i18n->get("no"), - "Yes" => $i18n->get("yes"), - "Free Add On" => $i18n->get("free"), - "Costs Extra" => $i18n->get("extra"), - "Limited" => $i18n->get("limited"), - ); - $var{product_loop} = \@prodcol; - $var{lastupdated_loop} = \@datecol; - my @categoryloop; - foreach my $category ($self->getCategories()) { - my @rowloop; - my $select = "select a.fieldType, a.label, a.description"; - my $from = "from Matrix_field a"; - my $tableCount = "b"; - foreach my $cms (@cmsList) { - $select .= ", ".$tableCount.".value"; - $from .= " left join Matrix_listingData ".$tableCount." on a.fieldId=" - .$tableCount.".fieldId and ".$tableCount.".listingId=".$self->session->db->quote($cms); - $tableCount++; - } - my $sth = $self->session->db->read("$select $from where a.category=".$self->session->db->quote($category)." and a.assetId=".$self->session->db->quote($self->getId)." order by a.label"); - while (my @row = $sth->array) { - my @columnloop; - my $first = 1; - my $type = shift @row; - foreach my $value (@row) { - my $desc = ""; - if ($first) { - $desc = $row[1]; - shift(@row); - $first = 0; - } - elsif ($type eq 'goodBad') { - $value = $goodBad{$value}; - } - my $class = lc($value); - $class =~ s/\s/_/g; - $class =~ s/\W//g; - push(@columnloop,{ - value=>$value, - class=>$class, - description=>$desc - }); - } - push(@rowloop,{ - column_loop=>\@columnloop - }); - } - $sth->finish; - push(@categoryloop,{ - category=>$category, - columnCount=>$#cmsList+2, - row_loop=>\@rowloop - }); - } - $var{category_loop} = \@categoryloop; - return $self->processStyle($self->processTemplate(\%var,$self->get("compareTemplateId"))); -} - -#------------------------------------------------------------------- -sub www_copy { - my $self = shift; - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - return $i18n->get('no copy'); -} - -#------------------------------------------------------------------- -sub www_deleteField { - my $self = shift; - my $id = $self->session->form->param("fieldId"); - $self->session->db->write("delete from Matrix_field where fieldId=?",[$id]); - $self->session->db->write("delete from Matrix_listingData where fieldId=?",[$id]); - $self->www_listFields(); -} - -#------------------------------------------------------------------- -sub www_deleteListing { - my $self = shift; - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - my $output = sprintf $i18n->get('delete listing confirmation'), - $self->getUrl("func=deleteListingConfirm;listingId=".$self->session->form->process("listingId")), - $self->formatURL("viewDetail",$self->session->form->process("listingId")); - return $self->processStyle($output); -} - -#------------------------------------------------------------------- -sub www_deleteListingConfirm { - my $self = shift; - return $self->session->privilege->insufficient() unless($self->canEdit); - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId})->purge; - $self->session->db->write("delete from Matrix_listing where listingId=".$self->session->db->quote($self->session->form->process("listingId"))); - $self->session->db->write("delete from Matrix_listingData where listingId=".$self->session->db->quote($self->session->form->process("listingId"))); - $self->session->db->write("delete from Matrix_rating where listingId=".$self->session->db->quote($self->session->form->process("listingId"))); - $self->session->db->write("delete from Matrix_ratingSummary where listingId=".$self->session->db->quote($self->session->form->process("listingId"))); - my $inbox = WebGUI::Inbox->new($self->session); - $inbox->addMessage({ - status=>'completed', - subject=>"Listing Deleted", - message=>"Your listing, ".$listing->{productName}.", has been deleted from the matrix.", - userId=>$listing->{maintainerId} - }); - my $message = $inbox->getMessage($listing->{approvalMessageId}); - if (defined $message) { - $message->setCompleted; - } - return ""; -} - -#------------------------------------------------------------------- -sub getEditForm { - my $self = shift; - my $tabform = $self->SUPER::getEditForm(); - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - $tabform->getTab("display")->interval( - -name=>"visitorCacheTimeout", - -label=>$i18n->get('visitor cache timeout'), - -hoverHelp=>$i18n->get('visitor cache timeout help'), - -value=>$self->getValue('visitorCacheTimeout'), - -uiLevel=>8, - -defaultValue=>3600 - ); - $tabform->getTab("properties")->textarea( - -name=>"categories", - -label=>$i18n->get('categories'), - -hoverHelp=>$i18n->get('categories description'), - -value=>$self->getValue("categories"), - -subtext=>$i18n->get('categories subtext'), - ); - $tabform->getTab("properties")->integer( - -name=>"maxComparisons", - -label=>$i18n->get("max comparisons"), - -hoverHelp=>$i18n->get("max comparisons description"), - -value=>$self->getValue("maxComparisons") - ); - $tabform->getTab("properties")->integer( - -name=>"maxComparisonsPrivileged", - -label=>$i18n->get("max comparisons privileged"), - -hoverHelp=>$i18n->get("max comparisons privileged description"), - -value=>$self->getValue("maxComparisonsPrivileged") - ); - $tabform->getTab("properties")->interval( - -name=>"ratingTimeout", - -label=>$i18n->get("rating timeout"), - -hoverHelp=>$i18n->get("rating timeout description"), - -value=>$self->getValue("ratingTimeout") - ); - $tabform->getTab("properties")->interval( - -name=>"ratingTimeoutPrivileged", - -label=>$i18n->get("rating timeout privileged"), - -hoverHelp=>$i18n->get("rating timeout privileged description"), - -value=>$self->getValue("ratingTimeoutPrivileged") - ); - $tabform->getTab("security")->group( - -name=>"groupToAdd", - -label=>$i18n->get("group to add"), - -hoverHelp=>$i18n->get("group to add description"), - -value=>[$self->getValue("groupToAdd")] - ); - $tabform->getTab("security")->group( - -name=>"privilegedGroup", - -label=>$i18n->get("privileged group"), - -hoverHelp=>$i18n->get("privileged group description"), - -value=>[$self->getValue("privilegedGroup")] - ); - $tabform->getTab("security")->group( - -name=>"groupToRate", - -label=>$i18n->get("rating group"), - -hoverHelp=>$i18n->get("rating group description"), - -value=>[$self->getValue("groupToRate")] - ); - $tabform->getTab("display")->template( - -name=>"templateId", - -value=>$self->getValue("templateId"), - -label=>$i18n->get("main template"), - -hoverHelp=>$i18n->get("main template description"), - -namespace=>"Matrix" - ); - $tabform->getTab("display")->template( - -name=>"detailTemplateId", - -value=>$self->getValue("detailTemplateId"), - -label=>$i18n->get("detail template"), - -hoverHelp=>$i18n->get("detail template description"), - -namespace=>"Matrix/Detail" - ); - $tabform->getTab("display")->template( - -name=>"ratingDetailTemplateId", - -value=>$self->getValue("ratingDetailTemplateId"), - -label=>$i18n->get("rating detail template"), - -hoverHelp=>$i18n->get("rating detail template description"), - -namespace=>"Matrix/RatingDetail" - ); - $tabform->getTab("display")->template( - -name=>"searchTemplateId", - -value=>$self->getValue("searchTemplateId"), - -label=>$i18n->get("search template"), - -hoverHelp=>$i18n->get("search template description"), - -namespace=>"Matrix/Search" - ); - $tabform->getTab("display")->template( - -name=>"compareTemplateId", - -value=>$self->getValue("compareTemplateId"), - -label=>$i18n->get("compare template"), - -hoverHelp=>$i18n->get("compare template description"), - -namespace=>"Matrix/Compare" - ); - return $tabform; -} - -#------------------------------------------------------------------- -sub www_edit { - my $self = shift; - return $self->session->privilege->insufficient() unless $self->canEdit; - return $self->session->privilege->locked() unless $self->canEditIfLocked; - my $i18n = WebGUI::International->new($self->session, 'Asset_Wobject'); - my $addEdit = ($self->session->form->process("func") eq 'add') ? $i18n->get('add') : $i18n->get('edit'); - return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel); -} - -#------------------------------------------------------------------- - -=head2 www_deleteImage ( ) - -Deletes and attached file. - -=cut - -sub www_deleteImage { - my $self = shift; - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - return $i18n->get('no edit rights') unless ($self->session->user->userId eq $listing->{maintainerId} || $self->canEdit); - if ($listing->{storageId} ne "") { - my $storage = WebGUI::Storage::Image->get($self->session, $listing->{storageId}); - $storage->delete; - } - return $self->www_editListing($listing, $i18n); -} - - - -#------------------------------------------------------------------- -sub www_editListing { - my $self = shift; - my $listing= shift || $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - my $i18n = shift || WebGUI::International->new($self->session,'Asset_Matrix'); - return $i18n->get('no edit rights') unless (($self->session->form->process("listingId") eq "new" && $self->session->user->isInGroup($self->get("groupToAdd"))) || $self->session->user->userId eq $listing->{maintainerId} || $self->canEdit); - my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); - $f->hidden( - -name=>"func", - -value=>"editListingSave" - ); - $f->hidden( - -name=>"listingId", - -value=>$self->session->form->process("listingId") - ); - $f->text( - -name=>"productName", - -value=>$listing->{productName} || 'Undefined', - -label=>$i18n->get('product name'), - -hoverHelp=>$i18n->get('product name description'), - -maxLength=>25 - ); - $f->text( - -name=>"versionNumber", - -value=>$listing->{versionNumber}, - -label=>$i18n->get('version number'), - -hoverHelp=>$i18n->get('version number description'), - ); - $f->url( - -name=>"productUrl", - -value=>$listing->{productUrl}, - -label=>$i18n->get('product url'), - -hoverHelp=>$i18n->get('product url description'), - ); - $f->image( - name=>"screenshot", - label=>$i18n->get("screenshot"), - value=>$listing->{storageId}, - hoverHelp=>$i18n->get("screenshot help"), - deleteFileUrl=>$self->getUrl("func=deleteImage;listingId=".$listing->{listingId}.";filename=") - ); - $f->text( - -name=>"manufacturerName", - -value=>$listing->{manufacturerName}, - -label=>$i18n->get('manufacturer name'), - -hoverHelp=>$i18n->get('manufacturer name description'), - ); - $f->url( - -name=>"manufacturerUrl", - -value=>$listing->{manufacturerUrl}, - -label=>$i18n->get('manufacturer url'), - ); - $f->textarea( - -name=>"description", - -value=>$listing->{description}, - -label=>$i18n->get('description'), - ); - if ($self->canEdit) { - $f->user( - name=>"maintainerId", - value=>$listing->{maintainerId}, - label=>$i18n->get('listing maintainer'), - hoverHelp=>$i18n->get('listing maintainer description'), - ); - } - my %goodBad = ( - "No" => $i18n->get("no"), - "Yes" => $i18n->get("yes"), - "Free Add On" => $i18n->get("free"), - "Costs Extra" => $i18n->get("extra"), - "Limited" => $i18n->get("limited"), - ); - foreach my $category ($self->getCategories()) { - $f->raw(''.$category.''); - my $a; - if ($self->session->form->process("listingId") ne "new") { - $a = $self->session->db->read( - "select a.name, a.fieldType, a.defaultValue, a.description, a.label, b.value, a.fieldId - from Matrix_field a left join Matrix_listingData b on a.fieldId=b.fieldId and - listingId=? where a.category=? and a.assetId=? order by a.label", - [$self->session->form->process("listingId"), $category, $self->getId]); - } else { - $a = $self->session->db->read("select name, fieldType, defaultValue, description, label, fieldId - from Matrix_field where category=".$self->session->db->quote($category)." and assetId=".$self->session->db->quote($self->getId)); - } - while (my $field = $a->hashRef) { - if ($field->{fieldType} eq "text") { - $f->text( - -name=>$field->{name}, - -value=>$field->{value} || $field->{defaultValue}, - -label=>$field->{label}, - -subtext=>"
".$field->{description} - ); - } elsif ($field->{fieldType} eq "goodBad") { - my $value = ($field->{value} || $field->{defaultValue} || $i18n->get("no")); - $f->selectBox( - -name=>$field->{name}, - -value=>[$value], - -label=>$field->{label}, - -options=>\%goodBad, - -subtext=>"
".$field->{description} - ); - } elsif ($field->{fieldType} eq "textarea") { - $f->textarea( - -name=>$field->{name}, - -value=>$field->{value} || $field->{defaultValue}, - -label=>$field->{label}, - -subtext=>"
".$field->{description} - ); - } elsif ($field->{fieldType} eq "url") { - $f->url( - -name=>$field->{name}, - -value=>$field->{value} || $field->{defaultValue}, - -label=>$field->{label}, - -subtext=>"
".$field->{description} - ); - } elsif ($field->{fieldType} eq "combo") { - my $value = ($field->{value} || $field->{defaultValue}); - $f->combo( - -name=>$field->{name}, - -value=>[$value], - -label=>$field->{label}, - -options=>$self->session->db->buildHashRef("select distinct value,value from Matrix_listingData - where fieldId=".$self->session->db->quote($field->{fieldId})." and - assetId=".$self->session->db->quote($self->getId)." order by value"), - -subtext=>"
".$field->{description} - ); - } - - } - $a->finish; - } - $f->submit; - return $self->processStyle($i18n->get('edit listing').$f->print); -} - - -#------------------------------------------------------------------- -sub www_editListingSave { - my $self = shift; - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$self->session->form->process("listingId")); - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - return $i18n->get('no edit rights') unless (($self->session->form->process("listingId") eq "new" && $self->session->user->isInGroup($self->get("groupToAdd"))) || $self->session->user->userId eq $listing->{maintainerId} || $self->canEdit); - my %data = ( - listingId => $self->session->form->process("listingId"), - lastUpdated => $self->session->datetime->time(), - productName => $self->session->form->process("productName") || 'Undefined', - productUrl => $self->session->form->process("productUrl"), - manufacturerName => $self->session->form->process("manufacturerName"), - manufacturerUrl => $self->session->form->process("manufacturerUrl"), - description => $self->session->form->process("description"), - versionNumber=>$self->session->form->process("versionNumber") - ); - - my $storageId = WebGUI::Form::Image->new($self->session,{name => 'screenshot', value => $listing->{storageId}})->getValue; - if ($storageId) { - $data{storageId} = $storageId; - $data{filename} = WebGUI::Storage->get($self->session, $storageId)->getFiles->[0]; - } - - my $productName = $self->session->form->process("productName"); - - my $isNew = 0; - if ($self->session->form->process("listingId") eq "new") { - $data{maintainerId} = $self->session->user->userId if ($self->session->form->process("listingId") eq "new"); - - my $newTag = WebGUI::VersionTag->create($self->session, { - name => $productName.' / '.$self->session->user->username, - workflowId => 'pbworkflow000000000003' }); - my $oldTag = WebGUI::VersionTag->getWorking($self->session, 1); - $newTag->setWorking; - - my $forum = $self->addChild({ - className=>"WebGUI::Asset::Wobject::Collaboration", - title=>$productName, - menuTitle=>$productName, - url=>$productName, - groupIdView=>$self->get('groupIdView'), - groupIdEdit=>$self->get('groupIdEdit'), - displayLastReply => 0, - allowReplies => 1, - threadsPerPage => 30, - postsPerPage => 10, - archiveAfter =>31536000, - useContentFilter => 1, - filterCode => 'javascript', - richEditor => "PBrichedit000000000002", - attachmentsPerPost => 0, - editTimeout => 3600, - addEditStampToPosts => 0, - usePreview => 1, - sortOrder => 'desc', - sortBy => 'assetData.revisionDate', - rssTemplateId=>'PBtmpl0000000000000142', - notificationTemplateId=>'PBtmpl0000000000000027', - searchTemplateId=>'PBtmpl0000000000000031', - postFormTemplateId=>'PBtmpl0000000000000029', - threadTemplateId=>'PBtmpl0000000000000032', - collaborationTemplateId=>'PBtmpl0000000000000026', - karmaPerPost =>0, - karmaSpentToRate => 0, - approvalWorkflow=>"pbworkflow000000000003", - karmaRatingMultiplier => 0, - moderatePosts => 0, - moderateGroupId => $self->get('groupIdEdit'), - postGroupId => $self->get('groupIdView'), - styleTemplateId => $self->get('styleTemplateId'), - printableStyleTemplateId => $self->get('printableStyleTemplateId'), - }); - $newTag->requestCommit; - $newTag->clearWorking; - $oldTag->setWorking if defined $oldTag; - - $data{forumId} = $forum->getId; - $data{status} = "pending"; - $isNew = 1; - } - else { - my $forum = WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId}); - if ($forum && $forum->get('title') ne $productName) { - my $oldTag = WebGUI::VersionTag->getWorking($self->session, 1); - my $newTag = WebGUI::VersionTag->create($self->session, { - name => $productName.' / '.$self->session->user->username, - workflowId => 'pbworkflow000000000003' }); - $newTag->setWorking; - $forum->addRevision({ - title => $productName, - menuTitle => $productName, - url => $productName, - }); - $newTag->requestCommit; - $newTag->clearWorking; - $oldTag->setWorking - if defined $oldTag; - } - my $forum = WebGUI:: - } - $data{maintainerId} = $self->session->form->process("maintainerId") if ($self->canEdit); - $data{assetId} = $self->getId; - my $listingId = $self->session->db->setRow("Matrix_listing","listingId",\%data); - if ($data{status} eq "pending" && !$listing->{approvalMessageId}) { - my $approvalMessage = WebGUI::Inbox->new($self->session)->addMessage({ - status=>'pending', - groupId=>$self->get("groupIdEdit"), - userId=>$self->get("ownerUserId"), - subject=>"New Listing Added", - message=>"A new listing, ".$data{productName}.", is waiting to be added.\n\n".$self->session->url->getSiteURL()."/".$self->formatURL("viewDetail",$listingId) - }); - $self->session->db->setRow("Matrix_listing","listingId",{listingId=>$listingId, approvalMessageId=>$approvalMessage->getId}); - } - my $a = $self->session->db->read("select fieldId, name, fieldType from Matrix_field"); - while (my ($id, $name, $type) = $a->array) { - my $value; - if ($type eq "goodBad") { - $value = $self->session->form->selectBox($name); - } else { - $value = $self->session->form->process($name,$type); - } - $self->session->db->write("replace into Matrix_listingData (assetId, listingId, fieldId, value) values ( - ".$self->session->db->quote($self->getId).", ".$self->session->db->quote($listingId).", ".$self->session->db->quote($id).", ".$self->session->db->quote($value).")"); - } - $a->finish; - return $self->www_viewDetail($listingId); -} - -#------------------------------------------------------------------- -sub www_editField { - my $self = shift; - return $self->session->privilege->insufficient() unless($self->canEdit); - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - my $field = $self->session->db->getRow("Matrix_field","fieldId",$self->session->form->process("fieldId")); - my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); - $f->hidden( - -name=>"func", - -value=>"editFieldSave" - ); - $f->hidden( - -name=>"fieldId", - -value=>$self->session->form->process("fieldId") - ); - $f->text( - -name=>"name", - -value=>$field->{name}, - -label=>$i18n->get('field name'), - -hoverHelp=>$i18n->get('field name description'), - ); - $f->text( - -name=>"label", - -value=>$field->{label}, - -label=>$i18n->get('field label'), - -hoverHelp=>$i18n->get('field label description'), - ); - $f->selectBox( - -name=>"fieldType", - -value=>[$field->{fieldType}], - -label=>$i18n->get('field type'), - -hoverHelp=>$i18n->get('field type description'), - -options=>{ - 'goodBad' => $i18n->get('good bad'), - 'text' => $i18n->get('text'), - 'url' => $i18n->get('url'), - 'textarea' => $i18n->get('text area'), - 'combo' => $i18n->get('combo'), - } - ); - $f->textarea( - -name=>"description", - -value=>$field->{description}, - -label=>$i18n->get('field description'), - -hoverHelp=>$i18n->get('field description description'), - ); - $f->text( - -name=>"defaultValue", - -value=>$field->{defaultValue}, - -label=>$i18n->get('default value'), - -hoverHelp=>$i18n->get('default value description'), - ); - my %cats; - foreach my $category ($self->getCategories) { - $cats{$category} = $category; - } - $f->selectBox( - -name=>"category", - -value=>[$field->{category}], - -label=>$i18n->get('category'), - -hoverHelp=>$i18n->get('category description'), - -options=>\%cats - ); - $f->submit; - return $self->processStyle($i18n->get('edit field').$f->print); -} - - -#------------------------------------------------------------------- -sub www_editFieldSave { - my $self = shift; - return $self->session->privilege->insufficient() unless($self->canEdit); - $self->session->db->setRow("Matrix_field","fieldId",{ - fieldId=>$self->session->form->process("fieldId"), - name=>$self->session->form->process("name"), - label=>$self->session->form->process("label"), - fieldType=>$self->session->form->process("fieldType"), - description=>$self->session->form->process("description"), - defaultValue=>$self->session->form->process("defaultValue"), - category=>$self->session->form->process("category"), - assetId=>$self->getId - }); - return $self->www_listFields(); -} - -#------------------------------------------------------------------- -sub www_listFields { - my $self = shift; - return $self->session->privilege->insufficient() unless($self->canEdit); - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - my $output = sprintf $i18n->get('list fields'), - $self->getUrl("func=editField;fieldId=new"); - my $sth = $self->session->db->read("select fieldId, label from Matrix_field where assetId=".$self->session->db->quote($self->getId)." order by label"); - while (my ($id, $label) = $sth->array) { - $output .= $self->session->icon->delete("func=deleteField;fieldId=".$id, $self->get("url"), $i18n->get("delete field confirm")) - .$self->session->icon->edit("func=editField;fieldId=".$id) - .' '.$label."
\n"; - } - $sth->finish; - return $self->processStyle($output); -} - - -#------------------------------------------------------------------- -sub www_rate { - my $self = shift; - my $hasRated = $self->hasRated($self->session->form->process("listingId")); - my $sameRating = 1; - my $first = 1; - my $lastRating; - foreach my $category ($self->getCategories) { - if ($first) { - $first=0; - } else { - if ($lastRating != $self->session->form->process($category)) { - $sameRating = 0; - } - } - $lastRating = $self->session->form->process($category); - } - return $self->www_viewDetail("",1) if ($hasRated || $sameRating); # Throw out ratings that are all the same number, or if the user rates twice. - $self->setRatings($self->session->form->process("listingId"),$self->session->form->paramsHashRef); - return $self->www_viewDetail; -} - -#------------------------------------------------------------------- -sub www_search { - my $self = shift; - my %var; - my @list = $self->session->db->buildArray("select listingId from Matrix_listing"); - if ($self->session->form->process("doit")) { - my $count; - my $keyword; - if ($self->session->form->process("keyword")) { - $keyword = " and (a.value like ".$self->session->db->quote('%'.$self->session->form->process("keyword").'%')." or a.value='Any')"; - } - my $sth = $self->session->db->read("select name,fieldType from Matrix_field"); - while (my ($name,$fieldType) = $sth->array) { - next unless ($self->session->form->process($name)); - push(@list,0); - my $where; - if ($fieldType ne "goodBad") { - $where = "(" - ."a.value like ".$self->session->db->quote("%".$self->session->form->process($name)."%") - ." or a.value='Any'" - ." or a.value='Free'" - .")"; - } else { - $where = "a.value<>'no'"; - } - @list = $self->session->db->buildArray("select a.listingId from Matrix_listingData a left join Matrix_field b - on (a.fieldId=b.fieldId) - where a.listingId in (".$self->session->db->quoteAndJoin(\@list).") and $where and b.name=".$self->session->db->quote($name)); - $count = scalar(@list); - last unless ($count > 0); - } - $sth->finish; - if ($count > 1 && $count < 11) { - return $self->www_compare(@list); - } elsif ($count == 1) { - return $self->www_viewDetail($list[0]); - } else { - my $max = $self->session->user->isInGroup($self->get("privilegedGroup")) ? $self->get("maxComparisonsPrivileged") : $self->get("maxComparisons"); - $var{isTooMany} = ($count>$max); - $var{isTooFew} = ($count<2); - } - } - $var{'isLoggedIn'} = ($self->session->user->isRegistered); - $var{'compare.form'} = $self->getCompareForm(@list); - $var{'form.header'} = WebGUI::Form::formHeader($self->session,{action=>$self->getUrl}) - .WebGUI::Form::hidden($self->session,{ - name=>"doit", - value=>"1" - }) - .WebGUI::Form::hidden($self->session,{ - name=>"func", - value=>"search" - }); - $var{'form.footer'} = ""; - $var{'form.keyword'} = WebGUI::Form::text($self->session,{ - name=>"keyword", - value=>$self->session->form->process("keyword") - }); - $var{'form.submit'} = WebGUI::Form::submit($self->session,{ - value=>"search" - }); - foreach my $category ($self->getCategories()) { - my $sth = $self->session->db->read("select name, fieldType, label, description from Matrix_field where category = ".$self->session->db->quote($category)." order by label"); - my @loop; - while (my $data = $sth->hashRef) { - if ($data->{fieldType} ne "goodBad") { - $data->{form} = WebGUI::Form::text($self->session,{ - name=>$data->{name}, - value=>$self->session->form->process($data->{name}) - }); - } else { - $data->{form} = WebGUI::Form::checkbox($self->session,{ - name=>$data->{name}, - value=>"1", - checked=>$self->session->form->process($data->{name}) - }); - } - push(@loop,$data); - } - $sth->finish; - $var{$self->session->url->urlize($category)."_loop"} = \@loop; - } - return $self->processStyle($self->processTemplate(\%var,$self->get("searchTemplateId"))); -} - - -#------------------------------------------------------------------- sub view { - my $self = shift; - if ($self->session->user->isVisitor) { - my $out = WebGUI::Cache->new($self->session,"view_".$self->getId)->get; - return $out if $out; - } - my (%var); - $var{'compare.form'} = $self->getCompareForm; - $var{'search.url'} = $self->getUrl("func=search"); - $var{'isLoggedIn'} = ($self->session->user->isRegistered); - $var{'field.list.url'} = $self->getUrl('func=listFields'); - $var{'listing.add.url'} = $self->formatURL("editListing","new"); + my $self = shift; + my $session = $self->session; - my $data = $self->session->db->quickHashRef("select views, productName, listingId from Matrix_listing - where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by views desc limit 1"); - $var{'best.views.url'} = $self->formatURL("viewDetail",$data->{listingId}); - $var{'best.views.count'} = $data->{views}; - $var{'best.views.name'} = $data->{productName}; - $data = $self->session->db->quickHashRef("select compares, productName, listingId from Matrix_listing - where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by compares desc limit 1"); - $var{'best.compares.url'} = $self->formatURL("viewDetail",$data->{listingId}); - $var{'best.compares.count'} = $data->{compares}; - $var{'best.compares.name'} = $data->{productName}; - $data = $self->session->db->quickHashRef("select clicks, productName, listingId from Matrix_listing - where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by clicks desc limit 1"); - $var{'best.clicks.url'} = $self->formatURL("viewDetail",$data->{listingId}); - $var{'best.clicks.count'} = $data->{clicks}; - $var{'best.clicks.name'} = $data->{productName}; - my (@best,@worst); - foreach my $category ($self->getCategories) { - my $sql = " - select - Matrix_listing.productName, - Matrix_listing.listingId, - Matrix_ratingSummary.meanValue, - Matrix_ratingSummary.medianValue, - Matrix_ratingSummary.countValue - from - Matrix_listing - left join - Matrix_ratingSummary - on - Matrix_listing.listingId=Matrix_ratingSummary.listingId and - Matrix_ratingSummary.category=".$self->session->db->quote($category)." - where - Matrix_listing.assetId=".$self->session->db->quote($self->getId)." and - Matrix_listing.status='approved' and - Matrix_ratingSummary.countValue >= 10 - order by - Matrix_ratingSummary.meanValue - "; - $data = $self->session->db->quickHashRef($sql." desc limit 1"); - push(@best,{ - url=>$self->formatURL("viewDetail",$data->{listingId}), - category=>$category, - name=>$data->{productName}, - mean=>$data->{meanValue}, - median=>$data->{medianValue}, - count=>$data->{countValue} - }); - $data = $self->session->db->quickHashRef($sql." asc limit 1"); - push(@worst,{ - url=>$self->formatURL("viewDetail",$data->{listingId}), - category=>$category, - name=>$data->{productName}, - mean=>$data->{meanValue}, - median=>$data->{medianValue}, - count=>$data->{countValue} - }); - } - $var{'best_rating_loop'} = \@best; - $var{'worst_rating_loop'} = \@worst; - $var{'ratings.details.url'} = $self->getUrl("func=viewRatingDetails"); - $data = $self->session->db->quickHashRef("select lastUpdated, productName, listingId from Matrix_listing - where assetId=".$self->session->db->quote($self->getId)." and status='approved' order by lastUpdated desc limit 1"); - my @lastUpdated; - my $sth = $self->session->db->read("select listingId,lastUpdated,productName from Matrix_listing order by lastUpdated desc limit 20"); - while (my ($listingId, $lastUpdated, $productName) = $sth->array) { - push(@lastUpdated, { - url => $self->formatURL("viewDetail",$listingId), - name=>$productName, - lastUpdated=>$self->session->datetime->epochToHuman($lastUpdated,"%z") - }); - } - $var{'last_updated_loop'} = \@lastUpdated; - $var{'best.updated.url'} = $self->formatURL("viewDetail",$data->{listingId}); - $var{'best.updated.date'} = $self->session->datetime->epochToHuman($data->{lastUpdated},"%z");; - $var{'best.updated.name'} = $data->{productName}; - - # site stats - ($var{'user.count'}) = $self->session->db->quickArray("select count(*) from users"); - ($var{'current.user.count'}) = $self->session->db->quickArray("select count(*)+0 from userSession where lastPageView>".($self->session->datetime->time()-600)); - ($var{'listing.count'}) = $self->session->db->quickArray("select count(*) from Matrix_listing where status = 'approved' and assetId=".$self->session->db->quote($self->getId)); - $sth = $self->session->db->read("select listingId,productName from Matrix_listing where status='pending' and assetId=?",[$self->getId]); - while (my ($id,$name) = $sth->array) { - push(@{$var{pending_list}},{ - url=>$self->formatURL("viewDetail",$id), - productName=>$name - }); - } - $sth->finish; - my $out = $self->processTemplate(\%var,undef,$self->{_viewTemplate}); - if ($self->session->user->isVisitor) { - WebGUI::Cache->new($self->session,"view_".$self->getId)->set($out,$self->get("visitorCacheTimeout")); - } - return $out; + #This automatically creates template variables for all of your wobject's properties. + my $var = $self->get; + + #This is an example of debugging code to help you diagnose problems. + #WebGUI::ErrorHandler::warn($self->get("templateId")); + + return $self->processTemplate($var, undef, $self->{_viewTemplate}); } - + #------------------------------------------------------------------- -=head2 www_view ( ) +=head2 www_deleteAttribute ( ) -See WebGUI::Asset::Wobject::www_view() for details. +Deletes an Attribute, including listing data for this attribute. =cut -sub www_view { - my $self = shift; - $self->session->http->setCacheControl($self->get("visitorCacheTimeout")) if ($self->session->user->isVisitor); - $self->SUPER::www_view(@_); +sub www_deleteAttribute { + my $self = shift; + my $attributeId = $self->session->form->process("attributeId"); + return $self->session->privilege->insufficient() unless $self->canEdit; + + $self->deleteAttribute($attributeId); + + return $self->www_listAttributes; } #------------------------------------------------------------------- -sub www_viewDetail { - my $self = shift; - my $listingId = shift || $self->session->form->process("listingId"); - my $hasRated = shift || $self->hasRated($listingId); - my %var; - my $i18n = WebGUI::International->new($self->session,'Asset_Matrix'); - my $listing = $self->session->db->getRow("Matrix_listing","listingId",$listingId); - my $forum = WebGUI::Asset::Wobject::Collaboration->new($self->session, $listing->{forumId}); - if ($listing->{storageId} && $listing->{filename}) { - my $storage = WebGUI::Storage::Image->get($self->session, $listing->{storageId}); - $var{screenshot} = $storage->getUrl($listing->{filename}); - $var{thumbnail} = $storage->getThumbnailUrl($listing->{filename}); - } - $var{"discussion"} = $forum && $forum->view; - $var{'isLoggedIn'} = ($self->session->user->isRegistered); - if ($self->session->form->process("do") eq "sendEmail" && $self->session->form->process("verify","captcha")) { - if ($self->session->form->process("body") ne "") { - my $u = WebGUI::User->new($self->session, $listing->{maintainerId}); - my $mail = WebGUI::Mail::Send->create($self->session, {to=>$u->profileField("email"),subject=>$listing->{productName}." - ".$self->session->form->process("subject"),from=>$self->session->form->process("from")}); - $mail->addText($self->session->form->process("body")); - $mail->addFooter; - $mail->queue; - } - $var{'email.wasSent'} = 1; - } else { - $self->incrementCounter($listingId,"views"); - } - $var{'edit.url'} = $self->formatURL("editListing",$listingId); - $var{id} = $listingId; - $var{'user.canEdit'} = ($self->session->user->userId eq $listing->{maintainerId} || $self->canEdit); - $var{'user.canApprove'} = $self->canEdit; - $var{'approve.url'} = $self->getUrl("func=approveListing;listingId=".$listingId); - $var{'delete.url'} = $self->getUrl("func=deleteListing;listingId=".$listingId); - $var{'isPending'} = ($listing->{status} eq "pending"); - $var{'lastUpdated.epoch'} = $listing->{lastupdated}; - $var{'lastUpdated.date'} = $self->session->datetime->epochToHuman($listing->{lastUpdated},"%z"); - $var{description} = $listing->{description}; - $var{productName} = $listing->{productName}; - $var{productUrl} = $listing->{productUrl}; - $var{'productUrl.click'} = $self->formatURL("click",$listingId); - $var{manufacturerName} = $listing->{manufacturerName}; - $var{manufacturerUrl} = $listing->{manufacturerUrl}; - $var{'manufacturerUrl.click'} = $self->getUrl("m=1;func=click;listingId=".$listingId); - $var{versionNumber} = $listing->{versionNumber}; - my $f = WebGUI::HTMLForm->new($self->session, - -extras=>'class="content"', - -tableExtras=>'class="content"' - ); - $f->hidden( - -name=>"func", - -value=>"viewDetail" - ); - $f->hidden( - -name=>"do", - -value=>"sendEmail" - ); - $f->hidden( - -name=>"listingId", - -value=>$listingId - ); - $f->captcha( - -name=>"verify" - ); - $f->email( - -extras=>'class="content"', - -name=>"from", - -value=>$self->session->user->profileField("email"), - -label=>$i18n->get('your email'), - ); - $f->selectBox( - -name=>"subject", - -extras=>'class="content"', - -options=>{ - $i18n->get('report error')=>"Report an error.", - $i18n->get('general comment')=>"General comment.", - }, - -label=>$i18n->get('request type'), - ); - $f->textarea( - -rows=>4, - -extras=>'class="content"', - -columns=>35, - -name=>"body", - -label=>$i18n->get('comment'), - ); - $f->submit( - -extras=>'class="content"', - -value=>"Send..." - ); - $var{'email.form'} = $f->print; - $var{views} = $listing->{views}; - $var{compares} = $listing->{compares}; - $var{clicks} = $listing->{clicks}; - my $sth = $self->session->db->read("select a.value, b.name, b.label, b.description, category, fieldType from Matrix_listingData a left join - Matrix_field b on a.fieldId=b.fieldId and b.assetId=? where listingId=? order by b.label",[$self->getId, $listingId]); - my %goodBad = ( - "No" => $i18n->get("no"), - "Yes" => $i18n->get("yes"), - "Free Add On" => $i18n->get("free"), - "Costs Extra" => $i18n->get("extra"), - "Limited" => $i18n->get("limited"), - ); - while (my $data = $sth->hashRef) { - $data->{class} = lc($data->{value}); - $data->{class} =~ s/\s/_/g; - $data->{class} =~ s/\W//g; - if ($data->{fieldType} eq 'goodBad') { - $data->{value} = $goodBad{$data->{value}}; - } - my $cat = $self->session->url->urlize($data->{category})."_loop"; - push(@{$var{$cat}},$data); - } - $sth->finish; - my %rating; - tie %rating, 'Tie::IxHash'; - %rating = ( - 1=>"1 - Worst", - 2=>2, - 3=>3, - 4=>4, - 5=>"5 - Respectable", - 6=>6, - 7=>7, - 8=>8, - 9=>9, - 10=>"10 - Best" - ); - my $ratingsTable = ''; - $f = WebGUI::HTMLForm->new($self->session, - -extras=>'class="ratingForm"', - -tableExtras=>'class="ratingForm"' - ); - $f->hidden( - -name=>"listingId", - -value=>$listingId - ); - $f->hidden( - -name=>"func", - -value=>"rate" - ); - foreach my $category ($self->getCategories) { - my ($mean,$median,$count) = $self->session->db->quickArray("select meanValue, medianValue, countValue from Matrix_ratingSummary - where listingId=".$self->session->db->quote($listingId)." and category=".$self->session->db->quote($category)); - $ratingsTable .= ''; - $f->selectBox( - -name=>$category, - -label=>$category, - -value=>[5], - -extras=>'class="ratingForm"', - -options=>\%rating - ); - } - $ratingsTable .= '
MeanMedianCount
'.$category.''.$mean.''.$median.''.$count.'
'; - $f->submit( - -extras=>'class="ratingForm"', - -value=>"Rate", - -label=>''.$i18n->get('show ratings').'' - ); - if ($hasRated) { - $var{'ratings'} = $ratingsTable; - } else { - $var{'ratings'} = $f->print; - } - return $self->processStyle($self->processTemplate(\%var,$self->get("detailTemplateId"))); + +=head2 www_edit ( ) + +Web facing method which is the default edit page. This method is entirely +optional. Take it out unless you specifically want to set a submenu in your +adminConsole views. + +=cut + +#sub www_edit { +# my $self = shift; +# return $self->session->privilege->insufficient() unless $self->canEdit; +# return $self->session->privilege->locked() unless $self->canEditIfLocked; +# my $i18n = WebGUI::International->new($self->session, "Asset_Matrix"); +# return $self->getAdminConsole->render($self->getEditForm->print, $i18n->get("edit title")); +#} + +#------------------------------------------------------------------- + +=head2 www_editAttribute ( ) + +Shows a form to edit or add an attribute. + +=cut + +sub www_editAttribute { + my $self = shift; + my $session = $self->session; + my ($attributeId, $attribute); + + return $session->privilege->insufficient() unless $self->canEdit; + my $i18n = WebGUI::International->new($session, "Asset_Matrix"); + + $attributeId = $session->form->process("attributeId") || 'new'; + + unless($attributeId eq 'new'){ + $attribute = $self->getAttribute($attributeId); + } + + my $form = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); + $form->hidden( + -name =>"func", + -value =>"editAttributeSave" + ); + $form->hidden( + -name =>"attributeId", + -value =>$attributeId, + ); + $form->text( + -name =>"name", + -value =>$attribute->{name}, + -label =>$i18n->get('attribute name label'), + -hoverHelp =>$i18n->get('attribute name description'), + ); + $form->textarea( + -name =>"description", + -value =>$attribute->{description}, + -label =>$i18n->get('attribute description label'), + -hoverHelp =>$i18n->get('attribute description description'), + ); + $form->matrixFieldType( + -name =>"fieldType", + -value =>$attribute->{fieldType}, + -label =>$i18n->get('fieldType label'), + -hoverHelp =>$i18n->get('fieldType description'), + ); + my $defaultValueForm = WebGUI::Form::Text($self->session, { + name=>"defaultValue", + value=>$attribute->{defaultValue}, + #subtext=>'
'.$i18n->get('default value subtext'), + #width=>200, + #height=>60, + resizable=>0, + }); + my $optionsForm = WebGUI::Form::Textarea($self->session, { + name=>"options", + value=>$attribute->{options}, + }); + + my $html = "\n\n"; + $html .= "\t
\n"; + $html .= "\t
\n"; + $html .= "\t\n"; + + $html .= "\t" + ."" + ."\t\n\n"; + + $html .= "\t" + ."" + ."\t\n\n"; + + + $html .= "\t
" + .$i18n->get('attribute defaultValue label') + ."
".$i18n->get('attribute defaultValue description')."
" + .$defaultValueForm."
" + .$i18n->get('attribute options label') + ."
".$i18n->get('attribute options description')."
" + .$optionsForm."
"; + $html .= "\t\n
\t\n
\n"; + $html .= ""; + + $html .= "\n"; + + $form->raw($html); +=cut + $form->text( + -name =>"defaultValue", + -value =>$attribute->{defaultValue}, + -label =>$i18n->get('attribute defaultValue label'), + -hoverHelp =>$i18n->get('attribute defaultValue description'), + ); + $form->textarea( + -name =>"options", + -value =>$attribute->{options}, + -label =>$i18n->get('attribute options label'), + -hoverHelp =>$i18n->get('attribute options description'), + ); +=cut + $form->selectBox( + -name =>"category", + -value =>[$attribute->{category}], + -label =>$i18n->get('category label'), + -hoverHelp =>$i18n->get('category description'), + -options =>$self->getCategories, + ); + $form->submit; + return $self->getAdminConsole->render($form->print, $i18n->get('edit attribute title')); } +#------------------------------------------------------------------- -#----------------------------------------------- -sub www_viewRatingDetails { - my $self = shift; - my %var; - my @ratingloop; - foreach my $category ($self->getCategories) { - my @detailloop; - my $sql = " - select - Matrix_listing.productName, - Matrix_listing.listingId, - Matrix_ratingSummary.meanValue, - Matrix_ratingSummary.medianValue, - Matrix_ratingSummary.countValue - from - Matrix_listing - left join - Matrix_ratingSummary - on - Matrix_listing.listingId=Matrix_ratingSummary.listingId and - Matrix_ratingSummary.category=".$self->session->db->quote($category)." - where - Matrix_listing.assetId=".$self->session->db->quote($self->getId)." and - Matrix_listing.status='approved' and - Matrix_ratingSummary.countValue > 0 - order by - Matrix_ratingSummary.meanValue desc - "; - my $sth = $self->session->db->read($sql); - while (my $data = $sth->hashRef) { - push(@detailloop,{ - url=>$self->formatURL("viewDetail",$data->{listingId}), - mean=>$data->{meanValue}, - median=>$data->{medianValue}, - count=>$data->{countValue}, - name=>$data->{productName} - }); - } - $sth->finish; - push(@ratingloop,{ - category=>$category, - detail_loop=>\@detailloop - }); - } - $var{rating_loop} = \@ratingloop; - return $self->processStyle($self->processTemplate(\%var,$self->get("ratingDetailTemplateId"))); +=head2 www_editAttributeSave ( ) + +Processes and saves an attribute. + +=cut + +sub www_editAttributeSave { + my $self = shift; + my $session = $self->session; + my $form = $session->form; + + return $session->privilege->insufficient() unless $self->canEdit; + + my $attributeProperties = { + attributeId =>$form->process("attributeId") || 'new', + assetId =>$self->getId, + name =>$form->process('name'), + description =>$form->process('description'), + fieldType =>$form->process('fieldType'), + options =>$form->process('options'), + defaultValue =>$form->process('defaultValue'), + category =>$form->process('category'), + }; + + $self->editAttributeSave($attributeProperties); + + return $self->www_listAttributes; } +#------------------------------------------------------------------- - +=head2 www_listAttributes ( ) + +Lists all attributes of this Matrix. + +=cut + +sub www_listAttributes { + my $self = shift; + my $session = $self->session; + + return $session->privilege->insufficient() unless($self->canEdit); + + my $i18n = WebGUI::International->new($session,'Asset_Matrix'); + my $output = "
" + .$i18n->get('add attribute label')."

"; + + my $attributes = $session->db->read("select attributeId, name from Matrix_attribute where assetId=? order by name" + ,[$self->getId]); + while (my $attribute = $attributes->hashRef) { + $output .= $session->icon->delete("func=deleteAttribute;attributeId=".$attribute->{attributeId} + , $self->getUrl,$i18n->get("delete attribute confirm message")) + .$session->icon->edit("func=editAttribute;attributeId=".$attribute->{attributeId}) + .' '.$attribute->{name}."
\n"; + } + return $self->getAdminConsole->render($output, $i18n->get('list attributes title')); +} + +#------------------------------------------------------------------- +# Everything below here is to make it easier to install your custom +# wobject, but has nothing to do with wobjects in general +#------------------------------------------------------------------- +# cd /data/WebGUI/lib +# perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf [ /path/to/WebGUI ] +# - or - +# perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf [ /path/to/WebGUI ] +#------------------------------------------------------------------- + + +use base 'Exporter'; +our @EXPORT = qw(install uninstall); +use WebGUI::Session; + +#------------------------------------------------------------------- +sub install { + my $config = $ARGV[0]; + my $home = $ARGV[1] || "/data/WebGUI"; + die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e install www.example.com.conf\n" unless ($home && $config); + print "Installing asset.\n"; + my $session = WebGUI::Session->open($home, $config); + $session->config->addToArray("assets","WebGUI::Asset::Wobject::Matrix"); + $session->db->write("create table Matrix ( + assetId varchar(22) binary not null, + revisionDate bigint not null, + templateId varchar(22) not null, + searchTemplateId varchar(22) not null, + compareTemplateId varchar(22) not null, + detailTemplateId varchar(22) not null, + maxComparisons int(11) not null default 10, + maxComparisonsPrivileged int(11) not null default 25, + defaultSort varchar(22) not null default 'score', + categories text, + compareColorNo varchar(22) not null default '#ffaaaa', + compareColorLimited varchar(22) not null default '#ffffaa', + compareColorCostsExtra varchar(22) not null default '#ffffaa', + compareColorFreeAddOn varchar(22) not null default '#ffffaa', + compareColorYes varchar(22) not null default '#aaffaa', + submissionApprovalWorkflowId varchar(22) not null, + ratingsDuration int(11) not null default 7776000, + primary key (assetId, revisionDate) + )"); + $session->db->write("create table Matrix_attribute ( + assetId varchar(22) binary not null, + attributeId varchar(22) binary not null, + name varchar(255) not null, + description text, + fieldType varchar(255) not null default 'MatrixField', + category varchar(22) not null, + options text, + defaultValue varchar(255), + primary key (attributeId) + )"); + $session->var->end; + $session->close; + print "Done. Please restart Apache.\n"; +} + +#------------------------------------------------------------------- +sub uninstall { + my $config = $ARGV[0]; + my $home = $ARGV[1] || "/data/WebGUI"; + die "usage: perl -MWebGUI::Asset::Wobject::Matrix -e uninstall www.example.com.conf\n" unless ($home && $config); + print "Uninstalling asset.\n"; + my $session = WebGUI::Session->open($home, $config); + $session->config->deleteFromArray("assets","WebGUI::Asset::Wobject::Matrix"); + my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Matrix'"); + while (my ($id) = $rs->array) { + my $asset = WebGUI::Asset->new($session, $id, "WebGUI::Asset::Wobject::Matrix"); + $asset->purge if defined $asset; + } + $session->db->write("drop table Matrix"); + $session->var->end; + $session->close; + print "Done. Please restart Apache.\n"; +} 1; - diff --git a/lib/WebGUI/Form/MatrixCompare.pm b/lib/WebGUI/Form/MatrixCompare.pm new file mode 100644 index 000000000..476925235 --- /dev/null +++ b/lib/WebGUI/Form/MatrixCompare.pm @@ -0,0 +1,156 @@ +package WebGUI::Form::MatrixCompare; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::SelectBox'; +use Tie::IxHash; +use WebGUI::International; +use WebGUI::Pluggable; +use WebGUI::Utility; + +=head1 NAME + +Package WebGUI::Form::MatrixCompare + +=head1 DESCRIPTION + +Creates a form control that will allow you to select a field type that can be used by the Matrix wobject. +It's meant to be used in conjunction with the DynamicField form control. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::SelectBox. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 types + +An array reference containing the form control types to be selectable. Defaults to all available dynamic types. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + my $i18n = WebGUI::International->new($session); + push(@{$definition}, { + label=>{ + defaultValue=>$i18n->get("matrix compare","WebGUI") + }, + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('matrix compare'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) + +Returns either what's posted or if nothing comes back it returns "text". + +=cut + +sub getValue { + my $self = shift; + my $compareValue = $self->SUPER::getValue(@_); + $compareValue =~ s/[^\w]//g; + return $compareValue || 0; +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a fieldType selector. + +=cut + +sub toHtml { + my $self = shift; + my $i18n = WebGUI::International->new($session,'Form_MatrixCompare'); + my %options; + tie %options, "Tie::IxHash"; + %options = ( + 0 => $i18n->get('no'), + 1 => $i18n->get('limited'), + 2 => $i18n->get('costs extra'), + 3 => $i18n->get('free add on'), + 4 => $i18n->get('yes'), + ); + $self->set('options', \%options); + $self->set('defaultValue',0); + return $self->SUPER::toHtml(); +} + + + +1; + diff --git a/lib/WebGUI/Form/MatrixFieldType.pm b/lib/WebGUI/Form/MatrixFieldType.pm new file mode 100644 index 000000000..0485d033f --- /dev/null +++ b/lib/WebGUI/Form/MatrixFieldType.pm @@ -0,0 +1,153 @@ +package WebGUI::Form::MatrixFieldType; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use base 'WebGUI::Form::SelectBox'; +use Tie::IxHash; +use WebGUI::International; +use WebGUI::Pluggable; +use WebGUI::Utility; + +=head1 NAME + +Package WebGUI::Form::MatrixFieldType + +=head1 DESCRIPTION + +Creates a form control that will allow you to select a field type that can be used by the Matrix wobject. +It's meant to be used in conjunction with the DynamicField form control. + +=head1 SEE ALSO + +This is a subclass of WebGUI::Form::SelectBox. + +=head1 METHODS + +The following methods are specifically available from this class. Check the superclass for additional methods. + +=cut + +#------------------------------------------------------------------- + +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + +=head2 definition ( [ additionalTerms ] ) + +See the super class for additional details. + +=head3 additionalTerms + +The following additional parameters have been added via this sub class. + +=head4 types + +An array reference containing the form control types to be selectable. Defaults to all available dynamic types. + +=head4 label + +A text label that will be displayed if toHtmlWithWrapper() is called. Defaults to getName(). + +=cut + +sub definition { + my $class = shift; + my $session = shift; + my $definition = shift || []; + my $i18n = WebGUI::International->new($session); + push(@{$definition}, { + label=>{ + defaultValue=>$i18n->get("matrix fieldtype","WebGUI") + }, + }); + return $class->SUPER::definition($session, $definition); +} + +#------------------------------------------------------------------- + +=head2 getName ( session ) + +Returns the human readable name of this control. + +=cut + +sub getName { + my ($self, $session) = @_; + return WebGUI::International->new($session, 'WebGUI')->get('matrix fieldtype'); +} + +#------------------------------------------------------------------- + +=head2 getValue ( ) + +Returns either what's posted or if nothing comes back it returns "text". + +=cut + +sub getValue { + my $self = shift; + my $fieldType = $self->SUPER::getValue(@_); + $fieldType =~ s/[^\w]//g; + return $fieldType || "MatrixCompare"; +} + +#------------------------------------------------------------------- + +=head2 isDynamicCompatible ( ) + +Returns 0. + +=cut + +sub isDynamicCompatible { + return 0; +} + +#------------------------------------------------------------------- + +=head2 toHtml ( ) + +Renders a fieldType selector. + +=cut + +sub toHtml { + my $self = shift; + my %options; + tie %options, "Tie::IxHash"; + %options = ( + MatrixCompare => WebGUI::Pluggable::instanciate('WebGUI::Form::MatrixCompare', 'getName',[$self->session]), + SelectBox => WebGUI::Pluggable::instanciate('WebGUI::Form::SelectBox', 'getName',[$self->session]), + Combo => WebGUI::Pluggable::instanciate('WebGUI::Form::Combo', 'getName',[$self->session]), + ); + $self->set('options', \%options); + $self->set('defaultValue','MatrixCompare'); + return $self->SUPER::toHtml(); +} + + + +1; + diff --git a/lib/WebGUI/i18n/English/Asset_Matrix.pm b/lib/WebGUI/i18n/English/Asset_Matrix.pm index a120a9156..32a8c9d0a 100644 --- a/lib/WebGUI/i18n/English/Asset_Matrix.pm +++ b/lib/WebGUI/i18n/English/Asset_Matrix.pm @@ -4,30 +4,18 @@ use strict; our $I18N = { 'delete field confirm' => { message => q|Are you certain you wish to delete this field and all the data linked to it?|, - lastUpdated => 0, + lastUpdated => 1230, context => q|displayed in field manager before delete| }, - 'screenshot' => { - message => q|Screenshot/Photo|, - lastUpdated => 0, - context => q|edit listing property| - }, - - 'screenshot help' => { - message => q|Upload a picture of the product, or a screen shot if it's a software package.|, - lastUpdated => 0, - context => q|edit listing property help| - }, - 'visitor cache timeout' => { message => q|Visitor Cache Timeout|, - lastUpdated => 0 + lastUpdated => 1230 }, 'visitor cache timeout help' => { message => q|Since all visitors will see this asset the same way, we can cache it to increase performance. How long should we cache it?|, - lastUpdated => 0 + lastUpdated => 1230 }, 'isTooMany' => { @@ -55,11 +43,6 @@ our $I18N = { lastUpdated => 1149783768, }, - 'version' => { - message => q|The version number or model number of the product.|, - lastUpdated => 1149783768, - }, - 'details url' => { message => q|The URL to the details page for this listing.|, lastUpdated => 1149783768, @@ -210,11 +193,6 @@ our $I18N = { lastUpdated => 1149784175, }, - 'manufacturerName' => { - message => q|The name of the company that manufactures the product or provides the service represented in this listing.|, - lastUpdated => 1167186054, - }, - 'manufacturerUrl' => { message => q|The manufacturer's URL.|, lastUpdated => 1149784175, @@ -225,11 +203,6 @@ our $I18N = { lastUpdated => 1149784175, }, - 'versionNumber' => { - message => q|The version number or model number of this product.|, - lastUpdated => 1149784175, - }, - 'views' => { message => q|The total number of views this listing has received.|, lastUpdated => 1149784175, @@ -281,7 +254,7 @@ our $I18N = { }, 'detail template help title' => { - lastUpdated => 0, + lastUpdated => message => q|Matrix Listing Detail Template Variables| }, @@ -501,7 +474,7 @@ our $I18N = { }, 'ratings detail template help title' => { - lastUpdated => 0, + lastUpdated => 1230, message => q|Matrix Ratings Detail Template Variables| }, @@ -582,23 +555,68 @@ our $I18N = { 'categories description' => { message => q|Specify one category per line here to define the categories for this matrix. Categories are used to subdivide fields and also represent the things users can rate each listing on.|, - lastUpdated => 1136503559, - }, + lastUpdated => 0, + }, + + 'categories default value' => { + message => q|Features\nBenefits|, + lastUpdated => 0, + }, + + 'submission approval workflow description' => { + message => q|Select the workflow that is used to approve submissions.|, + lastUpdated => 0, + }, + + 'ratings duration description' => { + message => q|Select the interval after which old ratings are cleaned out.|, + lastUpdated => 0, + }, + + 'default sort description' => { + message => q|Select the default sort order for the listings in the compare box.|, + lastUpdated => 0, + }, + + 'compare color no description' => { + message => q|Select the color for compare result 'No' in the compare display.|, + lastUpdated => 0, + }, + + 'compare color limited description' => { + message => q|Select the color for compare result 'Limited' in the compare display.|, + lastUpdated => 0, + }, + + 'compare color costs extra description' => { + message => q|Select the color for compare result 'Costs Extra' in the compare display.|, + lastUpdated => 0, + }, + + 'compare color free add on description' => { + message => q|Select the color for compare result 'Free Add On' in the compare display.|, + lastUpdated => 0, + }, + + 'compare color yes description' => { + message => q|Select the color for compare result 'Yes' in the compare display.|, + lastUpdated => 0, + }, 'categories subtext' => { message => q|
Enter one per line in the order you want them to appear. Be sure to watch leading and trailing whitespace.|, lastUpdated => 1135271460, }, - 'max comparisons description' => { - message => q|Specifies how many comparisons are allowed in searches and comparisons.|, - lastUpdated => 1135271460, - }, + 'max comparisons description' => { + message => q|Specifies how many comparisons are allowed in searches and comparisons.|, + lastUpdated => 0, + }, - 'max comparisons privileged description' => { - message => q|Specifies how many comparisons are allowed in searches and comparisons for users in the privileged group.|, - lastUpdated => 1135271460, - }, + 'max comparisons privileged description' => { + message => q|Specifies how many comparisons are allowed in searches and comparisons for users in the privileged group.|, + lastUpdated => 0, + }, 'rating timeout description' => { message => q|Set a timeout so that users are prevented from rating a given listing too often.|, @@ -625,43 +643,103 @@ our $I18N = { lastUpdated => 1135271460, }, - 'main template description' => { + 'template description' => { message => q|Select a template to be used to display the default view of the Matrix.|, - lastUpdated => 1135271460, + lastUpdated => 0, }, 'detail template description' => { message => q|Select a template to be used to display the detailed information about a listing.|, - lastUpdated => 1135271460, + lastUpdated => 0, }, 'rating detail template description' => { message => q|Select a template to be used to display the detailed ratings information.|, - lastUpdated => 1135271460, + lastUpdated => 0, }, 'search template description' => { message => q|Select a template to be used to display the search engine interface.|, - lastUpdated => 1135271460, + lastUpdated => 0, }, 'compare template description' => { message => q|Select a template to be used to show the listing comparison data.|, - lastUpdated => 1135271460, + lastUpdated => 0, }, - 'categories' => { + 'categories label' => { message => q|Categories|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'max comparisons' => { + 'submission approval workflow label' => { + message => q|Submission Approval Workflow|, + lastUpdated => 0, + }, + + 'ratings duration label' => { + message => q|Ratings Duration|, + lastUpdated => 0, + }, + + 'default sort label' => { + message => q|Default Sort|, + lastUpdated => 0, + }, + + 'sort by score label' => { + message => q|Score|, + lastUpdated => 0, + }, + + 'sort alpha numeric label' => { + message => q|Alpha Numeric|, + lastUpdated => 0, + }, + + 'sort by asset rank label' => { + message => q|Asset Rank|, + lastUpdated => 0, + }, + + 'sort by last updated label' => { + message => q|Most Recent Update|, + lastUpdated => 0, + }, + + 'compare color no label' => { + message => q|Compare Color: No|, + lastUpdated => 0, + }, + + 'compare color limited label' => { + message => q|Compare Color: Limited|, + lastUpdated => 0, + }, + + 'compare color costs extra label' => { + message => q|Compare Color: Costs Extra|, + lastUpdated => 0, + }, + + 'compare color free add on label' => { + message => q|Compare Color: Free Add On|, + lastUpdated => 0, + }, + + 'compare color yes label' => { + message => q|Compare Color: Yes|, + lastUpdated => 0, + }, + + 'max comparisons label' => { message => q|Maximum Comparisons|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'max comparisons privileged' => { + 'max comparisons privileged label' => { message => q|Maximum Comparisons (For Privileged Users)|, - lastUpdated => 1133758944, + lastUpdated => 0, }, 'rating timeout' => { @@ -689,29 +767,29 @@ our $I18N = { lastUpdated => 1133758944, }, - 'main template' => { - message => q|Main Template|, - lastUpdated => 1133758944, + 'template label' => { + message => q|Matrix Template|, + lastUpdated => 0, }, - 'detail template' => { + 'detail template label' => { message => q|Detail Template|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'rating detail template' => { + 'rating detail template label' => { message => q|Rating Detail Template|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'search template' => { + 'search template label' => { message => q|Search Template|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'compare template' => { + 'compare template label' => { message => q|Compare Template|, - lastUpdated => 1133758944, + lastUpdated => 0, }, 'product name' => { @@ -719,59 +797,34 @@ our $I18N = { lastUpdated => 1133758944, }, - 'version number' => { - message => q|Version/Model Number|, - lastUpdated => 1133758944, + 'attribute name label' => { + message => q|Name|, + lastUpdated => 0, }, - 'product url' => { - message => q|Product URL|, - lastUpdated => 1135279964, - }, - - 'manufacturer name' => { - message => q|Manufacturer Name|, - lastUpdated => 1133758944, - }, - - 'manufacturer url' => { - message => q|Manufacturer URL|, - lastUpdated => 1133758944, - }, - - 'description' => { - message => q|Description|, - lastUpdated => 1133758944, - }, - - 'listing maintainer' => { - message => q|Listing Maintainer|, - lastUpdated => 1133758944, - }, - - 'field name' => { - message => q|Field Name|, - lastUpdated => 1136499280, - }, - - 'field label' => { - message => q|Field Label|, - lastUpdated => 1136499282, - }, - - 'field type' => { +# 'field label' => { +# message => q|Field Label|, +# lastUpdated => 1136499282, +# }, + + 'fieldType label' => { message => q|Field Type|, - lastUpdated => 1136499283, + lastUpdated => 0, }, - 'default value' => { + 'attribute defaultValue label' => { message => q|Default Value|, - lastUpdated => 1133758944, + lastUpdated => 0, }, - 'category' => { + 'attribute options label' => { + message => q|Options|, + lastUpdated => 0, + }, + + 'category label' => { message => q|Category|, - lastUpdated => 1133758944, + lastUpdated => 0, }, 'your email' => { @@ -829,9 +882,9 @@ our $I18N = { message => q|

Edit Listing

| }, - 'edit field' => { - lastUpdated => 1135279558, - message => q|

Edit Field

| + 'edit attribute title' => { + lastUpdated => 0, + message => q|Edit/Add Attribute| }, 'good bad' => { @@ -869,12 +922,20 @@ our $I18N = {

No, I made a mistake.

|, }, - 'list fields' => { - lastUpdated => 1135289632, - message => q|

Field List

- Add new field. -

|, - }, + 'list attributes title' => { + lastUpdated => 0, + message => q|Attribute List|, + }, + + 'delete attribute confirm message' => { + message => q|Are you certain you wish to delete this attribute and all the data linked to it?|, + lastUpdated => 0, + }, + + 'add attribute label' => { + lastUpdated => 0, + message => q|Add Attribute|, + }, 'yes' => { lastUpdated => 1135279558, @@ -906,38 +967,6 @@ our $I18N = { message => q|Enter the name of the product. If there are entries for the product with different revisions, it would be best to make sure the names are the same.| }, - 'version number description' => { - lastUpdated => 1135279558, - message => q|Enter the release or version number for the product.| - }, - - 'product url description' => { - lastUpdated => 1135279558, - message => q|If the product has its own website, enter the complete URL for it here.| - }, - - 'manufacturer name description' => { - lastUpdated => 1135279558, - message => q|Enter the manufacturer of the product.| - }, - - 'manufacturer url description' => { - lastUpdated => 1135279558, - message => q|If the manufacturer has a website, enter the complete URL for it here.| - }, - - 'description description' => { - lastUpdated => 1135279558, - message => q|Please give a general description of the product. Specific details can be rated in the form fields below.| - }, - - 'listing maintainer description' => { - lastUpdated => 1136488950, - message => q|If left blank, this will be the name of the user who created this product listing. The - listing maintainer is allowed to edit this listing, even if they are not members of the group - to add or edit listings.| - }, - 'matrix specific fields description' => { lastUpdated => 1135279558, message => q|Each matrix is configured to compare the features and performance of various products. These features and performance criteria are displayed for you to rate on an item by item basis.| @@ -948,55 +977,46 @@ our $I18N = { message => q|Matrix Specific Fields| }, - 'field name description' => { - lastUpdated => 1135279558, - message => q|The name of the field that you are creating. It is case sensitive and must be unique.| + 'attribute name description' => { + lastUpdated => 0, + message => q|The name of the attribute that you are creating. It is case sensitive and must be unique.| }, - 'field label description' => { - lastUpdated => 1135279558, - message => q|The name of the field that you are creating. It is case sensitive and must be unique.| +# 'field label description' => { +# lastUpdated => 1135279558, +# message => q|The name of the field that you are creating. It is case sensitive and must be unique.| +# }, + + 'fieldType description' => { + lastUpdated => 0, + message => q|

The field type of attribute you are creating. Please select the field type from the options in the drop-down list.

| }, - 'field type description' => { - lastUpdated => 1167185918, - message => q|

The type of field you are creating. Please select the type from the following options in the drop-down list.

-
-
-
Good Bad
-
Defines availability of a feature, has it, doesn't have it, limited functionality, free add on, etc.
-
Text
-
A single line of text, like a short description or title.
-
TextArea
-
Multiple lines of text.
-
URL
-
A URL.
-
Combo
-
A combination Text box and drop down list.
-
| + 'attribute description label' => { + lastUpdated => 0, + message => q|Description| }, - 'field description' => { - lastUpdated => 1135279558, - message => q|Field Description| + 'attribute description description' => { + lastUpdated => 0, + message => q|Please give a general description of the attribute.| }, - 'field description description' => { - lastUpdated => 1135279558, - message => q|Please give a general description of the field.| + 'attribute defaultValue description' => { + lastUpdated => 0, + message => q|

Enter in a default value for the attribute that will be used if the fieldType is +selectBox.

| }, - 'default value description' => { - translatorsNote => q|Please do not translate the GoodBad field values, as described below|, - lastUpdated => 1135279558, - message => q|

Enter in a default value for the field that will be used if the user leaves the field blank.

-

For the GoodBad field, the possible values are "No", "Yes", "Free Add On", "Costs Extra", "Limited". While the displayed labels are internationalized, these values are not.

-

For the Combo field, you may only enter in 1 value, but the user will be allowed to select any value entered in by other users. In other words, the drop-down list will contain all values entered in by users who enter unique data into this field.

| + 'attribute options description' => { + lastUpdated => 0, + message => q|

Enter in options (one per line) for the attribute that will be used if the fieldType is +selectBox.

| }, 'category description' => { - lastUpdated => 1136503500, - message => q|Select the category which this field falls into.| + lastUpdated => 0, + message => q|Select the category which this attribute falls into.| }, }; diff --git a/lib/WebGUI/i18n/English/Asset_MatrixListing.pm b/lib/WebGUI/i18n/English/Asset_MatrixListing.pm new file mode 100644 index 000000000..100a6393f --- /dev/null +++ b/lib/WebGUI/i18n/English/Asset_MatrixListing.pm @@ -0,0 +1,103 @@ +package WebGUI::i18n::English::Asset_MatrixListing; + +use strict; + +our $I18N = { + 'assetName' => { + message => q|Matrix Listing|, + lastUpdated => 0, + }, + + 'edit matrix listing title' => { + message => q|Edit/Add Listing|, + lastUpdated => 0, + }, + + + 'template description' => { + message => q|Select a template to be used to display the default view of the Matrix.|, + lastUpdated => 0, + }, + + 'template label' => { + message => q|Matrix Listing Template|, + lastUpdated => 0, + }, + + 'screenshots description' => { + message => q|Upload a picture of the product, or a screen shot if it's a software package.|, + lastUpdated => 0, + }, + + 'screenshots label' => { + message => q|Screenshots/Photos|, + lastUpdated => 0, + }, + + 'description description' => { + message => q|Please give a general description of the product. Specific details can be rated in the form +fields below.|, + lastUpdated => 0, + }, + + 'description label' => { + message => q|Description|, + lastUpdated => 0, + }, + + 'version description' => { + message => q|Enter the version/edition/model number for the product.|, + lastUpdated => 0, + }, + + 'version label' => { + message => q|Version/Model|, + lastUpdated => 0, + }, + + 'maintainer description' => { + message => q|If left blank, this will be the name of the user who created this product listing. The + listing maintainer is allowed to edit this listing, even if they are not members of the group + to add or edit listings.|, + lastUpdated => 0, + }, + + 'maintainer label' => { + message => q|Maintainer|, + lastUpdated => 0, + }, + + 'manufacturerName description' => { + message => q|The name of the company that manufactures the product or provides the service represented in +this listing.|, + lastUpdated => 0, + }, + + 'manufacturerName label' => { + message => q|Manufacturer Name|, + lastUpdated => 0, + }, + + 'manufacturerURL description' => { + message => q|If the manufacturer has a website, enter the complete URL for it here.|, + lastUpdated => 0, + }, + + 'manufacturerURL label' => { + message => q|Manufacturer URL|, + lastUpdated => 0, + }, + + 'productURL description' => { + message => q|If the product has its own website, enter the complete URL for it here.|, + lastUpdated => 0, + }, + + 'productURL label' => { + message => q|Product URL|, + lastUpdated => 0, + }, + +}; + +1; diff --git a/lib/WebGUI/i18n/English/Form_MatrixCompare.pm b/lib/WebGUI/i18n/English/Form_MatrixCompare.pm new file mode 100644 index 000000000..2c3dff83f --- /dev/null +++ b/lib/WebGUI/i18n/English/Form_MatrixCompare.pm @@ -0,0 +1,32 @@ +package WebGUI::i18n::English::Form_MatrixCompare; +use strict; + +our $I18N = { + 'no' => { + message => q|No|, + lastUpdated => 0, + }, + + 'limited' => { + message => q|Limited|, + lastUpdated => 0, + }, + + 'costs extra' => { + message => q|Costs Extra|, + lastUpdated => 0, + }, + + 'free add on' => { + message => q|Free Add On|, + lastUpdated => 0, + }, + + 'yes' => { + message => q|Yes|, + lastUpdated => 0, + }, + +}; + +1; diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 080cbfcdf..ea63f9f0a 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -2880,6 +2880,18 @@ or are under your current version tag.

context => q|Field type name| }, + 'matrix fieldtype' => { + message => q|Matrix Field Type|, + lastUpdated =>0, + context => q|Field type name| + }, + + 'matrix compare' => { + message => q|Matrix Compare|, + lastUpdated =>0, + context => q|Field type name| + }, + 'hidden list' => { message => q|Hidden List|, lastUpdated =>0, diff --git a/t/Asset/MatrixListing.t b/t/Asset/MatrixListing.t new file mode 100644 index 000000000..3ff5fd1a0 --- /dev/null +++ b/t/Asset/MatrixListing.t @@ -0,0 +1,63 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2008 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +##The goal of this test is to test the creation of a MatrixListing Asset. + +use WebGUI::Test; +use WebGUI::Session; +use Test::More tests => 2; # increment this value for each test you create +use WebGUI::Asset::Wobject::Matrix; +use WebGUI::Asset::MatrixListing; + + +my $session = WebGUI::Test->session; +my $node = WebGUI::Asset->getImportNode($session); +my ($matrix, $matrixListing); + +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Matrix Listing Test"}); + +$matrix = $node->addChild({className=>'WebGUI::Asset::Wobject::Matrix'}); +$versionTag->commit; +$matrixListing = $matrix->addChild({className=>'WebGUI::Asset::MatrixListing'}); + +# Wikis create and autocommit a version tag when a child is added. Lets get the name so we can roll it back. +my $secondVersionTag = WebGUI::VersionTag->new($session,$matrixListing->get("tagId")); + +# Test for sane object types +isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix'); +isa_ok($matrixListing, 'WebGUI::Asset::MatrixListing'); + +# Try to add content under a MatrixListing asset +#my $article = $matrixListing->addChild({className=>'WebGUI::Asset::Wobject::Article'}); +#is($article, undef, "Can't add an Article wobject as a child to a Matrix Listing."); + +# See if the duplicate method works +#my $wikiPageCopy = $wikipage->duplicate(); +#isa_ok($wikiPageCopy, 'WebGUI::Asset::WikiPage'); +#my $thirdVersionTag = WebGUI::VersionTag->new($session,$wikiPageCopy->get("tagId")); + + +#TODO: { +# local $TODO = "Tests to make later"; +# ok(0, 'Lots and lots to do'); +#} + +END { + # Clean up after thy self + $versionTag->rollback(); + $secondVersionTag->rollback(); + #$thirdVersionTag->rollback(); +} + diff --git a/t/Asset/Wobject/Matrix.t b/t/Asset/Wobject/Matrix.t new file mode 100644 index 000000000..4fc36012b --- /dev/null +++ b/t/Asset/Wobject/Matrix.t @@ -0,0 +1,98 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2008 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use File::Spec; +use lib "$FindBin::Bin/../../lib"; + +##The goal of this test is to test the creation of UserList Wobjects. + +use WebGUI::Test; +use WebGUI::Session; +use Test::More tests => 10; # increment this value for each test you create +use Test::Deep; +use WebGUI::Asset::Wobject::Matrix; + +my $session = WebGUI::Test->session; + +# Do our work in the import node +my $node = WebGUI::Asset->getImportNode($session); + +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Matrix Test"}); +my $matrix = $node->addChild({className=>'WebGUI::Asset::Wobject::Matrix'}); + +# Test for a sane object type +isa_ok($matrix, 'WebGUI::Asset::Wobject::Matrix'); + +# Test to see if we can set new values +my $newMatrixSettings = { + maxComparisons => 20, + defaultSort => 'assetRank', + compareColorNo => '#aaffaa', + submissionApprovalWorkflowId => 'pbworkflow000000000005', + categories => "category1\ncategory2", +}; +$matrix->update($newMatrixSettings); + +foreach my $newSetting (keys %{$newMatrixSettings}) { + unless ($newSetting eq 'categories'){ + is ($matrix->get($newSetting), $newMatrixSettings->{$newSetting}, "updated $newSetting is ".$newMatrixSettings->{$newSetting}); + } +} + +cmp_deeply ( + $matrix->getCategories, + { + category1=>'category1', + category2=>'category2' + }, + 'getCategories method returned correct hashref' + ); + + +# add a new attribute + +$session->user({userId => 3}); + +my $attributeProperties = { + name =>'test attribute', + description =>'description of the test attribute', + category =>'category1', + }; + +my $newAttributeId = $matrix->editAttributeSave($attributeProperties); + +my $newAttribute = $matrix->getAttribute($newAttributeId); + +my $isValidId = $session->id->valid($newAttributeId); + +is($isValidId,1,"editAttributeSave returnes a valid guid"); + +is($newAttribute->{name},'test attribute',"Adding a new attribute, attribute name was set correctly"); +is($newAttribute->{fieldType},'MatrixCompare',"Adding a new attribute, undefined fieldType was set correctly to +default value"); + +# delete new attribute + +$matrix->deleteAttribute($newAttributeId); + +my $newAttribute = $matrix->getAttribute($newAttributeId); + +is($newAttribute->{attributeId},undef,"The new attribute was successfully deleted."); + +# TODO: test deleting of listing data for attribute + +END { + # Clean up after thy self + $versionTag->rollback(); +} +