BxReputationFormLevel.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. *
  6. * @defgroup Reputation Reputation
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxReputationFormLevel extends BxTemplStudioFormView
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct($aInfo, $oTemplate = false)
  16. {
  17. $this->_sModule = 'bx_reputation';
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. parent::__construct($aInfo, $oTemplate);
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. if(isset($this->aInputs[$CNF['FIELD_LEVEL_NAME']])) {
  22. $sJsObject = $this->_oModule->_oConfig->getJsObject('levels');
  23. $iId = $this->getLevelId();
  24. $aMask = array('mask' => "javascript:%s.checkName('%s');", $sJsObject, $CNF['FIELD_LEVEL_NAME']);
  25. if(!empty($iId) && $this->aParams['display'] == $CNF['OBJECT_FORM_LEVEL_DISPLAY_EDIT']) {
  26. $aMask['mask'] = "javascript:%s.checkName('%s', %d);";
  27. $aMask[] = $iId;
  28. }
  29. $sOnBlur = call_user_func_array('sprintf', array_values($aMask));
  30. $this->aInputs[$CNF['FIELD_LEVEL_NAME']]['attrs']['onblur'] = $sOnBlur;
  31. }
  32. if(isset($this->aInputs[$CNF['FIELD_LEVEL_ICON']]))
  33. $this->aInputs[$CNF['FIELD_LEVEL_ICON']]['code'] = 1;
  34. }
  35. public function insert ($aValsToAdd = [], $isIgnore = false)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. if(isset($this->aInputs[$CNF['FIELD_LEVEL_NAME']])) {
  39. $sName = BxDolForm::getSubmittedValue($CNF['FIELD_LEVEL_NAME'], $this->aFormAttrs['method'], $this->_aSpecificValues);
  40. $sName = $this->_oModule->_oConfig->getLevelName($sName);
  41. BxDolForm::setSubmittedValue($CNF['FIELD_LEVEL_NAME'], $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  42. }
  43. return parent::insert ($aValsToAdd, $isIgnore);
  44. }
  45. function update ($iContentId, $aValsToAdd = [], &$aTrackTextFieldsChanges = null)
  46. {
  47. $CNF = &$this->_oModule->_oConfig->CNF;
  48. $sNameKey = $CNF['FIELD_LEVEL_NAME'];
  49. if(isset($this->aInputs[$sNameKey])) {
  50. $sName = $this->getCleanValue($sNameKey);
  51. $aContentInfo = $this->_oModule->_oDb->getLevels(['sample' => 'id', 'id' => $iContentId]);
  52. if($aContentInfo[$sNameKey] != $sName) {
  53. $sName = $this->_oModule->_oConfig->getLevelName($sName);
  54. BxDolForm::setSubmittedValue($sNameKey, $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  55. }
  56. }
  57. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  58. }
  59. public function getLevelId()
  60. {
  61. $iResult = 0;
  62. $aIds = bx_get('ids');
  63. if(!$aIds || !is_array($aIds)) {
  64. $sId = bx_get('id');
  65. if(!empty($sId))
  66. $iResult = $sId;
  67. }
  68. else
  69. $iResult = array_shift($aIds);
  70. return (int)$iResult;
  71. }
  72. }
  73. /** @} */