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.

167 lines
7.4KB

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