<?php
//--Class ClassTimeTable--------------------------

include_once "clsbase_ClassTimeTable.php";

class 
ClassTimeTable extends base_ClassTimeTable{

function 
RSClassTimeTableLimit($xKey$start$pageSize){
    
$this->SetQuery("select * from ClassTimeTable where classId='$xKey' order by classId limit $start, $pageSize");
}

function 
RSClassTimeTableByClId($xKey){
    
$this->SetQuery("select * from ClassTimeTable where classId='$xKey' order by sequenceId");
}

function 
RSClassTimeTableByClIdAndDayAndPr($xKey$yKey$zKey){
    
$this->SetQuery("select * from ClassTimeTable where classId='$xKey' and weekDay='$yKey' and '$zKey' between timeSlotStart and timeSlotEnd order by sequenceId");
}

//-- Use on page processClass.php --
function SearchByKeyRoIdAndWD($ClsId$xKey$yKey){
    
$this->SetQuery("select * from ClassTimeTable where classId='$ClsId' and roomId='$xKey' and weekDay='$yKey'");
}

function 
SearchByKeyRoIdAndWDAndTss($AcY$SeM$Dy$rm$S1$E1){
/*    $sql="SELECT count(*) as num 
                     from Class c, ClassTimeTable t
                     where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=t.classId and t.weekDay='$Dy' 
                     and t.roomId='$rm' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1')";
    die($sql); */
    
    
$this->setQuery("select count(*) as num 
                     from Class c, ClassTimeTable t
                     where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=t.classId and t.weekDay='$Dy' 
                     and t.roomId='$rm' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1')"
);
    
$result=$this->GetResult();
    return 
$result['num'];
}

function 
RSClassTimeTableByRoIdAndWDAndTss($AcY$SeM$Dy$rm$S1$E1){
    
$sql "select * from Class c, ClassTimeTable t 
            where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=t.classId and t.weekDay='$Dy' 
            and t.roomId='$rm' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1')"
;
    
$this->setQuery($sql);
}

function 
SearchByKeyRoIdAndWDAndTssAndCoIdAndSectionAndOVL($AcY$SeM$Dy$rm$S1$E1$coId$section){
    
$this->setQuery("select count(*) as num 
                     from Class c, ClassTimeTable t
                     where c.acadYear='$AcY' and c.semester='$SeM' and c.classId=t.classId and t.weekDay='$Dy' 
                     and t.roomId='$rm' and t.timeSlotStart='$S1' and t.timeSlotEnd='$E1' 
                     and c.courseId='$coId' and c.section!='$section' and t.overlap='Y'"
);
    
$result=$this->GetResult();
    return 
$result['num'];
}

function 
RSClassTimeTableByAcYAndSe($xKey$yKey){
    
$this->SetQuery("select * from ClassTimeTable t, Class c where t.classId=c.classId and acadYear='$xKey' and semester='$yKey' order by sequenceId");
}

function 
SearchByKeyClsIdTseTssWD($ClsId$S1$E1$WD){
    
$this->SetQuery("SELECT count(*) as num from ClassTimeTable t where t.classId='$ClsId' and (t.timeSlotEnd >= '$S1' and t.timeSlotStart <= '$E1') and (t.weekDay='$WD')");
    
$result=$this->GetResult();
    return 
$result['num'];
}

//-- Use on page beforeShowClassStudy.php --
function SearchCTTByClsIdWdSt($ClsId,$wd,$st){
    if(
$this->SetQuery("select * from ClassTimeTable where classId='$ClsId' and weekDay='$wd' and timeSlotStart='$st' ")){
        return 
1;
    }else{
        return 
0;
    }
}
//-- The end --

//--End class ClassTimeTable--
?>