Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

nav_user_top.php 7.6KB

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