BxBaseModTextGridAdministration.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 _switcherState2Checked($mixedState)
  53. {
  54. return 'active' == $mixedState ? true : false;
  55. }
  56. protected function _enable ($mixedId, $isChecked)
  57. {
  58. $CNF = &$this->_oModule->_oConfig->CNF;
  59. $bStatusAdmin = $this->_sStatusField == $CNF['FIELD_STATUS_ADMIN'];
  60. $sStatusBefore = '';
  61. if($bStatusAdmin) {
  62. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  63. if(!empty($aContentInfo) && is_array($aContentInfo))
  64. $sStatusBefore = $aContentInfo[$this->_sStatusField];
  65. }
  66. $mixedResult = parent::_enable($mixedId, $isChecked);
  67. if((int)$mixedResult > 0) {
  68. if($bStatusAdmin && $sStatusBefore == BX_BASE_MOD_GENERAL_STATUS_PENDING) {
  69. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($mixedId);
  70. if($aContentInfo[$this->_sStatusField] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  71. $this->_oModule->onApprove($aContentInfo);
  72. }
  73. }
  74. return $mixedResult;
  75. }
  76. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  77. {
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. $aFilterParts = explode($this->_sParamsDivider, $sFilter);
  80. switch (substr_count($sFilter, $this->_sParamsDivider)) {
  81. case 1:
  82. list($this->_sFilter1Value, $sFilter) = $aFilterParts;
  83. break;
  84. case 2:
  85. list($this->_sFilter1Value, $this->_sFilter2Value, $sFilter) = $aFilterParts;
  86. break;
  87. }
  88. if(!empty($this->_sFilter1Value))
  89. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sStatusField . "`=?", $this->_sFilter1Value);
  90. if($this->_bContentFilter && !empty($this->_sFilter2Value))
  91. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $CNF['FIELD_CF'] . "`=?", $this->_sFilter2Value);
  92. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  93. }
  94. //--- Layout methods ---//
  95. protected function _getFilterControls()
  96. {
  97. parent::_getFilterControls();
  98. $sContent = $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values);
  99. if($this->_bContentFilter)
  100. $sContent .= $this->_getFilterSelectOne($this->_sFilter2Name, $this->_sFilter2Value, $this->_aFilter2Values);
  101. $sContent .= $this->_getSearchInput();
  102. return $sContent;
  103. }
  104. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  108. if((int)$aField['chars_limit'] > 0)
  109. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  110. if ($sTitle == '')
  111. $sTitle = _t('_sys_txt_no_title');
  112. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  113. }
  114. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  115. {
  116. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  117. }
  118. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  119. {
  120. $oProfile = $this->_getProfileObject($aRow['author']);
  121. $sProfile = $oProfile->getDisplayName();
  122. $oAcl = BxDolAcl::getInstance();
  123. $sAccountEmail = '';
  124. $sManageAccountUrl = '';
  125. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  126. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  127. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  128. }
  129. $sAddon = '';
  130. if(!empty($sManageAccountUrl))
  131. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  132. 'href' => $sManageAccountUrl,
  133. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  134. 'content' => $sAccountEmail,
  135. 'class' => 'bx-def-font-grayed'
  136. ));
  137. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  138. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  139. }
  140. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  141. {
  142. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  143. return '';
  144. $CNF = &$this->_oModule->_oConfig->CNF;
  145. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]));
  146. $a['attr'] = array_merge($a['attr'], array(
  147. "onclick" => "window.open('" . $sUrl . "','_self');"
  148. ));
  149. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  150. }
  151. protected function _getEntryLink($mixedValue, $aRow)
  152. {
  153. $CNF = &$this->_oModule->_oConfig->CNF;
  154. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]));
  155. return $this->_oTemplate->parseHtmlByName('title_link.html', array(
  156. 'href' => $sUrl,
  157. 'title' => bx_html_attribute($mixedValue),
  158. 'content' => bx_process_output($mixedValue)
  159. ));
  160. }
  161. }
  162. /** @} */