1
0

BxTasksTimeQuery.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 updateTrack($aParamsSet, $aParamsWhere)
  17. {
  18. if(empty($aParamsSet) || empty($aParamsWhere))
  19. return false;
  20. $sSql = "UPDATE `{$this->_sTableTrack}` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND ");
  21. return $this->query($sSql);
  22. }
  23. public function getReport($iObjectId)
  24. {
  25. $aResult = $this->getRow("SELECT `count` as `count`, `sum` AS `sum` FROM `{$this->_sTable}` WHERE `object_id` = :object_id LIMIT 1", ['object_id' => $iObjectId]);
  26. if(empty($aResult) || !is_array($aResult))
  27. $aResult = ['count' => 0, 'sum' => 0];
  28. return $aResult;
  29. }
  30. public function updateReport($iObjectId, $iValue, $bUndo = false)
  31. {
  32. return (int)$this->query("UPDATE `{$this->_sTable}` SET `sum` = `sum` " . ($bUndo ? "-" : "+") . " :value WHERE `object_id` = :object_id", [
  33. 'object_id' => $iObjectId,
  34. 'value' => $iValue
  35. ]) != 0;
  36. }
  37. /**
  38. * Note. Tracks shouldn't be deleted on Undo.
  39. *
  40. * @see BxDolReportQuery::putReport
  41. */
  42. protected function _deleteTrack($iObjectId, $iAuthorId)
  43. {
  44. return true;
  45. }
  46. protected function _updateTriggerTable($iObjectId, $aEntry)
  47. {
  48. return (int)$this->query("UPDATE `{$this->_sTriggerTable}` SET `{$this->_sTriggerFieldCount}` = :field_count WHERE `{$this->_sTriggerFieldId}` = :field_id", [
  49. 'field_count' => $aEntry['sum'],
  50. 'field_id' => $iObjectId
  51. ]) > 0;
  52. }
  53. }
  54. /** @} */