src/Twig/LearnedSurah.php line 15

  1. <?php
  2. namespace App\Twig;
  3. use App\Repository\LearningsRepository;
  4. use App\Repository\LessonsRepository;
  5. use Twig\Extension\AbstractExtension;
  6. use Twig\TwigFunction;
  7. class LearnedSurah extends AbstractExtension
  8. {
  9.     private LearningsRepository $lessonsRepository;
  10.     public function __construct(LearningsRepository $learningsRepository)
  11.     {
  12.         $this->learningsRepository $learningsRepository;
  13.     }
  14.     public function getFunctions()
  15.     {
  16.         return [
  17.             new TwigFunction('isLearnedSurah', [$this'isLearnedSurah']),
  18.             new TwigFunction('getAllLearnsFromSurahAndStudent', [$this'getAllLearnsFromSurahAndStudent']),
  19.             new TwigFunction('getLastLearnFromSurahAndStudent', [$this'getLastLearnFromSurahAndStudent']),
  20.         ];
  21.     }
  22.     public function isLearnedSurah($surah$student)
  23.     {
  24.         $allSurahLessons $this->learningsRepository->findBy(['lesson' => $surah->getId(), 'student' => $student], $orderBy = ['id' => 'desc']);
  25.         foreach($allSurahLessons as $key => $lesson)
  26.         {
  27.             if($lesson->getStatus() == 1)
  28.                 return 1;
  29.             if($lesson->getStatus() == 0)
  30.                 return 2;
  31.         }
  32.         return 0;
  33.     }
  34.     public function getAllLearnsFromSurahAndStudent($surah$student)
  35.     {
  36.         return $this->learningsRepository->findAllLearningsBySurahAndStudent($surah$student);
  37.     }
  38.     public function getLastLearnFromSurahAndStudent($surah$student)
  39.     {
  40.         if(isset($this->learningsRepository->getLastLearnFromSurahAndStudent($surah$student)[0]))
  41.         {
  42.             return $this->learningsRepository->getLastLearnFromSurahAndStudent($surah$student)[0]->getComment();
  43.         }
  44.         return '';
  45.     }
  46. }