1
0

BxBaseCmtsGridAdministration.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. class BxBaseCmtsGridAdministration extends BxDolCmtsGridAdministration
  10. {
  11. protected $sJsObject = 'oBxDolCmtsManageTools';
  12. public function __construct($aInfo, $oTemplate = false)
  13. {
  14. parent::__construct($aInfo, $oTemplate);
  15. $this->_aQueryReset = [$this->_aOptions['filter_get'], $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']];
  16. }
  17. public function getCode($isDisplayHeader = true)
  18. {
  19. return $this->getJsCode() . parent::getCode($isDisplayHeader);
  20. }
  21. public function getJsCode()
  22. {
  23. $aParams = array(
  24. 'sObjName' => $this->sJsObject,
  25. 'aHtmlIds' => array(),
  26. 'oRequestParams' => array(),
  27. 'sObjNameGrid' => 'sys_cmts_administration'
  28. );
  29. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->sJsObject . " = new BxDolCmtsManageTools(" . json_encode($aParams) . ");");
  30. }
  31. public function performActionDelete($aParams = array())
  32. {
  33. $iAffected = 0;
  34. $aIds = bx_get('ids');
  35. if(!$aIds || !is_array($aIds)) {
  36. echoJson(array());
  37. exit;
  38. }
  39. $sFilter = bx_get('filter');
  40. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  41. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  42. if(!empty($this->_sFilter1Value)){
  43. $this->_oSelectedModule = BxDolModule::getInstance($this->_sFilter1Value);
  44. $oCmts = BxDolCmts::getObjectInstance($this->_oSelectedModule->_oConfig->CNF['OBJECT_COMMENTS'], 0, false);
  45. if ($oCmts){
  46. $aIdsAffected = array ();
  47. foreach($aIds as $iId) {
  48. $aTmp = $oCmts->remove($iId);
  49. if (isset($aTmp['id'])){
  50. $aIdsAffected[] = $iId;
  51. $iAffected++;
  52. }
  53. }
  54. }
  55. }
  56. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_sys_grid_delete_failed')));
  57. }
  58. protected function _getFilterControls()
  59. {
  60. parent::_getFilterControls();
  61. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  62. }
  63. protected function _getFilterOnChange()
  64. {
  65. return $this->sJsObject . '.onChangeFilter(this)';
  66. }
  67. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, $mixedAddSelectOne = true, $bAsArray = false)
  68. {
  69. return parent::_getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues, '_adm_txt_select_module', $bAsArray);
  70. }
  71. protected function _getCellHeaderCmtModule($sKey, $aField)
  72. {
  73. if(!$this->_bShowModule)
  74. return;
  75. return parent::_getCellHeaderDefault($sKey, $aField);
  76. }
  77. protected function _getCellCmtTime($mixedValue, $sKey, $aField, $aRow)
  78. {
  79. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  80. }
  81. protected function _getCellCmtModule($mixedValue, $sKey, $aField, $aRow)
  82. {
  83. if(!$this->_bShowModule)
  84. return;
  85. $sKey = '_' . $mixedValue;
  86. $sTitle = _t($sKey);
  87. if(strcmp($sKey, $sTitle) != 0)
  88. $mixedValue = $sTitle;
  89. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  90. }
  91. protected function _getCellCmtText($mixedValue, $sKey, $aField, $aRow)
  92. {
  93. $mixedValue = strmaxtextlen($aRow['cmt_text']);
  94. if(!empty($this->_aCmts[$aRow['cmt_system_id']]) && ($oCmts = $this->_aCmts[$aRow['cmt_system_id']]) instanceof BxDolCmts && $oCmts->isEnabled()) {
  95. $oCmts->setId($aRow['cmt_object_id']);
  96. $mixedValue = $this->_oTemplate->parseLink($oCmts->getViewUrl($aRow['cmt_id']), $mixedValue, ['target' => '_blank']);
  97. }
  98. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  99. }
  100. protected function _getCellCmtAuthorId($mixedValue, $sKey, $aField, $aRow)
  101. {
  102. $oProfile = null;
  103. if((int)$aRow['cmt_author_id'] != 0)
  104. $oProfile = BxDolProfile::getInstance($aRow['cmt_author_id']);
  105. if(!$oProfile)
  106. $oProfile = BxDolProfileUndefined::getInstance();
  107. $sProfile = $oProfile->getDisplayName();
  108. $sAccountEmail = '';
  109. $sManageAccountUrl = '';
  110. if($oProfile && $oProfile instanceof BxDolProfile && BxDolAcl::getInstance()->isMemberLevelInSet(128)) {
  111. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  112. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  113. }
  114. $mixedValue = $this->_oTemplate->parseHtmlByName('author_link.html', [
  115. 'href' => $oProfile->getUrl(),
  116. 'title' => bx_html_attribute($sProfile),
  117. 'content' => $sProfile,
  118. 'bx_if:show_account' => [
  119. 'condition' => !empty($sManageAccountUrl),
  120. 'content' => [
  121. 'href' => $sManageAccountUrl,
  122. 'title' => _t('_sys_grid_txt_account_manager'),
  123. 'content' => $sAccountEmail
  124. ]
  125. ]
  126. ]);
  127. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  128. }
  129. protected function _getCellHeaderReports ($sKey, $aField)
  130. {
  131. $s = parent::_getCellHeaderDefault($sKey, $aField);
  132. return preg_replace ('/<a(.*?)>(.*?)<\/a>/', '<a$1 title="' . bx_html_attribute(_t('_sys_txt_reports_title')) . '"><i class="sys-icon exclamation-triangle"></i></a>', $s);
  133. }
  134. protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
  135. {
  136. if ($mixedValue == 0){
  137. $mixedValue = '';
  138. }
  139. else{
  140. $oReports = BxDolReport::getObjectInstance('sys_cmts', $aRow['id']);
  141. if ($oReports){
  142. $mixedValue = $oReports->getCounter().$oReports->getJsScript();
  143. }
  144. }
  145. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  146. }
  147. protected function _getManageAccountUrl($sFilter = '')
  148. {
  149. $sModuleAccounts = 'bx_accounts';
  150. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  151. return '';
  152. $sTypeUpc = strtoupper($this->_sManageType);
  153. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  154. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
  155. return '';
  156. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
  157. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sLink));
  158. if(!empty($sFilter))
  159. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  160. return $sLink;
  161. }
  162. }
  163. /** @} */