BxBaseCmtsGridAdministration.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. }
  16. public function getCode($isDisplayHeader = true)
  17. {
  18. return $this->getJsCode() . parent::getCode($isDisplayHeader);
  19. }
  20. public function getJsCode()
  21. {
  22. $aParams = array(
  23. 'sObjName' => $this->sJsObject,
  24. 'aHtmlIds' => array(),
  25. 'oRequestParams' => array(),
  26. 'sObjNameGrid' => 'sys_cmts_administration'
  27. );
  28. return BxDolTemplate::getInstance()->_wrapInTagJsCode("var " . $this->sJsObject . " = new BxDolCmtsManageTools(" . json_encode($aParams) . ");");
  29. }
  30. public function performActionDelete($aParams = array())
  31. {
  32. $iAffected = 0;
  33. $aIds = bx_get('ids');
  34. if(!$aIds || !is_array($aIds)) {
  35. echoJson(array());
  36. exit;
  37. }
  38. $sFilter = bx_get('filter');
  39. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  40. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  41. if(!empty($this->_sFilter1Value)){
  42. $this->_oSelectedModule = BxDolModule::getInstance($this->_sFilter1Value);
  43. $oCmts = BxDolCmts::getObjectInstance($this->_oSelectedModule->_oConfig->CNF['OBJECT_COMMENTS'], 0, false);
  44. if ($oCmts){
  45. $aIdsAffected = array ();
  46. foreach($aIds as $iId) {
  47. $aTmp = $oCmts->remove($iId);
  48. if (isset($aTmp['id'])){
  49. $aIdsAffected[] = $iId;
  50. $iAffected++;
  51. }
  52. }
  53. }
  54. }
  55. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_sys_grid_delete_failed')));
  56. }
  57. protected function _getFilterControls()
  58. {
  59. parent::_getFilterControls();
  60. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  61. }
  62. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  63. {
  64. if(empty($sFilterName) || empty($aFilterValues))
  65. return '';
  66. //todo
  67. $CNF = &$this->_oModule->_oConfig->CNF;
  68. foreach($aFilterValues as $sKey => $sValue)
  69. $aFilterValues[$sKey] = _t($sValue);
  70. $aInputModules = array(
  71. 'type' => 'select',
  72. 'name' => $sFilterName,
  73. 'attrs' => array(
  74. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  75. 'onChange' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)'
  76. ),
  77. 'value' => $sFilterValue,
  78. 'values' => array_merge(array('' => _t($CNF['T']['filter_item_select_one_' . $sFilterName])), $aFilterValues)
  79. );
  80. $oForm = new BxTemplFormView(array());
  81. return $oForm->genRow($aInputModules);
  82. }
  83. protected function _getSearchInput()
  84. {
  85. $aInputSearch = array(
  86. 'type' => 'text',
  87. 'name' => 'search',
  88. 'attrs' => array(
  89. 'id' => 'bx-grid-search-' . $this->_sObject,
  90. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $this->sJsObject . '.onChangeFilter(this)',
  91. 'onBlur' => 'javascript:' . $this->sJsObject . '.onChangeFilter(this)',
  92. )
  93. );
  94. $oForm = new BxTemplFormView(array());
  95. return $oForm->genRow($aInputSearch);
  96. }
  97. protected function _getCellCmtTime($mixedValue, $sKey, $aField, $aRow)
  98. {
  99. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  100. }
  101. protected function _getCellCmtText($mixedValue, $sKey, $aField, $aRow)
  102. {
  103. $sTmp = strip_tags($aRow['cmt_text']);
  104. return parent::_getCellDefault($sTmp, $sKey, $aField, $aRow);
  105. }
  106. protected function _getCellCmtAuthorId($mixedValue, $sKey, $aField, $aRow)
  107. {
  108. $oProfile = BxDolProfile::getInstance($aRow['cmt_author_id']);
  109. $sProfile = $oProfile->getDisplayName();
  110. $oAcl = BxDolAcl::getInstance();
  111. $sAccountEmail = '';
  112. $sManageAccountUrl = '';
  113. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  114. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  115. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  116. }
  117. $mixedValue = $this->_oTemplate->parseHtmlByName('author_link.html', array(
  118. 'href' => $oProfile->getUrl(),
  119. 'title' => $sProfile,
  120. 'content' => $sProfile,
  121. 'bx_if:show_account' => array(
  122. 'condition' => !empty($sManageAccountUrl),
  123. 'content' => array(
  124. 'href' => $sManageAccountUrl,
  125. 'title' => _t('_sys_grid_txt_account_manager'),
  126. 'content' => $sAccountEmail
  127. )
  128. )
  129. ));
  130. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  131. }
  132. protected function _getCellHeaderReports ($sKey, $aField)
  133. {
  134. $s = parent::_getCellHeaderDefault($sKey, $aField);
  135. 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);
  136. }
  137. protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
  138. {
  139. if ($mixedValue == 0){
  140. $mixedValue = '';
  141. }
  142. else{
  143. $oReports = BxDolReport::getObjectInstance('sys_cmts', $aRow['id']);
  144. if ($oReports){
  145. $mixedValue = $oReports->getCounter().$oReports->getJsScript();
  146. }
  147. }
  148. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  149. }
  150. protected function _getManageAccountUrl($sFilter = '')
  151. {
  152. $sModuleAccounts = 'bx_accounts';
  153. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  154. return '';
  155. $sTypeUpc = strtoupper($this->_sManageType);
  156. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  157. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc]))
  158. return '';
  159. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_' . $sTypeUpc];
  160. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($sLink);
  161. if(!empty($sFilter))
  162. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  163. return $sLink;
  164. }
  165. }
  166. /** @} */