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.

164 satır
7.2KB

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