PageRenderTime 26ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/OA/Dal/Statistics/Advertiser.php

https://bitbucket.org/blackriver/openx
PHP | 371 lines | 198 code | 31 blank | 142 comment | 0 complexity | a2ed2a323e07bac68757c7bd0d0e546d MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  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:$
  25. */
  26. /**
  27. * @package OpenXDal
  28. * @subpackage Statistics
  29. * @author Ivan Klishch <iklishch@lohika.com>
  30. *
  31. */
  32. // Required classes
  33. require_once MAX_PATH . '/lib/OA/Dal/Statistics.php';
  34. /**
  35. * The Data Abstraction Layer (DAL) class for statistics for Advertiser.
  36. */
  37. class OA_Dal_Statistics_Advertiser extends OA_Dal_Statistics
  38. {
  39. /**
  40. * This method returns statistics for a given advertiser, broken down by day.
  41. *
  42. * @access public
  43. *
  44. * @param integer $advertiserId The ID of the advertiser to view statistics
  45. * @param date $oStartDate The date from which to get statistics (inclusive)
  46. * @param date $oEndDate The date to which to get statistics (inclusive)
  47. * @param bool $localTZ Should stats be using the manager TZ or UTC?
  48. *
  49. * @return array Each row containing:
  50. * <ul>
  51. * <li><b>day date</b> The day
  52. * <li><b>requests integer</b> The number of requests for the day
  53. * <li><b>impressions integer</b> The number of impressions for the day
  54. * <li><b>clicks integer</b> The number of clicks for the day
  55. * <li><b>revenue decimal</b> The revenue earned for the day
  56. * </ul>
  57. *
  58. */
  59. function getAdvertiserDailyStatistics($advertiserId, $oStartDate, $oEndDate, $localTZ = false)
  60. {
  61. $advertiserId = $this->oDbh->quote($advertiserId, 'integer');
  62. $tableClients = $this->quoteTableName('clients');
  63. $tableCampaigns = $this->quoteTableName('campaigns');
  64. $tableBanners = $this->quoteTableName('banners');
  65. $tableSummary = $this->quoteTableName('data_summary_ad_hourly');
  66. $query = "
  67. SELECT
  68. SUM(s.impressions) AS impressions,
  69. SUM(s.clicks) AS clicks,
  70. SUM(s.requests) AS requests,
  71. SUM(s.total_revenue) AS revenue,
  72. DATE_FORMAT(s.date_time, '%Y-%m-%d') AS day,
  73. HOUR(s.date_time) AS hour
  74. FROM
  75. $tableClients AS c,
  76. $tableCampaigns AS m,
  77. $tableBanners AS b,
  78. $tableSummary AS s
  79. WHERE
  80. c.clientid = $advertiserId
  81. AND
  82. c.clientid = m.clientid
  83. AND
  84. m.campaignid = b.campaignid
  85. AND
  86. b.bannerid = s.ad_id
  87. " . $this->getWhereDate($oStartDate, $oEndDate, $localTZ) . "
  88. GROUP BY
  89. day,
  90. hour
  91. ";
  92. return $this->getDailyStatsAsArray($query, $localTZ);
  93. }
  94. /**
  95. * This method returns statistics for a given advertiser, broken down by campaign.
  96. *
  97. * @access public
  98. *
  99. * @param integer $advertiserId The ID of the advertiser to view statistics
  100. * @param date $oStartDate The date from which to get statistics (inclusive)
  101. * @param date $oEndDate The date to which to get statistics (inclusive)
  102. * @param bool $localTZ Should stats be using the manager TZ or UTC?
  103. *
  104. * @return RecordSet
  105. * <ul>
  106. * <li><b>campaignID integer</b> The ID of the campaign
  107. * <li><b>campaignName string (255)</b> The name of the campaign
  108. * <li><b>requests integer</b> The number of requests for the day
  109. * <li><b>impressions integer</b> The number of impressions for the day
  110. * <li><b>clicks integer</b> The number of clicks for the day
  111. * <li><b>revenue decimal</b> The revenue earned for the day
  112. * </ul>
  113. *
  114. */
  115. function getAdvertiserCampaignStatistics($advertiserId, $oStartDate, $oEndDate, $localTZ = false)
  116. {
  117. $advertiserId = $this->oDbh->quote($advertiserId, 'integer');
  118. $tableClients = $this->quoteTableName('clients');
  119. $tableCampaigns = $this->quoteTableName('campaigns');
  120. $tableBanners = $this->quoteTableName('banners');
  121. $tableSummary = $this->quoteTableName('data_summary_ad_hourly');
  122. $query = "
  123. SELECT
  124. SUM(s.impressions) AS impressions,
  125. SUM(s.clicks) AS clicks,
  126. SUM(s.requests) AS requests,
  127. SUM(s.total_revenue) AS revenue,
  128. m.campaignid AS campaignID,
  129. m.campaignname AS campaignName
  130. FROM
  131. $tableClients AS c,
  132. $tableCampaigns AS m,
  133. $tableBanners AS b,
  134. $tableSummary AS s
  135. WHERE
  136. c.clientid = $advertiserId
  137. AND
  138. c.clientid = m.clientid
  139. AND
  140. m.campaignid = b.campaignid
  141. AND
  142. b.bannerid = s.ad_id
  143. " . $this->getWhereDate($oStartDate, $oEndDate, $localTZ) . "
  144. GROUP BY
  145. m.campaignid, m.campaignname
  146. ";
  147. return DBC::NewRecordSet($query);
  148. }
  149. /**
  150. * This method returns statistics for a given advertiser, broken down by banner.
  151. *
  152. * @access public
  153. *
  154. * @param integer $advertiserId The ID of the advertiser to view statistics
  155. * @param date $oStartDate The date from which to get statistics (inclusive)
  156. * @param date $oEndDate The date to which to get statistics (inclusive)
  157. * @param bool $localTZ Should stats be using the manager TZ or UTC?
  158. *
  159. * @return RecordSet
  160. * <ul>
  161. * <li><b>campaignID integer</b> The ID of the campaign
  162. * <li><b>campaignName string (255)</b> The name of the campaign
  163. * <li><b>bannerID integer</b> The ID of the banner
  164. * <li><b>bannerName string (255)</b> The name of the banner
  165. * <li><b>requests integer</b> The number of requests for the day
  166. * <li><b>impressions integer</b> The number of impressions for the day
  167. * <li><b>clicks integer</b> The number of clicks for the day
  168. * <li><b>revenue decimal</b> The revenue earned for the day
  169. * </ul>
  170. *
  171. */
  172. function getAdvertiserBannerStatistics($advertiserId, $oStartDate, $oEndDate, $localTZ = false)
  173. {
  174. $advertiserId = $this->oDbh->quote($advertiserId, 'integer');
  175. $tableClients = $this->quoteTableName('clients');
  176. $tableCampaigns = $this->quoteTableName('campaigns');
  177. $tableBanners = $this->quoteTableName('banners');
  178. $tableSummary = $this->quoteTableName('data_summary_ad_hourly');
  179. $query = "
  180. SELECT
  181. SUM(s.impressions) AS impressions,
  182. SUM(s.clicks) AS clicks,
  183. SUM(s.requests) AS requests,
  184. SUM(s.total_revenue) AS revenue,
  185. m.campaignid AS campaignID,
  186. m.campaignname AS campaignName,
  187. b.bannerid AS bannerID,
  188. b.description AS bannerName
  189. FROM
  190. $tableClients AS c,
  191. $tableCampaigns AS m,
  192. $tableBanners AS b,
  193. $tableSummary AS s
  194. WHERE
  195. c.clientid = $advertiserId
  196. AND
  197. c.clientid = m.clientid
  198. AND
  199. m.campaignid = b.campaignid
  200. AND
  201. b.bannerid = s.ad_id
  202. " . $this->getWhereDate($oStartDate, $oEndDate, $localTZ) . "
  203. GROUP BY
  204. b.bannerid, b.description, m.campaignid, m.campaignname
  205. ";
  206. return DBC::NewRecordSet($query);
  207. }
  208. /**
  209. * This method returns statistics for a given advertiser, broken down by publisher.
  210. *
  211. * @access public
  212. *
  213. * @param integer $advertiserId The ID of the advertiser to view statistics
  214. * @param date $oStartDate The date from which to get statistics (inclusive)
  215. * @param date $oEndDate The date to which to get statistics (inclusive)
  216. * @param bool $localTZ Should stats be using the manager TZ or UTC?
  217. *
  218. * @return RecordSet
  219. * <ul>
  220. * <li><b>publisherID integer</b> The ID of the publisher
  221. * <li><b>publisherName string (255)</b> The name of the publisher
  222. * <li><b>requests integer</b> The number of requests for the day
  223. * <li><b>impressions integer</b> The number of impressions for the day
  224. * <li><b>clicks integer</b> The number of clicks for the day
  225. * <li><b>revenue decimal</b> The revenue earned for the day
  226. * </ul>
  227. *
  228. */
  229. function getAdvertiserPublisherStatistics($advertiserId, $oStartDate, $oEndDate, $localTZ = false)
  230. {
  231. $advertiserId = $this->oDbh->quote($advertiserId, 'integer');
  232. $tableClients = $this->quoteTableName('clients');
  233. $tableCampaigns = $this->quoteTableName('campaigns');
  234. $tableBanners = $this->quoteTableName('banners');
  235. $tableSummary = $this->quoteTableName('data_summary_ad_hourly');
  236. $tableZones = $this->quoteTableName('zones');
  237. $tableAffiliates = $this->quoteTableName('affiliates');
  238. $query = "
  239. SELECT
  240. SUM(s.impressions) AS impressions,
  241. SUM(s.clicks) AS clicks,
  242. SUM(s.requests) AS requests,
  243. SUM(s.total_revenue) AS revenue,
  244. p.affiliateid AS publisherID,
  245. p.name AS publisherName
  246. FROM
  247. $tableClients AS c,
  248. $tableCampaigns AS m,
  249. $tableBanners AS b,
  250. $tableZones AS z,
  251. $tableAffiliates AS p,
  252. $tableSummary AS s
  253. WHERE
  254. c.clientid = $advertiserId
  255. AND
  256. c.clientid = m.clientid
  257. AND
  258. m.campaignid = b.campaignid
  259. AND
  260. b.bannerid = s.ad_id
  261. AND
  262. p.affiliateid = z.affiliateid
  263. AND
  264. z.zoneid = s.zone_id
  265. " . $this->getWhereDate($oStartDate, $oEndDate, $localTZ) . "
  266. GROUP BY
  267. p.affiliateid, p.name
  268. ";
  269. return DBC::NewRecordSet($query);
  270. }
  271. /**
  272. * This method returns statistics for a given advertiser, broken down by zone.
  273. *
  274. * @access public
  275. *
  276. * @param integer $advertiserId The ID of the advertiser to view statistics
  277. * @param date $oStartDate The date from which to get statistics (inclusive)
  278. * @param date $oEndDate The date to which to get statistics (inclusive)
  279. * @param bool $localTZ Should stats be using the manager TZ or UTC?
  280. *
  281. * @return RecordSet
  282. * <ul>
  283. * <li><b>publisherID integer</b> The ID of the publisher
  284. * <li><b>publisherName string (255)</b> The name of the publisher
  285. * <li><b>zoneID integer</b> The ID of the zone
  286. * <li><b>zoneName string (255)</b> The name of the zone
  287. * <li><b>requests integer</b> The number of requests for the day
  288. * <li><b>impressions integer</b> The number of impressions for the day
  289. * <li><b>clicks integer</b> The number of clicks for the day
  290. * <li><b>revenue decimal</b> The revenue earned for the day
  291. * </ul>
  292. *
  293. */
  294. function getAdvertiserZoneStatistics($advertiserId, $oStartDate, $oEndDate, $localTZ = false)
  295. {
  296. $advertiserId = $this->oDbh->quote($advertiserId, 'integer');
  297. $tableClients = $this->quoteTableName('clients');
  298. $tableCampaigns = $this->quoteTableName('campaigns');
  299. $tableBanners = $this->quoteTableName('banners');
  300. $tableSummary = $this->quoteTableName('data_summary_ad_hourly');
  301. $tableZones = $this->quoteTableName('zones');
  302. $tableAffiliates = $this->quoteTableName('affiliates');
  303. $query = "
  304. SELECT
  305. SUM(s.impressions) AS impressions,
  306. SUM(s.clicks) AS clicks,
  307. SUM(s.requests) AS requests,
  308. SUM(s.total_revenue) AS revenue,
  309. p.affiliateid AS publisherID,
  310. p.name AS publisherName,
  311. z.zoneid AS zoneID,
  312. z.zonename AS zoneName
  313. FROM
  314. $tableClients AS c,
  315. $tableCampaigns AS m,
  316. $tableBanners AS b,
  317. $tableZones AS z,
  318. $tableAffiliates AS p,
  319. $tableSummary AS s
  320. WHERE
  321. c.clientid = $advertiserId
  322. AND
  323. c.clientid = m.clientid
  324. AND
  325. m.campaignid = b.campaignid
  326. AND
  327. b.bannerid = s.ad_id
  328. AND
  329. p.affiliateid = z.affiliateid
  330. AND
  331. z.zoneid = s.zone_id
  332. " . $this->getWhereDate($oStartDate, $oEndDate, $localTZ) . "
  333. GROUP BY
  334. p.affiliateid, p.name,
  335. z.zoneid, z.zonename
  336. ";
  337. return DBC::NewRecordSet($query);
  338. }
  339. }
  340. ?>