Author: ornicar2
Date: 2010-02-03 12:44:12 +0100 (Wed, 03 Feb 2010)
New Revision: 27482
Modified:
plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmLogChart.php
plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmVisitChart.php
plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmChart.php
plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmGaChart.php
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/actions/actions.class.php
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/templates/indexSuccess.php
Log:
[Diem]
- fixed visit chart
- improved admin charts module performances
Modified: plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmLogChart.php
===================================================================
--- plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmLogChart.php
2010-02-03 10:42:08 UTC (rev 27481)
+++ plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmLogChart.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -6,11 +6,6 @@
$eventsFilter = array(
'clear cache'
);
-
- protected function configure()
- {
-// $this->options['lifetime'] = 1;
- }
protected function draw()
{
Modified: plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmVisitChart.php
===================================================================
--- plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmVisitChart.php
2010-02-03 10:42:08 UTC (rev 27481)
+++ plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/dmVisitChart.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -2,6 +2,7 @@
class dmVisitChart extends dmGaChart
{
+
protected function draw()
{
$this->choosePalette('diem');
@@ -23,7 +24,7 @@
// Draw the pageviews graph
$dataSet->AddSerie("pageviews");
$dataSet->SetYAxisName("Pages");
-
$this->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_START0,
self::$colors['grey2'][0], self::$colors['grey2'][1],
self::$colors['grey2'][2],TRUE,0,0, false, 3);
+
$this->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_START0,
self::$colors['grey2'][0], self::$colors['grey2'][1],
self::$colors['grey2'][2],TRUE,0,0, false, 2);
$this->drawGrid(4,TRUE, self::$colors['grey1'][0],
self::$colors['grey1'][1], self::$colors['grey1'][2]);
$this->setShadowProperties(3,3,0,0,0,30,4);
$this->drawCubicCurve($dataSet->GetData(),$dataSet->GetDataDescription());
@@ -33,12 +34,12 @@
// Clear the scale
$this->clearScale();
-
+
// Draw the 2nd graph
$dataSet->RemoveAllSeries();
$dataSet->AddSerie("visitors");
$dataSet->SetYAxisName("Visitors");
-
$this->drawRightScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_START0,
self::$colors['grey2'][0], self::$colors['grey2'][1],
self::$colors['grey2'][2],TRUE,0,0, false, 3);
+
$this->drawRightScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_START0,
self::$colors['grey2'][0], self::$colors['grey2'][1],
self::$colors['grey2'][2],TRUE,0,0, false, 2);
$this->setShadowProperties(3,3,0,0,0,30,4);
$this->drawCubicCurve($dataSet->GetData(),$dataSet->GetDataDescription());
$this->clearShadow();
@@ -51,15 +52,19 @@
protected function getData()
{
- if (!$data = $this->getCache('data'))
+ if (!$this->options['use_cache'] || !$data = $this->getCache('data'))
{
+ $to = mktime(0, 0, 0, date('m'), 0, date('Y'));
+ $from = strtotime('-12 month', $to);
+
$report = $this->gapi->getReport(array(
- 'dimensions' => array('month', 'year'),
- 'metrics' => array('pageviews', 'visits')
+ 'dimensions' => array('year', 'month'),
+ 'metrics' => array('pageviews', 'visits'),
+ 'sort_metric' => 'year,ga:month',
+ 'start_date' => date('Y-m-d', $from),
+ 'end_date' => date('Y-m-d', $to)
));
- // dmDebug::kill($report);
-
$data = array(
'dates' => array(),
'pageviews' => array(),
@@ -68,10 +73,11 @@
foreach($report as $entry)
{
- $data['dates'][] = $entry->get('month').'/'.$entry->get('year');
+ $data['dates'][] =
$entry->get('month').'/'.substr($entry->get('year'), -2);
$data['pageviews'][] = $entry->get('pageviews');
$data['visitors'][] = $entry->get('visits');
}
+
$this->setCache('data', $data);
}
Modified: plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmChart.php
===================================================================
--- plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmChart.php
2010-02-03 10:42:08 UTC (rev 27481)
+++ plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmChart.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -16,9 +16,7 @@
$serviceContainer,
$cacheKey = '',
$data,
- $name,
- $available = true,
- $credentials;
+ $available = true;
function __construct(dmBaseServiceContainer $serviceContainer, array
$options = array())
{
@@ -28,7 +26,7 @@
parent::pChart($this->getWidth(), $this->getHeight());
- $this->setup();
+ $this->initialize($options);
}
public function isAvailable()
@@ -36,8 +34,10 @@
return $this->available;
}
- protected function setup()
+ protected function initialize(array $options)
{
+ $this->configure($options);
+
$this->addToCacheKey($this->options);
$this->setFontProperties("Fonts/tahoma.ttf", 10);
@@ -47,13 +47,11 @@
$reflection = new ReflectionClass(get_class($this));
$this->addToCacheKey(filemtime($reflection->getFilename()));
}
-
- $this->configure();
}
- protected function configure()
+ protected function configure(array $options)
{
- // override me
+ $this->options = array_merge($this->getDefaultOptions(), $options);
}
protected function getCache($name)
@@ -88,7 +86,7 @@
$imageFullPath = dmOs::join(sfConfig::get('sf_web_dir'), 'cache', $image);
- if (!file_exists($imageFullPath))
+ if (!$this->options['use_cache'] || !file_exists($imageFullPath))
{
if
(!$this->serviceContainer->getService('filesystem')->mkdir(dirname($imageFullPath)))
{
@@ -115,7 +113,8 @@
'name' => get_class($this),
'key' => preg_replace('|(\w+)Chart|', '$1', get_class($this)),
'credentials' => 'see_chart',
- 'lifetime' => 60 * 60 * 24
+ 'lifetime' => 60 * 60 * 24,
+ 'use_cache' => true
);
}
Modified: plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmGaChart.php
===================================================================
--- plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmGaChart.php
2010-02-03 10:42:08 UTC (rev 27481)
+++ plugins/diemPlugin/trunk/dmAdminPlugin/lib/chart/generic/dmGaChart.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -5,7 +5,7 @@
protected
$gapi;
- protected function setup()
+ protected function initialize(array $options)
{
try
{
@@ -21,7 +21,7 @@
}
}
- parent::setup();
+ parent::initialize($options);
}
protected function reportToData($report, array $keys)
Modified:
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/actions/actions.class.php
===================================================================
---
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/actions/actions.class.php
2010-02-03 10:42:08 UTC (rev 27481)
+++
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/actions/actions.class.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -2,27 +2,6 @@
class dmChartActions extends dmAdminBaseActions
{
- protected function getCharts()
- {
- $charts = array();
-
- $sc = $this->context->getServiceContainer();
-
- foreach($sc->getServiceIds() as $serviceId)
- {
- if (substr($serviceId, -6) === '_chart')
- {
- $chart = $sc->getService($serviceId);
-
- if ($chart instanceof dmChart)
- {
- $charts[substr($serviceId, 0, strlen($serviceId)-6)] = $chart;
- }
- }
- }
-
- return $charts;
- }
public function executeImage(dmWebRequest $request)
{
@@ -50,7 +29,20 @@
public function executeIndex(dmWebRequest $request)
{
- $this->charts = $this->getCharts();
+ $this->charts = array();
+
+ foreach($this->getServiceContainer()->getServiceIds() as $serviceId)
+ {
+ if (substr($serviceId, -6) === '_chart')
+ {
+ $reflection = new
ReflectionClass($this->getServiceContainer()->getParameter($serviceId.'.class'));
+
+ if ($reflection->isSubClassOf('dmChart'))
+ {
+ $this->charts[substr($serviceId, 0, strlen($serviceId)-6)] =
$this->getServiceContainer()->getParameter($serviceId.'.options');
+ }
+ }
+ }
$this->selectedIndex = array_search($request->getParameter('name'),
array_keys($this->charts));
}
Modified:
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/templates/indexSuccess.php
===================================================================
---
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/templates/indexSuccess.php
2010-02-03 10:42:08 UTC (rev 27481)
+++
plugins/diemPlugin/trunk/dmAdminPlugin/modules/dmChart/templates/indexSuccess.php
2010-02-03 11:44:12 UTC (rev 27482)
@@ -5,11 +5,11 @@
)));
echo _open('ul');
-foreach($charts as $chartKey => $chart)
+foreach($charts as $chartKey => $options)
{
echo _tag('li',
_link('@dm_chart?action=show&name='.$chartKey)
- ->text(__($chart->getName()))
+ ->text(__($options['name']))
->set('.dm_chart_link')
);
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.