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.

171 lines
8.5KB

  1. <?php
  2. use common\helpers\GlobalParam;
  3. use domain\Producer\Producer\Producer;
  4. use domain\Producer\Producer\ProducerModule;
  5. use domain\User\User\UserModule;
  6. use yii\bootstrap5\Nav;
  7. use yii\helpers\Html;
  8. $userModule = UserModule::getInstance();
  9. $producerModule = ProducerModule::getInstance();
  10. $userCurrent = GlobalParam::getCurrentUser();
  11. $isUserCurrentGrantedAsProducer = $userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent);
  12. $producer = null;
  13. if ($isUserCurrentGrantedAsProducer && $userCurrent->id_producer) {
  14. $producer = $producerModule->getRepository()->findOneProducerById($userCurrent->id_producer);
  15. }
  16. ?>
  17. <div class="container">
  18. <div class="nav-user-top">
  19. <nav class="navbar navbar-expand-lg">
  20. <div class="container-fluid">
  21. <?php
  22. $producersArray = Producer::find()
  23. ->joinWith(['userProducer user_producer'])
  24. ->where([
  25. 'user_producer.id_user' => GlobalParam::getCurrentUserId(),
  26. 'user_producer.bookmark' => 1,
  27. ])
  28. ->all();
  29. $itemsProducersArray = [];
  30. if (count($producersArray)) {
  31. $itemsProducersArray[] = [
  32. 'label' => 'Mes favoris',
  33. ];
  34. foreach ($producersArray as $producerItem) {
  35. $itemsProducersArray[] = [
  36. 'label' => Html::encode($producerItem->name),
  37. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producerItem->slug]),
  38. ];
  39. }
  40. } else {
  41. $itemsProducersArray[] = [
  42. 'label' => 'Aucun producteur dans vos favoris.',
  43. ];
  44. }
  45. $itemsProducersArray[] = [
  46. 'options' => ['class' => 'divider'],
  47. 'label' => ''
  48. ];
  49. $itemsProducersArray[] = [
  50. 'label' => '<span class="glyphicon glyphicon-search"></span> Rechercher un producteur',
  51. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producers'])
  52. ];
  53. // Items du menu
  54. /*$itemHome = [
  55. 'label' => '<span class="glyphicon glyphicon-home"></span> Accueil',
  56. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/index']),
  57. 'linkOptions' => ['class' => 'btn btn-default navbar-btn']
  58. ];*/
  59. $itemAdministration = [
  60. 'label' => '<span class="glyphicon glyphicon-cog"></span> <span class="link-text">Administration</span>',
  61. 'url' => $this->getUrlManagerBackend()->createAbsoluteUrl(['dashboard/index']),
  62. 'visible' => $isUserCurrentGrantedAsProducer,
  63. 'linkOptions' => ['class' => '']
  64. ];
  65. $itemProducerSpace = [
  66. 'label' => '<span class="glyphicon glyphicon-eye-open"></span> <span class="link-text">Mon espace producteur</span>',
  67. 'url' => $this->getUrlManagerProducer()->createAbsoluteUrl(['site/index', 'slug_producer' => $producer ? $producer->slug : '']),
  68. 'visible' => $isUserCurrentGrantedAsProducer,
  69. 'linkOptions' => ['class' => '']
  70. ];
  71. $itemProducers = [
  72. 'label' => '<span class="glyphicon glyphicon-star"></span> <span class="link-text">Mes producteurs</span>',
  73. 'url' => '#',
  74. 'items' => $itemsProducersArray,
  75. 'linkOptions' => ['class' => ''],
  76. 'visible' => !Yii::$app->user->isGuest
  77. ];
  78. $itemsUserArray = [];
  79. if ($context == 'producer') {
  80. $itemsUserArray = [
  81. [
  82. 'label' => '<span class="glyphicon glyphicon-home"></span> Retour à l\'accueil',
  83. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/index']),
  84. ]
  85. ];
  86. }
  87. $itemsUserArray[] = [
  88. 'label' => '<span class="glyphicon glyphicon-user"></span> Mon profil',
  89. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['user/update']),
  90. ];
  91. $itemsUserArray[] = [
  92. 'label' => '<span class="glyphicon glyphicon-off"></span> Déconnexion',
  93. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/logout']),
  94. ];
  95. $itemUser = [
  96. 'label' => '<span class="glyphicon glyphicon-user"></span> <span class="link-text">' .
  97. ((!Yii::$app->user->isGuest) ? Html::encode(Yii::$app->user->identity->name . ' ' . strtoupper(substr(Yii::$app->user->identity->lastname, 0, 1)) . '.') : '') .
  98. '</span>',
  99. 'options' => ['id' => 'label1'],
  100. 'url' => '#',
  101. 'linkOptions' => ['class' => ''],
  102. 'items' => $itemsUserArray,
  103. 'visible' => !Yii::$app->user->isGuest
  104. ];
  105. $itemConnexion = [
  106. 'label' => '<i class="bi bi-box-arrow-in-right"></i> Connexion',
  107. 'url' => ($context == 'producer')
  108. ? $this->getUrlManagerFrontend()->createAbsoluteUrl([
  109. 'site/producer',
  110. 'id' => $this->context->getProducerCurrent()->id,
  111. 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $this->context->getProducerCurrent()->slug])
  112. ])
  113. : $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/login']),
  114. 'linkOptions' => ['class' => ''],
  115. 'visible' => \Yii::$app->user->isGuest,
  116. 'active' => $this->getControllerAction() == 'site/login'
  117. ];
  118. $itemSignup = [
  119. 'label' => '<i class="bi bi-person-plus"></i> Inscription',
  120. 'url' => ($context == 'producer')
  121. ? $this->getUrlManagerFrontend()->createAbsoluteUrl([
  122. 'site/producer',
  123. 'id' => $this->context->getProducerCurrent()->id,
  124. 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['site/index', 'slug_producer' => $this->context->getProducerCurrent()->slug])
  125. ])
  126. : $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/signup']),
  127. 'linkOptions' => ['class' => ''],
  128. 'visible' => \Yii::$app->user->isGuest,
  129. 'active' => $this->getControllerAction() == 'site/signup'
  130. ];
  131. if ($context == 'frontend') {
  132. $itemsMenu = [
  133. $itemAdministration,
  134. $itemProducerSpace,
  135. $itemProducers,
  136. $itemUser,
  137. $itemConnexion,
  138. $itemSignup
  139. ];
  140. } elseif ($context == 'producer') {
  141. $itemsMenu = [
  142. $itemAdministration,
  143. $itemProducers,
  144. $itemUser,
  145. $itemConnexion,
  146. $itemSignup
  147. ];
  148. }
  149. echo Nav::widget([
  150. 'encodeLabels' => false,
  151. 'options' => ['class' => 'nav nav-pills navbar-nav navbar-right'],
  152. 'items' => $itemsMenu
  153. ]);
  154. ?>
  155. </div>
  156. </nav>
  157. </div>
  158. </div>