You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 line
5.6KB

  1. <?php
  2. use common\helpers\GlobalParam;
  3. use common\logic\Producer\Producer\Model\Producer;
  4. use common\logic\User\User\Wrapper\UserManager;
  5. use yii\bootstrap\Nav;
  6. use yii\helpers\Html;
  7. $userManager = UserManager::getInstance();
  8. $producer = null;
  9. if ($userManager->isCurrentProducer()) {
  10. $producer = Producer::searchOne(['id' => \Yii::$app->user->identity->id_producer]);
  11. }
  12. ?>
  13. <section class="nav-user-top">
  14. <nav class="navbar navbar-default">
  15. <div class="container">
  16. <?php
  17. $producersArray = Producer::find()
  18. ->joinWith(['userProducer user_producer'])
  19. ->where([
  20. 'user_producer.id_user' => GlobalParam::getCurrentUserId(),
  21. 'user_producer.bookmark' => 1,
  22. ])
  23. ->all();
  24. $itemsProducersArray = [];
  25. if (count($producersArray)) {
  26. $itemsProducersArray[] = [
  27. 'label' => 'Mes favoris',
  28. ];
  29. foreach($producersArray as $producerItem) {
  30. $itemsProducersArray[] = [
  31. 'label' => Html::encode($producerItem->name),
  32. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producerItem->slug]),
  33. ];
  34. }
  35. }
  36. else {
  37. $itemsProducersArray[] = [
  38. 'label' => 'Aucun producteur dans vos favoris.',
  39. ];
  40. }
  41. $itemsProducersArray[] = [
  42. 'options' => ['class' => 'divider'],
  43. 'label' => ''
  44. ];
  45. $itemsProducersArray[] = [
  46. 'label' => '<span class="glyphicon glyphicon-search"></span> Rechercher un producteur',
  47. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producers'])
  48. ];
  49. // Items du menu
  50. $itemAdministration = [
  51. 'label' => '<span class="glyphicon glyphicon-cog"></span> <span class="link-text">Administration</span>',
  52. 'url' => $this->getUrlManagerBackend()->createAbsoluteUrl(['site/index']),
  53. 'visible' => $userManager->isCurrentProducer()
  54. ];
  55. $itemProducerSpace = [
  56. 'label' => '<span class="glyphicon glyphicon-grain"></span> <span class="link-text">Espace producteur</span>',
  57. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']),
  58. 'visible' => $userManager->isCurrentProducer()
  59. ];
  60. $itemProducers = [
  61. 'label' => '<span class="glyphicon glyphicon-star"></span> <span class="link-text">Producteurs</span>',
  62. 'url' => '#',
  63. 'items' => $itemsProducersArray,
  64. 'visible' => !Yii::$app->user->isGuest
  65. ];
  66. $itemUser = [
  67. 'label' => '<span class="glyphicon glyphicon-user"></span> <span class="link-text">' . ((!Yii::$app->user->isGuest) ? Html::encode(Yii::$app->user->identity->name . ' ' . strtoupper(substr(Yii::$app->user->identity->lastname, 0, 1))) : '') . '. </span>',
  68. 'options' => ['id' => 'label1'],
  69. 'url' => '#',
  70. 'items' => [
  71. [
  72. 'label' => '<span class="glyphicon glyphicon-chevron-left"></span> Retour à l\'accueil',
  73. 'url' => $this->getUrlManagerFrontend()->createUrl(['site/index']),
  74. ],
  75. [
  76. 'label' => '<span class="glyphicon glyphicon-user"></span> Mon profil',
  77. 'url' => $this->getUrlManagerFrontend()->createUrl(['user/update']),
  78. ],
  79. [
  80. 'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
  81. 'url' => $this->getUrlManagerFrontend()->createUrl(['site/logout']),
  82. ]
  83. ],
  84. 'visible' => !Yii::$app->user->isGuest
  85. ];
  86. $itemConnexion = [
  87. 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion',
  88. 'url' => $this->getUrlManagerFrontend()->createUrl(['site/login']),
  89. 'visible' => \Yii::$app->user->isGuest,
  90. 'active' => $this->getControllerAction() == 'site/login'
  91. ];
  92. $itemSignup = [
  93. 'label' => '<span class="glyphicon glyphicon-user"></span> Inscription',
  94. 'url' => $this->getUrlManagerFrontend()->createUrl(['site/signup']),
  95. 'visible' => \Yii::$app->user->isGuest,
  96. 'active' => $this->getControllerAction() == 'site/signup'
  97. ];
  98. if($context == 'frontend') {
  99. $itemsMenu = [
  100. $itemAdministration,
  101. $itemProducerSpace,
  102. $itemProducers,
  103. $itemUser,
  104. $itemConnexion,
  105. $itemSignup
  106. ];
  107. }
  108. elseif($context == 'producer') {
  109. $itemsMenu = [
  110. $itemAdministration,
  111. $itemProducers,
  112. $itemUser,
  113. $itemConnexion,
  114. $itemSignup
  115. ];
  116. }
  117. echo Nav::widget([
  118. 'encodeLabels' => false,
  119. 'options' => ['class' => 'nav nav-pills navbar-nav navbar-right'],
  120. 'items' => $itemsMenu
  121. ]);
  122. ?>
  123. </div>
  124. </nav>
  125. </section>