Viewing file: 2553-11-18-1.1.01-clsRadioQuestion.php (8.51 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//--Class RadioQuestion--------------------------
//--PK of RadioQuestion ::
// 1. RQid
//include_once "clsDB.php";
class RadioQuestion extends clsDB{
var $result;
var $RQid;
var $assid;
var $sectionRQid;
var $nameRQ;
var $parrentRQid;
var $levelRQ;
var $subtract;
var $sequence;
function RadioQuestion(&$c){
$this->c=$c->c;
$this->DB=$c->db;
}
function Save(){
//--ใช้เมธอดนี้เมื่อต้องการบันทึกข้อมูลในอ๊อบเจ๊กเข้าสู่ฐานข้อมูล
//--โดยจะตรวจสอบสถานะของข้อมูลว่าข้อมูลในอ๊อบเจ๊กเป็นข้อมูลใหม่หรือข้อมูลเดิม
//--1 เป็นข้อมูลใหม่ 2 เป็นข้อมูลเดิม
if ($this->status==1){
//uncomment a line below if your table use ID as running number
$this->RQid=$this->GetNextCode();
$this->sequence=$this->GetNextCodeSeq();
$sql = "insert into RadioQuestion values(
'$this->RQid',
'$this->assid',
'$this->sectionRQid',
'$this->nameRQ',
'$this->parrentRQid',
'$this->levelRQ',
'$this->subtract',
'$this->sequence'
)";
}else {
$sql = "update RadioQuestion set
assid='$this->assid',
sectionRQid='$this->sectionRQid',
nameRQ='$this->nameRQ',
parrentRQid='$this->parrentRQid',
levelRQ='$this->levelRQ',
subtract='$this->subtract',
sequence='$this->sequence'
where RQid='$this->RQid'";
}
return $this->Dml($sql);
}
function DeleteRQ(){
//--ใช้เมธอดนี้เพื่อลบข้อมูลเดิมในอ๊อบเจ๊ก
//--เป็นการลบข้อมูลทีละ 1 เรคอร์ด
//--ต้องเรียกเมธอดตามลำดับดังนี้ SearchByKey()-->GetRecord()-->Delete()
//return $this->Dml("delete from RadioQuestion where RQid='$this->RQid'");
$sql = "delete from RadioQuestion where RQid = '$this->RQid'";
//echo "<br> sql RadioQuestion delete ==> ".$sql;
return $this->Dml($sql);
}
function DeleteSubRQ(){
$sql = "delete from RadioQuestion where parrentRQid = '$this->RQid'";
return $this->Dml($sql);
}
function DeleteRQBySectonRQid(){
$sql = "delete from RadioQuestion where sectionRQid = '$this->sectionRQid'";
return $this->Dml($sql);
}
function GetNextCode(){
//--ใช้เมธอดนี้เพื่อหาค่าสูงสุดของฟิลด์ที่ใช้เป็นคีย์ของตาราง ในลักษณะ auto increment
//--ต้องเป็นฟิลด์ที่ไม่ได้กำหนดรหัสเองทางจอภาพ
$this->SetQuery("select max(RQid) as num from RadioQuestion");
if ($result=$this->GetResult()) {
return $result['num']+1;
}
}
function GetNextCodeSeq(){
//--ใช้เมธอดนี้เพื่อหาค่าสูงสุดของฟิลด์ที่ใช้เป็นคีย์ของตาราง ในลักษณะ auto increment
//--ต้องเป็นฟิลด์ที่ไม่ได้กำหนดรหัสเองทางจอภาพ
$this->SetQuery("select max(sequence) as num from RadioQuestion");
if ($result=$this->GetResult()) {
return $result['num']+1;
}
}
function RSRadioQuestion(){
//--เมธอดที่ขึ้นต้นด้วย RS (Result Set) มีความหมายว่าจะได้รับข้อมูลกลับมาจากการ select มากกว่า 1 เรคอร์ด
//--ปกติเมื่อเรียกใช้เมธอด RSxxxx จะต้องเรียกเมธอด GetRecord() ด้วยเสมอ
//--โดยสามารถเพิ่มเมธอดได้ตามต้องการ แต่ต้องขึ้นต้นด้วย RS
$this->SetQuery("select * from RadioQuestion order by RQid");
}
function GetRecord(){
//--เป็นเมธอดที่นำข้อมูลจาก ResultSet มากำหนดให้กับแอตทริบิวต์ของอ๊อบเจ็ก
//--เรียก GetRecord() หนึ่งครั้ง จะเลื่อนตัวชี้เรคอร์ดไปอีกหนึ่งเรคอร์ด
if ($this->result = $this->GetResult()) {
$this->RQid = $this->result['RQid'];
$this->assid = $this->result['assid'];
$this->sectionRQid = $this->result['sectionRQid'];
$this->nameRQ = $this->result['nameRQ'];
$this->parrentRQid = $this->result['parrentRQid'];
$this->levelRQ = $this->result['levelRQ'];
$this->subtract = $this->result['subtract'];
$this->sequence = $this->result['sequence'];
return 1;
}else {
return 0;
}
}
function SearchByKey($xKey){
//--ใช้เมธอดนี้เพื่อค้นหาข้อมูลตาม PK ต้องระบุพารามิเตอร์ด้วย
//--และต้องตามด้วยเมธอด GetRecord() เสมอ
if ($this->SetQuery("select * from RadioQuestion where RQid= '$xKey'")){
return 1;
}else {
return 0;
}
}
function SearchByKeySectionRQid($xKey){
//--ใช้เมธอดนี้เพื่อค้นหาข้อมูลตาม PK ต้องระบุพารามิเตอร์ด้วย
//--และต้องตามด้วยเมธอด GetRecord() เสมอ
if ($this->SetQuery("select * from RadioQuestion where sectionRQid= '$xKey'")){
return 1;
}else {
return 0;
}
}
//****************** You can add new functions below **********************//
function SearchByAssidRQid($xassid,$xRQid){
$sql = "select * from RadioQuestion where assid= '$xassid' and RQid = '$xRQid'";
$this->SetQuery($sql);
}
function RSRadioQByKey($xassid,$xsectionRQid,$xlevelRQ){
$sql = "select * from RadioQuestion where assid= '$xassid' and sectionRQid = '$xsectionRQid' and levelRQ = '$xlevelRQ' order by 'sequence'";
$this->SetQuery($sql);
}
function RSSearchRQByKey($xassid,$xRQid,$xsectionRQid,$xlevelRQ){
$sql = "select * from RadioQuestion where assid= '$xassid' and RQid = '$xRQid' and sectionRQid = '$xsectionRQid' and levelRQ = '$xlevelRQ'";
//echo "<br>sql = ".$sql;
$this->SetQuery($sql);
}
function RSCheckLevel($xKey1,$xKey2){
$sql = "select * from RadioQuestion where assid = '$xKey1' and parrentRQid = '$xKey2' order by 'sequence'";
$this->SetQuery($sql);
}
function getMinSeqMQ($xKey1,$xKey2,$xKey3){
$this->SetQuery("select min(sequence) as num from RadioQuestion where assid = '$xKey1' and sectionRQid = '$xKey2' and levelRQ = '$xKey3'");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function getMaxSeqMQ($xKey1,$xKey2,$xKey3){
$this->SetQuery("select max(sequence) as num from RadioQuestion where assid = '$xKey1' and sectionRQid = '$xKey2' and levelRQ = '$xKey3'");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function getMinSeq($xKey1,$xKey2){
$this->SetQuery("select min(sequence) as num from RadioQuestion where assid = '$xKey1' and parrentRQid = '$xKey2'");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function getMaxSeq($xKey1,$xKey2){
$this->SetQuery("select max(sequence) as num from RadioQuestion where assid = '$xKey1' and parrentRQid = '$xKey2'");
if ($result=$this->GetResult()) {
return $result['num'];
}
}
function RSCountParrentRQid($xRQid){
$this->SetQuery("select count(*) as num from RadioQuestion where parrentRQid = '$xRQid'");
$result = $this->GetResult();
return $result['num'];
}
function RSCountSectionRQid($xKey1,$xKey2,$xKey3){
$this->SetQuery("select count(*) as num from RadioQuestion where assid = '$xKey1' and sectionRQid = '$xKey2' and levelRQ = '$xKey3'");
$result = $this->GetResult();
return $result['num'];
}
function RSCountMainRQid($xassid,$xsectionRQid,$xlevelRQ){
$this->SetQuery("select count(*) as num from RadioQuestion where assid = '$xassid' and sectionRQid = '$xsectionRQid' and levelRQ = '$xlevelRQ'");
$result = $this->GetResult();
return $result['num'];
}
function RSCountSubRQid($xassid,$xparrentRQid,$xlevelRQ){
$this->SetQuery("select count(*) as num from RadioQuestion where assid = '$xassid' and parrentRQid = '$xparrentRQid' and levelRQ = '$xlevelRQ'");
$result = $this->GetResult();
return $result['num'];
}
function CountByAssidSectionRQid($xassid,$xsectionRQid){
$this->SetQuery("select count(*) as num from RadioQuestion where assid = '$xassid' and sectionRQid = '$xsectionRQid'");
$result = $this->GetResult();
return $result['num'];
}
function updateSubtract($xRQid,$xsubtract){
$sql = "update RadioQuestion set
subtract ='$xsubtract'
where RQid='$xRQid'";
return $this->Dml($sql);
}
function swapQuestion($xud,$xassid,$xRQid,$xsectionRQid,$xparrentRQid,$xlevelRQ,$xsequence){
if($xud == "u"){
$sql = "select RQid, sequence from RadioQuestion where assid = '$xassid' and parrentRQid = '$xparrentRQid' and levelRQ = '$xlevelRQ' and sequence < '$xsequence' order by 'sequence' Desc limit 0,1";
$this->SetQuery($sql);
$result=$this->GetResult();
$upRQid = $result['RQid'];
$upSequence = $result['sequence'];
$sql = "update RadioQuestion set sequence = '$xsequence' where RQid = '$upRQid'";
$this->Dml($sql);
$sql = "update RadioQuestion set sequence = '$upSequence' where RQid = '$xRQid'";
$this->Dml($sql);
}
if($xud == "d"){
$sql = "select RQid, sequence from RadioQuestion where assid = '$xassid' and parrentRQid = '$xparrentRQid' and levelRQ = '$xlevelRQ' and sequence > '$xsequence' order by 'sequence' limit 0,1";
$this->SetQuery($sql);
$result=$this->GetResult();
$upRQid = $result['RQid'];
$upSequence = $result['sequence'];
$sql = "update RadioQuestion set sequence = '$xsequence' where RQid = '$upRQid'";
$this->Dml($sql);
$sql = "update RadioQuestion set sequence = '$upSequence' where RQid = '$xRQid'";
$this->Dml($sql);
}
}
} //--End class RadioQuestion--
?>
|