BxBaseModTextGridAdministration.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModGeneralGridAdministration');
  12. class BxBaseModTextGridAdministration extends BxBaseModGeneralGridAdministration
  13. {
  14. protected $_sFilter1;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. parent::__construct ($aOptions, $oTemplate);
  18. $sFilter1 = bx_get('filter1');
  19. if(!empty($sFilter1)) {
  20. $this->_sFilter1 = bx_process_input($sFilter1);
  21. $this->_aQueryAppend['filter1'] = $this->_sFilter1;
  22. }
  23. }
  24. public function performActionDelete()
  25. {
  26. $sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
  27. $iAffected = 0;
  28. $aIds = bx_get('ids');
  29. if(!$aIds || !is_array($aIds)) {
  30. $this->_echoResultJson(array());
  31. exit;
  32. }
  33. $aIdsAffected = array ();
  34. foreach($aIds as $iId) {
  35. if((int)$this->_delete($iId) == 0)
  36. continue;
  37. $aIdsAffected[] = $iId;
  38. $iAffected++;
  39. }
  40. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($sPrefixLang . '_grid_action_err_delete')));
  41. }
  42. protected function _switcherChecked2State($isChecked)
  43. {
  44. return $isChecked ? 'active' : 'hidden';
  45. }
  46. protected function _switcherState2Checked($mixedState)
  47. {
  48. return 'active' == $mixedState ? true : false;
  49. }
  50. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  51. {
  52. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  53. list($this->_sFilter1, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  54. if(!empty($this->_sFilter1))
  55. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepare(" AND `status`=?", $this->_sFilter1);
  56. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  57. }
  58. //--- Layout methods ---//
  59. protected function _getFilterControls()
  60. {
  61. parent::_getFilterControls();
  62. $sPrefixLang = $this->_oModule->_oConfig->getPrefix('lang');
  63. $sFilterName = 'filter1';
  64. $aFilterValues = array(
  65. 'active' => $sPrefixLang . '_grid_filter_item_title_adm_active',
  66. 'hidden' => $sPrefixLang . '_grid_filter_item_title_adm_hidden',
  67. );
  68. return $this->_getFilterSelectOne($sFilterName, $aFilterValues) . $this->_getSearchInput();
  69. }
  70. protected function _getCellTitle($mixedValue, $sKey, $aField, $aRow)
  71. {
  72. $CNF = &$this->_oModule->_oConfig->CNF;
  73. bx_import('BxDolPermalinks');
  74. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aRow[$CNF['FIELD_ID']]);
  75. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  76. 'href' => $sUrl,
  77. 'title' => $mixedValue,
  78. 'bx_repeat:attrs' => array(),
  79. 'content' => $mixedValue
  80. ));
  81. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  82. }
  83. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  84. {
  85. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  86. }
  87. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  88. {
  89. $oProfile = $this->_getProfileObject($aRow['author']);
  90. $sProfile = $oProfile->getDisplayName();
  91. $mixedValue = $this->_oTemplate->parseHtmlByName('bx_a.html', array(
  92. 'href' => $oProfile->getUrl(),
  93. 'title' => $sProfile,
  94. 'bx_repeat:attrs' => array(),
  95. 'content' => $sProfile
  96. ));
  97. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  98. }
  99. protected function _getProfileObject($iId)
  100. {
  101. bx_import('BxDolProfile');
  102. $oProfile = BxDolProfile::getInstance($iId);
  103. if (!$oProfile) {
  104. bx_import('BxDolProfileUndefined');
  105. $oProfile = BxDolProfileUndefined::getInstance();
  106. }
  107. return $oProfile;
  108. }
  109. }
  110. /** @} */