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.

371 lines
18KB

  1. <?php
  2. /**
  3. * Copyright La boîte à pain (2018)
  4. *
  5. * contact@souke.fr
  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\helpers\GlobalParam;
  38. use common\helpers\Image;
  39. use domain\Feature\Feature\Feature;
  40. use domain\Feature\Feature\FeatureModule;
  41. use domain\Order\Order\Order;
  42. use domain\PointSale\PointSale\PointSaleModule;
  43. use domain\Producer\Producer\ProducerModule;
  44. use domain\Product\Product\ProductModule;
  45. use domain\User\User\UserModule;
  46. use domain\User\UserProducer\UserProducer;
  47. use yii\bootstrap5\Nav;
  48. use yii\helpers\Html;
  49. \common\assets\CommonAsset::register($this);
  50. \producer\assets\AppAsset::register($this);
  51. $userModule = UserModule::getInstance();
  52. $userCurrent = GlobalParam::getCurrentUser();
  53. $producerModule = ProducerModule::getInstance();
  54. $featureModule = FeatureModule::getInstance();
  55. $productModule = ProductModule::getInstance();
  56. $pointSaleModule = PointSaleModule::getInstance();
  57. $producerUser = null;
  58. if ($userModule->getAuthorizationChecker()->isGrantedAsProducer($userCurrent)) {
  59. $producerUser = $producerModule->findOneProducerById($userCurrent->id_producer);
  60. }
  61. $producer = $this->context->getProducerCurrent();
  62. if (!Yii::$app->user->isGuest) {
  63. $userProducer = UserProducer::findOne(['id_user' => GlobalParam::getCurrentUserId(), 'id_producer' => $producer->id]);
  64. }
  65. $mainColor = $producer->option_main_color ?: '#ee6f42' ;
  66. ?>
  67. <?php $this->beginPage() ?>
  68. <!DOCTYPE html>
  69. <html lang="fr-FR">
  70. <head>
  71. <title><?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?></title>
  72. <meta charset="utf-8">
  73. <meta name="viewport" content="width=device-width, initial-scale=1">
  74. <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">
  75. <meta name="slug-producer" content="<?= $producer->slug; ?>">
  76. <?= Html::csrfMetaTags() ?>
  77. <link rel="icon" type="image/png"
  78. href="<?php echo \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon-souke-1.png"/>
  79. <?php $this->head() ?>
  80. <?= $this->render('@common/views/matomo.php') ?>
  81. <style>
  82. #header #title h1 a.producer-name,
  83. #header #title h2 .location .bi,
  84. #content a,
  85. .credit-history #credit-user,
  86. .credit-history #content .table span.payment-positive,
  87. .order-order #main #app-order-order #steps ul li .info-step,
  88. .block-date .month {
  89. color: <?= $mainColor ?>
  90. }
  91. #header nav#main-nav ul a.active,
  92. #header nav#main-nav ul li a:hover,
  93. #header nav#main-nav ul li a span.label-success,
  94. #main .btn-primary,
  95. .order-order #main #app-order-order #steps ul li .btn.btn-primary,
  96. ul.pagination li.active a, ul.pagination li a:hover, ul.pagination li a:focus, ul.pagination li a:active {
  97. background-color: <?= $mainColor ?>;
  98. }
  99. #header nav#main-nav {
  100. border-top: solid 5px <?= $mainColor ?>;
  101. }
  102. #main form .form-control:focus {
  103. box-shadow: 0px 0px 0px 1px <?= $mainColor ?>;
  104. border: solid 1px <?= $mainColor ?>;
  105. }
  106. .order-order #main #app-order-order #steps ul li .btn.btn-primary::after {
  107. border-left: 17px solid <?= $mainColor ?>;
  108. }
  109. #header nav#main-nav ul li a span.label.label-success {
  110. border: solid 1px <?= $mainColor ?>;
  111. }
  112. </style>
  113. </head>
  114. <body class="<?= \Yii::$app->controller->id . '-' . \Yii::$app->controller->action->id ?>">
  115. <?php $this->beginBody() ?>
  116. <?= $this->render('@common/views/nav_user_top', [
  117. 'context' => 'producer'
  118. ]); ?>
  119. <div id="main" class="container">
  120. <?php $hasLogo = strlen($producer->logo) && Image::isPhotoExist($producer->logo); ?>
  121. <div id="header" class="<?= $hasLogo ? 'with-logo' : 'without-logo'; ?>">
  122. <?php if (strlen($producer->photo) || strlen($producer->logo)): ?>
  123. <div id="banner" style="background-color: <?= $mainColor ?>;<?php if(strlen($producer->photo)): ?>background-image:url(<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->photo; ?>);<?php endif; ?>">
  124. </div>
  125. <?php endif; ?>
  126. <?php if ($hasLogo): ?>
  127. <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; ?>>
  128. <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
  129. <img class="img-logo"
  130. src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  131. alt="Logo <?= Html::encode($producer->name) ?>"/>
  132. </a>
  133. </div>
  134. <?php endif; ?>
  135. <div id="title">
  136. <h1>
  137. <a class="producer-name" href="<?= Yii::$app->urlManager->createUrl(['site/index']); ?>">
  138. <?= Html::encode($producer->name); ?>
  139. </a>
  140. <?php if (!Yii::$app->user->isGuest): ?>
  141. <?php if ($userProducer && $userProducer->bookmark): ?>
  142. <a class="bookmark"
  143. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'delete']); ?>"
  144. data-bs-toggle="tooltip" data-bs-placement="top" title="Supprimer de ma liste de producteurs">
  145. <i class="bi bi-bookmark-heart-fill"></i>
  146. </a>
  147. <?php else: ?>
  148. <a class="bookmark"
  149. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'add']); ?>"
  150. data-bs-toggle="tooltip" data-bs-placement="top"
  151. title="Ajouter à ma liste de producteurs">
  152. <i class="bi bi-bookmark-heart"></i>
  153. </a>
  154. <?php endif; ?>
  155. <?php endif; ?>
  156. </h1>
  157. <h2>
  158. <?= Html::encode($producer->type) ?>
  159. <span class="location">
  160. <i class="bi bi-geo-alt-fill"></i>
  161. <?= Html::encode($producer->postcode); ?> <?= Html::encode($producer->city); ?>
  162. </span>
  163. </h2>
  164. </div>
  165. <nav id="main-nav">
  166. <?php
  167. $credit = '';
  168. if (isset($userProducer) && $userProducer) {
  169. $labelType = $userProducer->credit > 0 ? 'success' : 'danger';
  170. $credit = ' <span class="label label-' . $labelType . '">' . number_format($userProducer->credit, 2) . ' €</span>';
  171. }
  172. $countSubcriptions = 0;
  173. if ($userCurrent) {
  174. $countSubcriptions = $this->getSubscriptionModule()->countSubscriptionsByUser(
  175. $userCurrent
  176. );
  177. }
  178. $labelSubscription = $countSubcriptions > 0 ? 'success' : 'default';
  179. $countOrders = Order::find()
  180. ->joinWith(['distribution'])
  181. ->where([
  182. 'id_user' => GlobalParam::getCurrentUserId(),
  183. 'distribution.id_producer' => GlobalParam::getCurrentProducerId()
  184. ])
  185. ->params([':date_today' => date('Y-m-d')])
  186. ->andWhere('distribution.date >= :date_today')
  187. ->count();
  188. $labelOrders = $countOrders > 0 ? 'success' : 'default';
  189. $isUserSubscribedNewsletter = $userModule->isUserSubscribedNewsletter($userCurrent);
  190. $isHome = in_array($this->getControllerAction(), ['site/index', 'site/products', 'site/points-sale']);
  191. echo Nav::widget([
  192. 'encodeLabels' => false,
  193. 'options' => ['class' => ''],
  194. 'items' => [
  195. [
  196. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  197. 'label' => '<i class="bi bi-house-door"></i>',
  198. 'active' => $isHome,
  199. ],
  200. [
  201. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  202. 'url' => $this->getUrlManagerProducer()->createUrl(['order/order']),
  203. 'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
  204. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  205. ],
  206. [
  207. 'label' => '<i class="bi bi-pencil-square"></i> Commander',
  208. '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])]),
  209. 'visible' => !$producer->option_allow_order_guest && \Yii::$app->user->isGuest,
  210. 'active' => in_array($this->getControllerAction(), ['order/order', 'order/confirm']),
  211. ],
  212. [
  213. 'label' => '<i class="bi bi-folder2-open"></i> Mes commandes <span class="label label-' . $labelOrders . '">' . $countOrders . '</span>',
  214. 'url' => $this->getUrlManagerProducer()->createUrl(['order/history']),
  215. 'visible' => !Yii::$app->user->isGuest,
  216. 'active' => $this->getControllerAction() == 'order/history',
  217. ],
  218. [
  219. 'label' => '<i class="bi bi-arrow-repeat"></i> Abonnements <span class="label label-' . $labelSubscription . '">' . $countSubcriptions . '</span>',
  220. 'url' => $this->getUrlManagerProducer()->createUrl(['subscription/index']),
  221. 'visible' => !Yii::$app->user->isGuest && $producer->user_manage_subscription,
  222. 'active' => in_array($this->getControllerAction(), ['subscription/index', 'subscription/form']),
  223. ],
  224. [
  225. 'label' => '<i class="bi bi-piggy-bank"></i> Cagnotte' . $credit,
  226. 'url' => $this->getUrlManagerProducer()->createUrl(['credit/history']),
  227. 'visible' => !Yii::$app->user->isGuest && $producer->credit,
  228. 'active' => $this->getControllerAction() == 'credit/history',
  229. ],
  230. [
  231. 'label' => '<i class="bi bi-megaphone"></i> Infolettre <span class="label label-' . ($isUserSubscribedNewsletter ? 'success' : 'danger') . '">' . ($isUserSubscribedNewsletter ? 'Oui' : 'Non') . '</span>',
  232. 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
  233. 'visible' => !Yii::$app->user->isGuest,
  234. 'active' => $this->getControllerAction() == 'newsletter/index',
  235. ],
  236. [
  237. 'label' => '<i class="bi bi-envelope"></i> Contact',
  238. 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']),
  239. 'active' => $this->getControllerAction() == 'site/contact',
  240. 'visible' => $featureModule->getChecker()->isEnabled(Feature::ALIAS_CONTACT)
  241. ],
  242. ],
  243. ]);
  244. $submenuItems = null;
  245. if($isHome) {
  246. $submenuItems = [
  247. [
  248. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  249. 'label' => 'Présentation',
  250. 'active' => $this->getControllerAction() == 'site/index',
  251. ],
  252. [
  253. 'url' => $this->getUrlManagerProducer()->createUrl(['site/products']),
  254. 'label' => 'Produits <span class="label label-default">'.$productModule->getRepository()->countProducts(true).'</span>',
  255. 'active' => $this->getControllerAction() == 'site/products',
  256. ],
  257. [
  258. 'url' => $this->getUrlManagerProducer()->createUrl(['site/points-sale']),
  259. 'label' => 'Points de vente <span class="label label-default">'.$pointSaleModule->getRepository()->countPointSalesPublic().'</span>',
  260. 'active' => $this->getControllerAction() == 'site/points-sale',
  261. ],
  262. ];
  263. }
  264. if($submenuItems) {
  265. echo Nav::widget([
  266. 'encodeLabels' => false,
  267. 'options' => ['class' => 'submenu'],
  268. 'items' => $submenuItems
  269. ]);
  270. }
  271. ?>
  272. </nav>
  273. <div id="infos-producer">
  274. <?php if (!$this->getProducerModule()->hasSpecificDelays($producer) && $producer->order_deadline && $producer->order_delay): ?>
  275. <span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
  276. <span class="glyphicon glyphicon-time"></span> Commande avant
  277. <strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
  278. <span data-toggle="tooltip" data-placement="bottom"
  279. title="Exemple : commande le lundi pour le
  280. <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi
  281. <?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi
  282. <?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche
  283. <?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>
  284. <?php endif; ?>
  285. <div class="clr"></div>
  286. </div>
  287. </div>
  288. <section id="content">
  289. <?php if (strlen($this->getTitle())): ?>
  290. <h2 id="page-title">
  291. <?= $this->getTitle(); ?>
  292. <?php
  293. if ($this->buttons && count($this->buttons)): ?>
  294. <span id="buttons">
  295. <?php foreach ($this->buttons as $button) {
  296. echo '<a href="' . \Yii::$app->urlManagerProducer->createUrl($button['url']) . '" class="' . $button['class'] . '">' . $button['label'] . '</a>';
  297. }
  298. ?>
  299. </span>
  300. <?php endif; ?>
  301. </h2>
  302. <?php endif; ?>
  303. <?php if (Yii::$app->session->hasFlash('error')): ?>
  304. <div class="alert alert-danger" role="alert">
  305. <?= \Yii::$app->session->getFlash('error') ?>
  306. </div>
  307. <?php endif; ?>
  308. <?php if (Yii::$app->session->hasFlash('success')): ?>
  309. <div class="alert alert-success" role="alert">
  310. <?= \Yii::$app->session->getFlash('success') ?>
  311. </div>
  312. <?php endif; ?>
  313. <?= $content ?>
  314. </section>
  315. <?php if (strlen($producer->mentions) || strlen($producer->gcs)): ?>
  316. <section id="footer-producer">
  317. <?= Html::encode($producer->name) ?> :
  318. <?php if (strlen($producer->mentions)): ?>
  319. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/mentions']); ?>">Mentions
  320. légales</a>
  321. <?php endif; ?>
  322. <?php if (strlen($producer->mentions) && strlen($producer->gcs)): ?>
  323. &bull;
  324. <?php endif; ?>
  325. <?php if (strlen($producer->gcs)): ?>
  326. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/gcs']); ?>">Conditions générales
  327. de vente</a>
  328. <?php endif; ?>
  329. </section>
  330. <?php endif; ?>
  331. </div>
  332. <footer id="footer" class="container">
  333. <div class="content">
  334. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">Opendistrib</a>
  335. &bull;
  336. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/mentions']); ?>">Mentions
  337. légales</a> &bull;
  338. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/cgv']); ?>">CGS</a>
  339. </div>
  340. </footer>
  341. <script type="text/javascript" src="https://cdn.polyfill.io/v3/polyfill.min.js?features=Intl.~locale.fr"></script>
  342. <?php $this->endBody() ?>
  343. </body>
  344. </html>
  345. <?php $this->endPage() ?>