Add user id to docs/todos/notes tables
This commit is contained in:
26
inc/catc.php
26
inc/catc.php
@@ -12,7 +12,8 @@ class CATC extends Main
|
||||
{
|
||||
$asClasses = array(
|
||||
array('name'=>'auth', 'project'=>true),
|
||||
array('name'=>'course', 'project'=>true)
|
||||
array('name'=>'course', 'project'=>true),
|
||||
array('name'=>'note', 'project'=>true)
|
||||
);
|
||||
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
|
||||
|
||||
@@ -24,6 +25,7 @@ class CATC extends Main
|
||||
{
|
||||
//Install DB
|
||||
$this->oDb->install();
|
||||
$this->oDb->loadFile('db_build.sql');
|
||||
}
|
||||
|
||||
protected function getSqlOptions()
|
||||
@@ -34,9 +36,10 @@ class CATC extends Main
|
||||
(
|
||||
Auth::USER_TABLE => array(Db::getText(Auth::USER_TABLE), 'nickname', 'pass', 'cookie'),
|
||||
Course::WS_TABLE => array('dates'),
|
||||
Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot', 'notes'),
|
||||
'docs' => array(Db::getId('courses'), 'type', 'path'),
|
||||
'todos' => array(Db::getId('courses'), 'description')
|
||||
Course::COURSE_TABLE=> array(Db::getId('workshops'), 'description', 'timeslot'),
|
||||
'notes' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
'docs' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'path'),
|
||||
'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
|
||||
),
|
||||
'types' => array
|
||||
(
|
||||
@@ -145,19 +148,20 @@ class CATC extends Main
|
||||
/* Notes*/
|
||||
|
||||
public function getNote($iCourseId) {
|
||||
$oCourse = new Course($this->oDb, $iCourseId);
|
||||
$asNote = $oCourse->getNote();
|
||||
$iCourseId = $asNote[Db::getId(Course::COURSE_TABLE)];
|
||||
$oNote = new Note($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$asNote = $oNote->getNote();
|
||||
|
||||
return self::getJsonResult(($iCourseId > 0), '', array('id'=>$iCourseId, 'ops'=>$asNote['notes'], 'led'=>$asNote['led']));
|
||||
return self::getJsonResult(!empty($asNote), '', $asNote);
|
||||
}
|
||||
|
||||
public function setNote($iCourseId, $asOps) {
|
||||
$oCourse = new Course($this->oDb, $iCourseId);
|
||||
$sError = $oCourse->setNote($asOps);
|
||||
$oNote = new Note($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$sError = $oNote->setNote($asOps);
|
||||
$bSuccess = ($sError=='');
|
||||
|
||||
return self::getJsonResult(($sError==''), $sError, array('led' => $oCourse->getNote()['led']));
|
||||
$asData = ($bSuccess)?array('led' => $oNote->getNote()['led']):array();
|
||||
|
||||
return self::getJsonResult($bSuccess, $sError, $asData);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,26 +28,6 @@ class Course extends PhpObject {
|
||||
$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'),
|
||||
|
||||
57
inc/note.php
Normal file
57
inc/note.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
class Note extends PhpObject {
|
||||
|
||||
const NOTE_TABLE = 'notes';
|
||||
|
||||
/**
|
||||
* DB
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
|
||||
private $iNoteId;
|
||||
private $iUserId;
|
||||
private $iCourseId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId, $iCourseId)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setNoteId(0);
|
||||
$this->setUserCourseId($iUserId, $iCourseId);
|
||||
}
|
||||
|
||||
public function setNoteId($iNoteId) {
|
||||
$this->iNoteId = $iNoteId;
|
||||
}
|
||||
|
||||
public function setUserCourseId($iUserId, $iCourseId) {
|
||||
$this->iUserId = $iUserId;
|
||||
$this->iCourseId = $iCourseId;
|
||||
}
|
||||
|
||||
private function getNoteKeys() {
|
||||
return array(Db::getId(Auth::USER_TABLE) => $this->iUserId, Db::getId(Course::COURSE_TABLE) => $this->iCourseId);
|
||||
}
|
||||
|
||||
public function getNote() {
|
||||
$asCourse = $this->oDb->selectRow(self::NOTE_TABLE, $this->getNoteKeys());
|
||||
if(!empty($asCourse)) $asCourse['notes'] = json_decode($asCourse['notes'], true);
|
||||
|
||||
return $asCourse;
|
||||
}
|
||||
|
||||
public function setNote($asOps) {
|
||||
$sError = '';
|
||||
|
||||
if($this->iUserId > 0 && $this->iCourseId > 0) {
|
||||
$asData = array_merge($this->getNoteKeys(), array('notes'=>json_encode($asOps)));
|
||||
$iNoteId = $this->oDb->insertUpdateRow(self::NOTE_TABLE, $asData, array_keys($this->getNoteKeys()));
|
||||
if(!$iNoteId) $sError = $this->oDb->getLastError();
|
||||
}
|
||||
else $sError = 'Course ID not set';
|
||||
|
||||
return $sError;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user