Adding new files for Dashboard and ancillary wobjects.
This commit is contained in:
parent
72619fb9c0
commit
e1f3c61946
136 changed files with 2751 additions and 0 deletions
257
lib/WebGUI/Asset/Wobject/Dashboard.pm
Normal file
257
lib/WebGUI/Asset/Wobject/Dashboard.pm
Normal file
|
|
@ -0,0 +1,257 @@
|
|||
package WebGUI::Asset::Wobject::Dashboard;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2005 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::Utility;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::ErrorHandler;
|
||||
use Time::HiRes;
|
||||
use WebGUI::Asset::Field;
|
||||
use WebGUI::Style;
|
||||
use WebGUI::Asset::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub canManage {
|
||||
my $self = shift;
|
||||
return WebGUI::Grouping::isInGroup($self->get("adminsGroupId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub canPersonalize {
|
||||
my $self = shift;
|
||||
return WebGUI::Grouping::isInGroup($self->get("usersGroupId"));
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>'DashboardViewTmpl00001',
|
||||
namespace=>"Dashboard"
|
||||
},
|
||||
adminsGroupId =>{
|
||||
fieldType=>"group",
|
||||
defaultValue=>4
|
||||
},
|
||||
usersGroupId =>{
|
||||
fieldType=>"group",
|
||||
defaultValue=>2
|
||||
},
|
||||
mapFieldId =>{
|
||||
fieldType=>"text",
|
||||
defaultValue=>''
|
||||
}
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>WebGUI::International::get('assetName',"Asset_Dashboard"),
|
||||
icon=>'dashboard.gif',
|
||||
tableName=>'Dashboard',
|
||||
className=>'WebGUI::Asset::Wobject::Dashboard',
|
||||
properties=>\%properties
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getContentPositions {
|
||||
my $self = shift;
|
||||
my $dummy = $self->initializeDashletFields unless $self->get("mapFieldId");
|
||||
return WebGUI::Asset::Field->getUserPref($self->get("mapFieldId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm;
|
||||
my $i18n = WebGUI::International->new("Asset_Dashboard");
|
||||
$tabform->getTab("display")->template(
|
||||
-value=>$self->getValue('templateId'),
|
||||
-namespace=>"Dashboard",
|
||||
-label=>$i18n->get('dashboard template field label'),
|
||||
-hoverHelp=>$i18n->get('dashboard template description'),
|
||||
);
|
||||
$tabform->getTab("security")->group(
|
||||
-name=>"adminsGroupId",
|
||||
-label=>$i18n->get('dashboard adminsGroupId field label'),
|
||||
-hoverHelp=>$i18n->get('dashboard adminsGroupId description'),
|
||||
-value=>[$self->get("adminsGroupId")]
|
||||
);
|
||||
$tabform->getTab("security")->group(
|
||||
-name=>"usersGroupId",
|
||||
-label=>$i18n->get('dashboard usersGroupId field label'),
|
||||
-hoverHelp=>$i18n->get('dashboard usersGroupId description'),
|
||||
-value=>[$self->get("usersGroupId")]
|
||||
);
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub initializeDashletFields {
|
||||
my $self = shift;
|
||||
my $child = $self->addChild({
|
||||
className=>'WebGUI::Asset::Field',
|
||||
title=>'Dashboard User Preference - Content Positions',
|
||||
menuTitle=>'Dashboard User Preference - Content Positions',
|
||||
isHidden=>1,
|
||||
startDate=>$self->get("startDate"),
|
||||
endDate=>$self->get("endDate"),
|
||||
ownerUserId=>$self->get("ownerUserId"),
|
||||
groupIdEdit=>$self->get("groupIdEdit"),
|
||||
groupIdView=>$self->get("groupIdView"),
|
||||
url=>'Dashboard User Preference - Content Positions',
|
||||
isUserPref=>1,
|
||||
fieldName=>'contentPositions'
|
||||
});
|
||||
$self->update({mapFieldId=>$child->getId});
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub isManaging {
|
||||
my $self = shift;
|
||||
return 1 if ($self->canManage && WebGUI::Session::isAdminOn());
|
||||
return 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
if ($session{form}{assetId} eq "new" && $session{form}{class} eq 'WebGUI::Asset::Wobject::Dashboard') {
|
||||
$self->initializeDashletFields;
|
||||
$self->update({styleTemplateId=>'PBtmplBlankStyle000001'});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub view {
|
||||
my $self = shift;
|
||||
my %vars = $self->get();
|
||||
my $templateId = $self->get("templateId");
|
||||
my $children = $self->getLineage( ["children"], { returnObjects=>1, excludeClasses=>["WebGUI::Asset::Field","WebGUI::Asset::Wobject::Layout","WebGUI::Asset::Wobject::Dashboard"] });
|
||||
my %vars;
|
||||
# I'm sure there's a more efficient way to do this. We'll figure it out someday.
|
||||
my @positions = split(/\./,$self->getContentPositions);
|
||||
my @hidden = split("\n",$self->get("assetsToHide"));
|
||||
foreach my $child (@{$children}) {
|
||||
push(@hidden,$child->get('shortcutToAssetId')) if ref $child eq 'WebGUI::Asset::Shortcut';
|
||||
}
|
||||
my $i = 1;
|
||||
my $templateAsset = WebGUI::Asset->newByDynamicClass($templateId) || WebGUI::Asset->getImportNode;
|
||||
my $template = $templateAsset->get("template");
|
||||
my $numPositions = 1;
|
||||
foreach my $j (2..15) {
|
||||
$numPositions = $j if $template =~ m/position${j}\_loop/;
|
||||
}
|
||||
|
||||
my @found;
|
||||
my $showPerformance = WebGUI::ErrorHandler::canShowPerformanceIndicators();
|
||||
foreach my $position (@positions) {
|
||||
my @assets = split(",",$position);
|
||||
foreach my $asset (@assets) {
|
||||
foreach my $child (@{$children}) {
|
||||
if ($asset eq $child->getId) {
|
||||
unless (isIn($asset,@hidden) || !($child->canView)) {
|
||||
WebGUI::Style::setRawHeadTags($child->getExtraHeadTags);
|
||||
my $t = [Time::HiRes::gettimeofday()] if ($showPerformance);
|
||||
my $view = $child->view;
|
||||
$view .= "Asset:".Time::HiRes::tv_interval($t) if ($showPerformance);
|
||||
$child->{_properties}{title} = $child->getShortcut->get("title") if ref $child eq 'WebGUI::Asset::Shortcut';
|
||||
if ($i > $numPositions) {
|
||||
push(@{$vars{"position1_loop"}},{
|
||||
id=>$child->getId,
|
||||
content=>$view,
|
||||
dashletTitle=>$child->get("title")
|
||||
});
|
||||
} else {
|
||||
push(@{$vars{"position".$i."_loop"}},{
|
||||
id=>$child->getId,
|
||||
content=>$view,
|
||||
dashletTitle=>$child->get("title")
|
||||
});
|
||||
}
|
||||
}
|
||||
push(@found, $child->getId);
|
||||
}
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
# deal with unplaced children
|
||||
foreach my $child (@{$children}) {
|
||||
unless (isIn($child->getId, @found)||isIn($child->getId,@hidden)) {
|
||||
if ($child->canView) {
|
||||
my $t = [Time::HiRes::gettimeofday()] if ($showPerformance);
|
||||
my $view = $child->view;
|
||||
$view .= "Asset:".Time::HiRes::tv_interval($t) if ($showPerformance);
|
||||
push(@{$vars{"position1_loop"}},{
|
||||
id=>$child->getId,
|
||||
content=>$view,
|
||||
dashletTitle=>$child->get("title")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
$vars{showAdmin} = ($session{var}{adminOn} && $self->canEdit);
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}."/wobject/Dashboard/draggable.js",{ type=>"text/javascript" });
|
||||
WebGUI::Style::setLink($session{config}{extrasURL}."/wobject/Dashboard/draggable.css",{ type=>"text/css", rel=>"stylesheet", media=>"all" });
|
||||
$vars{"dragger.init"} = '
|
||||
<script type="text/javascript">
|
||||
dragable_init("'.$self->getUrl.'");
|
||||
</script>
|
||||
';
|
||||
|
||||
return $self->processTemplate(\%vars, $templateId);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_setContentPositions {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless ($self->canPersonalize);
|
||||
return '' unless $self->get("mapFieldId");
|
||||
my $success = WebGUI::Asset::Field->setUserPref($self->get("mapFieldId"),$session{form}{map});
|
||||
return "Map set: ".$session{form}{map} if $success;
|
||||
return "Map failed to set.";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
||||
Returns the view() method of the asset object if the requestor canView.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
return $self->SUPER::www_view(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
1;
|
||||
94
lib/WebGUI/Asset/Wobject/MultiSearch.pm
Normal file
94
lib/WebGUI/Asset/Wobject/MultiSearch.pm
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
package WebGUI::Asset::Wobject::MultiSearch;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Portions of the below are originally from Weather::Underground,
|
||||
and are not included in this copyright.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
|
||||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use JSON;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Asset::Wobject;
|
||||
use WebGUI::Utility;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 definition
|
||||
|
||||
defines wobject properties for MultiSearch instances
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
my $properties = {
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
tab=>"display",
|
||||
defaultValue=>'MultiSearchTmpl0000001',
|
||||
namespace=>"MultiSearch",
|
||||
hoverHelp=>WebGUI::International::get('article template description','Asset_Article'),
|
||||
label=>WebGUI::International::get(72,"Asset_Article")
|
||||
},
|
||||
predefinedSearches=>{
|
||||
fieldType=>"textarea",
|
||||
defaultValue=>"WebGUI",
|
||||
tab=>"properties",
|
||||
hoverHelp=>WebGUI::International::get('article template description','Asset_Article'),
|
||||
label=>WebGUI::International::get(72,"Asset_Article")
|
||||
},
|
||||
};
|
||||
push(@{$definition}, {
|
||||
tableName=>'MultiSearch',
|
||||
className=>'WebGUI::Asset::Wobject::MultiSearch',
|
||||
assetName=>'MultiSearch',
|
||||
# icon=>'MultiSearch.gif',
|
||||
autoGenerateForms=>1,
|
||||
properties=>$properties
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=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->get();
|
||||
#Set some template variables
|
||||
|
||||
#Build list of stocks as an array
|
||||
my $defaults = $self->getValue("predefinedSearches");
|
||||
|
||||
return $self->processTemplate(\%var, $self->get("templateId"));
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
476
lib/WebGUI/Asset/Wobject/StockData.pm
Normal file
476
lib/WebGUI/Asset/Wobject/StockData.pm
Normal file
|
|
@ -0,0 +1,476 @@
|
|||
package WebGUI::Asset::Wobject::StockData;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2005 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 WebGUI::ErrorHandler;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Asset::Wobject;
|
||||
|
||||
use Finance::Quote;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _appendStockVars ( hash, data, symbol )
|
||||
|
||||
Appends stock variables for the symbol passed in to the hash passed in
|
||||
|
||||
=head3 hash
|
||||
|
||||
hash to append stock variables to
|
||||
|
||||
=head3 data
|
||||
|
||||
hash reference in the format passed by the fetch method from Finance::Quote
|
||||
|
||||
=head3 symbol
|
||||
|
||||
stock symbol to append variables for
|
||||
|
||||
=cut
|
||||
|
||||
sub _appendStockVars {
|
||||
my $self = shift;
|
||||
my $hash = $_[0];
|
||||
my $data = $_[1];
|
||||
my $symbol = $_[2];
|
||||
$hash->{'stocks.symbol'} = _na($symbol);
|
||||
$hash->{'stocks.name'} = _na($data->{$symbol,"name"});
|
||||
$hash->{'stocks.last'} = _na($data->{$symbol,"last"});
|
||||
$hash->{'stocks.high'} = _na($data->{$symbol,"high"});
|
||||
$hash->{'stocks.low'} = _na($data->{$symbol,"low"});
|
||||
$hash->{'stocks.date'} = _na($data->{$symbol,"date"});
|
||||
$hash->{'stocks.time'} = _na($data->{$symbol,"time"});
|
||||
|
||||
$hash->{'stocks.net'} = _na($data->{$symbol,"net"});
|
||||
$hash->{'stocks.net.isDown'} = $hash->{'stocks.net'} < 0;
|
||||
$hash->{'stocks.net.isUp'} = $hash->{'stocks.net'} > 0;
|
||||
$hash->{'stocks.net.noChange'} = $hash->{'stocks.net'} == 0;
|
||||
|
||||
$hash->{'stocks.net.icon'} = "nc.gif";
|
||||
if($hash->{'stocks.net.isDown'}) {
|
||||
$hash->{'stocks.net.icon'} = "down.gif";
|
||||
} elsif($hash->{'stocks.net.isUp'}) {
|
||||
$hash->{'stocks.net.icon'} = "up.gif";
|
||||
}
|
||||
$hash->{'stocks.p_change'} = _na($data->{$symbol,"p_change"});
|
||||
$hash->{'stocks.volume'} = _na($data->{$symbol,"volume"});
|
||||
$hash->{'stocks.volume.millions'} = _na(WebGUI::Utility::round(($hash->{'stocks.volume'}/1000000),2));
|
||||
$hash->{'stocks.avg_vol'} = _na($data->{$symbol,"avg_vol"});
|
||||
$hash->{'stocks.bid'} = _na($data->{$symbol,"bid"});
|
||||
$hash->{'stocks.ask'} = _na(WebGUI::Utility::commify($data->{$symbol,"ask"}));
|
||||
$hash->{'stocks.close'} = _na($data->{$symbol,"close"});
|
||||
$hash->{'stocks.open'} = _na($data->{$symbol,"open"});
|
||||
$hash->{'stocks.day_range'} = _na($data->{$symbol,"day_range"});
|
||||
$hash->{'stocks.year_range'} = _na($data->{$symbol,"year_range"});
|
||||
my ($yrLo,$yrHi) = split("-",$hash->{'stocks.year_range'});
|
||||
|
||||
$hash->{'stocks.year_high'} = _na($self->_trim($yrHi));
|
||||
$hash->{'stocks.year_low'} = _na($self->_trim($yrLo));
|
||||
$hash->{'stocks.eps'} = _na($data->{$symbol,"eps"});
|
||||
$hash->{'stocks.pe'} = _na($data->{$symbol,"pe"});
|
||||
$hash->{'stocks.div_date'} = _na($data->{$symbol,"div_date"});
|
||||
$hash->{'stocks.div'} = _na($data->{$symbol,"div"});
|
||||
$hash->{'stocks.div_yield'} = _na($data->{$symbol,"div_yield"});
|
||||
$hash->{'stocks.cap'} = _na(lc($data->{$symbol,"cap"}));
|
||||
$hash->{'stocks.ex_div'} = _na($data->{$symbol,"ex_div"});
|
||||
$hash->{'stocks.nav'} = _na($data->{$symbol,"nav"});
|
||||
$hash->{'stocks.yield'} = _na($data->{$symbol,"yield"});
|
||||
$hash->{'stocks.exchange'} = _na($data->{$symbol,"exchange"});
|
||||
$hash->{'stocks.success'} = _na($data->{$symbol,"success"});
|
||||
$hash->{'stocks.errormsg'} = _na($data->{$symbol,"errormsg"});
|
||||
$hash->{'stocks.method'} = _na($data->{$symbol,"method"});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _na( string )
|
||||
|
||||
If string passed in is empty, returns N/A
|
||||
|
||||
=head3 string
|
||||
|
||||
a string
|
||||
|
||||
=cut
|
||||
|
||||
sub _na {
|
||||
my $str = $_[0];
|
||||
unless($str) {
|
||||
$str = "N/A";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _appendZero( intger )
|
||||
|
||||
Appends a zero to an integer if it is 0-9
|
||||
|
||||
=head3 integer
|
||||
|
||||
an integer
|
||||
|
||||
=cut
|
||||
|
||||
sub _appendZero {
|
||||
my $self = shift;
|
||||
my $num = $_[0];
|
||||
if (length($num) == 1) {
|
||||
$num = "0".$num;
|
||||
}
|
||||
return $num;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _clearStockEditSession ( )
|
||||
|
||||
Clears the session variables from session used by the stock list edit form
|
||||
|
||||
=cut
|
||||
|
||||
sub _clearStockEditSession {
|
||||
my $self = shift;
|
||||
$session{form}{symbol} = "";
|
||||
$session{form}{stockId} = "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _convertToEpoch (date,time)
|
||||
|
||||
Converts the date and time returned by Finance::Quote to an epoch
|
||||
|
||||
=head3 date
|
||||
|
||||
date format returned by Finance::Quote
|
||||
|
||||
=head3 time
|
||||
|
||||
time format returned by Finance::Quote
|
||||
|
||||
=cut
|
||||
|
||||
sub _convertToEpoch {
|
||||
my $self = shift;
|
||||
my $date = $_[0];
|
||||
my $time = $_[1];
|
||||
|
||||
my ($month,$day,$year) = split("/",$date);
|
||||
$month = $self->_appendZero($month);
|
||||
$day = $self->_appendZero($day);
|
||||
my $tfixed = substr($time,0,-2);
|
||||
my ($hour,$minute) = split(":",$tfixed);
|
||||
if($time =~ m/pm/i) {
|
||||
$hour += 12;
|
||||
}
|
||||
$hour = $self->_appendZero($hour);
|
||||
$minute - $self->_appendZero($minute);
|
||||
return WebGUI::DateTime::humanToEpoch("$year-$month-$day $hour:$minute:00");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _getStocks ( stocks )
|
||||
|
||||
Private method which retrieves stock information from the Finance::Quote package
|
||||
|
||||
=head3 stocks
|
||||
|
||||
list of stock symbols to find passed in as an array reference. stock symbols should all be uppercase
|
||||
|
||||
=cut
|
||||
|
||||
sub _getStocks {
|
||||
my $self = shift;
|
||||
my $stocks = $_[0];
|
||||
#Create a new Finance::Quote object
|
||||
my $q = Finance::Quote->new;
|
||||
#Disable failover if specified
|
||||
unless ($self->getValue("failover")) {
|
||||
$q->failover(0);
|
||||
}
|
||||
#Fetch the stock information and return the results
|
||||
return $q->fetch($self->getValue("source"),@{$stocks});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _getStockSources ( )
|
||||
|
||||
Private method which retrieves the list of available stock sources from Finance::Quote package
|
||||
and returns the results as a hash reference for the selectList Form API
|
||||
|
||||
=cut
|
||||
|
||||
sub _getStockSources {
|
||||
my $self = shift;
|
||||
#Instantiate Finance::Quote
|
||||
my $q = Finance::Quote->new;
|
||||
#Retrieve array of available sources and sort them
|
||||
my @srcs = sort $q->sources;
|
||||
#Create a hash reference with the name referencing itself
|
||||
my %sources;
|
||||
#Tie to IxHash to preserve alphabetical order
|
||||
tie %sources, "Tie::IxHash";
|
||||
foreach my $src (@srcs) {
|
||||
$sources{$src} = $src;
|
||||
}
|
||||
return \%sources;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _submenu
|
||||
|
||||
renders the admin console view
|
||||
|
||||
=cut
|
||||
|
||||
sub _submenu {
|
||||
my $self = shift;
|
||||
my $workarea = shift;
|
||||
my $title = shift;
|
||||
my $help = shift;
|
||||
my $ac = WebGUI::AdminConsole->new("editstocks");
|
||||
$ac->setHelp($help) if ($help);
|
||||
$ac->setIcon($self->getIcon);
|
||||
return $ac->render($workarea, $title);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _trim (str)
|
||||
|
||||
Trims whitespace form front and end of a string
|
||||
|
||||
=head3 str
|
||||
|
||||
a string to trim
|
||||
|
||||
=cut
|
||||
|
||||
sub _trim {
|
||||
my $self = shift;
|
||||
my $str = $_[0];
|
||||
$str =~ s/^\s//;
|
||||
$str =~ s/\s$//;
|
||||
return $str;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 definition
|
||||
|
||||
defines wobject properties for Stock Data instances
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
my $properties = {
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>'StockDataTMPL000000001'
|
||||
},
|
||||
displayTemplateId=>{
|
||||
fieldType=>"template",
|
||||
defaultValue=>'StockDataTMPL000000002'
|
||||
},
|
||||
defaultStocks=>{
|
||||
fieldType=>"textarea",
|
||||
defaultValue=>"DELL\nMSFT\nORCL\nSUNW\nYHOO"
|
||||
},
|
||||
source=>{
|
||||
fieldType=>"selectList",
|
||||
defaultValue=>"usa"
|
||||
},
|
||||
failover=>{
|
||||
fieldType=>"checkbox",
|
||||
defaultValue=>undef
|
||||
}
|
||||
};
|
||||
push(@{$definition}, {
|
||||
tableName=>'StockData',
|
||||
className=>'WebGUI::Asset::Wobject::StockData',
|
||||
icon=>'stockData.gif',
|
||||
assetName=>WebGUI::International::get("app_name","Asset_StockData"),
|
||||
properties=>$properties
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 getEditForm
|
||||
|
||||
returns the tabform object that will be used in generating the edit page for Stock Lists
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
|
||||
$tabform->getTab("display")->template(
|
||||
-value=>$self->get("templateId"),
|
||||
-label=>WebGUI::International::get("template_label","Asset_StockData"),
|
||||
-namespace=>"StockData"
|
||||
);
|
||||
|
||||
$tabform->getTab("display")->template(
|
||||
-value=>$self->get("displayTemplateId"),
|
||||
-label=>WebGUI::International::get("display_template_label","Asset_StockData"),
|
||||
-namespace=>"StockData/Display"
|
||||
);
|
||||
|
||||
$tabform->getTab("properties")->textarea(
|
||||
-name => "defaultStocks",
|
||||
-label=> WebGUI::International::get("default_stock_label","Asset_StockData"),
|
||||
-value=> $self->getValue("defaultStocks")
|
||||
);
|
||||
|
||||
$tabform->getTab("properties")->selectList(
|
||||
-name => "source",
|
||||
-label=> WebGUI::International::get("stock_source","Asset_StockData"),
|
||||
-options=>$self->_getStockSources(),
|
||||
-value=> [$self->getValue("source")],
|
||||
-hoverHelp=>WebGUI::International::get("stock_source_description","Asset_StockData")
|
||||
);
|
||||
|
||||
$tabform->getTab("properties")->yesNo(
|
||||
-name=> "failover",
|
||||
-label=> WebGUI::International::get("failover_label","Asset_StockData"),
|
||||
-value=>$self->getValue("failover"),
|
||||
-hoverHelp=> WebGUI::International::get("failover_description","Asset_StockData")
|
||||
);
|
||||
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 purge ( )
|
||||
|
||||
removes collateral data associated with a StockData when the system
|
||||
purges it's data.
|
||||
|
||||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
return $self->SUPER::purge;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=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 = {};
|
||||
#Set some template variables
|
||||
$var->{'extrasFolder'} = $session{config}{extrasURL}."/wobject/StockData";
|
||||
$var->{'editUrl'} = $self->getUrl("func=editStocks");
|
||||
$var->{'isVisitor'} = $session{user}{userId} eq 1;
|
||||
$var->{'stock.display.url'} = $self->getUrl("func=displayStock&symbol=");
|
||||
|
||||
#Build list of stocks as an array
|
||||
my $defaults = $self->getValue("defaultStocks");
|
||||
#replace any windows newlines
|
||||
$defaults =~ s/\r//;
|
||||
my @array = split("\n",$defaults);
|
||||
#trim default stocks of whitespace
|
||||
for (my $i = 0; $i < scalar(@array); $i++) {
|
||||
$array[$i] = $self->_trim($array[$i]);
|
||||
}
|
||||
my $data = $self->_getStocks(\@array);
|
||||
|
||||
my @stocks = ();
|
||||
foreach my $symbol (@array) {
|
||||
my $hash = {};
|
||||
|
||||
#Append Template Variables for stock symbol
|
||||
$self->_appendStockVars($hash,$data,$symbol);
|
||||
|
||||
#Create last update date formats
|
||||
unless ($var->{'lastUpdate.default'}) {
|
||||
my $luEpoch = $self->_convertToEpoch($hash->{'stocks.date'},$hash->{'stocks.time'});
|
||||
$var->{'lastUpdate.intl'} = WebGUI::DateTime::epochToHuman($luEpoch,"%y-%m-%d %j:%n");
|
||||
$var->{'lastUpdate.us'} = WebGUI::DateTime::epochToHuman($luEpoch,"%m/%d/%y %h:%n %p");
|
||||
$var->{'lastUpdate.default'} = WebGUI::DateTime::epochToHuman($luEpoch,"%C %d %H:%n %P");
|
||||
}
|
||||
|
||||
push (@stocks, $hash);
|
||||
}
|
||||
$var->{'stocks.loop'} = \@stocks;
|
||||
return $self->processTemplate($var, $self->get("templateId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 www_displayStock ( )
|
||||
|
||||
Web facing method which allows users to view details about their stocks
|
||||
|
||||
=cut
|
||||
|
||||
sub www_displayStock {
|
||||
my $self = shift;
|
||||
my $var = {};
|
||||
return WebGUI::Privilege::noAccess() unless $self->canView();
|
||||
|
||||
$var->{'extrasFolder'} = $session{config}{extrasURL}."/wobject/StockData";
|
||||
|
||||
my $symbol = $session{form}{symbol};
|
||||
my $data = $self->_getStocks([$symbol]);
|
||||
#Append Template Variables for stock symbol
|
||||
$self->_appendStockVars($var,$data,$symbol);
|
||||
|
||||
#Configure last update dates
|
||||
my $luEpoch = $self->_convertToEpoch($var->{'stocks.date'},$var->{'stocks.time'});
|
||||
$var->{'lastUpdate.intl'} = WebGUI::DateTime::epochToHuman($luEpoch,"%y-%m-%d");
|
||||
$var->{'lastUpdate.us'} = WebGUI::DateTime::epochToHuman($luEpoch,"%m/%d/%y");
|
||||
|
||||
$session{setting}{showDebug} = 0;
|
||||
return $self->processTemplate($var, $self->get("displayTemplateId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 www_edit ( )
|
||||
|
||||
Web facing method which is the default edit page
|
||||
|
||||
=cut
|
||||
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->getAdminConsole->setHelp("stock_list_add_edit","Asset_StockData");
|
||||
return $self->getAdminConsole->render($self->getEditForm->print,
|
||||
WebGUI::International::get("edit_title","Asset_StockData"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 www_view ( )
|
||||
|
||||
Overwrite www_view method and call the superclass object, passing in a 1 to disable cache
|
||||
|
||||
=cut
|
||||
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
$self->SUPER::www_view(1);
|
||||
}
|
||||
|
||||
1;
|
||||
221
lib/WebGUI/Asset/Wobject/WeatherData.pm
Normal file
221
lib/WebGUI/Asset/Wobject/WeatherData.pm
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
package WebGUI::Asset::Wobject::WeatherData;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2005 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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Portions of the below are originally from Weather::Underground,
|
||||
and are not included in this copyright.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
|
||||
use LWP::UserAgent qw($ua);
|
||||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use JSON;
|
||||
use WebGUI::Cache;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Asset::Wobject;
|
||||
use WebGUI::Utility;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 definition
|
||||
|
||||
defines wobject properties for WeatherData instances
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
my $properties = {
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
tab=>"display",
|
||||
defaultValue=>'WeatherDataTmpl0000001',
|
||||
namespace=>"WeatherData",
|
||||
hoverHelp=>WebGUI::International::get('article template description','Asset_Article'),
|
||||
label=>WebGUI::International::get(72,"Asset_Article")
|
||||
},
|
||||
locations=>{
|
||||
fieldType=>"textarea",
|
||||
defaultValue=>"Grayslake,IL",
|
||||
tab=>"properties",
|
||||
hoverHelp=>WebGUI::International::get('article template description','Asset_Article'),
|
||||
label=>WebGUI::International::get(72,"Asset_Article")
|
||||
},
|
||||
};
|
||||
push(@{$definition}, {
|
||||
tableName=>'WeatherData',
|
||||
className=>'WebGUI::Asset::Wobject::WeatherData',
|
||||
assetName=>'WeatherData',
|
||||
icon=>'weatherData.gif',
|
||||
autoGenerateForms=>1,
|
||||
properties=>$properties
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _getLocationData
|
||||
|
||||
Accepts an array ref of locations, and returns
|
||||
|
||||
=cut
|
||||
|
||||
sub _getLocationData {
|
||||
my $self = shift;
|
||||
my $location = shift;
|
||||
my $cache = WebGUI::Cache->new(["weatherLocation",$location]);
|
||||
my $locData = $cache->get;
|
||||
unless ($locData->{cityState}) {
|
||||
my $oldagent;
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->timeout(10);
|
||||
$oldagent = $ua->agent();
|
||||
$ua->agent($session{env}{HTTP_USER_AGENT}); # Act as a proxy.
|
||||
my $response = $ua->get('http://www.srh.noaa.gov/port/port_zc.php?inputstring='.$location);
|
||||
my $document = $response->content;
|
||||
$document =~ s/\n/ /g;
|
||||
$document =~ s/\s+/ /g;
|
||||
$document =~ m!<hr>\s<div\salign="center">\s(.*?)<br>.*?<br>.*?<br>.*?<br>\s(.*?):\s(.*?) °F<br>!;
|
||||
$locData = {
|
||||
query => $location,
|
||||
cityState => $1,
|
||||
sky => $2,
|
||||
tempF => $3,
|
||||
iconUrl => $session{config}{extrasURL}.'/wobject/WeatherData/'.$self->_chooseWeatherConditionsIcon($2).'.jpg'
|
||||
};
|
||||
$cache->set($locData, 60*60) if $locData->{cityState};
|
||||
}
|
||||
return $locData;
|
||||
|
||||
# return $cityState.'<br />'.$sky.'<br />'.$ftemp.'°F<br /><img src="'.$iconUrl.'" />';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _chooseWeatherConditionsIcon ( currentSkyConditionsEnglish )
|
||||
|
||||
Accepts a string that represents the current sky conditions. Taken
|
||||
largely from http://www.weather.gov/data/current_obs/weather.php
|
||||
|
||||
=cut
|
||||
|
||||
sub _chooseWeatherConditionsIcon {
|
||||
my $self = shift;
|
||||
my $currCond = shift;
|
||||
if (isIn($currCond,'Mostly Cloudy','Mostly Cloudy with Haze','Mostly Cloudy and Breezy')) {return 'bkn';}
|
||||
if (isIn($currCond,'Fair','Clear','Fair with Haze','Clear with Haze','Fair and Breezy','Clear and Breezy')) {return 'skc';}
|
||||
if (isIn($currCond,'A Few Clouds','A Few Clouds with Haze','A Few Clouds and Breezy')) {return 'few';}
|
||||
if (isIn($currCond,'Partly Cloudy','Party Cloudy with Haze','Partly Cloudy and Breezy')) {return 'sct';}
|
||||
if (isIn($currCond,'Overcast','Overcast with Haze','Overcast and Breezy')) {return 'ovc';}
|
||||
if (isIn($currCond,'Fog/Mist','Fog','Freezing Fog','Shallow Fog','Partial Fog','Patches of Fog','Fog in Vicinity','Freezing Fog in Vicinity','Shallow Fog in Vicinity','Partial Fog in Vicinity','Patches of Fog in Vicinity','Showers in Vicinity Fog','Light Freezing Fog','Heavy Freezing Fog')) {return 'nfg';}
|
||||
if (isIn($currCond,'Smoke')) {return 'smoke';}
|
||||
if (isIn($currCond,'Freezing Rain','Freezing Drizzle','Light Freezing Rain','Light Freezing Drizzle','Heavy Freezing Rain','Heavy Freezing Drizzle','Freezing Rain in Vicinity','Freezing Drizzle in Vicinity')) {return 'fzra';}
|
||||
if (isIn($currCond,'Ice Pellets','Light Ice Pellets','Heavy Ice Pellets','Ice Pellets in Vicinity','Showers Ice Pellets','Thunderstorm Ice Pellets','Ice Crystals','Hail','Small Hail/Snow Pellets','Light Small Hail/Snow Pellets','Heavy Small Hail/Snow Pellets','Showers Hail','Hail Showers')) {return 'ip';}
|
||||
if (isIn($currCond,'Freezing Rain Snow','Light Freezing Rain Snow','Heavy Freezing Rain Snow','Freezing Drizzle Snow','Light Freezing Drizzle Snow','Heavy Freezing Drizzle Snow','Snow Freezing Rain| Light Snow Freezing Rain','Heavy Snow Freezing Rain','Snow Freezing Drizzle','Light Snow Freezing Drizzle','Heavy Snow Freezing Drizzle')) {return 'mix';}
|
||||
if (isIn($currCond,'Rain Ice Pellets','Light Rain Ice Pellets','Heavy Rain Ice Pellets','Drizzle Ice Pellets','Light Drizzle Ice Pellets','Heavy Drizzle Ice Pellets','Ice Pellets Rain','Light Ice Pellets Rain','Heavy Ice Pellets Rain','Ice Pellets Drizzle','Light Ice Pellets Drizzle','Heavy Ice Pellets Drizzle')) {return 'raip';}
|
||||
if (isIn($currCond,'Rain Snow','Light Rain Snow','Heavy Rain Snow','Snow Rain','Light Snow Rain','Heavy Snow Rain','Drizzle Snow','Light Drizzle Snow','Heavy Drizzle Snow','Snow Drizzle','Light Snow Drizzle','Heavy Snow Drizzle')) {return 'rasn';}
|
||||
if (isIn($currCond,'Rain Showers','Light Rain Showers','Heavy Rain Showers','Rain Showers in Vicinity','Light Showers Rain','Heavy Showers Rain','Showers Rain','Showers Rain in Vicinity','Rain Showers Fog/Mist','Light Rain Showers Fog/Mist','Heavy Rain Showers Fog/Mist','Rain Showers in Vicinity Fog/Mist','Light Showers Rain Fog/Mist','Heavy Showers Rain Fog/Mist','Showers Rain Fog/Mist','Showers Rain in Vicinity Fog/Mist')) {return 'shra';}
|
||||
if (isIn($currCond,'Thunderstorm','Light Thunderstorm Rain','Heavy Thunderstorm Rain','Thunderstorm Rain Fog/Mist','Light Thunderstorm Rain Fog/Mist','Heavy Thunderstorm Rain Fog/Mist','Thunderstorm Showers in Vicinity','| Light Thunderstorm Rain Haze','Heavy Thunderstorm Rain Haze','Thunderstorm Fog','Light Thunderstorm Rain Fog','Heavy Thunderstorm Rain Fog','Thunderstorm Light Rain','Thunderstorm Heavy Rain','Thunderstorm Rain Fog/Mist','Thunderstorm Light Rain Fog/Mist','Thunderstorm Heavy Rain Fog/Mist','Thunderstorm in Vicinity Fog/Mist','Thunderstorm Showers in Vicinity','Thunderstorm in Vicinity','Thunderstorm in Vicinity Haze','Thunderstorm Haze in Vicinity','Thunderstorm Light Rain Haze','Thunderstorm Heavy Rain Haze','Thunderstorm Fog','Thunderstorm Light Rain Fog','Thunderstorm Heavy Rain Fog','Thunderstorm Hail','Light Thunderstorm Rain Hail','Heavy Thunderstorm Rain Hail','Thunderstorm Rain Hail Fog/Mist','Light Thunderstorm Rain Hail Fog/Mist','Heavy Thunderstorm Rain Hail Fog/Mist','Thunderstorm Showers in Vicinity Hail','| Light Thunderstorm Rain Hail Haze','Heavy Thunderstorm Rain Hail Haze','Thunderstorm Hail Fog','Light Thunderstorm Rain Hail Fog','Heavy Thunderstorm Rain Hail Fog','Thunderstorm Light Rain Hail','Thunderstorm Heavy Rain Hail','Thunderstorm Rain Hail Fog/Mist','Thunderstorm Light Rain Hail Fog/Mist','Thunderstorm Heavy Rain Hail Fog/Mist','Thunderstorm in Vicinity Hail Fog/Mist','Thunderstorm Showers in Vicinity Hail','Thunderstorm in Vicinity Hail','Thunderstorm in Vicinity Hail Haze','Thunderstorm Haze in Vicinity Hail','Thunderstorm Light Rain Hail Haze','Thunderstorm Heavy Rain Hail Haze','Thunderstorm Hail Fog','Thunderstorm Light Rain Hail Fog','Thunderstorm Heavy Rain Hail Fog','Thunderstorm Small Hail/Snow Pellets','Thunderstorm Rain Small Hail/Snow Pellets','Light Thunderstorm Rain Small Hail/Snow Pellets','Heavy Thunderstorm Rain Small Hail/Snow Pellets')) {return 'tsra';}
|
||||
if (isIn($currCond,'Snow','Light Snow','Heavy Snow','Snow Showers','Light Snow Showers','Heavy Snow Showers','Showers Snow','Light Showers Snow','Heavy Showers Snow','Snow Fog/Mist','Light Snow Fog/Mist','Heavy Snow Fog/Mist','Snow Showers Fog/Mist','Light Snow Showers Fog/Mist','Heavy Snow Showers Fog/Mist','Showers Snow Fog/Mist','Light Showers Snow Fog/Mist','Heavy Showers Snow Fog/Mist','Snow Fog','Light Snow Fog','Heavy Snow Fog','Snow Showers Fog','Light Snow Showers Fog','Heavy Snow Showers Fog','Showers Snow Fog','Light Showers Snow Fog','Heavy Showers Snow Fog','Showers in Vicinity Snow','Snow Showers in Vicinity','Snow Showers in Vicinity Fog/Mist','Snow Showers in Vicinity Fog','Low Drifting Snow','Blowing Snow','Snow Low Drifting Snow','Snow Blowing Snow','Light Snow Low Drifting Snow','Light Snow Blowing Snow','Heavy Snow Low Drifting Snow','Heavy Snow Blowing Snow','Thunderstorm Snow','Light Thunderstorm Snow','Heavy Thunderstorm Snow','Snow Grains','Light Snow Grains','Heavy Snow Grains','Heavy Blowing Snow','Blowing Snow in Vicinity')) {return 'sn';}
|
||||
if (isIn($currCond,'Windy','Fair and Windy','A Few Clouds and Windy','Partly Cloudy and Windy','Mostly Cloudy and Windy','Overcast and Windy')) {return 'wind';}
|
||||
if (isIn($currCond,'Showers in Vicinity','Showers in Vicinity Fog/Mist','Showers in Vicinity Fog','Showers in Vicinity Haze')) {return 'hi_shwrs';}
|
||||
if (isIn($currCond,'Freezing Rain Rain','Light Freezing Rain Rain','Heavy Freezing Rain Rain','Rain Freezing Rain','Light Rain Freezing Rain','Heavy Rain Freezing Rain','Freezing Drizzle Rain','Light Freezing Drizzle Rain','Heavy Freezing Drizzle Rain','Rain Freezing Drizzle','Light Rain Freezing Drizzle','Heavy Rain Freezing Drizzle')) {return 'fzrara';}
|
||||
if (isIn($currCond,'Thunderstorm in Vicinity','Thunderstorm in Vicinity Fog/Mist','Thunderstorm in Vicinity Fog','Thunderstorm Haze in Vicinity','Thunderstorm in Vicinity Haze')) {return 'hi_tsra';}
|
||||
if (isIn($currCond,'Light Rain','Drizzle','Light Drizzle','Heavy Drizzle','Light Rain Fog/Mist','Drizzle Fog/Mist','Light Drizzle Fog/Mist','Heavy Drizzle Fog/Mist','Light Rain Fog','Drizzle Fog','Light Drizzle Fog','Heavy Drizzle Fog')) {return 'ra1';}
|
||||
if (isIn($currCond,'Rain','Heavy Rain','Rain Fog/Mist','Heavy Rain Fog/Mist','Rain Fog','Heavy Rain Fog')) {return 'ra';}
|
||||
if (isIn($currCond,'Funnel Cloud','Funnel Cloud in Vicinity','Tornado/Water Spout')) {return 'nsvrtsra';}
|
||||
if (isIn($currCond,'Dust','Low Drifting Dust','Blowing Dust','Sand','Blowing Sand','Low Drifting Sand','Dust/Sand Whirls','Dust/Sand Whirls in Vicinity','Dust Storm','Heavy Dust Storm','Dust Storm in Vicinity','Sand Storm','Heavy Sand Storm','Sand Storm in Vicinity')) {return 'dust';}
|
||||
if (isIn($currCond,'Haze')) {return 'mist.jpg';}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _na( string )
|
||||
|
||||
If string passed in is empty, returns N/A
|
||||
|
||||
=head3 string
|
||||
|
||||
a string
|
||||
|
||||
=cut
|
||||
|
||||
sub _na {
|
||||
my $str = $_[0];
|
||||
unless($str) {
|
||||
$str = "N/A";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=head2 _trim (str)
|
||||
|
||||
Trims whitespace form front and end of a string
|
||||
|
||||
=head3 str
|
||||
|
||||
a string to trim
|
||||
|
||||
=cut
|
||||
|
||||
sub _trim {
|
||||
my $self = shift;
|
||||
my $str = $_[0];
|
||||
$str =~ s/^\s//;
|
||||
$str =~ s/\s$//;
|
||||
return $str;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
=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->get();
|
||||
#Set some template variables
|
||||
|
||||
#Build list of locations as an array
|
||||
my $defaults = $self->getValue("locations");
|
||||
#replace any windows newlines
|
||||
$defaults =~ s/\r//;
|
||||
my @array = split("\n",$defaults);
|
||||
#trim locations of whitespace
|
||||
for (my $i = 0; $i < scalar(@array); $i++) {
|
||||
$array[$i] = $self->_trim($array[$i]);
|
||||
}
|
||||
my $data = $self->_getLocationData(\@array);
|
||||
|
||||
my @locs = ();
|
||||
foreach my $location (@array) {
|
||||
push (@locs, $self->_getLocationData($location));
|
||||
}
|
||||
$var->{'locations.loop'} = \@locs;
|
||||
return $self->processTemplate($var, $self->get("templateId"));
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue