1
0

BxSpacesFormEntry.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @defdroup Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit Space Form.
  13. */
  14. class BxSpacesFormEntry extends BxBaseModGroupsFormEntry
  15. {
  16. public function __construct($aInfo, $oTemplate = false)
  17. {
  18. $this->MODULE = 'bx_spaces';
  19. parent::__construct($aInfo, $oTemplate);
  20. }
  21. protected function genCustomInputParentSpace($aInput)
  22. {
  23. $iCurrent = ($iCurrent = bx_get('id')) !== false ? (int)$iCurrent : - 1;
  24. if($this->_bIsApi) {
  25. $aInput = array_merge($aInput, [
  26. 'title' => $aInput['caption'],
  27. 'ajax_get_suggestions' => $this->_oModule->_oConfig->getName() . "/ajax_get_parent_space&params[]=" . $iCurrent . "&params[]=",
  28. 'value_data' => []
  29. ]);
  30. $aInput['value_data'] = [];
  31. if(!empty($aInput['value'])) {
  32. if(!is_array($aInput['value']))
  33. $aInput['value'] = [$aInput['value']];
  34. foreach($aInput['value'] as $iProfileId)
  35. if(($oProfile = BxDolProfile::getInstance($iProfileId)) !== false)
  36. $aInput['value_data'][] = BxDolProfile::getData($oProfile);
  37. }
  38. }
  39. else {
  40. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_parent_space&id=" . $iCurrent;
  41. if (isset($aInput['value']) && !is_array($aInput['value']))
  42. $aInput['value'] = array($aInput['value']);
  43. }
  44. if(($sK = 'custom') && (empty($aInput[$sK]) || !is_array($aInput[$sK])))
  45. $aInput[$sK] = [];
  46. $aInput['custom']['only_once'] = 1;
  47. return $this->genCustomInputUsernamesSuggestions($aInput);
  48. }
  49. public function insert ($aValsToAdd = array(), $isIgnore = false)
  50. {
  51. $this->defineLevelById($aValsToAdd);
  52. return parent::insert ($aValsToAdd, $isIgnore);
  53. }
  54. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  55. {
  56. $this->defineLevelById($aValsToAdd);
  57. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  58. }
  59. function defineLevelById(&$aValsToAdd)
  60. {
  61. $CNF = &$this->_oModule->_oConfig->CNF;
  62. if(isset($CNF['FIELD_PARENT']) && isset($this->aInputs[$CNF['FIELD_PARENT']])){
  63. $iParentId = $this->aInputs[$CNF['FIELD_PARENT']]['value'];
  64. if(is_array($iParentId))
  65. $iParentId = array_shift($iParentId);
  66. $aValsToAdd[$CNF['FIELD_PARENT']] = (int)$iParentId;
  67. if(isset($CNF['FIELD_LEVEL']) && !empty($iParentId) && ($oParent = BxDolProfile::getInstance($iParentId)) !== false)
  68. $aValsToAdd[$CNF['FIELD_LEVEL']] = $this->_oModule->_oDb->getLevelById($oParent->getContentId()) + 1;
  69. }
  70. }
  71. }
  72. /** @} */