<?php

use Doctrine\ORM\EntityRepository;

class ClasstestRepository extends EntityRepository
{

    public function getClassTestByStudent($student_id){
        
        $sql = "SELECT a.*,b.sub_name FROM classtest a,subject_master b  WHERE a.sub_code=b.sub_code AND a.type !='CLASSTEST' AND  json_contains(a.marks->'$[*].id', json_array(:id))";

        $em = $this->getEntityManager();
        $stmt = $em->getConnection()->prepare($sql);
        $stmt->bindParam(':id',$student_id,PDO::PARAM_STR);
        $stmt->execute();
        $result =  $stmt->fetchAll();
        
        $overall_mark = 0;$e = [];$d = [];
        foreach($result as $r){
            $a = json_decode($r['marks'],true);
            foreach($a as $b){
                if($b['id'] == $student_id){
                    $c['marks_obtained'] = $b['marks_obtained'];
                    $c['status'] = $b['status'];
                    $overall_mark += (float)$b['marks_obtained'];
                    $d = array_merge($r,$c);
                    array_push($e,$d);
                }
            }
        }
        return $e;
    }
}
