Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.php 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * Copyright La boîte à pain (2018)
  4. *
  5. * contact@opendistrib.net
  6. *
  7. * Ce logiciel est un programme informatique servant à aider les producteurs
  8. * à distribuer leur production en circuits courts.
  9. *
  10. * Ce logiciel est régi par la licence CeCILL soumise au droit français et
  11. * respectant les principes de diffusion des logiciels libres. Vous pouvez
  12. * utiliser, modifier et/ou redistribuer ce programme sous les conditions
  13. * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  14. * sur le site "http://www.cecill.info".
  15. *
  16. * En contrepartie de l'accessibilité au code source et des droits de copie,
  17. * de modification et de redistribution accordés par cette licence, il n'est
  18. * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  19. * seule une responsabilité restreinte pèse sur l'auteur du programme, le
  20. * titulaire des droits patrimoniaux et les concédants successifs.
  21. *
  22. * A cet égard l'attention de l'utilisateur est attirée sur les risques
  23. * associés au chargement, à l'utilisation, à la modification et/ou au
  24. * développement et à la reproduction du logiciel par l'utilisateur étant
  25. * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  26. * manipuler et qui le réserve donc à des développeurs et des professionnels
  27. * avertis possédant des connaissances informatiques approfondies. Les
  28. * utilisateurs sont donc invités à charger et tester l'adéquation du
  29. * logiciel à leurs besoins dans des conditions permettant d'assurer la
  30. * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  31. * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  32. *
  33. * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  34. * pris connaissance de la licence CeCILL, et que vous en avez accepté les
  35. * termes.
  36. */
  37. use common\logic\Order\Order\Model\Order;
  38. use common\logic\Producer\Producer\Module\ProducerModule;
  39. use common\logic\User\User\Module\UserModule;
  40. use common\logic\User\UserProducer\Model\UserProducer;
  41. use yii\bootstrap\Nav;
  42. use common\helpers\GlobalParam;
  43. use yii\helpers\Html;
  44. \common\assets\CommonAsset::register($this);
  45. \producer\assets\AppAsset::register($this);
  46. $userModule = UserModule::getInstance();
  47. $userCurrent = GlobalParam::getCurrentUser();
  48. $producerModule = ProducerModule::getInstance();
  49. $producerUser = null;
  50. if($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
  51. $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);
  52. }
  53. $producer = $this->context->getProducerCurrent();
  54. if (!Yii::$app->user->isGuest) {
  55. $userProducer = UserProducer::findOne(['id_user' => GlobalParam::getCurrentUserId(), 'id_producer' => $producer->id]);
  56. }
  57. ?>
  58. <?php $this->beginPage() ?>
  59. <!DOCTYPE html>
  60. <html lang="fr-FR">
  61. <head>
  62. <title><?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?></title>
  63. <meta charset="utf-8">
  64. <meta name="viewport" content="width=device-width, initial-scale=1">
  65. <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">
  66. <meta name="slug-producer" content="<?= $producer->slug; ?>">
  67. <?= Html::csrfMetaTags() ?>
  68. <link rel="icon" type="image/png"
  69. href="<?php echo \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon-distrib.png"/>
  70. <?php $this->head() ?>
  71. <?= $this->render('@common/views/matomo.php') ?>
  72. </head>
  73. <body class="<?= \Yii::$app->controller->id . '-' . \Yii::$app->controller->action->id ?>">
  74. <?php $this->beginBody() ?>
  75. <?= $this->render('@common/views/nav_user_top', [
  76. 'context' => 'producer'
  77. ]); ?>
  78. <div class="container">
  79. <div id="left" class="col-md-3">
  80. <div class="fixed">
  81. <?php if (strlen($producer->logo)): ?>
  82. <div id="logo"<?php if (!is_null($producer->background_color_logo) && strlen($producer->background_color_logo)): ?> style="background-color:<?= Html::encode($producer->background_color_logo); ?>"<?php endif; ?>>
  83. <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
  84. <img class="img-logo"
  85. src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  86. alt="Logo <?= Html::encode($producer->name) ?>"/>
  87. </a>
  88. </div>
  89. <?php endif; ?>
  90. <h1><?= Html::encode($producer->name); ?></h1>
  91. <h2><?= Html::encode($producer->type) ?> à <?= Html::encode($producer->city); ?>
  92. (<?= Html::encode($producer->postcode); ?>)</h2>
  93. <nav id="main-nav">
  94. <?php
  95. $credit = '';
  96. if (isset($userProducer) && $userProducer) {
  97. $labelType = $userProducer->credit > 0 ? 'success' : 'danger';
  98. $credit = ' <span class="label label-' . $labelType . '">' . number_format($userProducer->credit, 2) . ' €</span>';
  99. }
  100. $countSubcriptions = 0;
  101. if ($userCurrent) {
  102. $countSubcriptions = $this->getSubscriptionModule()->countSubscriptionsByUser(
  103. $userCurrent
  104. );
  105. }
  106. $labelSubscription = $countSubcriptions > 0 ? 'success' : 'default';
  107. $countOrders = Order::find()
  108. ->joinWith(['distribution'])
  109. ->where([
  110. 'id_user' => GlobalParam::getCurrentUserId(),
  111. 'distribution.id_producer' => GlobalParam::getCurrentProducerId()
  112. ])
  113. ->params([':date_today' => date('Y-m-d')])
  114. ->andWhere('distribution.date >= :date_today')
  115. ->count();
  116. $labelOrders = $countOrders > 0 ? 'success' : 'default';
  117. $isUserSubscribedNewsletter = $userModule->isUserSubscribedNewsletter($userCurrent);
  118. echo Nav::widget([
  119. 'encodeLabels' => false,
  120. 'options' => ['class' => 'nav'],
  121. 'items' => [
  122. [
  123. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  124. 'label' => '<span class="glyphicon glyphicon-home"></span> Accueil',
  125. 'active' => $this->getControllerAction() == 'site/index',
  126. ],
  127. [
  128. 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
  129. 'url' => $this->getUrlManagerProducer()->createUrl(['order/order']),
  130. 'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
  131. 'active' => $this->getControllerAction() == 'order/order',
  132. ],
  133. [
  134. 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
  135. 'url' => $this->getUrlManagerFrontend()->createAbsoluteUrl(['site/producer', 'id' => $this->context->getProducerCurrent()->id, 'return_url' => \Yii::$app->urlManagerProducer->createAbsoluteUrl(['order/order', 'slug_producer' => $this->context->getProducerCurrent()->slug])]),
  136. 'visible' => !$producer->option_allow_order_guest && \Yii::$app->user->isGuest,
  137. 'active' => $this->getControllerAction() == 'order/order',
  138. ],
  139. [
  140. 'label' => '<span class="glyphicon glyphicon-folder-open"></span> Mes commandes <span class="label label-' . $labelOrders . '">' . $countOrders . '</span>',
  141. 'url' => $this->getUrlManagerProducer()->createUrl(['order/history']),
  142. 'visible' => !Yii::$app->user->isGuest,
  143. 'active' => $this->getControllerAction() == 'order/history',
  144. ],
  145. [
  146. 'label' => '<span class="glyphicon glyphicon-repeat"></span> Abonnements <span class="label label-' . $labelSubscription . '">' . $countSubcriptions . '</span>',
  147. 'url' => $this->getUrlManagerProducer()->createUrl(['subscription/index']),
  148. 'visible' => !Yii::$app->user->isGuest && $producer->user_manage_subscription,
  149. 'active' => $this->getControllerAction() == 'subscription/index',
  150. ],
  151. [
  152. 'label' => '<span class="glyphicon glyphicon-euro"></span> Crédit' . $credit,
  153. 'url' => $this->getUrlManagerProducer()->createUrl(['credit/history']),
  154. 'visible' => !Yii::$app->user->isGuest && $producer->credit,
  155. 'active' => $this->getControllerAction() == 'credit/history',
  156. ],
  157. [
  158. 'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Bulletin d\'information <span class="label label-'.($isUserSubscribedNewsletter ? 'success' : 'danger').'">'.($isUserSubscribedNewsletter ? 'Oui' : 'Non').'</span>',
  159. 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
  160. 'visible' => !Yii::$app->user->isGuest,
  161. 'active' => $this->getControllerAction() == 'newsletter/index',
  162. ],
  163. [
  164. 'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact',
  165. 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']),
  166. 'active' => $this->getControllerAction() == 'site/contact',
  167. ],
  168. ],
  169. ]);
  170. ?>
  171. </nav>
  172. </div>
  173. </div>
  174. <div id="main" class="col-md-9">
  175. <?php if (strlen($producer->photo)): ?>
  176. <div id="img-big">
  177. <img class="img-photo" src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->photo; ?>"
  178. alt="Photo <?= Html::encode($producer->name) ?>"/>
  179. </div>
  180. <?php endif; ?>
  181. <div id="infos-producer">
  182. <?php if (!$this->getProducerModule()->hasSpecificDelays($producer) && $producer->order_deadline && $producer->order_delay): ?>
  183. <span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
  184. <span class="glyphicon glyphicon-time"></span> Commande avant
  185. <strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
  186. <span data-toggle="tooltip" data-placement="bottom"
  187. title="Exemple : commande le lundi pour le
  188. <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi
  189. <?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi
  190. <?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche
  191. <?php elseif ($producer->order_delay == 7): ?>lundi d'après<?php endif; ?>"><strong><?= Html::encode($producer->order_delay) ?> jour<?php if ($producer->order_delay > 1): ?>s<?php endif; ?></strong> à l'avance</span>
  192. <?php endif; ?>
  193. <?php if (!Yii::$app->user->isGuest): ?>
  194. <span class="favorite">
  195. <?php if ($userProducer && $userProducer->bookmark): ?>
  196. <span class="glyphicon glyphicon-star"></span> <a
  197. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'delete']); ?>"
  198. data-toggle="tooltip" data-placement="bottom" title="Supprimer de mes favoris">Favoris</a>
  199. <?php else: ?>
  200. <span class="glyphicon glyphicon glyphicon-star-empty"></span> <a
  201. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'add']); ?>"
  202. data-toggle="tooltip" data-placement="bottom"
  203. title="Ajouter à mes favoris">Favoris</a>
  204. <?php endif; ?>
  205. </span>
  206. <?php endif; ?>
  207. <div class="clr"></div>
  208. </div>
  209. <?php if (strlen($this->getTitle())): ?>
  210. <h2 id="page-title">
  211. <?= $this->getTitle(); ?>
  212. <?php
  213. if ($this->buttons && count($this->buttons)): ?>
  214. <span id="buttons">
  215. <?php foreach ($this->buttons as $button) {
  216. echo '<a href="' . \Yii::$app->urlManagerProducer->createUrl($button['url']) . '" class="' . $button['class'] . '">' . $button['label'] . '</a>';
  217. }
  218. ?>
  219. </span>
  220. <?php endif; ?>
  221. </h2>
  222. <?php endif; ?>
  223. <section id="content">
  224. <?php if (Yii::$app->session->hasFlash('error')): ?>
  225. <div class="alert alert-danger" role="alert">
  226. <?= \Yii::$app->session->getFlash('error') ?>
  227. </div>
  228. <?php endif; ?>
  229. <?php if (Yii::$app->session->hasFlash('success')): ?>
  230. <div class="alert alert-success" role="alert">
  231. <?= \Yii::$app->session->getFlash('success') ?>
  232. </div>
  233. <?php endif; ?>
  234. <?= $content ?>
  235. </section>
  236. <?php if (strlen($producer->mentions) || strlen($producer->gcs)): ?>
  237. <section id="footer-producer">
  238. <?= Html::encode($producer->name) ?> :
  239. <?php if (strlen($producer->mentions)): ?>
  240. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/mentions']); ?>">Mentions
  241. légales</a>
  242. <?php endif; ?>
  243. <?php if (strlen($producer->mentions) && strlen($producer->gcs)): ?>
  244. &bull;
  245. <?php endif; ?>
  246. <?php if (strlen($producer->gcs)): ?>
  247. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/gcs']); ?>">Conditions générales
  248. de vente</a>
  249. <?php endif; ?>
  250. </section>
  251. <?php endif; ?>
  252. </div>
  253. </div>
  254. <footer id="footer" class="container">
  255. <div class="content">
  256. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">Opendistrib</a> &bull;
  257. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/opinion']); ?>">Avis & suggestions</a> &bull;
  258. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/mentions']); ?>">Mentions
  259. légales</a> &bull;
  260. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/cgv']); ?>">CGS</a> &bull;
  261. <a id="code-source" href="https://forge.laclic.fr/Laclic/Opendistrib">Code source</a>
  262. </div>
  263. </footer>
  264. <script type="text/javascript" src="https://cdn.polyfill.io/v3/polyfill.min.js?features=Intl.~locale.fr"></script>
  265. <?php $this->endBody() ?>
  266. </body>
  267. </html>
  268. <?php $this->endPage() ?>