PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/OA/Dashboard/Widgets/GraphOAP.php

https://github.com/orchestra-io/sample-openx
PHP | 117 lines | 67 code | 21 blank | 29 comment | 5 complexity | 34f613a798357818fcee2afcb9e3efe5 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: GraphOAP.php 47145 2009-12-05 02:27:22Z nick.conrad $
  25. */
  26. require_once MAX_PATH . '/lib/OA/Dashboard/Graph.php';
  27. require_once MAX_PATH . '/lib/OA/Admin/Statistics/Factory.php';
  28. /**
  29. * A dashboard widget to diplay an RSS feed of the OpenX Blog
  30. *
  31. */
  32. class OA_Dashboard_Widget_GraphOAP extends OA_Dashboard_Widget_Graph
  33. {
  34. function OA_Dashboard_Widget_GraphOAP($aParams)
  35. {
  36. parent::OA_Dashboard_Widget_Graph($aParams);
  37. $this->oTpl->setCacheLifetime(new Date_Span('0-3-0-0'));
  38. if ($this->isDataRequired()) {
  39. $this->setData($this->getStats());
  40. }
  41. }
  42. function getCacheId()
  43. {
  44. return array_merge(parent::getCacheId(), array(OA_Permission::getAccountId()));
  45. }
  46. function getStats()
  47. {
  48. // Set time zone to local
  49. OA_setTimeZoneLocal();
  50. $oEnd = new Date();
  51. $oEnd->setHour(0);
  52. $oEnd->setMinute(0);
  53. $oEnd->setSecond(0);
  54. $oEnd->toUTC();
  55. $oStart = new Date($oEnd);
  56. $oStart->subtractSpan(new Date_Span('7-0-0-0'));
  57. $oStart->toUTC();
  58. $doDsah = OA_Dal::factoryDO('data_summary_ad_hourly');
  59. $doDsah->selectAdd();
  60. $doDsah->selectAdd("DATE_FORMAT(date_time, '%Y-%m-%d') AS day");
  61. $doDsah->selectAdd('SUM('.$doDsah->tableName().'.impressions) AS total_impressions');
  62. $doDsah->selectAdd('SUM('.$doDsah->tableName().'.clicks) AS total_clicks');
  63. $doDsah->whereAdd("date_time >= '".$doDsah->escape($oStart->format('%Y-%m-%d %H:%M:%S'))."'");
  64. $doDsah->whereAdd("date_time < '".$doDsah->escape($oEnd->format('%Y-%m-%d %H:%M:%S'))."'");
  65. if (OA_Permission::isAccount(OA_ACCOUNT_MANAGER)) {
  66. $doBanners = OA_Dal::factoryDO('banners');
  67. $doCampaigns = OA_Dal::factoryDO('campaigns');
  68. $doClients = OA_Dal::factoryDO('clients');
  69. $doClients->agencyid = OA_Permission::getEntityId();
  70. $doCampaigns->joinAdd($doClients);
  71. $doBanners->joinAdd($doCampaigns);
  72. $doBanners->selectAdd ();
  73. $doBanners->selectAdd("bannerid");
  74. $doBanners->find();
  75. $ad_ids = array();
  76. while ($doBanners->fetch()) {
  77. $ad_ids[] = $doBanners->bannerid;
  78. }
  79. if (empty ($ad_ids)) {
  80. return array();
  81. }
  82. $doDsah->whereAdd("ad_id IN (".implode (",", $ad_ids).")");
  83. }
  84. $doDsah->groupBy('day');
  85. $doDsah->orderBy('day');
  86. $doDsah->find();
  87. $aStats = array();
  88. while ($doDsah->fetch()) {
  89. $row = $doDsah->toArray();
  90. $aStats[0][date('D', strtotime($row['day']))] = $row['total_impressions'];
  91. $aStats[1][date('D', strtotime($row['day']))] = $row['total_clicks'];
  92. }
  93. return $aStats;
  94. }
  95. }
  96. ?>