BxBasePrivacy.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Privacy representation.
  11. * @see BxDolPrivacy
  12. */
  13. class BxBasePrivacy extends BxDolPrivacy
  14. {
  15. protected $_oTemplate;
  16. protected $_sJsObjClass;
  17. protected $_sJsObjName;
  18. public function __construct ($aOptions, $oTemplate)
  19. {
  20. parent::__construct ($aOptions);
  21. if ($oTemplate)
  22. $this->_oTemplate = $oTemplate;
  23. else
  24. $this->_oTemplate = BxDolTemplate::getInstance();
  25. $this->_sJsObjClass = 'BxDolPrivacy';
  26. $this->_sJsObjName = 'oBxDolPrivacy' . bx_gen_method_name($this->_sObject);
  27. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $this->_sObject);
  28. $this->_aHtmlIds = array(
  29. 'group_element' => 'bx-form-element-' . $this->convertActionToField($this->_aObject['action']),
  30. 'group_custom_element' => 'sys-pgc-' . $sHtmlId,
  31. 'users_select_popup' => 'sys-privacy-usp-' . $sHtmlId . '-'
  32. );
  33. }
  34. public function getJsObjectName()
  35. {
  36. return $this->_sJsObjName;
  37. }
  38. /**
  39. * Get initialization section of comments box
  40. *
  41. * @return string
  42. */
  43. public function getJsScript($bDynamicMode = false)
  44. {
  45. $aParams = array(
  46. 'sObject' => $this->_sObject,
  47. 'sObjName' => $this->_sJsObjName,
  48. 'sRootUrl' => BX_DOL_URL_ROOT,
  49. 'aGroupSettings' => $this->_aGroupsSettings,
  50. 'aHtmlIds' => $this->_aHtmlIds
  51. );
  52. return $this->addCssJs($bDynamicMode) . $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . ");");
  53. }
  54. protected function addCssJs($bDynamicMode = false)
  55. {
  56. $sInclude = '';
  57. $sInclude .= $this->_oTemplate->addJs(array(
  58. 'jquery-ui/jquery-ui.custom.min.js',
  59. 'jquery-ui/jquery.ui.widget.min.js',
  60. 'jquery-ui/jquery.ui.autocomplete.min.js',
  61. 'BxDolPrivacy.js'
  62. ), $bDynamicMode);
  63. $sInclude .= $this->_oTemplate->addCss(array(
  64. 'forms.css',
  65. 'privacy.css'
  66. ), $bDynamicMode);
  67. return $bDynamicMode ? $sInclude : '';
  68. }
  69. protected function getSelectGroup($aValues = array(), $aParams = array())
  70. {
  71. $sJsObject = $this->getJsObjectName();
  72. $oForm = BxDolForm::getObjectInstance($this->_sFormUsers, $this->_sFormDisplayUsersSelect);
  73. $oForm->initChecker($aValues);
  74. if($oForm->isSubmittedAndValid()) {
  75. $aMembers = array();
  76. if(($aMembersSearch = $oForm->getCleanValue('search')) !== false)
  77. $aMembers = array_merge($aMembers, $aMembersSearch);
  78. if(($aMembersList = $oForm->getCleanValue('list')) !== false)
  79. $aMembers = array_merge($aMembers, $aMembersList);
  80. if(empty($aMembers) || !is_array($aMembers))
  81. return array();
  82. $iGroupCustomId = $oForm->getGroupCustomId();
  83. if(!$iGroupCustomId) {
  84. $this->deleteGroupCustom(array(
  85. 'profile_id' => $oForm->getCleanValue('profile_id'),
  86. 'content_id' => $oForm->getCleanValue('content_id'),
  87. 'object' => $oForm->getCleanValue('object')
  88. ));
  89. $iGroupCustomId = $oForm->insert();
  90. foreach($aMembers as $iMemberId)
  91. $this->_oDb->insertGroupCustomMember(array('group_id' => $iGroupCustomId, 'member_id' => $iMemberId));
  92. }
  93. else {
  94. $this->_oDb->deleteGroupCustomMember(array('group_id' => $iGroupCustomId));
  95. foreach($aMembers as $iMemberId)
  96. $this->_oDb->insertGroupCustomMember(array('group_id' => $iGroupCustomId, 'member_id' => $iMemberId));
  97. }
  98. return array('eval' => $sJsObject . '.onSelectUsers(oData);', 'content' => $oForm->getElementGroupCustom(array(
  99. 'value' => $iGroupCustomId,
  100. 'value_members' => $aMembers
  101. )));
  102. }
  103. $iGroupId = $oForm->getGroupId();
  104. $sContent = BxTemplFunctions::getInstance()->transBox($this->_aHtmlIds['users_select_popup'] . $iGroupId, $this->_oTemplate->parseHtmlByName('privacy_users_select_popup.html', array(
  105. 'js_object' => $sJsObject,
  106. 'group' => $iGroupId,
  107. 'form' => $oForm->getCode(),
  108. 'form_id' => $oForm->getId()
  109. )));
  110. $aResult = array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false)));
  111. if(isset($aParams['popup_only']) && (bool)$aParams['popup_only'] === true)
  112. return $aResult;
  113. return array_merge($aResult, array(
  114. 'eval' => $sJsObject . '.onSelectGroup(oData);',
  115. 'content' => $oForm->getElementGroupCustom()
  116. ));
  117. }
  118. }
  119. /** @} */