BxPostsGridCategories.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 Posts Posts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPostsGridCategories extends BxTemplGrid
  12. {
  13. protected $MODULE;
  14. protected $_oModule;
  15. public function __construct ($aOptions, $oTemplate = false)
  16. {
  17. $this->MODULE = 'bx_posts';
  18. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  19. parent::__construct ($aOptions, $oTemplate);
  20. $this->_sDefaultSortingOrder = 'DESC';
  21. }
  22. public function performActionAdd()
  23. {
  24. $sAction = 'add';
  25. $oForm = BxDolForm::getObjectInstance('bx_posts_category', 'bx_posts_category_add');
  26. if (!$oForm)
  27. return '';
  28. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
  29. $oForm->initChecker();
  30. if($oForm->isSubmittedAndValid()) {
  31. $mixedResult = $oForm->insert(array('added' => time(), 'module' => $this->MODULE));
  32. if(is_numeric($mixedResult))
  33. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  34. else
  35. $aRes = array('msg' => $mixedResult);
  36. echoJson($aRes);
  37. }
  38. else {
  39. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx_posts_form_category_add', _t('_bx_posts_form_category_add_title'), $this->_oModule->_oTemplate->parseHtmlByName('manage_item.html', array(
  40. 'form_id' => $oForm->id,
  41. 'form' => $oForm->getCode(true),
  42. 'object' => $this->_sObject,
  43. 'action' => $sAction
  44. )));
  45. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => true))));
  46. }
  47. }
  48. public function performActionEdit()
  49. {
  50. $sAction = 'edit';
  51. $aIds = bx_get('ids');
  52. $iId = $aIds[0];
  53. $oForm = BxDolForm::getObjectInstance('bx_posts_category', 'bx_posts_category_edit');
  54. if (!$oForm)
  55. return '';
  56. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('_r'));
  57. $aContentInfo = array();
  58. $aContentInfo = $this->_oModule->_oDb->getCategoryInfoById($iId);
  59. $oForm->initChecker($aContentInfo, array());
  60. if($oForm->isSubmittedAndValid()) {
  61. $mixedResult = $oForm->update($iId);
  62. if(is_numeric($mixedResult))
  63. $aRes = array('grid' => $this->getCode(false), 'blink' => $mixedResult);
  64. else
  65. $aRes = array('msg' => $mixedResult);
  66. echoJson($aRes);
  67. }
  68. else {
  69. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx_posts_form_category_edit', _t('_bx_posts_form_category_edit_title'), $this->_oModule->_oTemplate->parseHtmlByName('manage_item.html', array(
  70. 'form_id' => $oForm->id,
  71. 'form' => $oForm->getCode(true),
  72. 'object' => $this->_sObject,
  73. 'action' => $sAction
  74. )));
  75. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  76. }
  77. }
  78. protected function _switcherChecked2State($isChecked)
  79. {
  80. return $isChecked ? 'active' : 'hidden';
  81. }
  82. protected function _switcherState2Checked($mixedState)
  83. {
  84. return 'active' == $mixedState ? true : false;
  85. }
  86. protected function _getCellAuthor($mixedValue, $sKey, $aField, $aRow)
  87. {
  88. if ($aRow['author'] > 0){
  89. $oProfile = BxDolProfile::getInstanceMagic($aRow['author']);
  90. $sProfile = $oProfile->getDisplayName();
  91. $mixedValue = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  92. 'href' => $oProfile->getUrl(),
  93. 'title' => $sProfile,
  94. 'content' => $sProfile,
  95. 'class' => 'bx-def-font-grayed'
  96. ));
  97. }
  98. else{
  99. $mixedValue = '';
  100. }
  101. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  102. }
  103. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  104. {
  105. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  106. }
  107. }
  108. /** @} */