1
0

BxBaseModTextGridAdministration.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  76. switch (substr_count($sFilter, $this->_sParamsDivider)) {
  77. case 1:
  78. list($this->_sFilter1Value, $sFilter) = $aFilterParts;
  79. break;
  80. case 2:
  81. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilterParts;
  82. break;
  83. }
  84. if(!empty($this->_sFilter1Value))
  85. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  86. if($this->_bContentFilter && !empty($this->_sFilter2Value))
  87. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  88. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  89. }
  90. //--- Layout methods ---//
  91. protected function _getFilterControls()
  92. {
  93. parent::_getFilterControls();
  94. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  95. if($this->_bContentFilter)
  96. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  97. $sContent .= $this->_getSearchInput();
  98. return $sContent;
  99. }
  100. protected function _getFilterControlsAPI($aFilters = [])
  101. {
  102. $aFilters = [
  103. $this->_sFilter1Name => [],
  104. $this->_sFilter2Name => []
  105. ];
  106. return parent::_getFilterControlsAPI($aFilters);
  107. }
  108. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  109. {
  110. $CNF = &$this->_oModule->_oConfig->CNF;
  111. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  112. if((int)$aField['chars_limit'] > 0)
  113. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  114. if ($sTitle == '')
  115. $sTitle = _t('_sys_txt_no_title');
  116. if (bx_is_api()){
  117. return ['type' => 'link', 'data' => [
  118. 'text' => $aRow[$CNF['FIELD_TITLE']],
  119. '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']])))
  120. ]];
  121. }
  122. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  123. }
  124. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  125. {
  126. if (bx_is_api()){
  127. return ['type' => 'time', 'data' => $mixedValue];
  128. }
  129. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  130. }
  131. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  132. {
  133. if (bx_is_api()){
  134. return ['type' => 'profile', 'data' => BxDolProfile::getData($mixedValue)];
  135. }
  136. $oProfile = $this->_getProfileObject($aRow['author']);
  137. $sProfile = $oProfile->getDisplayName();
  138. $oAcl = BxDolAcl::getInstance();
  139. $sAccountEmail = '';
  140. $sManageAccountUrl = '';
  141. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  142. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  143. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  144. }
  145. $sAddon = '';
  146. if(!empty($sManageAccountUrl))
  147. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  148. 'href' => $sManageAccountUrl,
  149. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  150. 'content' => $sAccountEmail,
  151. 'class' => 'bx-def-font-grayed'
  152. ));
  153. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  154. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  155. }
  156. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  157. {
  158. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  159. return '';
  160. $CNF = &$this->_oModule->_oConfig->CNF;
  161. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]));
  162. if (bx_is_api()){
  163. $a['type'] = 'link';
  164. $a['name'] = $sKey;
  165. $a['url'] = bx_api_get_relative_url($sUrl);
  166. return $a;
  167. }
  168. $a['attr'] = array_merge($a['attr'], array(
  169. "onclick" => "window.open('" . $sUrl . "','_self');"
  170. ));
  171. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  172. }
  173. protected function _getEntryLink($mixedValue, $aRow)
  174. {
  175. $CNF = &$this->_oModule->_oConfig->CNF;
  176. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]));
  177. return $this->_oTemplate->parseHtmlByName('title_link.html', array(
  178. 'href' => $sUrl,
  179. 'title' => bx_html_attribute($mixedValue),
  180. 'content' => bx_process_output($mixedValue)
  181. ));
  182. }
  183. }
  184. /** @} */