BxBaseModTextGridAdministration.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. 'active' => $CNF['T']['filter_item_active'],
  25. 'hidden' => $CNF['T']['filter_item_hidden'],
  26. );
  27. $sFilter1 = bx_get($this->_sFilter1Name);
  28. if(!empty($sFilter1)) {
  29. $this->_sFilter1Value = bx_process_input($sFilter1);
  30. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  31. }
  32. }
  33. protected function _switcherChecked2State($isChecked)
  34. {
  35. return $isChecked ? 'active' : 'hidden';
  36. }
  37. protected function _switcherState2Checked($mixedState)
  38. {
  39. return 'active' == $mixedState ? true : false;
  40. }
  41. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  42. {
  43. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  44. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  45. if(!empty($this->_sFilter1Value))
  46. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `" . $this->_sFieldStatus . "`=?", $this->_sFilter1Value);
  47. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  48. }
  49. //--- Layout methods ---//
  50. protected function _getFilterControls()
  51. {
  52. parent::_getFilterControls();
  53. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  54. }
  55. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $sTitle = $aRow[$CNF['FIELD_TITLE']];
  59. if((int)$aField['chars_limit'] > 0)
  60. $sTitle = strmaxtextlen($sTitle, (int)$aField['chars_limit']);
  61. return parent::_getCellDefault($this->_getEntryLink($sTitle, $aRow), $sKey, $aField, $aRow);
  62. }
  63. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  64. {
  65. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  66. }
  67. protected function _getCellHeaderReports ($sKey, $aField)
  68. {
  69. $s = parent::_getCellHeaderDefault($sKey, $aField);
  70. return preg_replace ('/<a(.*?)>(.*?)<\/a>/', '<a$1 title="' . _t('_sys_txt_reports_title') . '"><i class="sys-icon exclamation-triangle"></i></a>', $s);
  71. }
  72. protected function _getCellReports($mixedValue, $sKey, $aField, $aRow)
  73. {
  74. if ($mixedValue == 0){
  75. $mixedValue = '';
  76. }
  77. else{
  78. $CNF = &$this->_oModule->_oConfig->CNF;
  79. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aRow[$CNF['FIELD_ID']]) : null;
  80. if ($oReports){
  81. $mixedValue = $oReports->getCounter().$oReports->getJsScript();
  82. }
  83. }
  84. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  85. }
  86. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  87. {
  88. $oProfile = $this->_getProfileObject($aRow['author']);
  89. $sProfile = $oProfile->getDisplayName();
  90. $oAcl = BxDolAcl::getInstance();
  91. $sAccountEmail = '';
  92. $sManageAccountUrl = '';
  93. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  94. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  95. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  96. }
  97. $mixedValue = $this->_oTemplate->parseHtmlByName('author_link.html', array(
  98. 'href' => $oProfile->getUrl(),
  99. 'title' => $sProfile,
  100. 'content' => $sProfile,
  101. 'bx_if:show_account' => array(
  102. 'condition' => !empty($sManageAccountUrl),
  103. 'content' => array(
  104. 'href' => $sManageAccountUrl,
  105. 'title' => _t($this->_oModule->_oConfig->CNF['T']['grid_txt_account_manager']),
  106. 'content' => $sAccountEmail
  107. )
  108. )
  109. ));
  110. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  111. }
  112. protected function _getActionEdit($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  113. {
  114. if($this->_sManageType == BX_DOL_MANAGE_TOOLS_ADMINISTRATION && $this->_oModule->checkAllowedEditAnyEntry() !== CHECK_ACTION_RESULT_ALLOWED)
  115. return '';
  116. $CNF = &$this->_oModule->_oConfig->CNF;
  117. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_EDIT_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  118. $a['attr'] = array_merge($a['attr'], array(
  119. "onclick" => "window.open('" . $sUrl . "','_self');"
  120. ));
  121. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  122. }
  123. protected function _getProfileObject($iId)
  124. {
  125. $oProfile = BxDolProfile::getInstance($iId);
  126. if (!$oProfile)
  127. $oProfile = BxDolProfileUndefined::getInstance();
  128. return $oProfile;
  129. }
  130. protected function _getEntryLink($mixedValue, $aRow)
  131. {
  132. $CNF = &$this->_oModule->_oConfig->CNF;
  133. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  134. return $this->_oTemplate->parseHtmlByName('title_link.html', array(
  135. 'href' => $sUrl,
  136. 'title' => bx_html_attribute($mixedValue),
  137. 'content' => bx_process_output($mixedValue)
  138. ));
  139. }
  140. }
  141. /** @} */