BxBaseCmtsGridAdministration.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  64. {
  65. if(empty($sFilterName) || empty($aFilterValues))
  66. return '';
  67. foreach($aFilterValues as $sKey => $sValue)
  68. $aFilterValues[$sKey] = _t($sValue);
  69. $aInputModules = array(
  70. 'type' => 'select',
  71. 'name' => $sFilterName,
  72. 'attrs' => array(
  73. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  74. 'onChange' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)'
  75. ),
  76. 'value' => $sFilterValue,
  77. 'values' => $aFilterValues
  78. );
  79. $oForm = new BxTemplFormView(array());
  80. return $oForm->genRow($aInputModules);
  81. }
  82. protected function _getSearchInput()
  83. {
  84. $aInputSearch = array(
  85. 'type' => 'text',
  86. 'name' => 'search',
  87. 'attrs' => array(
  88. 'id' => 'bx-grid-search-' . $this->_sObject,
  89. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $this->sJsObject . '.onChangeFilter(this)',
  90. 'onBlur' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)',
  91. )
  92. );
  93. $oForm = new BxTemplFormView(array());
  94. return $oForm->genRow($aInputSearch);
  95. }
  96. protected function _getCellHeaderCmtModule($sKey, $aField)
  97. {
  98. if(!$this->_bShowModule)
  99. return;
  100. return parent::_getCellHeaderDefault($sKey, $aField);
  101. }
  102. protected function _getCellCmtTime($mixedValue, $sKey, $aField, $aRow)
  103. {
  104. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  105. }
  106. protected function _getCellCmtModule($mixedValue, $sKey, $aField, $aRow)
  107. {
  108. if(!$this->_bShowModule)
  109. return;
  110. $sKey = '_' . $mixedValue;
  111. $sTitle = _t($sKey);
  112. if(strcmp($sKey, $sTitle) != 0)
  113. $mixedValue = $sTitle;
  114. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  115. }
  116. protected function _getCellCmtText($mixedValue, $sKey, $aField, $aRow)
  117. {
  118. $mixedValue = strmaxtextlen($aRow['cmt_text']);
  119. if(!empty($this->_aCmts[$aRow['cmt_system_id']]) && ($oCmts = $this->_aCmts[$aRow['cmt_system_id']]) instanceof BxDolCmts && $oCmts->isEnabled()) {
  120. $oCmts->setId($aRow['cmt_object_id']);
  121. $mixedValue = $this->_oTemplate->parseLink($oCmts->getViewUrl($aRow['cmt_id']), $mixedValue, ['target' => '_blank']);
  122. }
  123. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  124. }
  125. protected function _getCellCmtAuthorId($mixedValue, $sKey, $aField, $aRow)
  126. {
  127. $oProfile = null;
  128. if((int)$aRow['cmt_author_id'] != 0)
  129. $oProfile = BxDolProfile::getInstance($aRow['cmt_author_id']);
  130. if(!$oProfile)
  131. $oProfile = BxDolProfileUndefined::getInstance();
  132. $sProfile = $oProfile->getDisplayName();
  133. $sAccountEmail = '';
  134. $sManageAccountUrl = '';
  135. if($oProfile && $oProfile instanceof BxDolProfile && BxDolAcl::getInstance()->isMemberLevelInSet(128)) {
  136. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  137. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  138. }
  139. $mixedValue = $this->_oTemplate->parseHtmlByName('author_link.html', [
  140. 'href' => $oProfile->getUrl(),
  141. 'title' => bx_html_attribute($sProfile),
  142. 'content' => $sProfile,
  143. 'bx_if:show_account' => [
  144. 'condition' => !empty($sManageAccountUrl),
  145. 'content' => [
  146. 'href' => $sManageAccountUrl,
  147. 'title' => _t('_sys_grid_txt_account_manager'),
  148. 'content' => $sAccountEmail
  149. ]
  150. ]
  151. ]);
  152. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  153. }
  154. protected function _getCellHeaderReports ($sKey, $aField)
  155. {
  156. $s = parent::_getCellHeaderDefault($sKey, $aField);
  157. 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);
  158. }
  159. protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
  160. {
  161. if ($mixedValue == 0){
  162. $mixedValue = '';
  163. }
  164. else{
  165. $oReports = BxDolReport::getObjectInstance('sys_cmts', $aRow['id']);
  166. if ($oReports){
  167. $mixedValue = $oReports->getCounter().$oReports->getJsScript();
  168. }
  169. }
  170. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  171. }
  172. protected function _getManageAccountUrl($sFilter = '')
  173. {
  174. $sModuleAccounts = 'bx_accounts';
  175. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  176. return '';
  177. $sTypeUpc = strtoupper($this->_sManageType);
  178. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  179. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
  180. return '';
  181. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
  182. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sLink));
  183. if(!empty($sFilter))
  184. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  185. return $sLink;
  186. }
  187. }
  188. /** @} */