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.

150 lines
6.2KB

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