Files
catc/inc/course.php
2019-09-05 22:55:40 +02:00

66 lines
1.8 KiB
PHP

<?php
class Course extends PhpObject {
const WS_TABLE = 'workshops';
const COURSE_TABLE = 'courses';
/**
* DB
* @var Db
*/
private $oDb;
private $iCourseId;
public function __construct(Db &$oDb, $iCourseId=0)
{
parent::__construct(__CLASS__, Settings::DEBUG);
$this->oDb = &$oDb;
$this->setCourseId($iCourseId);
}
public function getCourseId() {
return $this->iCourseId;
}
public function setCourseId($iCourseId) {
$this->iCourseId = $iCourseId;
}
public function getNote() {
$asCourse = $this->oDb->selectRow(self::COURSE_TABLE, $this->getCourseId(), array(Db::getId(self::COURSE_TABLE), 'notes', 'led'));
$asCourse['notes'] = json_decode($asCourse['notes'], true);
return $asCourse;
}
public function setNote($asOps) {
$sError = '';
$sIdCol = Db::getId(self::COURSE_TABLE);
if($this->getCourseId() > 0) {
$iCourseId = $this->oDb->insertUpdateRow(self::COURSE_TABLE, array($sIdCol=>$this->getCourseId(), 'notes'=>json_encode($asOps)), array($sIdCol));
if(!$iCourseId) $sError = $this->oDb->getLastError();
}
else $sError = 'Course ID not set';
return $sError;
}
public function getWorkshops() {
$asCourses = $this->oDb->selectRows(array(
'select'=> array(Db::getId(self::WS_TABLE), 'dates', Db::getId(self::COURSE_TABLE), 'description', 'timeslot'),
'from' => self::COURSE_TABLE,
'join' => array(self::WS_TABLE => Db::getId(self::WS_TABLE)))
);
$asWorkshops = array();
foreach($asCourses as $asCourse) {
$asWorkshops[$asCourse[Db::getId(self::WS_TABLE)]]['dates'] = $asCourse['dates'];
$asWorkshops[$asCourse[Db::getId(self::WS_TABLE)]]['courses'][$asCourse[Db::getId(self::COURSE_TABLE)]] = array('description'=>$asCourse['description'], 'timeslot'=>$asCourse['timeslot']);
}
return $asWorkshops;
}
}