mirror of
https://github.com/idanoo/nzart-exam-generator
synced 2025-07-03 06:42:17 +00:00
Added result tracking
This commit is contained in:
parent
0c6a5f3833
commit
b8794f6dc5
8 changed files with 167 additions and 47 deletions
|
@ -65,7 +65,7 @@ class DataItem {
|
|||
}
|
||||
|
||||
public function getTime() {
|
||||
$timeColumn = static::_getCreationTime();
|
||||
$timeColumn = self::_getTime();
|
||||
return $this->$timeColumn;
|
||||
}
|
||||
}
|
|
@ -22,18 +22,34 @@ class Result extends DataItem {
|
|||
return json_decode($this->resultdata_result, true);
|
||||
}
|
||||
|
||||
public function setScore($score)
|
||||
{
|
||||
$this->resultdata_score = json_encode($score);
|
||||
}
|
||||
|
||||
public function getScore()
|
||||
{
|
||||
return json_decode($this->resultdata_score, true);
|
||||
}
|
||||
|
||||
public function setUser($userId)
|
||||
{
|
||||
$this->resultdata_user = $userId;
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return $this->resultdata_user;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$db = new db();
|
||||
$db->query("INSERT INTO result(result_time, resultdata_user, resultdata_result)
|
||||
VALUES(:qTime, :qUser, :qContent)");
|
||||
$db->query("INSERT INTO result(result_time, resultdata_user, resultdata_result, resultdata_score)
|
||||
VALUES(:qTime, :qUser, :qContent, :qScore)");
|
||||
$db->bind("qTime", time());
|
||||
$db->bind("qUser", $this->resultdata_user);
|
||||
$db->bind("qScore", $this->resultdata_score);
|
||||
$db->bind("qContent", $this->resultdata_result);
|
||||
return $db->execute();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ class User extends DataItem {
|
|||
|
||||
public static function loginOrRegister($data)
|
||||
{
|
||||
if(isset($data['register'])) {
|
||||
if($data['method'] == "register") {
|
||||
self::register($data['username'], $data['password']);
|
||||
} elseif(isset($data['login'])) {
|
||||
} elseif ($data['method'] == "login") {
|
||||
self::login($data['username'], $data['password']);
|
||||
}
|
||||
}
|
||||
|
@ -97,11 +97,17 @@ class User extends DataItem {
|
|||
return $this->userdata_username;
|
||||
}
|
||||
|
||||
public function storeuser($dataArray)
|
||||
public function storeResult($dataArray, $score)
|
||||
{
|
||||
$user = new user();
|
||||
$user->setuser($dataArray);
|
||||
$user->setUser($this->getId());
|
||||
$user->save();
|
||||
$result = new Result();
|
||||
$result->setResult($dataArray);
|
||||
$result->setUser($this->getId());
|
||||
$result->setScore($score);
|
||||
$result->save();
|
||||
}
|
||||
|
||||
public function getResults()
|
||||
{
|
||||
return Result::getAllWhere("resultdata_user = ".$this->getId(), "ORDER BY result_time DESC");
|
||||
}
|
||||
}
|
|
@ -27,4 +27,14 @@ CREATE TABLE IF NOT EXISTS `answer` (
|
|||
`answerdata_correct` INT(1) DEFAULT 0,
|
||||
PRIMARY KEY (`answer_id`),
|
||||
UNIQUE KEY `answer_id_UNIQUE` (`answer_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `result` (
|
||||
`result_id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`result_time` INT(11) NOT NULL,
|
||||
`resultdata_user` INT(11) NOT NULL,
|
||||
`resultdata_result` MEDIUMTEXT DEFAULT NULL,
|
||||
`resultdata_score` VARCHAR(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`result_id`),
|
||||
UNIQUE KEY `result_id_UNIQUE` (`result_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
29
includes/fullDb.sql
Executable file → Normal file
29
includes/fullDb.sql
Executable file → Normal file
|
@ -71,6 +71,33 @@ INSERT INTO `question` VALUES (1,1483169094,'1.1','The Amateur Service may be br
|
|||
/*!40000 ALTER TABLE `question` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `result`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `result`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `result` (
|
||||
`result_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`result_time` int(11) NOT NULL,
|
||||
`resultdata_user` int(11) NOT NULL,
|
||||
`resultdata_result` mediumtext,
|
||||
`resultdata_score` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`result_id`),
|
||||
UNIQUE KEY `result_id_UNIQUE` (`result_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `result`
|
||||
--
|
||||
|
||||
LOCK TABLES `result` WRITE;
|
||||
/*!40000 ALTER TABLE `result` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `result` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `user`
|
||||
--
|
||||
|
@ -107,4 +134,4 @@ UNLOCK TABLES;
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2016-12-31 20:28:19
|
||||
-- Dump completed on 2017-01-02 10:44:10
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue