1
0

BxCnlTemplate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * @defdroup Channels Channels
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Channels module representation.
  13. */
  14. class BxCnlTemplate extends BxBaseModGroupsTemplate
  15. {
  16. function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_channels';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  22. {
  23. $CNF = &$this->_oConfig->CNF;
  24. $oLabel = BxDolLabel::getInstance();
  25. $oPermalink = BxDolPermalinks::getInstance();
  26. $aLabel = $oLabel->getLabels(array('type' => 'value', 'value' => $aContentInfo[$CNF['FIELD_NAME']]));
  27. if(empty($aLabel) || !is_array($aLabel))
  28. return '';
  29. $aTmplVarsItems = array();
  30. $this->_entryBreadcrumb($aLabel['id'], $oLabel, $oPermalink, $aTmplVarsItems);
  31. $aTmplVarsItems = array_reverse($aTmplVarsItems);
  32. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  33. }
  34. public function entryParent($aContentInfo)
  35. {
  36. $CNF = &$this->_oConfig->CNF;
  37. $oLabel = BxDolLabel::getInstance();
  38. $aLabel = $oLabel->getLabels(array('type' => 'value', 'value' => $aContentInfo[$CNF['FIELD_NAME']]));
  39. if(empty($aLabel) || !is_array($aLabel) || (int)$aLabel['parent'] == 0)
  40. return false;
  41. $aLabelParent = $oLabel->getLabels(array('type' => 'id', 'id' => $aLabel['parent']));
  42. $aContentInfoParent = $this->_oDb->getChannelInfoByName($aLabelParent['value']);
  43. if(empty($aContentInfoParent) || !is_array($aContentInfoParent))
  44. return false;
  45. return $this->parseHtmlByName('entry-parent.html', array('content' => $this->_entryRelatives(array($aContentInfoParent['profile_id']))));
  46. }
  47. public function entryChilds($aContentInfo)
  48. {
  49. $CNF = &$this->_oConfig->CNF;
  50. $oLabel = BxDolLabel::getInstance();
  51. $aLabel = $oLabel->getLabels(array('type' => 'value', 'value' => $aContentInfo[$CNF['FIELD_NAME']]));
  52. if(empty($aLabel) || !is_array($aLabel))
  53. return false;
  54. $aLabelChildren = $oLabel->getLabels(array('type' => 'parent', 'parent' => $aLabel['id']));
  55. if(empty($aLabelChildren) || !is_array($aLabelChildren))
  56. return false;
  57. $aIds = array();
  58. foreach($aLabelChildren as $aLabelChild) {
  59. $aContentInfoChild = $this->_oDb->getChannelInfoByName($aLabelChild['value']);
  60. if(empty($aContentInfoChild) || !is_array($aContentInfoChild))
  61. continue;
  62. $aIds[] = $aContentInfoChild['profile_id'];
  63. }
  64. if(empty($aIds))
  65. return false;
  66. return $this->parseHtmlByName('entry-childs.html', array('content' => $this->_entryRelatives($aIds)));
  67. }
  68. protected function _entryBreadcrumb($iLabel, &$oLabel, &$oPermalink, &$aTmplVarsItems)
  69. {
  70. $CNF = &$this->_oConfig->CNF;
  71. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabel));
  72. if(empty($aLabel) || !is_array($aLabel))
  73. return;
  74. $iChannel = (int)$this->_oDb->getChannelIdByName($aLabel['value']);
  75. $aTmplVarsItems[] = array(
  76. 'url' => $iChannel != 0 ? $oPermalink->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iChannel) : 'javascript:void(0)',
  77. 'title' => bx_process_output($aLabel['value'])
  78. );
  79. if(empty($aLabel['parent']))
  80. return;
  81. $this->_entryBreadcrumb((int)$aLabel['parent'], $oLabel, $oPermalink, $aTmplVarsItems);
  82. }
  83. protected function _entryRelatives($aProfiles)
  84. {
  85. $sResult = '';
  86. foreach($aProfiles as $iProfile) {
  87. $oProfile = BxDolProfile::getInstance($iProfile);
  88. if(!$oProfile)
  89. continue;
  90. $sResult .= $oProfile->getUnit(false, array('template' => 'unit_wo_cover'));
  91. }
  92. return $sResult;
  93. }
  94. }
  95. /** @} */