templates/learn/courseView.html.twig line 1

  1. {% extends 'base.html.twig' %}
  2. {% block title %}HYPA - Apprendre{% endblock %}
  3. {% block stylesheets %}
  4.     <link rel="stylesheet" href="{{ asset("css/reset.css") }}">
  5.     <link rel="stylesheet" href="{{ asset("css/learn/courseView.css") }}">
  6.     <style>
  7.         html {
  8.             font-family: HanMufa,sans-serif;
  9.         }
  10.         .character {
  11.             font-family: KaiTi,sans-serif;
  12.         }
  13.     </style>
  14. {% endblock %}
  15. {% block javascripts %}
  16.     <script src="https://kit.fontawesome.com/407f58a928.js" crossorigin="anonymous"></script>
  17.     <script>
  18.         document.addEventListener('DOMContentLoaded', principale);
  19.         function principale() {
  20.             console.log('js comportements chargĂ©');
  21.             const playsoundButton = document.querySelector(".playsound")
  22.             playsoundButton.addEventListener('click', playsound)
  23.             let semaphore = 1;
  24.             function resetSemaphore(){
  25.                 semaphore=1
  26.             }
  27.             const queryString = window.location.search;
  28.             const urlParams = new URLSearchParams(queryString);
  29.             let automatic = urlParams.get("automatic")
  30.             console.log(automatic)
  31.             let volume = urlParams.get("volume")
  32.             let volumeSlider = document.getElementById('volume')
  33.             volumeSlider.addEventListener('input', changeVolume)
  34.             let audio = new Audio(playsoundButton.id)
  35.             function changeVolume(){
  36.                 volume = volumeSlider.value
  37.                 audio.volume = volume/100
  38.             }
  39.             if(Object.is(volume,null)||volume==='null'){
  40.                 volumeSlider.value=50
  41.                 audio.volume=50/100
  42.             } else {
  43.                 audio.volume=volume/100
  44.                 volumeSlider.value=volume
  45.             }
  46.             if(automatic==null) {
  47.                 automatic = false;
  48.             }
  49.             if(automatic){
  50.                 document.getElementById('auto').checked = true
  51.                 playsound()
  52.             }
  53.             function playsound(evt){
  54.                 if(semaphore) {
  55.                     semaphore=0
  56.                     // try{
  57.                     //     let audio = new Audio(playsoundButton.id)
  58.                     //     audio.addEventListener('error',stay)
  59.                     //     audio.addEventListener('loadeddata',stay)
  60.                     // }
  61.                     // catch (error){
  62.                     //     console.log("whesh je catch")
  63.                     //     console.log(error)
  64.                     // }
  65.                     if(!Boolean(playsoundButton.id)){
  66.                         setTimeout(nextDiapo, 2000)
  67.                     }
  68.                     audio.play().catch((error)=>{
  69.                             console.log(error)
  70.                         }
  71.                     )
  72.                     audio.addEventListener('ended',resetSemaphore)
  73.                     audio.addEventListener('ended',nextDiapo)
  74.                 }
  75.             }
  76.             function nextDiapo(){
  77.                 if(document.getElementById('auto').checked)
  78.                 {
  79.                     automatic=true
  80.                     const nextPageButton = document.querySelector("#nextPageButton")
  81.                     if (nextPageButton){
  82.                         window.location.href = nextPageButton.href + "?automatic=" + automatic + "&volume=" + volume;
  83.                     }
  84.                 }
  85.             }
  86.             function stay(evt){
  87.                 if (evt.type==="error"){
  88.                     return null
  89.                 }
  90.                 else{
  91.                     console.log("good")
  92.                     nextDiapo()
  93.                 }
  94.             }
  95.         }
  96.     </script>
  97. {% endblock %}
  98. {% block body %}
  99.     <header>
  100.         <a href="{{ path("app_menu") }}" id="menu"><img src="{{ asset("images/nav_indicators/learn.png") }}" alt=""></a>
  101.         <h1>HYPA - Cours</h1>
  102.         <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ"></a>
  103.     </header>
  104.     <section>
  105.         <ul>
  106.             <li>
  107.                 {% if numberOfPage > 1%}
  108.                     <a href="{{ path("app_course_view",{"page": numberOfPage - 1, "course": course.courseId}) }}"><</a>
  109.                 {% endif %}
  110.             </li>
  111.             <li class = "picture">
  112.                 {% if character %}
  113.                     {% if character.course %}
  114.                         {% if character.rcc %}
  115.                              <div class="playsound" id="{{ asset("dictionary/sound/"~character.course.title~"_sons/"~character.rcc.shortcutPath~".m4a") }}">
  116.                                 <figure>
  117.                                     {% if character is not null %}
  118.                                         <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~"-"~character.shortcutPath~".png") }}" alt="{{ course.title }}">
  119.                                         <figcaption>future translation</figcaption>
  120.                                     {% else %}
  121.                                         <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~".png") }}" alt="{{ course.title }}">
  122.                                         <figcaption>future translation</figcaption>
  123.                                     {% endif %}
  124.                                 </figure>
  125.                             </div>
  126.                         {% else %}
  127.                             <div class="playsound" id="{{ asset("dictionary/sound/"~character.course.title~"_sons/"~character.shortcutPath~".m4a") }}">
  128.                                 <figure>
  129.                                     {% if character is not null %}
  130.                                         <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~"-"~character.shortcutPath~".png") }}" alt="{{ course.title }}">
  131.                                         <figcaption>future translation</figcaption>
  132.                                     {% else %}
  133.                                         <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~".png") }}" alt="{{ course.title }}">
  134.                                         <figcaption>future translation</figcaption>
  135.                                     {% endif %}
  136.                                 </figure>
  137.                             </div>
  138.                         {% endif %}
  139.                     {% endif %}
  140.                 {% else %}
  141.                     <div class="playsound" id="">
  142.                         <figure>
  143.                             {% if character is not null %}
  144.                                 <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~"-"~character.shortcutPath~".png") }}" alt="{{ course.title }}">
  145.                                 <figcaption>future translation</figcaption>
  146.                             {% else %}
  147.                                 <img src="{{ asset("dictionary/fr_FR/pictures/"~course.title~"_png/P"~course.courseId~"-D"~numberOfPage~".png") }}" alt="{{ course.title }}">
  148.                                 <figcaption>future translation</figcaption>
  149.                             {% endif %}
  150.                         </figure>
  151.                     </div>
  152.                 {% endif %}
  153.             </li>
  154.             <li>
  155.                 {% if numberOfPagesAvailable > numberOfPage%}
  156.                     <a id="nextPageButton" href="{{ path("app_course_view",{"page": numberOfPage + 1, "course": course.courseId}) }}">></a>
  157.                 {% endif %}
  158.             </li>
  159.         </ul>
  160.         <ul>
  161.             <li>
  162.                 <label for="auto"><i class="fa-solid fa-robot"></i></label>
  163.                 <input type="checkbox" name="auto" id="auto">
  164.             </li>
  165.             <li>
  166.                 <label for="volume"><i class="fa-solid fa-volume-high"></i></label>
  167.                 <input type="range" name="volume" id="volume" min="0" max="100">
  168.             </li>
  169.             <li>
  170.                 <a href="{{ path("app_dictionary") }}"><i class="fa-solid fa-book"></i></a>
  171.             </li>
  172.         </ul>
  173.     </section>
  174. {% endblock %}