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.

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\Model\Producer;
  39. use common\logic\Producer\Producer\Wrapper\ProducerManager;
  40. use common\logic\User\User\Wrapper\UserManager;
  41. use common\logic\User\UserProducer\Model\UserProducer;
  42. use yii\bootstrap\Nav;
  43. use common\helpers\GlobalParam;
  44. use yii\helpers\Html;
  45. \common\assets\CommonAsset::register($this);
  46. \producer\assets\AppAsset::register($this);
  47. $userManager = UserManager::getInstance();
  48. $userCurrent = GlobalParam::getCurrentUser();
  49. $producerManager = ProducerManager::getInstance();
  50. $producerUser = null;
  51. if($userManager->isCurrentProducer()) {
  52. $producerUser = $producerManager->findOneProducerById($userCurrent->id_producer);
  53. }
  54. $producer = $this->context->getProducerCurrent();
  55. if (!Yii::$app->user->isGuest) {
  56. $userProducer = UserProducer::findOne(['id_user' => GlobalParam::getCurrentUserId(), 'id_producer' => $producer->id]);
  57. }
  58. ?>
  59. <?php $this->beginPage() ?>
  60. <!DOCTYPE html>
  61. <html lang="fr-FR">
  62. <head>
  63. <title><?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?></title>
  64. <meta charset="utf-8">
  65. <meta name="viewport" content="width=device-width, initial-scale=1">
  66. <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">
  67. <meta name="slug-producer" content="<?= $producer->slug; ?>">
  68. <?= Html::csrfMetaTags() ?>
  69. <link rel="icon" type="image/png"
  70. href="<?php echo \Yii::$app->urlManager->getBaseUrl(); ?>/img/favicon-distrib.png"/>
  71. <?php $this->head() ?>
  72. <?= $this->render('@common/views/matomo.php') ?>
  73. </head>
  74. <body class="<?= \Yii::$app->controller->id . '-' . \Yii::$app->controller->action->id ?>">
  75. <?php $this->beginBody() ?>
  76. <?= $this->render('@common/views/nav_user_top', [
  77. 'context' => 'producer'
  78. ]); ?>
  79. <div class="container">
  80. <div id="left" class="col-md-3">
  81. <div class="fixed">
  82. <?php if (strlen($producer->logo)): ?>
  83. <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; ?>>
  84. <a href="<?= \Yii::$app->urlManager->createUrl(['site/index']) ?>">
  85. <img class="img-logo"
  86. src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->logo; ?>"
  87. alt="Logo <?= Html::encode($producer->name) ?>"/>
  88. </a>
  89. </div>
  90. <?php endif; ?>
  91. <h1><?= Html::encode($producer->name); ?></h1>
  92. <h2><?= Html::encode($producer->type) ?> à <?= Html::encode($producer->city); ?>
  93. (<?= Html::encode($producer->postcode); ?>)</h2>
  94. <nav id="main-nav">
  95. <?php
  96. $credit = '';
  97. if (isset($userProducer) && $userProducer) {
  98. $labelType = $userProducer->credit > 0 ? 'success' : 'danger';
  99. $credit = ' <span class="label label-' . $labelType . '">' . number_format($userProducer->credit, 2) . ' €</span>';
  100. }
  101. $countSubcriptions = 0;
  102. if ($userCurrent) {
  103. $countSubcriptions = $this->getSubscriptionManager()->countSubscriptionsByUser(
  104. $userCurrent
  105. );
  106. }
  107. $labelSubscription = $countSubcriptions > 0 ? 'success' : 'default';
  108. $countOrders = Order::find()
  109. ->joinWith(['distribution'])
  110. ->where([
  111. 'id_user' => GlobalParam::getCurrentUserId(),
  112. 'distribution.id_producer' => GlobalParam::getCurrentProducerId()
  113. ])
  114. ->params([':date_today' => date('Y-m-d')])
  115. ->andWhere('distribution.date >= :date_today')
  116. ->count();
  117. $labelOrders = $countOrders > 0 ? 'success' : 'default';
  118. $isUserSubscribedNewsletter = $userManager->isUserSubscribedNewsletter($userCurrent);
  119. echo Nav::widget([
  120. 'encodeLabels' => false,
  121. 'options' => ['class' => 'nav'],
  122. 'items' => [
  123. [
  124. 'label' => '<span class="glyphicon glyphicon-th-large"></span> Accueil',
  125. 'url' => $this->getUrlManagerProducer()->createUrl(['site/index']),
  126. 'active' => $this->getControllerAction() == 'site/index',
  127. ],
  128. [
  129. 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
  130. 'url' => $this->getUrlManagerProducer()->createUrl(['order/order']),
  131. 'visible' => $producer->option_allow_order_guest || !Yii::$app->user->isGuest,
  132. 'active' => $this->getControllerAction() == 'order/order',
  133. ],
  134. [
  135. 'label' => '<span class="glyphicon glyphicon-plus"></span> Commander',
  136. '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])]),
  137. 'visible' => !$producer->option_allow_order_guest && \Yii::$app->user->isGuest,
  138. 'active' => $this->getControllerAction() == 'order/order',
  139. ],
  140. [
  141. 'label' => '<span class="glyphicon glyphicon-folder-open"></span> Mes commandes <span class="label label-' . $labelOrders . '">' . $countOrders . '</span>',
  142. 'url' => $this->getUrlManagerProducer()->createUrl(['order/history']),
  143. 'visible' => !Yii::$app->user->isGuest,
  144. 'active' => $this->getControllerAction() == 'order/history',
  145. ],
  146. [
  147. 'label' => '<span class="glyphicon glyphicon-repeat"></span> Abonnements <span class="label label-' . $labelSubscription . '">' . $countSubcriptions . '</span>',
  148. 'url' => $this->getUrlManagerProducer()->createUrl(['subscription/index']),
  149. 'visible' => !Yii::$app->user->isGuest && $producer->user_manage_subscription,
  150. 'active' => $this->getControllerAction() == 'subscription/index',
  151. ],
  152. [
  153. 'label' => '<span class="glyphicon glyphicon-euro"></span> Crédit' . $credit,
  154. 'url' => $this->getUrlManagerProducer()->createUrl(['credit/history']),
  155. 'visible' => !Yii::$app->user->isGuest && $producer->credit,
  156. 'active' => $this->getControllerAction() == 'credit/history',
  157. ],
  158. [
  159. 'label' => '<span class="glyphicon glyphicon-bullhorn"></span> Bulletin d\'information <span class="label label-'.($isUserSubscribedNewsletter ? 'success' : 'danger').'">'.($isUserSubscribedNewsletter ? 'Oui' : 'Non').'</span>',
  160. 'url' => $this->getUrlManagerProducer()->createUrl(['newsletter/index']),
  161. 'visible' => !Yii::$app->user->isGuest,
  162. 'active' => $this->getControllerAction() == 'newsletter/index',
  163. ],
  164. [
  165. 'label' => '<span class="glyphicon glyphicon-envelope"></span> Contact',
  166. 'url' => $this->getUrlManagerProducer()->createUrl(['site/contact']),
  167. 'active' => $this->getControllerAction() == 'site/contact',
  168. ],
  169. ],
  170. ]);
  171. ?>
  172. </nav>
  173. </div>
  174. </div>
  175. <div id="main" class="col-md-9">
  176. <?php if (strlen($producer->photo)): ?>
  177. <div id="img-big">
  178. <img class="img-photo" src="<?= \Yii::$app->urlManager->baseUrl; ?>/uploads/<?= $producer->photo; ?>"
  179. alt="Photo <?= Html::encode($producer->name) ?>"/>
  180. </div>
  181. <?php endif; ?>
  182. <div id="infos-producer">
  183. <?php if (!$this->getProducerManager()->hasSpecificDelays($producer) && $producer->order_deadline && $producer->order_delay): ?>
  184. <span data-toggle="tooltip" data-placement="bottom" title="Heure limite de commande">
  185. <span class="glyphicon glyphicon-time"></span> Commande avant
  186. <strong><?php echo Html::encode($producer->order_deadline) ?> h</strong></span>,
  187. <span data-toggle="tooltip" data-placement="bottom"
  188. title="Exemple : commande le lundi pour le
  189. <?php if ($producer->order_delay == 1): ?>mardi<?php elseif ($producer->order_delay == 2): ?>mercredi
  190. <?php elseif ($producer->order_delay == 3): ?>jeudi<?php elseif ($producer->order_delay == 4): ?>vendredi
  191. <?php elseif ($producer->order_delay == 5): ?>samedi<?php elseif ($producer->order_delay == 6): ?>dimanche
  192. <?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>
  193. <?php endif; ?>
  194. <?php if (!Yii::$app->user->isGuest): ?>
  195. <span class="favorite">
  196. <?php if ($userProducer && $userProducer->bookmark): ?>
  197. <span class="glyphicon glyphicon-star"></span> <a
  198. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'delete']); ?>"
  199. data-toggle="tooltip" data-placement="bottom" title="Supprimer de mes favoris">Favoris</a>
  200. <?php else: ?>
  201. <span class="glyphicon glyphicon glyphicon-star-empty"></span> <a
  202. href="<?= \Yii::$app->urlManagerProducer->createUrl(['site/bookmarks', 'action' => 'add']); ?>"
  203. data-toggle="tooltip" data-placement="bottom"
  204. title="Ajouter à mes favoris">Favoris</a>
  205. <?php endif; ?>
  206. </span>
  207. <?php endif; ?>
  208. <div class="clr"></div>
  209. </div>
  210. <?php if (strlen($this->getTitle())): ?>
  211. <h2 id="page-title">
  212. <?= $this->getTitle(); ?>
  213. <?php
  214. if ($this->buttons && count($this->buttons)): ?>
  215. <span id="buttons">
  216. <?php foreach ($this->buttons as $button) {
  217. echo '<a href="' . \Yii::$app->urlManagerProducer->createUrl($button['url']) . '" class="' . $button['class'] . '">' . $button['label'] . '</a>';
  218. }
  219. ?>
  220. </span>
  221. <?php endif; ?>
  222. </h2>
  223. <?php endif; ?>
  224. <section id="content">
  225. <?php if (Yii::$app->session->hasFlash('error')): ?>
  226. <div class="alert alert-danger" role="alert">
  227. <?= \Yii::$app->session->getFlash('error') ?>
  228. </div>
  229. <?php endif; ?>
  230. <?php if (Yii::$app->session->hasFlash('success')): ?>
  231. <div class="alert alert-success" role="alert">
  232. <?= \Yii::$app->session->getFlash('success') ?>
  233. </div>
  234. <?php endif; ?>
  235. <?= $content ?>
  236. </section>
  237. <?php if (strlen($producer->mentions) || strlen($producer->gcs)): ?>
  238. <section id="footer-producer">
  239. <?= Html::encode($producer->name) ?> :
  240. <?php if (strlen($producer->mentions)): ?>
  241. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/mentions']); ?>">Mentions
  242. légales</a>
  243. <?php endif; ?>
  244. <?php if (strlen($producer->mentions) && strlen($producer->gcs)): ?>
  245. &bull;
  246. <?php endif; ?>
  247. <?php if (strlen($producer->gcs)): ?>
  248. <a href="<?php echo \Yii::$app->urlManager->createUrl(['site/gcs']); ?>">Conditions générales
  249. de vente</a>
  250. <?php endif; ?>
  251. </section>
  252. <?php endif; ?>
  253. </div>
  254. </div>
  255. <footer id="footer" class="container">
  256. <div class="content">
  257. <a href="<?php echo \Yii::$app->urlManagerFrontend->createAbsoluteUrl(['site/index']); ?>">Opendistrib</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() ?>