Merge commit '63865eb39f' into WebGUI8. up to 7.9.11

This commit is contained in:
Colin Kuskie 2010-08-13 11:52:08 -07:00
commit 7b218942b3
72 changed files with 3085 additions and 407 deletions

View file

@ -0,0 +1,245 @@
package WebGUI::Asset::Wobject::AssetReport;
$VERSION = "1.0.0";
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 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 Tie::IxHash;
use WebGUI::International;
use WebGUI::Paginator;
use WebGUI::Utility;
use WebGUI::Form::AssetReportQuery;
use Moose;
use WebGUI::Definition::Asset;
extends 'WebGUI::Asset::Wobject';
define assetName => ['assetName', 'Asset_AssetReport.pm'];
define tableName => 'AssetReport';
property settings => (
tab => 'properties',
fieldType => 'AssetReportQuery',
default => undef,
label => '',
);
property templateId => (
tab => "display",
fieldType => "template",
namespace => "AssetReport",
default => "sJtcUCfn0CVbKdb4QM61Yw",
label => ["templateId label", 'Asset_AssetReport.pm'],
hoverHelp => ["templateId description", 'Asset_AssetReport.pm'],
);
property paginateAfter => (
tab => 'display',
fieldType => 'integer',
default => 25,
label => [ 'paginateAfter label' , 'Asset_AssetReport.pm'],
hoverHelp => [ 'paginateAfter description' , 'Asset_AssetReport.pm'],
);
#-------------------------------------------------------------------
=head2 canAdd ( session )
Class method to verify that the user has the privileges necessary to add this type of asset. Return a boolean.
Override this method to ensure that admin is the default group.
Only allow admins to add AssetReport as AssetReport currently bypasses normal
asset security measures.
=head3 session
The session variable.
=cut
sub canAdd {
my $class = shift;
my $session = shift;
$class->SUPER::canAdd($session, undef, '3');
}
#----------------------------------------------------------------------------
=head2 prepareView ( )
Prepare the view. Add stuff to HEAD.
=cut
around prepareView => sub {
my $orig = shift;
my $self = shift;
$self->$orig(@_);
my $session = $self->session;
# Prepare the template
my $template = WebGUI::Asset::Template->new( $session, $self->templateId );
if (!$template) {
WebGUI::Error::ObjectNotFound::Template->throw(
error => qq{Template not found},
templateId => $self->get("templateId"),
assetId => $self->getId,
);
}
$template->prepare;
$self->{_template} = $template;
return;
};
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Get template variables common to all views of the Asset Report.
=cut
sub getTemplateVars {
my $self = shift;
my $session = $self->session;
my $db = $session->db;
my $var = $self->get;
#Build the lineage query
my $settings = JSON->new->decode($self->settings);
#TO DO - ADD CACHE CONTROL
my $assetId = $settings->{startNode};
my $asset = WebGUI::Asset->newById($session,$assetId);
my $rules = {};
$rules->{'isa'} = $settings->{className};
#Build where condition
my $condition = $settings->{anySelect};
$rules->{'whereClause'} = undef;
my $where = $settings->{where};
foreach my $key (sort(keys %{$where})) {
my $clause = $where->{$key};
my $prop = $self->secure_identifier($clause->{propSelect});
my $op = $self->validate_clause($clause->{opSelect});
my $value = $db->quote($clause->{valText});
$rules->{'whereClause'} .= qq{ $condition } if ($key > 1);
$rules->{'whereClause'} .= qq{$prop $op $value};
}
if($rules->{'whereClause'}) {
$rules->{'joinClass'} = $settings->{className};
}
#Build the order by condition
my $order = $settings->{order};
my @order = sort(keys %{$order});
if(scalar(@order)) {
$rules->{'orderByClause'} = undef;
foreach my $key (@order) {
my $orderBy = $order->{$key};
my $orderSelect = $self->secure_identifier($orderBy->{orderSelect});
my $dirSelect = (lc($orderBy->{dirSelect}) eq "desc") ? "DESC" : "ASC";
$rules->{'orderByClause'} .= q{, } if($key > 1);
$rules->{'orderByClause'} .= qq{$orderSelect $dirSelect};
}
}
if($settings->{'limit'}) {
$rules->{'limit'} = $settings->{'limit'};
}
my $sql = $asset->getLineageSql(["descendants"],$rules);
my $p = WebGUI::Paginator->new($session,$self->getUrl,$self->paginateAfter);
$p->setDataByQuery($sql);
#Build the data for all the assets on the page
$var->{'asset_loop'} = [];
my $data = $p->getPageData;
ROW: foreach my $row (@{$data}) {
my $returnAsset = eval { WebGUI::Asset->newById($session, $row->{assetId}); };
next ROW if Exception::Class->caught();
push(@{$var->{'asset_loop'}}, $returnAsset->get);
}
#Append template variables
$p->appendTemplateVars($var);
return $var;
}
#----------------------------------------------------------------------------
=head2 secure_identifier ( identifier )
Checks the identifier and passes back a secure string.
=cut
sub secure_identifier {
my $self = shift;
my $db = $self->session->db;
my $identifier = shift;
my @parts = split(/\./,$identifier);
if(scalar(@parts) > 1) {
my $table = $parts[0];
my $column = $parts[1];
$identifier = $db->dbh->quote_identifier($table).".".$db->dbh->quote_identifier($column);
}
else {
$identifier = $db->dbh->quote_identifier($identifier);
}
return $identifier;
}
#----------------------------------------------------------------------------
=head2 validate_clause ( clause )
validates a clause against valid types. Returns "=" if no match is found.
=cut
sub validate_clause {
my $self = shift;
my $clause = shift;
my $ops = WebGUI::Form::AssetReportQuery->getOps();
unless ($ops->{$clause}) {
$clause = "=";
}
return $clause;
}
#----------------------------------------------------------------------------
=head2 view ( )
method called by the www_view method. Returns a processed template
to be displayed within the page style.
=cut
sub view {
my $self = shift;
my $var = $self->getTemplateVars;
return $self->processTemplate( $var, undef, $self->{_template} );
}
1;

