1
0

BxFdbGridQuestions.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 Feedback Feedback
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFdbGridQuestions extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sParamsDivider;
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $this->_sModule = 'bx_feedback';
  20. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  21. $this->_sParamsDivider = '#-#';
  22. }
  23. public function getJsCode($sKey = 'question')
  24. {
  25. return $this->_oModule->_oTemplate->getJsCode($sKey, array(
  26. 'sObjNameGrid' => $this->_sObject,
  27. 'sParamsDivider' => $this->_sParamsDivider,
  28. 'sTextSearchInput' => _t('_sys_grid_search')
  29. ));
  30. }
  31. public function getCode ($isDisplayHeader = true)
  32. {
  33. $sResult = parent::getCode($isDisplayHeader);
  34. if(!empty($sResult))
  35. $sResult .= $this->getJsCode();
  36. return $sResult;
  37. }
  38. public function performActionAdd()
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. $sAction = 'add';
  42. $aActionParams = array('o' => $this->_sObject, 'a' => $sAction);
  43. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_QUESTION'], $CNF['OBJECT_FORM_QUESTION_DISPLAY_ADD']);
  44. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aActionParams);
  45. $oForm->initChecker();
  46. if($oForm->isSubmittedAndValid()) {
  47. $iNow = time();
  48. $aValsToAdd = array(
  49. 'author' => bx_get_logged_profile_id(),
  50. 'added' => $iNow,
  51. 'changed' => $iNow
  52. );
  53. if(($iId = $oForm->insert($aValsToAdd)) !== false) {
  54. $this->_oModule->onAddQuestion($iId);
  55. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  56. }
  57. else
  58. $aRes = array('msg' => _t('_bx_feedback_err_cannot_perform'));
  59. return echoJson($aRes);
  60. }
  61. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('question_popup_add'), _t('_bx_feedback_grid_question_popup_title_add'), $this->_oModule->_oTemplate->parseHtmlByName('question_popup_form.html', array(
  62. 'form_id' => $oForm->getId(),
  63. 'form' => $oForm->getCode(true),
  64. 'object' => $this->_sObject,
  65. 'action' => $sAction
  66. )));
  67. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  68. }
  69. public function performActionEdit()
  70. {
  71. $CNF = &$this->_oModule->_oConfig->CNF;
  72. $aIds = bx_get('ids');
  73. if(!$aIds || !is_array($aIds)) {
  74. $iId = (int)bx_get('id');
  75. if(!$iId)
  76. return echoJson(array());
  77. $aIds = array($iId);
  78. }
  79. $iId = $aIds[0];
  80. $sAction = 'edit';
  81. $aActionParams = array('o' => $this->_sObject, 'a' => $sAction, 'id' => $iId);
  82. $aQuestion = $this->_oModule->_oDb->getQuestions(array('type' => 'id', 'id' => $iId));
  83. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_QUESTION'], $CNF['OBJECT_FORM_QUESTION_DISPLAY_EDIT']);
  84. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aActionParams);
  85. $oForm->initChecker($aQuestion);
  86. if($oForm->isSubmittedAndValid()) {
  87. $aValsToAdd = array(
  88. 'changed' => time()
  89. );
  90. if($oForm->update($iId, $aValsToAdd) !== false) {
  91. $this->_oModule->onEditQuestion($iId);
  92. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  93. }
  94. else
  95. $aRes = array('msg' => _t('_bx_feedback_err_cannot_perform'));
  96. return echoJson($aRes);
  97. }
  98. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oModule->_oConfig->getHtmlIds('question_popup_edit'), _t('_bx_feedback_grid_question_popup_title_edit'), $this->_oModule->_oTemplate->parseHtmlByName('question_popup_form.html', array(
  99. 'form_id' => $oForm->getId(),
  100. 'form' => $oForm->getCode(true),
  101. 'object' => $this->_sObject,
  102. 'action' => $sAction
  103. )));
  104. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  105. }
  106. protected function _delete($mixedId)
  107. {
  108. $aQuestion = $this->_oModule->_oDb->getQuestions(array('type' => 'id', 'id' => $mixedId));
  109. if(empty($aQuestion) || !is_array($aQuestion))
  110. return false;
  111. $mixedResult = parent::_delete($mixedId);
  112. if($mixedResult !== false)
  113. $this->_oModule->onDeleteQuestion($aQuestion);
  114. return $mixedResult;
  115. }
  116. protected function _switcherChecked2State($isChecked)
  117. {
  118. return $isChecked ? 'active' : 'hidden';
  119. }
  120. protected function _switcherState2Checked($mixedState)
  121. {
  122. return 'active' == $mixedState ? true : false;
  123. }
  124. protected function _getCellSwitcher ($mixedValue, $sKey, $aField, $aRow)
  125. {
  126. $CNF = &$this->_oModule->_oConfig->CNF;
  127. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aRow[$CNF['FIELD_STATUS_ADMIN']]) && !in_array($aRow[$CNF['FIELD_STATUS_ADMIN']], array('active', 'hidden'))) {
  128. $sStatusKey = '_sys_status_' . $aRow[$CNF['FIELD_STATUS_ADMIN']];
  129. if(!empty($CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS_ADMIN']]]))
  130. $sStatusKey = $CNF['T']['txt_status_' . $aRow[$CNF['FIELD_STATUS_ADMIN']]];
  131. return parent::_getCellDefault(_t($sStatusKey), $sKey, $aField, $aRow);
  132. }
  133. return parent::_getCellSwitcher ($mixedValue, $sKey, $aField, $aRow);
  134. }
  135. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  136. {
  137. return parent::_getCellDefault(bx_time_js($mixedValue, BX_FORMAT_DATE, true), $sKey, $aField, $aRow);
  138. }
  139. }
  140. /** @} */