Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

154 lines
6.5KB

  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. <div 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. 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
  55. ];
  56. $itemProducerSpace = [
  57. //'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">'.Html::encode($producer->name).'</span>',
  58. 'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">Mon espace producteur</span>',
  59. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']),
  60. 'visible' => $userManager->isCurrentProducer(),
  61. 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
  62. ];
  63. $itemProducers = [
  64. 'label' => '<span class="glyphicon glyphicon-star"></span> <span class="link-text">Mes producteurs</span>',
  65. 'url' => '#',
  66. 'items' => $itemsProducersArray,
  67. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  68. 'visible' => !Yii::$app->user->isGuest
  69. ];
  70. $itemsUserArray = [];
  71. if($context == 'producer') {
  72. $itemsUserArray = [
  73. [
  74. 'label' => '<span class="glyphicon glyphicon-chevron-left"></span> Retour à l\'accueil',
  75. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/index']),
  76. ]
  77. ];
  78. }
  79. $itemsUserArray[] = [
  80. 'label' => '<span class="glyphicon glyphicon-user"></span> Mon profil',
  81. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['user/update']),
  82. ];
  83. $itemsUserArray[] = [
  84. 'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
  85. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/logout']),
  86. ];
  87. $itemUser = [
  88. 'label' => '<span class="glyphicon glyphicon-user"></span> <span class="link-text">' .
  89. ((!Yii::$app->user->isGuest) ? Html::encode(Yii::$app->user->identity->name . ' ' . strtoupper(substr(Yii::$app->user->identity->lastname, 0, 1)).'.') : '') .
  90. //($producer ? ' ('.Html::encode($producer->name).')' : '').
  91. '</span>',
  92. 'options' => ['id' => 'label1'],
  93. 'url' => '#',
  94. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  95. 'items' => $itemsUserArray,
  96. 'visible' => !Yii::$app->user->isGuest
  97. ];
  98. $itemConnexion = [
  99. 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion',
  100. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/login']),
  101. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  102. 'visible' => \Yii::$app->user->isGuest,
  103. 'active' => $this->getControllerAction() == 'site/login'
  104. ];
  105. $itemSignup = [
  106. 'label' => '<span class="glyphicon glyphicon-user"></span> Inscription',
  107. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/signup']),
  108. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  109. 'visible' => \Yii::$app->user->isGuest,
  110. 'active' => $this->getControllerAction() == 'site/signup'
  111. ];
  112. if($context == 'frontend') {
  113. $itemsMenu = [
  114. $itemAdministration,
  115. $itemProducerSpace,
  116. $itemProducers,
  117. $itemUser,
  118. $itemConnexion,
  119. $itemSignup
  120. ];
  121. }
  122. elseif($context == 'producer') {
  123. $itemsMenu = [
  124. $itemAdministration,
  125. $itemProducers,
  126. $itemUser,
  127. $itemConnexion,
  128. $itemSignup
  129. ];
  130. }
  131. echo Nav::widget([
  132. 'encodeLabels' => false,
  133. 'options' => ['class' => 'nav nav-pills navbar-nav navbar-right'],
  134. 'items' => $itemsMenu
  135. ]);
  136. ?>
  137. </div>
  138. </nav>
  139. </div>