src/Twig/LearnedSurah.php line 15
<?php
namespace App\Twig;
use App\Repository\LearningsRepository;
use App\Repository\LessonsRepository;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class LearnedSurah extends AbstractExtension
{
private LearningsRepository $lessonsRepository;
public function __construct(LearningsRepository $learningsRepository)
{
$this->learningsRepository = $learningsRepository;
}
public function getFunctions()
{
return [
new TwigFunction('isLearnedSurah', [$this, 'isLearnedSurah']),
new TwigFunction('getAllLearnsFromSurahAndStudent', [$this, 'getAllLearnsFromSurahAndStudent']),
new TwigFunction('getLastLearnFromSurahAndStudent', [$this, 'getLastLearnFromSurahAndStudent']),
];
}
public function isLearnedSurah($surah, $student)
{
$allSurahLessons = $this->learningsRepository->findBy(['lesson' => $surah->getId(), 'student' => $student], $orderBy = ['id' => 'desc']);
foreach($allSurahLessons as $key => $lesson)
{
if($lesson->getStatus() == 1)
return 1;
if($lesson->getStatus() == 0)
return 2;
}
return 0;
}
public function getAllLearnsFromSurahAndStudent($surah, $student)
{
return $this->learningsRepository->findAllLearningsBySurahAndStudent($surah, $student);
}
public function getLastLearnFromSurahAndStudent($surah, $student)
{
if(isset($this->learningsRepository->getLastLearnFromSurahAndStudent($surah, $student)[0]))
{
return $this->learningsRepository->getLastLearnFromSurahAndStudent($surah, $student)[0]->getComment();
}
return '';
}
}