Skip to content

Commit

Permalink
addng open flash cahrt wdget rework
Browse files Browse the repository at this point in the history
  • Loading branch information
padams committed Aug 24, 2008
1 parent 4f50949 commit 5e68926
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 90 deletions.
30 changes: 23 additions & 7 deletions modules/base/dashboardTrendWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function action() {
$m->setConstraint('is_browser', 1);
$m->setPeriod($this->params['period']);
$m->setOrder(OWA_SQL_ASCENDING);
$results = $m->generate();


if (array_key_exists('format', $this->params)):
$format = $this->params['format'];
Expand All @@ -50,31 +50,47 @@ function action() {
endif;

$data['title'] = 'Dashboard Trend';
$data['view'] = 'base.widget';
$data['y']['label'] = 'Page Views';
$data['y2']['label'] = 'Visits';
$data['x']['label'] = 'Day';
$data['params'] = $this->params;
$data['widget'] = 'base.dashboardTrendWidget';

switch ($format) {

case 'graph':

$data['view'] = 'base.openFlashChart';
$data['height'] = $this->params['height'];
$data['width'] = $this->params['width'];
break;

case 'graph-data':
$results = $m->generate();
$series = owa_lib::deconstruct_assoc($results);
$data['y']['label'] = 'Page Views';
$data['y2']['label'] = 'Visits';
$data['x']['label'] = 'Day';
$data['y']['series'] = $series['page_views'];
$data['y2']['series'] = $series['sessions'];
$data['x']['series'] = owa_lib::makeDateArray($results, "n/j");
$data['view'] = 'base.areaBarsFlashChart';
break;

case 'table':
$data['column_labels'] = array();
$data['data'] = '';
$m->setLimit(5);
$results = $m->generate();
$data['labels'] = $m->getLabels();
$data['rows'] = $results;
$data['view'] = 'base.genericTable';
break;


}

if ($this->params['initial-view'] == true):
$data['subview'] = $data['view'];
$data['view'] = 'base.widget';
endif;


return $data;

}
Expand Down
38 changes: 13 additions & 25 deletions modules/base/metrics/dashCoreByDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ class owa_dashCoreByDay extends owa_metric {

function owa_dashCoreByDay($params = null) {

$this->params = $params;
return owa_dashCoreByDay::__construct($params);

}

function __construct($params = null) {

parent::__construct($params);

$this->owa_metric();
$this->setLabels(array('Month', 'Day', 'Year', 'Unique Visitors', 'Sessions', 'Page Views'));

return;

Expand All @@ -61,32 +67,14 @@ function calculate() {
$db->orderBy('month');
$db->orderBy('day');

if (array_key_exists('limit', $this->params)):
$db->limit($this->params['limit']);
endif;

$ret = $db->getAllRows();

return $ret;


/*
$this->params['select'] = "session.month,
session.day,
session.year,
count(distinct session.visitor_id) as unique_visitors,
count(session.id) as sessions,
sum(session.num_pageviews) as page_views ";
$this->params['groupby'] = array('day', 'month');
$this->params['orderby'] = array('year', 'month', 'day');
$this->setTimePeriod($this->params['period']);
$s = owa_coreAPI::entityFactory('base.session');
return $s->query($this->params);
*/

}


Expand Down
32 changes: 8 additions & 24 deletions modules/base/metrics/dashCoreByMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class owa_dashCoreByMonth extends owa_metric {

function owa_dashCoreByMonth($params = null) {

$this->params = $params;
return owa_dashCoreByMonth::__construct($params);

$this->owa_metric();
}

function __construct($params = null) {

parent::__construct($params);

$this->setLabels(array('Month', 'Day', 'Year', 'Unique Visitors', 'Sessions', 'Page Views'));

return;

}
Expand All @@ -60,28 +66,6 @@ function calculate() {

return $db->getAllRows();

/*
$this->params['select'] = "session.month,
session.day,
session.year,
count(distinct session.visitor_id) as unique_visitors,
count(session.id) as sessions,
sum(session.num_pageviews) as page_views ";
$this->params['use_summary'] = true;
$this->params['groupby'] = array('month', 'year');
$this->params['orderby'] = array('year', 'month');
$this->setTimePeriod($this->params['period']);
$s = owa_coreAPI::entityFactory('base.session');
return $s->query($this->params);
*/
}


Expand Down
14 changes: 14 additions & 0 deletions modules/base/templates/generic_table.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<TABLE class="generic-data-table">
<TR>
<?php foreach ($labels as $label): ?>
<TH><?=$label;?></TH>
<?php endforeach;?>
</TR>
<?php foreach ($rows as $row): ?>
<TR>
<?php foreach ($row as $item): ?>
<TD><?=$item;?></TD>
<?php endforeach;?>
</TR>
<?php endforeach;?>
</TABLE>
1 change: 1 addition & 0 deletions modules/base/templates/ofc.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?=$this->ofc($width, $height, $this->makeAbsoluteLink(array('do' => $widget, 'period' => 'last_thirty_days', 'site_id' => $params['site_id'], 'format' => 'graph-data'), false , $this->config['action_url'])); ?>
5 changes: 4 additions & 1 deletion modules/base/templates/report_dashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
#recent_visitors{width:; margin-left: px}
</style>
<script type="text/javascript" src="<?=$this->config['public_url'];?>js/includes/jquery/jquery.js"></script>
<? include('report_header.tpl');?>
<table width="100%">
<TR>
<TD valign="top" id="trend_graph">
<img src="<?=$this->graphLink(array('view' => 'base.graphDashboardTrend', 'period' => 'last_thirty_days', 'site_id' => $params['site_id'])); ?>">
<!-- <img src="<?=$this->graphLink(array('view' => 'base.graphDashboardTrend', 'period' => 'last_thirty_days', 'site_id' => $params['site_id'])); ?>"> -->
<?=$this->getWidget('base.dashboardTrendWidget', 'graph', array('height' => 300, 'width' => 900));?>
<? //$this->getWidget('base.dashboardTrendWidget', 'table', array('height' => 300, 'width' => 900));?>
</TD>
</TR>
<TR>
Expand Down
75 changes: 66 additions & 9 deletions modules/base/templates/widget.tpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,73 @@
<div style="border: 2px solid red;">
<style>
<div id="flash-graph" style="visiblity:;">
.widget-container {border:1px solid #cccccc; width:100%;}
.widget-header {color: white;background-color:orange; padding:10px;text-align:left; font-weight:bold; font-size:18px;}
.widget-title {font-size:20px;text-align:right;}
.widget-title a {color: white;}
.widget-title-controls {font-size:14px;text-align:right;}
.widget-controls {text-align:right;padding:10px}
.widget-content {padding:10px;}
<?=$this->ofc($params['width'], $params['height'], $this->makeAbsoluteLink(array('do' => $widget, 'period' => 'last_thirty_days', 'site_id' => $params['site_id'], 'format' => $format), false , $this->config['action_url'])); ?>
</style>

</div>

<div id="data-table"></div>
<div id="data-export"></div>
<script>
var state = new Object;
state['<?=$widget;?>'] = new Object;
state['<?=$widget;?>'].url = "http://wp25-php5-test.openwebanalytics.com/index.php?owa_specialAction&owa_do=base.dashboardTrendWidget&owa_period=last_thirty_days&owa_format=";
</div>
</script>

<script>
<script>
//var widgeturl = "http://wp25-php5-test.openwebanalytics.com/index.php?owa_specialAction&owa_do=base.dashboardTrendWidget&owa_period=last_thirty_days&owa_format=";
var widgeturl = state['<?=$widget;?>'].url;
// When the document loads do everything inside here ...
jQuery(document).ready(function(){
//$('#content').load('boo.php'); //by default initally load text from boo.php
jQuery('.widget-control').click(function() { //start function when any link is clicked
var parentname = jQuery("div").parent(".widget-container").attr("id");
var widgetname2 = parentname.split("_");
var widgetname = widgetname2[0];
var widgetcontentid = "#"+widgetname+"_widget-content";
var format = jQuery(this).attr("name");
//alert(widgetcontentid);
jQuery(widgetcontentid).slideUp("slow");
//var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file
jQuery.ajax({
method: "get",url: widgeturl+format,
beforeSend: function(){ jQuery(".widget-status").show("fast");}, //show loading just when link is clicked
complete: function(){ jQuery(".widget-status").hide("fast");}, //stop showing loading when the process is complete
success: function(html){ //so, if data is retrieved, store it in html
jQuery(widgetcontentid).show("slow"); //animation
jQuery(widgetcontentid).html(html); //show the html inside .content div
}
}); //close $.ajax(
}); //close click(
}); //close $(
</script>
<div id="<?=$widget;?>_widget-container" class="widget-container">
</script>
<div id="<?=$widget;?>_widget-header"class="widget-header">
<span class="widget-title"><?=$title;?></span>
<div id="<?=$widget;?>_widget-title-controls" style="float:right;">
<span class="widget-title-controls"><a href="">Close</a></span>
</div>
</div>
<div id="<?=$widget;?>_widget-status" class="widget-status">LOADING</div>
<div id="<?=$widget;?>_widget-content" class="widget-content"><?=$subview;?></div>
<div id="<?=$widget;?>_widget-controls" class="widget-controls">
<a class="widget-control" href="#base-dashboardTrendWidget_widget-header" name="graph">Graph</a> |
<a class="widget-control" href="#base-dashboardTrendWidget_widget-header" name="table">Table</a> |
<a class="widget-control" href="#base-dashboardTrendWidget_widget-header" name="sparkline">Sparkline</a>
</div>
</div>
13 changes: 7 additions & 6 deletions modules/base/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,25 @@ function construct($data) {

// load template

if ($data['is_external'] == true):
if ($data['params']['is_external'] == true):
$this->t->set_template('wrapper_widget.tpl');
else:
$this->t->set_template('wrapper_blank.tpl');
endif;

if (!array_key_exists('width', $data)):
$data['width'] = 300;
$data['params']['width'] = 300;
endif;

if (!array_key_exists('width', $data)):
$data['height'] = 250;
$data['params']['height'] = 250;
endif;

$this->body->set_template('widget.tpl');
$this->body->set('format', $data['format']);
$this->body->set('widget', $data['widget']);
$this->body->set('params', $data['params']);
$this->body->set('format', $data['params']['format']);
$this->body->set('widget', str_replace('.', '-', $data['widget']));
$this->body->set('params', $data['params']['params']);
$this->body->set('title', $data['title']);
return;
}

Expand Down
8 changes: 7 additions & 1 deletion owa_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ class owa_base {
*/
function owa_base() {

return owa_base::__construct();

}

function __construct() {

$this->e = &owa_coreAPI::errorSingleton();
$this->c = &owa_coreAPI::configSingleton();
$this->config = &$this->c->fetch('base');

return;

}

/**
Expand Down
4 changes: 2 additions & 2 deletions owa_coreAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function moduleFactory($modulefile, $class_suffix = null, $params = '', $class_n

list($module, $file) = split("\.", $modulefile);
$class = $class_ns.$file.$class_suffix;

//print $class;
// Require class file if class does not already exist
if(!class_exists($class)):
owa_coreAPI::moduleRequireOnce($module, '', $file);
Expand Down Expand Up @@ -368,7 +368,7 @@ function subViewFactory($subview, $params = array()) {

list($module, $class) = split("\.", $subview);

owa_lib::moduleRequireOnce($module, $class);
//owa_lib::moduleRequireOnce($module, $class);

$subview = owa_lib::moduleFactory($module, $class.'View', $params);
$subview->is_subview = true;
Expand Down
Loading

0 comments on commit 5e68926

Please sign in to comment.