BxSpacesFormEntry.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 = bx_get('id');
  24. if ($iCurrent === false)
  25. $iCurrent = - 1;
  26. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . "modules/?r=" . $this->_oModule->_oConfig->getUri() . "/ajax_get_parent_space&id=" . $iCurrent;
  27. $aInput['custom']['only_once'] = 1;
  28. if (isset($aInput['value']) && !is_array($aInput['value']))
  29. $aInput['value'] = array($aInput['value']);
  30. return $this->genCustomInputUsernamesSuggestions($aInput);
  31. }
  32. public function insert ($aValsToAdd = array(), $isIgnore = false)
  33. {
  34. $this->defineLevelById($aValsToAdd);
  35. return parent::insert ($aValsToAdd, $isIgnore);
  36. }
  37. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  38. {
  39. $this->defineLevelById($aValsToAdd);
  40. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  41. }
  42. function defineLevelById(&$aValsToAdd)
  43. {
  44. $CNF = &$this->_oModule->_oConfig->CNF;
  45. if(isset($CNF['FIELD_PARENT']) && isset($this->aInputs[$CNF['FIELD_PARENT']])){
  46. $iParentId = $this->aInputs[$CNF['FIELD_PARENT']]['value'];
  47. if(is_array($iParentId))
  48. $iParentId = array_shift($iParentId);
  49. $aValsToAdd[$CNF['FIELD_PARENT']] = (int)$iParentId;
  50. if(isset($CNF['FIELD_LEVEL']) && !empty($iParentId) && ($oParent = BxDolProfile::getInstance($iParentId)) !== false)
  51. $aValsToAdd[$CNF['FIELD_LEVEL']] = $this->_oModule->_oDb->getLevelById($oParent->getContentId()) + 1;
  52. }
  53. }
  54. }
  55. /** @} */