Definitions v1
This commit is contained in:
34
inc/catc.php
34
inc/catc.php
@@ -14,7 +14,8 @@ class CATC extends Main
|
||||
array('name'=>'auth', 'project'=>true),
|
||||
array('name'=>'course', 'project'=>true),
|
||||
array('name'=>'note', 'project'=>true),
|
||||
array('name'=>'doc', 'project'=>true)
|
||||
array('name'=>'doc', 'project'=>true),
|
||||
array('name'=>'definition', 'project'=>true)
|
||||
);
|
||||
parent::__construct($oClassManagement, $sProcessPage, $asClasses);
|
||||
|
||||
@@ -35,12 +36,13 @@ class CATC extends Main
|
||||
(
|
||||
'tables' => array
|
||||
(
|
||||
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' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'),
|
||||
'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
|
||||
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'),
|
||||
Note::NOTE_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'notes'),
|
||||
Definition::DEF_TABLE => array(Db::getId(Auth::USER_TABLE), 'title', 'description'),
|
||||
Doc::DOC_TABLE => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'type', 'filename'),
|
||||
'todos' => array(Db::getId(Auth::USER_TABLE), Db::getId(Course::COURSE_TABLE), 'description')
|
||||
),
|
||||
'types' => array
|
||||
(
|
||||
@@ -49,6 +51,7 @@ class CATC extends Main
|
||||
'pass' => "VARCHAR(256) NOT NULL",
|
||||
'cookie' => "VARCHAR(255)",
|
||||
'dates' => "VARCHAR(50)",
|
||||
'title' => "VARCHAR(50)",
|
||||
'description' => "VARCHAR(200)",
|
||||
'timeslot' => "ENUM('SAT-M', 'SAT-A', 'SUN-M', 'SUN-A')",
|
||||
'notes' => "LONGTEXT",
|
||||
@@ -57,7 +60,8 @@ class CATC extends Main
|
||||
),
|
||||
'constraints' => array
|
||||
(
|
||||
Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)"
|
||||
Doc::DOC_TABLE => "UNIQUE KEY `uni_file` (`filename`)",
|
||||
Definition::DEF_TABLE => "UNIQUE KEY `uni_def_title` (`title`)"
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -160,4 +164,18 @@ class CATC extends Main
|
||||
|
||||
return self::getJsonResult($bResult, '');
|
||||
}
|
||||
|
||||
/* Defs */
|
||||
|
||||
public function getDefs() {
|
||||
$oDef = new Definition($this->oDb, $this->oAuth->getUserId());
|
||||
return self::getJsonResult(true, '', $oDef->getDefinitions());
|
||||
}
|
||||
|
||||
public function setDef($iDefId, $sTitle, $sDesc) {
|
||||
$bNew = ($iDefId == 0);
|
||||
$oDef = new Definition($this->oDb, $this->oAuth->getUserId(), $iDefId);
|
||||
$bResult = $oDef->setDefinition($sTitle, $sDesc);
|
||||
return self::getJsonResult($bResult, '', array('new_def'=>$bNew, 'def'=>$oDef->getDefinition()));
|
||||
}
|
||||
}
|
||||
59
inc/definition.php
Normal file
59
inc/definition.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
class Definition extends PhpObject {
|
||||
|
||||
const DEF_TABLE = 'definitions';
|
||||
|
||||
/**
|
||||
* DB
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
private $iDefId;
|
||||
private $iUserId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId=0, $iDefId=0)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setUserId($iUserId);
|
||||
$this->setDefId($iDefId);
|
||||
}
|
||||
|
||||
public function setUserId($iUserId) {
|
||||
$this->iUserId = $iUserId;
|
||||
}
|
||||
|
||||
public function setDefId($iDefId) {
|
||||
$this->iDefId = $iDefId;
|
||||
}
|
||||
|
||||
public function getDefinitions($iDefId=0) {
|
||||
$asConstraints = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId);
|
||||
if($iDefId > 0) $asConstraints[Db::getId(self::DEF_TABLE)] = $iDefId;
|
||||
|
||||
$asDefs = $this->oDb->selectRows(array('from'=>self::DEF_TABLE, 'constraint'=>$asConstraints), Db::getId(self::DEF_TABLE));
|
||||
return $asDefs;
|
||||
}
|
||||
|
||||
public function getDefinition() {
|
||||
$asDef = array();
|
||||
if($this->iDefId > 0) {
|
||||
$asDef = $this->getDefinitions($this->iDefId);
|
||||
if(!empty($asDef)) $asDef = array_shift($asDef);
|
||||
}
|
||||
return $asDef;
|
||||
}
|
||||
|
||||
public function setDefinition($sTitle, $sDesc) {
|
||||
$asInfo = array(Db::getId(Auth::USER_TABLE)=>$this->iUserId, 'title'=>$sTitle, 'description'=>$sDesc);
|
||||
if($this->iDefId == 0) {
|
||||
$iDefId = $this->oDb->insertRow(self::DEF_TABLE, $asInfo);
|
||||
}
|
||||
else {
|
||||
$iDefId = $this->oDb->updateRow(self::DEF_TABLE, $this->iDefId, $asInfo);
|
||||
}
|
||||
$this->setDefId($iDefId);
|
||||
return ($iDefId > 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user