BxBaseMenuAddRelation.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(!BxDolConnectionRelation::isEnabled())
  27. return '';
  28. return parent::getCode();
  29. }
  30. public function getMenuItems ()
  31. {
  32. $this->loadData();
  33. return parent::getMenuItems();
  34. }
  35. protected function loadData()
  36. {
  37. $sClassHidden = 'bx-menu-add-relation-hidden';
  38. if(bx_get('profile_id') !== false)
  39. $this->_iContent = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  40. $aSuggestions = [];
  41. $aRelations = BxDolConnection::getObjectInstance($this->_sConnection)->getRelations($this->_iInitiator, $this->_iContent, $aSuggestions);
  42. $bSuggestions = !empty($aSuggestions) && is_array($aSuggestions);
  43. $aItems = array();
  44. foreach($aRelations as $iId => $aRelation) {
  45. $aItems[] = [
  46. 'id' => 'bx-conn-rl-' . $iId,
  47. 'name' => 'bx-conn-rl-' . $iId,
  48. 'class_add' => $bSuggestions && !in_array($iId, $aSuggestions) ? $sClassHidden : '',
  49. 'title' => _t($aRelation[BX_DATA_VALUES_DEFAULT]),
  50. 'icon' => '',
  51. 'link' => 'javascript:void(0);',
  52. 'onclick' => "bx_conn_action(this, '" . $this->_sConnection . "', 'add', " . bx_js_string(json_encode(array('content' => $this->_iContent, 'relation' => $iId))) . ")"
  53. ];
  54. }
  55. if($bSuggestions)
  56. $aItems[] = [
  57. 'id' => 'see_more',
  58. 'name' => 'see_more',
  59. 'title' => _t('_see_more'),
  60. 'icon' => '',
  61. 'link' => 'javascript:void(0);',
  62. 'onclick' => bx_js_string("$(this).parents('li:first').hide().siblings('." . $sClassHidden . "').removeClass('" . $sClassHidden . "');")
  63. ];
  64. $this->_aObject['menu_items'] = $aItems;
  65. }
  66. }
  67. /** @} */