1
0

BxBaseModTextGridAdministration.php 7.4 KB

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