1
0

BxBaseModTextGridAdministration.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 $_sFieldStatus;
  14. protected $_sFilter1Name;
  15. protected $_sFilter1Value;
  16. protected $_aFilter1Values;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. parent::__construct ($aOptions, $oTemplate);
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. $this->_sFieldStatus = $CNF['FIELD_STATUS_ADMIN'];
  22. $this->_sFilter1Name = 'filter1';
  23. $this->_aFilter1Values = array(
  24. BX_BASE_MOD_TEXT_STATUS_ACTIVE => $CNF['T']['filter_item_active'],
  25. BX_BASE_MOD_TEXT_STATUS_HIDDEN => $CNF['T']['filter_item_hidden'],
  26. );
  27. if($this->_oModule->_oConfig->isAutoApprove())
  28. $this->_aFilter1Values[BX_BASE_MOD_TEXT_STATUS_PENDING] = $CNF['T']['filter_item_pending'];
  29. $sFilter1 = bx_get($this->_sFilter1Name);
  30. if(!empty($sFilter1)) {
  31. $this->_sFilter1Value = bx_process_input($sFilter1);
  32. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  33. }
  34. }
  35. protected function _switcherChecked2State($isChecked)
  36. {
  37. return $isChecked ? 'active' : 'hidden';
  38. }
  39. protected function _switcherState2Checked($mixedState)
  40. {
  41. return 'active' == $mixedState ? true : false;
  42. }
  43. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  44. {
  45. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  46. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  47. if(!empty($this->_sFilter1Value))
  48. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sFieldStatus . "`=?", $this->_sFilter1Value);
  49. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  50. }
  51. //--- Layout methods ---//
  52. protected function _getFilterControls()
  53. {
  54. parent::_getFilterControls();
  55. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  56. }
  57. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  58. {
  59. $CNF = &$this->_oModule->_oConfig->CNF;
  60. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  61. if((int)$aField['chars_limit'] > 0)
  62. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  63. if ($sTitle == '')
  64. $sTitle = _t('_sys_txt_no_title');
  65. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  66. }
  67. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  68. {
  69. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  70. }
  71. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  72. {
  73. $oProfile = $this->_getProfileObject($aRow['author']);
  74. $sProfile = $oProfile->getDisplayName();
  75. $oAcl = BxDolAcl::getInstance();
  76. $sAccountEmail = '';
  77. $sManageAccountUrl = '';
  78. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  79. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  80. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  81. }
  82. $sAddon = '';
  83. if(!empty($sManageAccountUrl))
  84. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  85. 'href' => $sManageAccountUrl,
  86. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  87. 'content' => $sAccountEmail,
  88. 'class' => 'bx-def-font-grayed'
  89. ));
  90. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  91. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  92. }
  93. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  94. {
  95. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  96. return '';
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  99. $a['attr'] = array_merge($a['attr'], array(
  100. "onclick" => "window.open('" . $sUrl . "','_self');"
  101. ));
  102. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  103. }
  104. protected function _getEntryLink($mixedValue, $aRow)
  105. {
  106. $CNF = &$this->_oModule->_oConfig->CNF;
  107. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  108. return $this->_oTemplate->parseHtmlByName('title_link.html', array(
  109. 'href' => $sUrl,
  110. 'title' => bx_html_attribute($mixedValue),
  111. 'content' => bx_process_output($mixedValue)
  112. ));
  113. }
  114. }
  115. /** @} */