BxCreditsFormBundle.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Credits Credits
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Add/Edit bundle form
  13. */
  14. class BxCreditsFormBundle extends BxTemplStudioFormView
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. $this->_sModule = 'bx_credits';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. parent::__construct($aInfo, $oTemplate);
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. if(isset($this->aInputs[$CNF['FIELD_NAME']])) {
  25. $sJsObject = $this->_oModule->_oConfig->getJsObject('studio');
  26. $iId = $this->getBundleId();
  27. $aMask = array('mask' => "javascript:%s.checkBundleName('%s');", $sJsObject, $CNF['FIELD_NAME']);
  28. if(!empty($iId) && $this->aParams['display'] == $CNF['OBJECT_FORM_BUNDLE_DISPLAY_EDIT']) {
  29. $aMask['mask'] = "javascript:%s.checkBundleName('%s', %d);";
  30. $aMask[] = $iId;
  31. }
  32. $sOnBlur = call_user_func_array('sprintf', array_values($aMask));
  33. $this->aInputs[$CNF['FIELD_NAME']]['attrs']['onblur'] = $sOnBlur;
  34. }
  35. }
  36. public function insert ($aValsToAdd = array(), $isIgnore = false)
  37. {
  38. $CNF = &$this->_oModule->_oConfig->CNF;
  39. if(isset($this->aInputs[$CNF['FIELD_NAME']])) {
  40. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  41. $aLanguages = $oLanguage->getLanguagesExt();
  42. $sLanguageCurrent = $oLanguage->getCurrentLangName(false);
  43. $sTitle = BxDolForm::getSubmittedValue($CNF['FIELD_TITLE'] . '-' . $sLanguageCurrent, $this->aFormAttrs['method']);
  44. $sName = $this->_oModule->_oConfig->getBundleName($sTitle);
  45. BxDolForm::setSubmittedValue($CNF['FIELD_TITLE'], '_bx_credits_txt_bundle_title_' . strtolower($sName), $this->aFormAttrs['method']);
  46. }
  47. return parent::insert ($aValsToAdd, $isIgnore);
  48. }
  49. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  50. {
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. $sNameKey = $CNF['FIELD_NAME'];
  53. if(isset($this->aInputs[$sNameKey])) {
  54. $sName = $this->getCleanValue($sNameKey);
  55. $aContentInfo = $this->_oModule->_oDb->getBundle(array('type' => 'id', 'id' => $iContentId));
  56. if($aContentInfo[$sNameKey] != $sName) {
  57. $sName = $this->_oModule->_oConfig->getBundleName($sName);
  58. BxDolForm::setSubmittedValue($sNameKey, $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  59. }
  60. }
  61. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  62. }
  63. public function getBundleId()
  64. {
  65. $iResult = 0;
  66. $aIds = bx_get('ids');
  67. if(!$aIds || !is_array($aIds)) {
  68. $sId = bx_get('id');
  69. if(!empty($sId))
  70. $iResult = $sId;
  71. }
  72. else
  73. $iResult = array_shift($aIds);
  74. return (int)$iResult;
  75. }
  76. }
  77. /** @} */