BxCoursesGridCntDataManage.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 Courses Courses
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCoursesGridCntDataManage extends BxTemplGrid
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_sPageUrl;
  16. protected $_iEntryId;
  17. protected $_iEntryPid;
  18. protected $_iNodeId;
  19. protected $_aNodeInfo;
  20. protected $_iLevelMax;
  21. public function __construct ($aOptions, $oTemplate = false)
  22. {
  23. $this->_sModule = 'bx_courses';
  24. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  25. parent::__construct ($aOptions, $oTemplate);
  26. $CNF = &$this->_oModule->_oConfig->CNF;
  27. $this->_iEntryId = 0;
  28. if(($iEntryId = bx_get('entry_id')) !== false)
  29. $this->setEntryId($iEntryId);
  30. $this->setNodeId(($iNodeId = bx_get('parent_id')) !== false ? $iNodeId : 0);
  31. $this->_iLevelMax = $this->_oModule->_oConfig->isContentLevelMax();
  32. }
  33. public function setEntryId($iEntryId)
  34. {
  35. $CNF = &$this->_oModule->_oConfig->CNF;
  36. $this->_iEntryId = (int)$iEntryId;
  37. $this->_iEntryPid = ($oProfile = BxDolProfile::getInstanceByContentAndType($this->_iEntryId, $this->_sModule)) !== false ? $oProfile->id() : 0;
  38. $this->_sPageUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_MANAGE_STRUCTURE'], ['profile_id' => $this->_iEntryPid]);
  39. $this->_aQueryAppend['entry_id'] = $this->_iEntryId;
  40. }
  41. public function setNodeId($iNodeId)
  42. {
  43. $this->_iNodeId = (int)$iNodeId;
  44. $this->_aNodeInfo = [];
  45. if($this->_iNodeId)
  46. $this->_aNodeInfo = $this->_oModule->_oDb->getContentNodes(['sample' => 'id_full', 'id' => $this->_iNodeId]);
  47. $this->_aQueryAppend['parent_id'] = $this->_iNodeId;
  48. }
  49. public function getCode ($isDisplayHeader = true)
  50. {
  51. if(empty($this->_aNodeInfo) || !is_array($this->_aNodeInfo) || $this->_aNodeInfo['level'] != $this->_iLevelMax)
  52. return '';
  53. return parent::getCode($isDisplayHeader);
  54. }
  55. protected function _getCellContentId($mixedValue, $sKey, $aField, $aRow)
  56. {
  57. $iContentId = (int)$mixedValue;
  58. $mixedValue = '';
  59. $sModule = $aRow['content_type'];
  60. if(($sMethod = 'get_title') && bx_is_srv($sModule, $sMethod))
  61. $mixedValue = bx_srv($sModule, $sMethod, [$iContentId]);
  62. if(!$mixedValue && ($sMethod = 'get_text') && bx_is_srv($sModule, $sMethod))
  63. $mixedValue = bx_srv($sModule, $sMethod, [$iContentId]);
  64. if(!$mixedValue)
  65. $mixedValue = _t('_undefined');
  66. if(($sMethod = 'get_link') && bx_is_srv($sModule, $sMethod))
  67. $mixedValue = $this->_oModule->_oTemplate->parseHtmlByName('name_link.html', [
  68. 'href' => bx_srv($sModule, $sMethod, [$iContentId]),
  69. 'title' => bx_html_attribute($mixedValue),
  70. 'content' => $mixedValue
  71. ]);
  72. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  73. }
  74. protected function _getCellContentType($mixedValue, $sKey, $aField, $aRow)
  75. {
  76. return parent::_getCellDefault(_t('_' . $mixedValue), $sKey, $aField, $aRow);
  77. }
  78. protected function _getCellUsage($mixedValue, $sKey, $aField, $aRow)
  79. {
  80. return parent::_getCellDefault(_t('_bx_courses_txt_data_usage_' . $mixedValue), $sKey, $aField, $aRow);
  81. }
  82. protected function _getCellAdded($mixedValue, $sKey, $aField, $aRow)
  83. {
  84. if($this->_bIsApi)
  85. return ['type' => 'time', 'data' => $mixedValue];
  86. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  87. }
  88. protected function _getActionBack($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  89. {
  90. if(empty($this->_aNodeInfo))
  91. return '';
  92. $sUrl = $this->_sPageUrl;
  93. if(!empty($this->_aNodeInfo['parent_id']))
  94. $sUrl = bx_append_url_params($sUrl, ['parent_id' => $this->_aNodeInfo['parent_id']]);
  95. $a['attr'] = array_merge($a['attr'], [
  96. "onclick" => "window.open('" . $sUrl . "', '_self');"
  97. ]);
  98. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  99. }
  100. protected function _getActionAddSt($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  101. {
  102. $CNF = &$this->_oModule->_oConfig->CNF;
  103. $a['attr'] = array_merge($a['attr'], [
  104. "onclick" => "$(this).off('click'); bx_menu_popup('" . $CNF['OBJECT_MENU_CONTENT_ADD'] . "', this, {removeOnClose: 1}, {entry_pid: " . $this->_iEntryPid . ", node_id: " . $this->_iNodeId . ", usage:0});"
  105. ]);
  106. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  107. }
  108. protected function _getActionAddAt($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = [])
  109. {
  110. $CNF = &$this->_oModule->_oConfig->CNF;
  111. $a['attr'] = array_merge($a['attr'], [
  112. "onclick" => "$(this).off('click'); bx_menu_popup('" . $CNF['OBJECT_MENU_CONTENT_ADD'] . "', this, {removeOnClose: 1}, {entry_pid: " . $this->_iEntryPid . ", node_id: " . $this->_iNodeId . ", usage:1});"
  113. ]);
  114. return $this->_getActionDefault ($sType, $sKey, $a, $isSmall, $isDisabled, $aRow);
  115. }
  116. protected function _delete($mixedId)
  117. {
  118. $aData = $this->_oModule->_oDb->getContentData(['sample' => 'id', 'id' => (int)$mixedId]);
  119. if(!empty($aData) && is_array($aData)) {
  120. $sModule = $aData['content_type'];
  121. $sMethod = 'delete_entity';
  122. if(bx_is_srv($sModule, $sMethod) && bx_srv($sModule, $sMethod, [$aData['content_id']]) != '')
  123. return false;
  124. }
  125. return parent::_delete($mixedId) !== false;
  126. }
  127. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  128. {
  129. if(!$this->_iEntryId)
  130. return [];
  131. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString(" AND `entry_id`=? AND `node_id`=?", $this->_iEntryId, $this->_iNodeId);
  132. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  133. }
  134. protected function _getIds()
  135. {
  136. $aIds = bx_get('ids');
  137. if(!$aIds || !is_array($aIds)) {
  138. $iId = (int)bx_get('id');
  139. if(!$iId)
  140. return false;
  141. $aIds = [$iId];
  142. }
  143. return $aIds;
  144. }
  145. }
  146. /** @} */