BxBaseModGroupsGridConnections.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGroupsGridConnections extends BxDolGridConnections
  12. {
  13. protected $_oModule;
  14. protected $_sContentModule;
  15. protected $_bRoles;
  16. protected $_aRoles;
  17. protected $_iGroupProfileId;
  18. protected $_aContentInfo = array();
  19. protected $_bPaidJoin;
  20. protected $_bMember;
  21. protected $_bManageMembers;
  22. protected $_sParamsDivider;
  23. protected $_sFilter1Name;
  24. protected $_sFilter1Value;
  25. protected $_aFilter1Values;
  26. public function __construct ($aOptions, $oTemplate = false)
  27. {
  28. $this->_oModule = BxDolModule::getInstance($this->_sContentModule);
  29. $CNF = &$this->_oModule->_oConfig->CNF;
  30. $this->_sObjectConnections = $CNF['OBJECT_CONNECTIONS'];
  31. parent::__construct ($aOptions, $oTemplate);
  32. if(!$this->_bInit)
  33. return;
  34. $this->_bRoles = $this->_oModule->_oConfig->isRoles();
  35. $this->_aRoles = $this->_oModule->_oConfig->getRoles();
  36. $this->_iGroupProfileId = $this->_oProfile->id();
  37. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_oProfile->getContentId());
  38. if($this->_oModule->checkAllowedEdit($this->_aContentInfo) === CHECK_ACTION_RESULT_ALLOWED || $this->_iGroupProfileId == bx_get_logged_profile_id())
  39. $this->_bOwner = true;
  40. $this->_bPaidJoin = $this->_oModule->isPaidJoinByProfile($this->_iGroupProfileId);
  41. $this->_bMember = $this->_oModule->isFan($this->_aContentInfo[$CNF['FIELD_ID']]);
  42. $this->_bManageMembers = $this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED || $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) === CHECK_ACTION_RESULT_ALLOWED;
  43. $this->_sParamsDivider = '#-#';
  44. if($this->_bRoles) {
  45. $this->_sFilter1Name = 'frole';
  46. $this->_aFilter1Values = [];
  47. foreach($this->_aRoles as $iRoleId => $sRoleTitle)
  48. $this->_aFilter1Values[] = [
  49. 'key' => $this->_roleItoS($iRoleId),
  50. 'value' => $sRoleTitle
  51. ];
  52. if(($sFilter1 = bx_get($this->_sFilter1Name))) {
  53. $this->_sFilter1Value = bx_process_input($sFilter1);
  54. $this->_aQueryAppend[$this->_sFilter1Name] = $this->_sFilter1Value;
  55. }
  56. }
  57. $aSQLParts = $this->_oConnection->getConnectedInitiatorsAsSQLParts('p', 'id', $this->_iGroupProfileId, $this->_bOwner ? false : true);
  58. if($this->_bRoles)
  59. $aSQLParts['join'] .= $this->_oModule->_oDb->prepareAsString(" LEFT JOIN `" . $CNF['TABLE_ADMINS'] . "` AS `ca` ON (`p`.`id` = `ca`.`fan_id` AND `ca`.`group_profile_id`= ?)", $this->_iGroupProfileId);
  60. $this->addMarkers([
  61. 'profile_id' => $this->_iGroupProfileId,
  62. 'join_connections' => $aSQLParts['join'],
  63. 'content_module' => $this->_sContentModule,
  64. ]);
  65. }
  66. public function getCode ($isDisplayHeader = true)
  67. {
  68. $sResult = parent::getCode($isDisplayHeader);
  69. if(!$sResult)
  70. return $sResult;
  71. if($this->_bRoles)
  72. $sResult .= $this->_oModule->_oTemplate->getJsCode('main', array(
  73. 'sObjNameGrid' => $this->_sObject,
  74. ));
  75. return $sResult;
  76. }
  77. public function performActionQuestionnaire()
  78. {
  79. $CNF = &$this->_oModule->_oConfig->CNF;
  80. if(($mixedResult = $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  81. return $this->_getActionResult(['msg' => $mixedResult]);
  82. if($this->_bIsApi)
  83. $iId = bx_get($CNF['FIELD_ID']);
  84. else
  85. list($iId, $iViewedId) = $this->_prepareIds();
  86. if(!$iId)
  87. return $this->_getActionResult(['msg' => _t('_sys_txt_error_occured')]);
  88. $sPopupContent = $this->_oModule->_oTemplate->getPopupQuestionnaire($this->_aContentInfo[$CNF['FIELD_ID']], $iId);
  89. if(!$sPopupContent)
  90. return $this->_getActionResult([]);
  91. if($this->_bIsApi)
  92. return [bx_api_get_block('simple_list', $sPopupContent)];
  93. $oFunctions = BxTemplFunctions::getInstance();
  94. return $this->_getActionResult(['popup' => $oFunctions->transBox(str_replace('_', '-', $this->_sContentModule) . '-questionnaire-popup', $oFunctions->simpleBoxContent($sPopupContent))]);
  95. }
  96. public function performActionSetRole()
  97. {
  98. if(!$this->_bRoles)
  99. return $this->_getActionResult([]);
  100. if(($mixedResult = $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  101. return $this->_getActionResult(['msg' => $mixedResult]);
  102. list($iId, $iViewedId) = $this->_prepareIds();
  103. if(!$iId)
  104. return $this->_getActionResult(['msg' => _t('_sys_txt_error_occured')]);
  105. if(empty($this->_aRoles) || !is_array($this->_aRoles))
  106. return $this->_getActionResult(['msg' => _t('_sys_txt_error_occured')]);
  107. $iRole = $this->_oModule->_oDb->getRole($this->_iGroupProfileId, $iId);
  108. if(!$this->_oModule->_oConfig->isMultiRoles()) {
  109. $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
  110. $sHtmlIdPrefix = str_replace('_', '-', $this->_sContentModule) . '-set-role-';
  111. $aMenuItems = [];
  112. foreach($this->_aRoles as $iRoleId => $sRoleTitle)
  113. $aMenuItems[] = array(
  114. 'id' => $sHtmlIdPrefix . $iRoleId,
  115. 'name' => $sHtmlIdPrefix . $iRoleId,
  116. 'class' => '',
  117. 'link' => 'javascript:void(0)',
  118. 'onclick' => $sJsObject . '.onClickSetRole(' . $iId . ', ' . $iRoleId . ')',
  119. 'target' => '_self',
  120. 'title' => $sRoleTitle,
  121. 'active' => 1
  122. );
  123. $oMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $sHtmlIdPrefix . 'menu', 'menu_items' => $aMenuItems));
  124. if(!empty($iRole))
  125. $oMenu->setSelected('', $sHtmlIdPrefix . $iRole);
  126. if($this->_bIsApi)
  127. $sPopupContent = $aMenuItems;
  128. else
  129. $sPopupContent = $oMenu->getCode();
  130. }
  131. else
  132. $sPopupContent = $this->_oModule->_oTemplate->getPopupSetRole($this->_aRoles, $iId, $iRole);
  133. if($this->_bIsApi){
  134. $sPopupContent['callback'] = '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=set_role_submit&profile_id=' . $this->_iGroupProfileId . '&content_module=' . $this->_sContentModule .'&ids[]=' . $iId . '&';
  135. $sPopupContent['title'] = _t('_' . $this->_sContentModule . '_txt_set_role');
  136. return [bx_api_get_block('membership', $sPopupContent)];
  137. }
  138. $oFunctions = BxTemplFunctions::getInstance();
  139. return $this->_getActionResult(['popup' => $oFunctions->transBox(str_replace('_', '-', $this->_sContentModule) . '-set-role-popup', $oFunctions->simpleBoxContent($sPopupContent))]);
  140. }
  141. public function performActionSetRoleSubmit()
  142. {
  143. if(!$this->_bRoles)
  144. return $this->_getActionResult([]);
  145. if(($mixedResult = $this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  146. return $this->_getActionResult(['msg' => $mixedResult]);
  147. list($iId, $iViewedId) = $this->_prepareIds();
  148. if(!$iId)
  149. return $this->_getActionResult(['msg' => _t('_sys_txt_error_occured')]);
  150. if(!$this->_oModule->setRole($this->_iGroupProfileId, $iId, bx_process_input(bx_get('role'), BX_DATA_INT)))
  151. return $this->_getActionResult(['msg' => _t('_error occured')]);
  152. return $this->_getActionResult(!$this->_bIsApi ? ['grid' => $this->getCode(false), 'blink' => $iId] : []);
  153. }
  154. public function performActionDeleteAndBan()
  155. {
  156. $this->_replaceMarkers ();
  157. $aResult = [];
  158. $iAffected = 0;
  159. $aIds = bx_get('ids');
  160. if(!$aIds || !is_array($aIds))
  161. return $this->_getActionResult($aResult);
  162. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_bans');
  163. foreach($aIds as $mixedId) {
  164. if(!$this->_delete($mixedId))
  165. continue;
  166. if($oConnection !== false) {
  167. list($iProfileId, $iContextId) = $this->__prepareIds($mixedId);
  168. $oConnection->addConnection($iContextId, $iProfileId, [
  169. 'module' => $this->_sContentModule
  170. ]);
  171. }
  172. $iAffected += 1;
  173. }
  174. if($iAffected)
  175. $aResult = !$this->_bIsApi ? ['grid' => $this->getCode(false)] : [];
  176. else
  177. $aResult = ['msg' => _t("_sys_grid_delete_failed")];
  178. return $this->_getActionResult($aResult);
  179. }
  180. protected function _getCellRole($mixedValue, $sKey, $aField, $aRow)
  181. {
  182. $iProfileRole = $this->_oModule->_oDb->getRole($this->_iGroupProfileId, $aRow[$this->_aOptions['field_id']]);
  183. if(!empty($iProfileRole) && $this->_oModule->_oConfig->isMultiRoles()) {
  184. $aRoles = array();
  185. foreach($this->_aRoles as $iRole => $sRole) {
  186. if(!$iRole)
  187. continue;
  188. if($iProfileRole & (1 << ($iRole - 1)))
  189. $aRoles[] = $sRole;
  190. }
  191. $mixedValue = implode(', ', $aRoles);
  192. }
  193. else
  194. $mixedValue = !empty($this->_aRoles[$iProfileRole]) ? $this->_aRoles[$iProfileRole] : _t('_uknown');
  195. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  196. }
  197. protected function _getCellHeaderRoleAdded($sKey, $aField)
  198. {
  199. if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
  200. return $this->_bIsApi ? [] : '';
  201. return parent::_getCellHeaderDefault ($sKey, $aField);
  202. }
  203. protected function _getCellRoleAdded($mixedValue, $sKey, $aField, $aRow)
  204. {
  205. $mixedValue = '';
  206. if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
  207. return $this->_bIsApi ? [] : $mixedValue;
  208. $iProfileId = (int)$aRow[$this->_aOptions['field_id']];
  209. if($this->_bManageMembers || $iProfileId == bx_get_logged_profile_id()) {
  210. $aRole = $this->_oModule->_oDb->getRoles(array('type' => 'by_gf_id', 'group_profile_id' => $this->_iGroupProfileId, 'fan_id' => $iProfileId));
  211. if(!empty($aRole) && is_array($aRole)) {
  212. if(!empty($aRole['added'])) {
  213. if($this->_bIsApi)
  214. return ['type' => 'time', 'data' => $aRole['added']];
  215. $mixedValue = bx_time_js($aRole['added'], BX_FORMAT_DATE, true);
  216. }
  217. else {
  218. if($this->_bIsApi)
  219. return ['type' => 'text', 'data' => ''];
  220. $mixedValue = '';
  221. }
  222. }
  223. }
  224. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  225. }
  226. protected function _getCellHeaderRoleExpired($sKey, $aField)
  227. {
  228. if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
  229. return $this->_bIsApi ? [] : '';
  230. return parent::_getCellHeaderDefault ($sKey, $aField);
  231. }
  232. protected function _getCellRoleExpired($mixedValue, $sKey, $aField, $aRow)
  233. {
  234. $mixedValue = '';
  235. if(!$this->_bPaidJoin || !($this->_bMember || $this->_bManageMembers))
  236. return $this->_bIsApi ? [] : '';
  237. $iProfileId = (int)$aRow[$this->_aOptions['field_id']];
  238. if($this->_bManageMembers || $iProfileId == bx_get_logged_profile_id()) {
  239. $aRole = $this->_oModule->_oDb->getRoles(array('type' => 'by_gf_id', 'group_profile_id' => $this->_iGroupProfileId, 'fan_id' => $iProfileId));
  240. if(!empty($aRole) && is_array($aRole)) {
  241. if(!empty($aRole['expired'])) {
  242. if($this->_bIsApi)
  243. return ['type' => 'time', 'data' => $aRole['expired']];
  244. $mixedValue = bx_time_js($aRole['expired'], BX_FORMAT_DATE, true);
  245. }
  246. else {
  247. if($this->_bIsApi)
  248. return ['type' => 'text', 'data' => ''];
  249. $mixedValue = '';
  250. }
  251. }
  252. }
  253. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  254. }
  255. protected function _getActionQuestionnaire ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  256. {
  257. $CNF = &$this->_oModule->_oConfig->CNF;
  258. if(!$this->_oModule->_oDb->areQuestionsAnswered($this->_aContentInfo[$CNF['FIELD_ID']], $aRow[$this->_aOptions['field_id']]))
  259. return $this->_bIsApi ? [] : '';
  260. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  261. }
  262. protected function _getActionSetRole ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  263. {
  264. if ($this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  265. return $this->_bIsApi ? [] : '';
  266. if($this->_bIsApi){
  267. $CNF = &$this->_oModule->_oConfig->CNF;
  268. return array_merge($a, [
  269. 'name' => $sKey,
  270. 'type' => 'modal',
  271. 'callback' => 'system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=set_role&profile_id=' . $this->_iGroupProfileId . '&content_module=' . $this->_sContentModule .'&ids[]=' . $aRow['id'],
  272. 'content_type' => $aRow['content_type']
  273. ]);
  274. }
  275. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  276. }
  277. protected function _getActionSetRoleSubmit ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  278. {
  279. return $this->_bIsApi ? [] : '';
  280. }
  281. protected function _getActionAccept ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  282. {
  283. if ($aRow['mutual'])
  284. return $this->_bIsApi ? [] : '';
  285. if ($this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  286. return $this->_bIsApi ? [] : '';
  287. if (isset($aRow[$this->_aOptions['field_id']]))
  288. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  289. return parent::_getActionAccept($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  290. }
  291. protected function _getActionDelete ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  292. {
  293. if ($this->_oModule->checkAllowedManageFans($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  294. return $this->_bIsApi ? [] : '';
  295. if (isset($aRow[$this->_aOptions['field_id']]))
  296. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  297. return parent::_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  298. }
  299. protected function _getActionDeleteAndBan ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  300. {
  301. return $this->_getActionDelete($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  302. }
  303. /**
  304. * Note. Methods related to 'To Admin'/'From Admin' functionality can be removed after UNA 12 will be released.
  305. */
  306. protected function _getActionToAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  307. {
  308. if ($this->_oModule->_oDb->isAdmin($this->_iGroupProfileId, $aRow[$this->_aOptions['field_id']]))
  309. return '';
  310. return $this->_getActionManageAdmins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  311. }
  312. protected function _getActionFromAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  313. {
  314. if (!$this->_oModule->_oDb->isAdmin($this->_iGroupProfileId, $aRow[$this->_aOptions['field_id']]))
  315. return '';
  316. return $this->_getActionManageAdmins ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  317. }
  318. protected function _getActionManageAdmins ($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  319. {
  320. if (!$this->_oConnection->isConnected($aRow[$this->_aOptions['field_id']], $this->_iGroupProfileId, true))
  321. return '';
  322. if ($this->_oModule->checkAllowedManageAdmins($this->_iGroupProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  323. return '';
  324. if (isset($aRow[$this->_aOptions['field_id']]))
  325. $a['attr']['bx_grid_action_data'] = $aRow[$this->_aOptions['field_id']] . ':' . $this->_iGroupProfileId;
  326. return parent::_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  327. }
  328. /**
  329. * 'To Admins' action handler
  330. */
  331. public function performActionToAdmins()
  332. {
  333. $this->_performActionAdmins('toAdmins');
  334. }
  335. /**
  336. * 'From Admins' action handler
  337. */
  338. public function performActionFromAdmins()
  339. {
  340. $this->_performActionAdmins('fromAdmins');
  341. }
  342. public function _performActionAdmins($sFunc)
  343. {
  344. list ($iId, $iGroupProfileId) = $this->_prepareIds();
  345. if (!$iId) {
  346. echoJson(array('msg' => _t('_sys_txt_error_occured')));
  347. exit;
  348. }
  349. if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedManageAdmins($iGroupProfileId)) {
  350. echoJson(array('msg' => _t('_sys_txt_access_denied')));
  351. exit;
  352. }
  353. if (!$this->_oModule->_oDb->$sFunc($iGroupProfileId, $iId)) {
  354. echoJson(array('msg' => _t('_sys_txt_error_occured')));
  355. }
  356. else {
  357. $sEmailTemplate = 'toAdmins' == $sFunc ? $this->_oModule->_oConfig->CNF['EMAIL_FAN_BECOME_ADMIN'] : $this->_oModule->_oConfig->CNF['EMAIL_ADMIN_BECOME_FAN'];
  358. list($iGroupProfileId, $iProfileId) = $this->_prepareGroupProfileAndMemberProfile($iGroupProfileId, $iId);
  359. if (bx_get_logged_profile_id() != $iProfileId) {
  360. // notify about admin status
  361. sendMailTemplate($sEmailTemplate, 0, $iProfileId, array(
  362. 'EntryUrl' => BxDolProfile::getInstance($iGroupProfileId)->getUrl(),
  363. 'EntryTitle' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName(),
  364. ), BX_EMAIL_NOTIFY);
  365. }
  366. // subscribe admins automatically
  367. if ('toAdmins' == $sFunc && ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
  368. $oConn->addConnection($iProfileId, $iGroupProfileId);
  369. echoJson(array('grid' => $this->getCode(false), 'blink' => $iId));
  370. }
  371. }
  372. protected function _delete ($mixedId)
  373. {
  374. list ($iId, $iViewedId) = $this->_prepareIds();
  375. // send email notification
  376. $sEmailTemplate = $this->_oConnection->isConnected($iViewedId, $iId, true) ? $this->_oModule->_oConfig->CNF['EMAIL_FAN_REMOVE'] : $this->_oModule->_oConfig->CNF['EMAIL_JOIN_REJECT'];
  377. list($iGroupProfileId, $iProfileId) = $this->_prepareGroupProfileAndMemberProfile($iId, $iViewedId);
  378. if (bx_get_logged_profile_id() != $iProfileId) {
  379. sendMailTemplate($sEmailTemplate, 0, $iProfileId, array(
  380. 'EntryUrl' => BxDolProfile::getInstance($iGroupProfileId)->getUrl(),
  381. 'EntryTitle' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName(),
  382. ), BX_EMAIL_NOTIFY);
  383. }
  384. // delete admin associated with profile
  385. $this->_oModule->_oDb->deleteAdminsByGroupId($iGroupProfileId, $iProfileId);
  386. return parent::_delete ($mixedId);
  387. }
  388. /**
  389. * @return array where first element is group profile id and second element is some other persons profile id
  390. */
  391. protected function _prepareGroupProfileAndMemberProfile($iId1, $iId2)
  392. {
  393. if (BxDolProfile::getInstance($iId1)->getModule() == $this->_sContentModule)
  394. return array($iId1, $iId2);
  395. else
  396. return array($iId2, $iId1);
  397. }
  398. protected function _getFilterControls()
  399. {
  400. parent::_getFilterControls();
  401. $sResult = '';
  402. if($this->_bRoles && !empty($this->_sFilter1Name))
  403. $sResult .= $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  404. $sResult .= $this->_getSearchInput();
  405. return $sResult;
  406. }
  407. protected function _getFilterOnChange()
  408. {
  409. return $this->_oModule->_oConfig->getJsObject('main') . '.onChangeMembersFilter(this)';
  410. }
  411. protected function _addJsCss()
  412. {
  413. parent::_addJsCss();
  414. if($this->_bRoles) {
  415. $this->_oModule->_oTemplate->addCss(['main.css']);
  416. $this->_oModule->_oTemplate->addJs(['modules/base/groups/js/|main.js', 'main.js']);
  417. $this->_oModule->_oTemplate->addJsTranslation(['_sys_grid_search']);
  418. }
  419. }
  420. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  421. {
  422. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  423. switch (substr_count($sFilter, $this->_sParamsDivider)) {
  424. case 1:
  425. list($this->_sFilter1Value, $sFilter) = $aFilterParts;
  426. break;
  427. }
  428. if(strpos($this->_aOptions['source'], 'WHERE') === false)
  429. $this->_aOptions['source'] .= ' WHERE 1';
  430. if($this->_bRoles && !empty($this->_sFilter1Value)) {
  431. $this->_sFilter1Value = $this->_roleStoI($this->_sFilter1Value);
  432. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString($this->_sFilter1Value == 0 ? " AND (ISNULL(`ca`.`role`) OR `ca`.`role` = ?)" : " AND `ca`.`role` = ?", $this->_sFilter1Value);
  433. }
  434. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  435. }
  436. protected function _roleItoS($iRole)
  437. {
  438. return 'r' . $iRole;
  439. }
  440. protected function _roleStoI($sRole)
  441. {
  442. return (int)substr($sRole, 1);
  443. }
  444. }
  445. /** @} */