1
0

BxDolReportQuery.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentCore Trident Core
  7. * @{
  8. */
  9. /**
  10. * @see BxDolReport
  11. */
  12. class BxDolReportQuery extends BxDolObjectQuery
  13. {
  14. public function __construct(&$oModule)
  15. {
  16. parent::__construct($oModule);
  17. $this->_sMethodGetEntry = 'getReport';
  18. }
  19. public function getSqlParts($sMainTable, $sMainField)
  20. {
  21. $aResult = parent::getSqlParts($sMainTable, $sMainField);
  22. if(empty($aResult))
  23. return $aResult;
  24. $aResult['fields'] = ", `{$this->_sTable}`.`count` as `report_count` ";
  25. return $aResult;
  26. }
  27. public function getPerformedBy($iObjectId)
  28. {
  29. $sQuery = $this->prepare("SELECT `author_id`, `type`, `text` FROM `{$this->_sTableTrack}` WHERE `object_id`=?", $iObjectId);
  30. return $this->getAll($sQuery);
  31. }
  32. public function getReport($iObjectId)
  33. {
  34. $sQuery = $this->prepare("SELECT `count` as `count` FROM {$this->_sTable} WHERE `object_id` = ? LIMIT 1", $iObjectId);
  35. $aResult = $this->getRow($sQuery);
  36. if(empty($aResult) || !is_array($aResult))
  37. $aResult = array('count' => 0);
  38. return $aResult;
  39. }
  40. public function putReport($iObjectId)
  41. {
  42. $sQuery = $this->prepare("SELECT `object_id` FROM `{$this->_sTable}` WHERE `object_id` = ? LIMIT 1", $iObjectId);
  43. $bExists = (int)$this->getOne($sQuery) != 0;
  44. if(!$bExists)
  45. $sQuery = $this->prepare("INSERT INTO {$this->_sTable} SET `object_id` = ?, `count` = '1'", $iObjectId);
  46. else
  47. $sQuery = $this->prepare("UPDATE `{$this->_sTable}` SET `count` = `count` + 1 WHERE `object_id` = ?", $iObjectId);
  48. return (int)$this->query($sQuery) != 0;
  49. }
  50. }
  51. /** @} */