View file

@ -61,6 +61,14 @@ sub _newsletterCategories_options {
return $session->db->buildHashRef("select fieldId, fieldName from metaData_properties where fieldType in ('selectBox', 'checkList', 'radioList') order by fieldName");
}
# XXX TODO: Do this in Moose instead, if we can.
# # Change the default Collaboration template
# for my $def ( @$definition ) {
# if ( exists $def->{properties}->{collaborationTemplateId} ) {
# $def->{properties}->{collaborationTemplateId}->{defaultValue} = 'newslettercs0000000001';
# }
# }
use WebGUI::Form;
use WebGUI::International;
use WebGUI::Utility;

View file

@ -24,6 +24,7 @@ property data => (
fieldType => 'DataTable',
default => undef,
label => '',
dateFormat => \&getDateFormat,
);
property templateId => (
tab => "display",
@ -120,6 +121,41 @@ sub getDataTemplateVars {
#----------------------------------------------------------------------------
=head2 getDateFormat ( )
Get the current date format for the current user in a strftime format that YUI can
understand.
=cut
sub getDateFormat {
my ( $self ) = @_;
my $dateFormat
= WebGUI::DateTime->new( $self->session )->webguiToStrftime( $self->session->user->get('dateFormat') );
# Special handle %_varmonth_ super special WebGUI field that strftime doesn't have
$dateFormat =~ s/%_varmonth_/%m/g;
return $dateFormat;
}
#----------------------------------------------------------------------------
=head2 getEditTabs ( )
Add a tab for the data table.
=cut
sub getEditTabs {
my $self = shift;
my $i18n = WebGUI::International->new( $self->session, "Asset_DataTable" );
return ( $self->SUPER::getEditTabs, [ "data" => $i18n->get("tab label data") ], );
}
#----------------------------------------------------------------------------
=head2 getTemplateVars ( )
Get the template vars for this asset.
@ -159,6 +195,7 @@ sub prepareView {
name => $self->getId,
value => $self->data,
defaultValue => undef,
dateFormat => $self->getDateFormat,
}
);
$dt->prepare;

View file

@ -1123,7 +1123,6 @@ sub www_getCompareFormData {
$parameter->{value} = $form->process($param);
my $attributeId = $param;
$attributeId =~ s/^search_//;
$attributeId =~ s/_____/-/g;
$parameter->{attributeId} = $attributeId;
push(@searchParamList, $db->quote($parameter->{attributeId}) );
push(@searchParams, $parameter);
@ -1175,20 +1174,17 @@ sub www_getCompareFormData {
$checked = 'checked';
}
}
$result->{assetId} =~ s/-/_____/g;
push @results, $result if $checked eq 'checked';
}
}
else {
foreach my $result (@{$self->getListings}) {
$result->{assetId} =~ s/-/_____/g;
push @results, $result;
}
}
}
else {
foreach my $result (@{$self->getListings}) {
$result->{assetId} =~ s/-/_____/g;
if(WebGUI::Utility::isIn($result->{assetId},@listingIds)){
$result->{checked} = 'checked';
}
@ -1233,7 +1229,6 @@ sub www_getCompareListData {
my @responseFields = ("attributeId", "name", "description","fieldType", "checked");
foreach my $listingId (@listingIds){
$listingId =~ s/_____/-/g;
my $listing = WebGUI::Asset::MatrixListing->newById($session,$listingId);
$listing->incrementCounter("compares");
my $listingId_safe = $listingId;

View file

@ -49,6 +49,23 @@ property storyTemplateId => (
namespace => 'Story',
default => 'TbDcVLbbznPi0I0rxQf2CQ',
);
property storySortOrder => (
fieldType => "selectBox",
tab => 'display',
default => 'Chronologically',
options => \&_storySortOrder_options,
label => ['sortAlphabeticallyChronologically', 'Asset_StoryArchive'],
hoverHelp => ['sortAlphabeticallyChronologically description', 'Asset_StoryArchive'],
);
sub _storySortOrder_options {
my $session = shift->session;
my $i18n = WebGUI::International->new($session, 'Asset_StoryArchive');
return {
Alphabetically => $i18n->get('alphabetically'),
Chronologically => $i18n->get('chronologically'),
};
}
with 'WebGUI::Role::Asset::RssFeed';
@ -147,10 +164,11 @@ sub viewTemplateVariables {
my $wordList = WebGUI::Keyword::string2list($self->keywords);
my $key = WebGUI::Keyword->new($session);
my $p = $key->getMatchingAssets({
keywords => $wordList,
isa => 'WebGUI::Asset::Story',
usePaginator => 1,
rowsPerPage => $numberOfStories,
sortOrder => $self->get('storySortOrder') || 'Chronologically',
keywords => $wordList,
isa => 'WebGUI::Asset::Story',
usePaginator => 1,
rowsPerPage => $numberOfStories,
});
my $storyIds = $p->getPageData();
$var->{story_loop} = [];
@ -180,7 +198,7 @@ sub viewTemplateVariables {
push @{$var->{story_loop}}, $storyVars;
}
if ($self->{_standAlone}) {
if ($self->{_standAlone} and @$storyIds) {
my $topStoryData = $storyIds->[0];
shift @{ $var->{story_loop} };
##Note, this could have saved from the loop above, but this looks more clean and encapsulated to me.

View file

@ -350,7 +350,8 @@ sub view {
my $self = shift;
my $form = $self->session->form;
my $url = $self->session->url;
my $url = $self->session->url;
my $dbh = $self->session->db->dbh;
my $i18n = WebGUI::International->new($self->session, "Asset_UserList");
my (%var, @users, @profileField_loop, @profileFields);
my ($user, $sth, $sql, $profileField);
@ -432,7 +433,6 @@ sub view {
# Query user profile data. Exclude the visitor account and users that have been deactivated.
$sql = "select distinct users.userId, users.userName, userProfileData.publicProfile ";
# Include remaining profile fields in the query
my $dbh = $self->session->db->dbh;
foreach my $profileField (@profileFields){
$sql .= ", userProfileData." . $dbh->quote_identifier($profileField->{fieldName});
}
@ -441,22 +441,22 @@ sub view {
my $constraint;
my @profileSearchFields = ();
my $searchType = $form->process('searchType') || 'or';
my $searchType = lc $form->process('searchType') eq 'and' ? 'and' : 'or';
if ($form->process('search')){
# Normal search with one keyword takes precedence over other search options
if($form->process('limitSearch')){
# Normal search with one keyword in a limited number of fields
foreach my $profileField (@profileFields){
if ($form->process('includeInSearch_'.$profileField->{fieldName})){
push(@profileSearchFields,'userProfileData.'.$profileField->{fieldName}
.' like "%'.$form->process('search').'%"');
push(@profileSearchFields, 'userProfileData.'.$dbh->quote_identifier($profileField->{fieldName})
.' like '. $dbh->quote('%'.$form->process('search').'%'));
}
}
}
else{
# Normal search with one keyword in all fields
$constraint = "(".join(' or ', map {'userProfileData.'.$_->{fieldName}
.' like "%'.$form->process('search').'%"'} @profileFields).")";
$constraint = "(".join(' or ', map {'userProfileData.'.$dbh->quote_identifier($_->{fieldName})
.' like '.$dbh->quote('%'.$form->process('search').'%')} @profileFields).")";
}
}
elsif ($form->process('searchExact')){
@ -465,15 +465,15 @@ sub view {
# Exact search with one keyword in a limited number of fields
foreach my $profileField (@profileFields){
if ($form->process('includeInSearch_'.$profileField->{fieldName})){
push(@profileSearchFields,'userProfileData.'.$profileField->{fieldName}
.' like "'.$form->process('search').'"');
push(@profileSearchFields,'userProfileData.'.$dbh->quote_identifier($profileField->{fieldName})
.' like '.$dbh->quote($form->process('search')));
}
}
}
else{
# Exact search with one keyword in all fields
$constraint = "(".join(' or ', map {'userProfileData.'.$_->{fieldName}
.' like "'.$form->process('searchExact').'"'} @profileFields).")";
$constraint = "(".join(' or ', map {'userProfileData.'.$dbh->quote_identifier($_->{fieldName})
.' like ' . $dbh->quote($form->process('searchExact'))} @profileFields).")";
}
}
else{
@ -481,12 +481,12 @@ sub view {
foreach my $profileField (@profileFields){
# Exact search has precedence over normal search
if ($form->process('searchExact_'.$profileField->{fieldName})){
push(@profileSearchFields,'userProfileData.'.$profileField->{fieldName}
.' like "'.$form->process('searchExact_'.$profileField->{fieldName}).'"');
push(@profileSearchFields,'userProfileData.'.$dbh->quote_identifier($profileField->{fieldName})
.' like '. $dbh->quote($form->process('searchExact_'.$profileField->{fieldName})));
}
elsif ($form->process('search_'.$profileField->{fieldName})){
push(@profileSearchFields,'userProfileData.'.$profileField->{fieldName}
.' like "%'.$form->process('search_'.$profileField->{fieldName}).'%"');
push(@profileSearchFields,'userProfileData.'.$dbh->quote_identifier($profileField->{fieldName})
.' like '. $dbh->quote('%'.$form->process('search_'.$profileField->{fieldName})));
}
}
}
@ -495,14 +495,17 @@ sub view {
}
$sql .= " and ".$constraint if ($constraint);
my $sortBy = $form->process('sortBy') || $self->sortBy || 'users.username';
my $sortBy = $form->process('sortBy') || $self->sortBy || 'users.username';
my $sortOrder = $form->process('sortOrder') || $self->sortOrder || 'asc';
if (lc $sortOrder ne 'desc') {
$sortOrder = 'asc';
}
my @sortByUserProperties = ('dateCreated', 'lastUpdated', 'karma', 'userId');
if(isIn($sortBy,@sortByUserProperties)){
$sortBy = 'users.'.$sortBy;
}
$sortBy = join '.', map { $self->session->db->quoteIdentifier($_) } split /\./, $sortBy;
$sortBy = join '.', map { $dbh->quote_identifier($_) } split /\./, $sortBy;
$sql .= " order by ".$sortBy." ".$sortOrder;
my $paginatePage = $form->param('pn') || 1;

View file

@ -554,7 +554,11 @@ sub getKeywordHierarchy {
my $datum = {
title => $keyword, ##Note, same as keyword
url => $self->getUrl('func=byKeyword;keyword='.$keyword),
descendants => scalar @{ $assetKeyword->getMatchingAssets( { startAsset => $self, keyword => $keyword, }) },
descendants => scalar @{ $assetKeyword->getMatchingAssets( {
startAsset => $self,
keyword => $keyword,
sortOrder => 'Alphabetically',
}) },
};
##Prevent recursion if seen again
if (! $seen->{$keyword}++) {