BxTasksTimeQuery.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. * @defgroup Tasks Tasks
  6. * @ingroup UnaModules
  7. *
  8. * @{
  9. */
  10. class BxTasksTimeQuery extends BxDolReportQuery
  11. {
  12. public function __construct(&$oModule)
  13. {
  14. parent::__construct($oModule);
  15. }
  16. public function getReport($iObjectId)
  17. {
  18. $aResult = $this->getRow("SELECT `count` as `count`, `sum` AS `sum` FROM `{$this->_sTable}` WHERE `object_id` = :object_id LIMIT 1", ['object_id' => $iObjectId]);
  19. if(empty($aResult) || !is_array($aResult))
  20. $aResult = ['count' => 0, 'sum' => 0];
  21. return $aResult;
  22. }
  23. public function updateReport($iObjectId, $iValue, $bUndo = false)
  24. {
  25. return (int)$this->query("UPDATE `{$this->_sTable}` SET `sum` = `sum` " . ($bUndo ? "-" : "+") . " :value WHERE `object_id` = :object_id", [
  26. 'object_id' => $iObjectId,
  27. 'value' => $iValue
  28. ]) != 0;
  29. }
  30. /**
  31. * Note. Tracks shouldn't be deleted on Undo.
  32. *
  33. * @see BxDolReportQuery::putReport
  34. */
  35. protected function _deleteTrack($iObjectId, $iAuthorId)
  36. {
  37. return true;
  38. }
  39. protected function _updateTriggerTable($iObjectId, $aEntry)
  40. {
  41. return (int)$this->query("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldCount}` = :field_count WHERE `{$this->_sTriggerFieldId}` = :field_id", [
  42. 'field_count' => $aEntry['sum'],
  43. 'field_id' => $iObjectId
  44. ]) > 0;
  45. }
  46. }
  47. /** @} */