BxTasksFormTime.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  11. * Create/Edit entry form
  12. */
  13. class BxTasksFormTime extends BxTemplFormView
  14. {
  15. protected $_sModule;
  16. protected $_oModule;
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. $this->_sModule = 'bx_tasks';
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. parent::__construct($aInfo, $oTemplate);
  22. if(($sKey = 'value') && isset($this->aInputs[$sKey])) {
  23. foreach($this->aInputs[$sKey] as $mixedKey => $mixedValue) {
  24. if(!is_numeric($mixedKey) || !is_array($mixedValue))
  25. continue;
  26. if(!empty($mixedValue['attrs']['placeholder']))
  27. $this->aInputs[$sKey][$mixedKey]['attrs']['placeholder'] = _t($mixedValue['attrs']['placeholder']);
  28. }
  29. }
  30. if(($sKey = 'value_date') && isset($this->aInputs[$sKey]))
  31. $this->aInputs[$sKey]['value'] ??= time();
  32. }
  33. public function initChecker ($aValues = [], $aSpecificValues = [])
  34. {
  35. if(($iContentId = $this->aInputs['object_id']['value'] ?? 0) && ($iProfileId = bx_get_logged_profile_id())) {
  36. $aTimer = $this->_oModule->_oDb->getTimers([
  37. 'sample' => 'content_profile_ids',
  38. 'content_id' => $iContentId,
  39. 'profile_id' => $iProfileId
  40. ]);
  41. if($aTimer && is_array($aTimer) && ($iDuration = (int)$aTimer['duration']) && ($sKey = 'value') && isset($this->aInputs[$sKey])) {
  42. list($iHours, $iMinutes) = $this->_oModule->_oConfig->timeI2A($iDuration, true);
  43. foreach($this->aInputs[$sKey] as $mixedKey => $mixedValue) {
  44. if(!is_numeric($mixedKey) || !is_array($mixedValue))
  45. continue;
  46. switch($this->aInputs[$sKey][$mixedKey]['name']) {
  47. case 'value_h':
  48. $this->aInputs[$sKey][$mixedKey]['value'] = $iHours;
  49. break;
  50. case 'value_m':
  51. $this->aInputs[$sKey][$mixedKey]['value'] = $iMinutes + 1;
  52. break;
  53. }
  54. }
  55. $this->aInputs['timer_id'] = [
  56. 'type' => 'hidden',
  57. 'name' => 'timer_id',
  58. 'value' => $aTimer['id']
  59. ];
  60. }
  61. }
  62. return parent::initChecker ($aValues, $aSpecificValues);
  63. }
  64. }
  65. /** @} */