BxBaseModTextGridAdministration.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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_TEXT_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. if(($this->_bContentFilter = !empty($CNF['FIELD_CF'])) !== false) {
  39. $this->_sFilter2Name = 'filter2';
  40. $this->_aFilter2Values = BxDolFormQuery::getDataItems('sys_content_filter');
  41. if(($sFilter2 = bx_get($this->_sFilter2Name)) !== false) {
  42. $this->_sFilter2Value = bx_process_input($sFilter2);
  43. $this->_aQueryAppend[$this->_sFilter2Name] = $this->_sFilter2Value;
  44. }
  45. }
  46. }
  47. protected function _switcherChecked2State($isChecked)
  48. {
  49. return $isChecked ? 'active' : 'hidden';
  50. }
  51. protected function _switcherState2Checked($mixedState)
  52. {
  53. return 'active' == $mixedState ? true : false;
  54. }
  55. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. if(strpos($sFilter, $this->_sParamsDivider) !== false) {
  59. $aFilters = explode($this->_sParamsDivider, $sFilter);
  60. if($this->_bContentFilter)
  61. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilters;
  62. else
  63. list($this->_sFilter1Value, $sFilter) = $aFilters;
  64. }
  65. if(!empty($this->_sFilter1Value))
  66. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  67. if(!empty($this->_sFilter2Value))
  68. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  69. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  70. }
  71. //--- Layout methods ---//
  72. protected function _getFilterControls()
  73. {
  74. parent::_getFilterControls();
  75. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  76. if($this->_bContentFilter)
  77. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  78. $sContent .= $this->_getSearchInput();
  79. return $sContent;
  80. }
  81. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  82. {
  83. $CNF = &$this->_oModule->_oConfig->CNF;
  84. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  85. if((int)$aField['chars_limit'] > 0)
  86. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  87. if ($sTitle == '')
  88. $sTitle = _t('_sys_txt_no_title');
  89. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  90. }
  91. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  92. {
  93. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  94. }
  95. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  96. {
  97. $oProfile = $this->_getProfileObject($aRow['author']);
  98. $sProfile = $oProfile->getDisplayName();
  99. $oAcl = BxDolAcl::getInstance();
  100. $sAccountEmail = '';
  101. $sManageAccountUrl = '';
  102. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  103. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  104. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  105. }
  106. $sAddon = '';
  107. if(!empty($sManageAccountUrl))
  108. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  109. 'href' => $sManageAccountUrl,
  110. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  111. 'content' => $sAccountEmail,
  112. 'class' => 'bx-def-font-grayed'
  113. ));
  114. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  115. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  116. }
  117. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  118. {
  119. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  120. return '';
  121. $CNF = &$this->_oModule->_oConfig->CNF;
  122. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  123. $a['attr'] = array_merge($a['attr'], array(
  124. "onclick" => "window.open('" . $sUrl . "','_self');"
  125. ));
  126. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  127. }
  128. protected function _getEntryLink($mixedValue, $aRow)
  129. {
  130. $CNF = &$this->_oModule->_oConfig->CNF;
  131. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  132. return $this->_oTemplate->parseHtmlByName('title_link.html', array(
  133. 'href' => $sUrl,
  134. 'title' => bx_html_attribute($mixedValue),
  135. 'content' => bx_process_output($mixedValue)
  136. ));
  137. }
  138. }
  139. /** @} */