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;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ oCATC.pageInit = function(asHash, bFirstPage) {
|
||||
self.setPageTitle('Course');
|
||||
self.tmp('id_course', asHash.items[0]);
|
||||
|
||||
//Setup Quill
|
||||
oEditor = new Editor('#notes');
|
||||
oEditor.onKeyStroke = (e) => {
|
||||
if(e.which == 83 && e.ctrlKey) {
|
||||
@@ -17,8 +18,19 @@ oCATC.pageInit = function(asHash, bFirstPage) {
|
||||
save(true);
|
||||
}
|
||||
else save();
|
||||
}
|
||||
oEditor.open(self.tmp('id_course'));
|
||||
};
|
||||
|
||||
//Load notes
|
||||
Tools.ajax(
|
||||
'get_note',
|
||||
(asData) => {
|
||||
oEditor.setContent(asData.ops);
|
||||
oCATC.feedback('notice', 'Last update on ('+asData.led.substr(11, 5)+')');
|
||||
},
|
||||
{id: self.tmp('id_course')},
|
||||
() => {console.log('Note not found for course ID = '+self.tmp('id_course'))}
|
||||
);
|
||||
|
||||
//oQuill.keyboard.addBinding({key: 'S', ctrlKey: true}, function(){saveNotes(true);});
|
||||
};
|
||||
|
||||
@@ -60,7 +72,7 @@ function save(bForce)
|
||||
self.tmp('saving', false);
|
||||
},
|
||||
{
|
||||
id: oEditor.id,
|
||||
id: self.tmp('id_course'),
|
||||
content: sContent
|
||||
},
|
||||
function(sError) {
|
||||
@@ -75,7 +87,7 @@ function save(bForce)
|
||||
}
|
||||
}
|
||||
else {
|
||||
oSaveTimer = setTimeout(function(){save(true);}, 1000*10);
|
||||
oSaveTimer = setTimeout(function(){save(true);}, 1000*5);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Prise de notes pour les cours du Collège des Arts Thérapeutiques Chinois
|
||||
|
||||
# Todo
|
||||
- [x] Upload docs: audio, video, word, pdf
|
||||
- [ ] Upload docs: audio, video, word, pdf
|
||||
- [ ] View docs online: audio, video, word, pdf
|
||||
- [ ] Take notes on courses
|
||||
- [ ] Quick view of musckes / nerves schemas
|
||||
- [X] Take notes on courses
|
||||
- [ ] Quick view of muscles / nerves schemas
|
||||
@@ -277,12 +277,8 @@ function CATC(asGlobals)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class Editor {
|
||||
constructor(sEditorId, bReadOnly) {
|
||||
this.id = 0;
|
||||
this.keystrokes = 0;
|
||||
this.readOnly = bReadOnly || false;
|
||||
this.sCursorPos = '';
|
||||
@@ -290,7 +286,7 @@ class Editor {
|
||||
//DOM Elements
|
||||
this.$Editor = $(sEditorId);
|
||||
|
||||
this.onKeyStroke = function(e){};
|
||||
this.onKeyStroke = function() {};
|
||||
|
||||
this.oQuill = new Quill(sEditorId, {
|
||||
theme: 'snow',
|
||||
@@ -319,18 +315,6 @@ class Editor {
|
||||
if(!this.readOnly) this.oQuill.focus();
|
||||
}
|
||||
|
||||
open(iCourseId) {
|
||||
Tools.ajax(
|
||||
'get_note',
|
||||
(asData) => {
|
||||
this.id = asData.id;
|
||||
this.oQuill.setContents(asData.ops);
|
||||
this._postInit();
|
||||
},
|
||||
{id: iCourseId}
|
||||
);
|
||||
}
|
||||
|
||||
_incKeyStrokes() {
|
||||
this.keystrokes += 1;
|
||||
}
|
||||
@@ -339,6 +323,11 @@ class Editor {
|
||||
return this.oQuill.getContents().ops;
|
||||
}
|
||||
|
||||
setContent(asOps) {
|
||||
this.oQuill.setContents(asOps);
|
||||
this._postInit();
|
||||
}
|
||||
|
||||
isEmpty() {
|
||||
const rEmpty = /^(<p>(<br>|<br\/>|<br\s\/>|\s+|)<\/p>|)$/gm;
|
||||
return rEmpty.test(this.oQuill.getText().trim());
|
||||
|
||||
Reference in New Issue
Block a user