BxBaseMenuAddRelation.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Menu to add relation between profiles.
  11. */
  12. class BxBaseMenuAddRelation extends BxTemplMenu
  13. {
  14. protected $_sConnection;
  15. protected $_iInitiator;
  16. protected $_iContent;
  17. public function __construct ($aObject, $oTemplate)
  18. {
  19. parent::__construct ($aObject, $oTemplate);
  20. $this->_sConnection = 'sys_profiles_relations';
  21. $this->_iInitiator = bx_get_logged_profile_id();
  22. $this->_iContent = 0;
  23. }
  24. public function getCode ()
  25. {
  26. if(!BxDolRelation::isEnabled())
  27. return '';
  28. return parent::getCode();
  29. }
  30. public function getMenuItems ()
  31. {
  32. $this->loadData();
  33. return parent::getMenuItems();
  34. }
  35. protected function _getMenuItem ($a)
  36. {
  37. $aResult = parent::_getMenuItem($a);
  38. if(empty($aResult) || !is_array($aResult))
  39. return $aResult;
  40. if(!empty($a['class']))
  41. $aResult['class_add'] .= ' ' . $a['class'];
  42. return $aResult;
  43. }
  44. protected function loadData()
  45. {
  46. $sClassHidden = 'bx-menu-add-relation-hidden';
  47. if(bx_get('profile_id') !== false)
  48. $this->_iContent = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  49. $aSuggestions = array();
  50. $aRelations = BxDolConnection::getObjectInstance($this->_sConnection)->getRelations($this->_iInitiator, $this->_iContent, $aSuggestions);
  51. $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
  52. $aItems = array();
  53. foreach($aRelations as $iId => $aRelation) {
  54. $aItems[] = array(
  55. 'id' => $iId,
  56. 'name' => $iId,
  57. 'class' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
  58. 'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
  59. 'icon' => '',
  60. 'link' => 'javascript:void(0);',
  61. 'onclick' => "bx_conn_action(this, '" . $this->_sConnection . "', 'add', " . bx_js_string(json_encode(array('content' => $this->_iContent, 'relation' => $iId))) . ")"
  62. );
  63. }
  64. if($bSuggestions)
  65. $aItems[] = array(
  66. 'id' => 'see_more',
  67. 'name' => 'see_more',
  68. 'class' => '',
  69. 'title' => _t('_see_more'),
  70. 'icon' => '',
  71. 'link' => 'javascript:void(0);',
  72. 'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
  73. );
  74. $this->_aObject['menu_items'] = $aItems;
  75. }
  76. }
  77. /** @} */