- Added keyword tagging to Wiki.

This commit is contained in:
JT Smith 2007-07-07 21:09:39 +00:00
parent 23fa0283b3
commit f36ba1b268
17 changed files with 323 additions and 213 deletions

View file

@ -1787,6 +1787,9 @@ sub processPropertiesFromFormPost {
);
}
}
if ($form->process("keywords")) {
$data{keywords} = $form->process("keywords");
}
if ($self->session->setting->get("metaDataEnabled")) {
my $meta = $self->getMetaDataFields;
foreach my $field (keys %{$meta}) {

View file

@ -158,7 +158,7 @@ sub getEditForm {
formKeywords => WebGUI::Form::text($session, {
name => "keywords",
value => WebGUI::Keyword->new($session)->getKeywordsForAsset({asset=>$self}),
});
}),
allowsAttachments => $wiki->get("maxAttachments"),
formFooter => WebGUI::Form::formFooter($session),
isNew => ($self->getId eq "new"),
@ -319,7 +319,20 @@ sub update {
sub view {
my $self = shift;
my $i18n = WebGUI::International->new($self->session, "Asset_WikiPage");
my $keywords = WebGUI::Keyword->new($self->session)->getKeywordsForAsset({
asset=>$self,
asArrayRef=>1,
});
my $wiki = $self->getWiki;
my @keywordsLoop = ();
foreach my $word (@{$keywords}) {
push(@keywordsLoop, {
keyword=>$word,
url=>$wiki->getUrl("func=byKeyword;keyword=".$word),
});
}
my $var = {
keywordsLoop => \@keywordsLoop,
viewLabel => $i18n->get("viewLabel"),
editLabel => $i18n->get("editLabel"),
historyLabel => $i18n->get("historyLabel"),

View file

@ -233,6 +233,13 @@ sub definition {
hoverHelp => $i18n->get('recentChangesTemplateId hoverHelp'),
label => $i18n->get('recentChangesTemplateId label') },
byKeywordTemplateId => { fieldType => 'template',
namespace => 'WikiMaster_byKeyword',
defaultValue => 'WikiKeyword00000000001',
tab => 'display',
hoverHelp => $i18n->get('byKeywordTemplateId hoverHelp'),
label => $i18n->get('byKeywordTemplateId label') },
searchTemplateId => { fieldType => 'template',
namespace => 'WikiMaster_search',
defaultValue => 'WikiSearchTmpl00000001',
@ -361,6 +368,10 @@ sub view {
recentChangesLabel=>$i18n->get("recentChangesLabel"),
restoreLabel => $i18n->get("restoreLabel"),
canAdminister => $self->canAdminister,
keywordCloud => WebGUI::Keyword->new($self->session)->generateCloud({
startAsset=>$self,
displayFunc=>"byKeyword",
}),
};
my $template = $self->{_frontPageTemplate};
$self->appendSearchBoxVars($var);
@ -370,6 +381,35 @@ sub view {
}
#-------------------------------------------------------------------
sub www_byKeyword {
my $self = shift;
my $keyword = $self->session->form->process("keyword");
my @pages = ();
my $p = WebGUI::Keyword->new($self->session)->getMatchingAssets({
startAsset => $self,
keyword => $keyword,
usePaginator => 1,
});
$p->setBaseUrl($self->getUrl("func=byKeyword"));
foreach my $assetData (@{$p->getPageData}) {
$self->session->errorHandler->warn($assetData->{assetId});
my $asset = WebGUI::Asset->newByDynamicClass($self->session, $assetData->{assetId});
next unless defined $asset;
push(@pages, {
title => $asset->getTitle,
url => $asset->getUrl,
});
}
my $var = {
keyword => $keyword,
pagesLoop => \@pages,
};
$p->appendTemplateVars($var);
return $self->processStyle($self->processTemplate($var, $self->get('byKeywordTemplateId')));
}
#-------------------------------------------------------------------
sub www_mostPopular {
my $self = shift;

View file

@ -17,6 +17,7 @@ package WebGUI::Keyword;
use strict;
use Class::InsideOut qw(public register id);
use HTML::TagCloud;
use WebGUI::Paginator;
=head1 NAME
@ -104,7 +105,7 @@ The www func that will be called on the displayAsset to display the list of asse
=head3 cloudLevels
How many levels of keyword sizes should there be displayed in the cloud. Defaults to 10.
How many levels of keyword sizes should there be displayed in the cloud. Defaults to 24. Range between 2 and 24.
=head3 startAsset
@ -124,7 +125,7 @@ sub generateCloud {
my $sth = $self->session->db->read("select count(*) as keywordTotal, keyword from assetKeyword
left join asset using (assetId) where lineage like ? group by keyword order by keywordTotal limit 50",
[ $options->{startAsset}->get("lineage").'%' ]);
my $cloud = HTML::TagCloud->new(levels=>$options->{cloudLevels} || 10);
my $cloud = HTML::TagCloud->new(levels=>$options->{cloudLevels} || 24);
while (my ($count, $keyword) = $sth->array) {
$cloud->add($keyword, $display->getUrl("func=".$options->{displayFunc}.";keyword=".$keyword), $count);
}
@ -148,8 +149,7 @@ A boolean, that if set to 1 will return the keywords as an array reference rathe
=cut
sub getKeywordsForAsset {
my $self = shift;
my $options = shift;
my ($self, $options) = @_;
my @keywords = $self->session->db->buildArray("select keyword from assetKeyword where assetId=?",
[$options->{asset}->getId]);
if ($options->{asArrayRef}) {
@ -163,7 +163,43 @@ sub getKeywordsForAsset {
#-------------------------------------------------------------------
=head2 new ( session )
=head2 getMatchingAssets ( { startAsset => $asset, keyword => $keyword } )
Returns an array reference of asset ids matching the start point + keyword.
=head3 startAsset
An asset object where you'd like to start searching for matching keywords.
=head3 keyword
The keyword to match.
=head3 usePaginator
Instead of returning an array reference of assetId's, return a paginator object.
=cut
sub getMatchingAssets {
my ($self, $options) = @_;
my $query = "select assetKeyword.assetId from assetKeyword left join asset using (assetId)
where lineage like ? and keyword=? order by creationDate desc";
my $params = [$options->{startAsset}->get("lineage").'%', $options->{keyword}];
if ($options->{usePaginator}) {
my $p = WebGUI::Paginator->new($self->session);
$p->setDataByQuery($query, undef, undef, $params);
return $p;
}
else {
return $self->session->db->buildArrayRef($query, $params);
}
}
#-------------------------------------------------------------------
=head2 new ( $session )
Constructor.

View file

@ -549,7 +549,7 @@ sub getRowCount {
#-------------------------------------------------------------------
=head2 new ( session, currentURL [, paginateAfter, formVar, pageNumber ] )
=head2 new ( session, baseUrl [, paginateAfter, formVar, pageNumber ] )
Constructor.
@ -557,7 +557,7 @@ Constructor.
A reference to the current session.
=head3 currentURL
=head3 baseUrl
The URL of the current page including attributes. The page number will be appended to this in all links generated by the paginator.
@ -599,6 +599,24 @@ sub session {
}
#-------------------------------------------------------------------
=head2 setBaseUrl ( url )
Override the baseUrl set in the constructor.
=head3 url
The new URL.
=cut
sub setBaseUrl {
my ($self, $url) = @_;
$self->{_url} = $url;
}
#-------------------------------------------------------------------
=head2 setDataByArrayRef ( arrayRef )

View file

@ -7,6 +7,12 @@ our $I18N = {
context => q|A button added to all asset properties pages when save and commit mode is enabled.|
},
'keywords' => {
message => q|Keywords|,
lastUpdated => 0,
context => q|A label for the property that relates assets to keywords.|
},
'add the missing page' => {
message => q|Add the missing page.|,
lastUpdated => 0,

View file

@ -132,6 +132,10 @@ our $I18N = {
lastUpdated => 1160157064,
},
'byKeywordTemplateId hoverHelp' => { lastUpdated => 1160157064, message => q|Which template to use to display a
listing of pages that are related to a specific keyword?| },
'byKeywordTemplateId label' => { lastUpdated => 1160157064, message => q|By Keyword Template| },
'pageTemplateId hoverHelp' => { lastUpdated => 1160157064, message => q|Which template to use to display pages?| },
'pageTemplateId label' => { lastUpdated => 1160157064, message => q|Page Template| },