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.

163 lines
7.1KB

  1. <?php
  2. use common\helpers\GlobalParam;
  3. use common\logic\Producer\Producer\Model\Producer;
  4. use common\logic\User\User\Wrapper\UserModule;
  5. use yii\bootstrap\Nav;
  6. use yii\helpers\Html;
  7. $userModule = UserModule::getInstance();
  8. $producer = null;
  9. if ($userModule->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. } else {
  36. $itemsProducersArray[] = [
  37. 'label' => 'Aucun producteur dans vos favoris.',
  38. ];
  39. }
  40. $itemsProducersArray[] = [
  41. 'options' => ['class' => 'divider'],
  42. 'label' => ''
  43. ];
  44. $itemsProducersArray[] = [
  45. 'label' => '<span class="glyphicon glyphicon-search"></span> Rechercher un producteur',
  46. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producers'])
  47. ];
  48. // Items du menu
  49. $itemAdministration = [
  50. 'label' => '<span class="glyphicon glyphicon-cog"></span> <span class="link-text">Administration</span>',
  51. 'url' => $this->getUrlManagerBackend()->createAbsoluteUrl(['dashboard/index']),
  52. 'visible' => $userModule->isCurrentProducer(),
  53. 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
  54. ];
  55. $itemProducerSpace = [
  56. 'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">Mon espace producteur</span>',
  57. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']),
  58. 'visible' => $userModule->isCurrentProducer(),
  59. 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
  60. ];
  61. $itemProducers = [
  62. 'label' => '<span class="glyphicon glyphicon-star"></span> <span class="link-text">Mes producteurs</span>',
  63. 'url' => '#',
  64. 'items' => $itemsProducersArray,
  65. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  66. 'visible' => !Yii::$app->user->isGuest
  67. ];
  68. $itemsUserArray = [];
  69. if ($context == 'producer') {
  70. $itemsUserArray = [
  71. [
  72. 'label' => '<span class="glyphicon glyphicon-chevron-left"></span> Retour à l\'accueil',
  73. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/index']),
  74. ]
  75. ];
  76. }
  77. $itemsUserArray[] = [
  78. 'label' => '<span class="glyphicon glyphicon-user"></span> Mon profil',
  79. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['user/update']),
  80. ];
  81. $itemsUserArray[] = [
  82. 'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
  83. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/logout']),
  84. ];
  85. $itemUser = [
  86. 'label' => '<span class="glyphicon glyphicon-user"></span> <span class="link-text">' .
  87. ((!Yii::$app->user->isGuest) ? Html::encode(Yii::$app->user->identity->name . ' ' . strtoupper(substr(Yii::$app->user->identity->lastname, 0, 1)) . '.') : '') .
  88. '</span>',
  89. 'options' => ['id' => 'label1'],
  90. 'url' => '#',
  91. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  92. 'items' => $itemsUserArray,
  93. 'visible' => !Yii::$app->user->isGuest
  94. ];
  95. $itemConnexion = [
  96. 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion',
  97. 'url' => ($context == 'producer')
  98. ? $this->getUrlManagerFrontend()->createAbsoluteUrl([
  99. 'site/producer',
  100. 'id' => $this->context->getProducerCurrent()->id,
  101. 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $this->context->getProducerCurrent()->slug])
  102. ])
  103. : $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/login']),
  104. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  105. 'visible' => \Yii::$app->user->isGuest,
  106. 'active' => $this->getControllerAction() == 'site/login'
  107. ];
  108. $itemSignup = [
  109. 'label' => '<span class="glyphicon glyphicon-user"></span> Inscription',
  110. 'url' => ($context == 'producer')
  111. ? $this->getUrlManagerFrontend()->createAbsoluteUrl([
  112. 'site/producer',
  113. 'id' => $this->context->getProducerCurrent()->id,
  114. 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $this->context->getProducerCurrent()->slug])
  115. ])
  116. : $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/signup']),
  117. 'linkOptions' => ['class' => 'btn btn-default navbar-btn'],
  118. 'visible' => \Yii::$app->user->isGuest,
  119. 'active' => $this->getControllerAction() == 'site/signup'
  120. ];
  121. if ($context == 'frontend') {
  122. $itemsMenu = [
  123. $itemAdministration,
  124. $itemProducerSpace,
  125. $itemProducers,
  126. $itemUser,
  127. $itemConnexion,
  128. $itemSignup
  129. ];
  130. } elseif ($context == 'producer') {
  131. $itemsMenu = [
  132. $itemAdministration,
  133. $itemProducers,
  134. $itemUser,
  135. $itemConnexion,
  136. $itemSignup
  137. ];
  138. }
  139. echo Nav::widget([
  140. 'encodeLabels' => false,
  141. 'options' => ['class' => 'nav nav-pills navbar-nav navbar-right'],
  142. 'items' => $itemsMenu
  143. ]);
  144. ?>
  145. </div>
  146. </nav>
  147. </div>