BxBaseModTextGridAdministration.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
  12. {
  13. protected $_sFilter1Name;
  14. protected $_sFilter1Value;
  15. protected $_aFilter1Values;
  16. protected $_sFilter2Name;
  17. protected $_sFilter2Value;
  18. protected $_aFilter2Values;
  19. protected $_bContentFilter;
  20. public function __construct ($aOptions, $oTemplate = false)
  21. {
  22. parent::__construct ($aOptions, $oTemplate);
  23. $CNF = &$this->_oModule->_oConfig->CNF;
  24. $this->_sStatusField = $CNF['FIELD_STATUS_ADMIN'];
  25. $this->_aStatusValues = array('active', 'hidden', 'pending');
  26. $this->_sFilter1Name = 'filter1';
  27. $this->_aFilter1Values = array(
  28. BX_BASE_MOD_TEXT_STATUS_ACTIVE => $CNF['T']['filter_item_active'],
  29. BX_BASE_MOD_TEXT_STATUS_HIDDEN => $CNF['T']['filter_item_hidden'],
  30. );
  31. if($this->_oModule->_oConfig->isAutoApprove())
  32. $this->_aFilter1Values[BX_BASE_MOD_GENERAL_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
  33. $sFilter1 = bx_get($this->_sFilter1Name);
  34. if(!empty($sFilter1)) {
  35. $this->_sFilter1Value = bx_process_input($sFilter1);
  36. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  37. }
  38. $oCf = BxDolContentFilter::getInstance();
  39. if(($this->_bContentFilter = ($oCf->isEnabled() && !empty($CNF['FIELD_CF']))) !== false) {
  40. $this->_sFilter2Name = 'filter2';
  41. $this->_aFilter2Values = $oCf->getValues();
  42. if(($sFilter2 = bx_get($this->_sFilter2Name)) !== false) {
  43. $this->_sFilter2Value = bx_process_input($sFilter2);
  44. $this->_aQueryAppend[$this->_sFilter2Name] = $this->_sFilter2Value;
  45. }
  46. }
  47. }
  48. protected function _switcherChecked2State($isChecked)
  49. {
  50. return $isChecked ? 'active' : 'hidden';
  51. }
  52. protected function _enable ($mixedId, $isChecked)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $bStatusAdmin = $this->_sStatusField == $CNF['FIELD_STATUS_ADMIN'];
  56. $sStatusBefore = '';
  57. if($bStatusAdmin) {
  58. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  59. if(!empty($aContentInfo) && is_array($aContentInfo))
  60. $sStatusBefore = $aContentInfo[$this->_sStatusField];
  61. }
  62. $mixedResult = parent::_enable($mixedId, $isChecked);
  63. if((int)$mixedResult > 0) {
  64. if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
  65. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  66. if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  67. $this->_oModule->onApprove($aContentInfo);
  68. }
  69. }
  70. return $mixedResult;
  71. }
  72. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  73. {
  74. $CNF = &$this->_oModule->_oConfig->CNF;
  75. $this->_parseFilterValue($sFilter);
  76. if(!empty($this->_sFilter1Value))
  77. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  78. if($this->_bContentFilter && !empty($this->_sFilter2Value))
  79. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  80. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  81. }
  82. //--- Layout methods ---//
  83. protected function _getFilterControls()
  84. {
  85. parent::_getFilterControls();
  86. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  87. if($this->_bContentFilter)
  88. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  89. $sContent .= $this->_getSearchInput();
  90. return $sContent;
  91. }
  92. protected function _getFilterControlsAPI($aFilters = [])
  93. {
  94. $aFilters = [
  95. $this->_sFilter1Name => []
  96. ];
  97. if(!empty($this->_sFilter2Name))
  98. $aFilters[$this->_sFilter2Name] = [];
  99. return parent::_getFilterControlsAPI($aFilters);
  100. }
  101. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  102. {
  103. $CNF = &$this->_oModule->_oConfig->CNF;
  104. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  105. if((int)$aField['chars_limit'] > 0)
  106. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  107. if($sTitle == '')
  108. $sTitle = _t('_sys_txt_no_title');
  109. if($this->_bIsApi)
  110. return ['type' => 'link', 'data' => [
  111. 'text' => $aRow[$CNF['FIELD_TITLE']],
  112. 'url' => $sUrl = bx_api_get_relative_url(bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']])))
  113. ]];
  114. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  115. }
  116. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  117. {
  118. if (bx_is_api()){
  119. return ['type' => 'time', 'data' => $mixedValue];
  120. }
  121. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  122. }
  123. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  124. {
  125. if (bx_is_api()){
  126. return ['type' => 'profile', 'data' => BxDolProfile::getData($mixedValue)];
  127. }
  128. $oProfile = $this->_getProfileObject($aRow['author']);
  129. $sProfile = $oProfile->getDisplayName();
  130. $oAcl = BxDolAcl::getInstance();
  131. $sAccountEmail = '';
  132. $sManageAccountUrl = '';
  133. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  134. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  135. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  136. }
  137. $sAddon = '';
  138. if(!empty($sManageAccountUrl))
  139. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  140. 'href' => $sManageAccountUrl,
  141. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  142. 'content' => $sAccountEmail,
  143. 'class' => 'bx-def-font-grayed'
  144. ));
  145. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  146. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  147. }
  148. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  149. {
  150. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  151. return '';
  152. $CNF = &$this->_oModule->_oConfig->CNF;
  153. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]));
  154. if ($this->_bIsApi) {
  155. $a['type'] = 'link';
  156. $a['name'] = $sKey;
  157. $a['url'] = bx_api_get_relative_url($sUrl);
  158. return $a;
  159. }
  160. $a['attr'] = array_merge($a['attr'], array(
  161. "onclick" => "window.open('" . $sUrl . "','_self');"
  162. ));
  163. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  164. }
  165. protected function _getEntryLink($mixedValue, $aRow)
  166. {
  167. $CNF = &$this->_oModule->_oConfig->CNF;
  168. return $this->_oTemplate->parseHtmlByName('title_link.html', [
  169. 'href' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']])),
  170. 'title' => bx_html_attribute($mixedValue),
  171. 'content' => bx_process_output($mixedValue),
  172. 'target' => '_blank'
  173. ]);
  174. }
  175. }
  176. /** @} */