Files
chocomae/src/web/php/db/menu_collection.php
T

353 lines
8.6 KiB
PHP

<?php
class MenuCollection extends DBMethodContainer
{
private $writingCollection = null;
public function getAppGroupName($appGroupCode)
{
switch(intval($appGroupCode)) {
case 0:
return "typing practice";
case 1:
return "typing test";
case 2:
return "typing exam";
case 3:
return "typing play";
case 4:
return "mouse play";
}
}
public function getLanguageName($language)
{
switch(intval($language)) {
case 0:
return "Korean";
case 1:
return "English";
}
}
public function getTypingAppType($appGroupCode, $language)
{
switch(intval($appGroupCode)) {
case 0: // typing practice"
if(intval($language) === 0) // Korean
return 1;
else // English
return 2;
case 1: // typing test
if(intval($language) === 0) // Korean
return 11;
else // English
return 12;
case 3: // typing play
if(intval($language) === 0) // Korean
return 51;
else // English
return 52;
default:
return -1;
}
}
// app list
public function getAppList($maestroID, $playerID, $appGroup, $language)
{
switch($appGroup) {
case 0: // typing practice
case 1: // typing test
case 3: // typing play
return $this->getTypingAppList($maestroID, $playerID, $appGroup, $language);
case 2:
if($this->writingCollection === null)
$this->writingCollection = new WritingCollection($this->mysqli);
$systemWritingList = $this->writingCollection->getSystemList($language);
return $systemWritingList;
case 4: // mouse play
return $this->getMouseAppList();
}
}
public function getTypingAppList($maestroID, $playerID, $appGroup, $language)
{
$query = "
SELECT AppID, AppName, KoreanName
FROM app
WHERE AppType=? AND Status=1";
$stmt = $this->mysqli->prepare($query);
$appType = $this->getTypingAppType($appGroup, $language);
$stmt->bind_param("i", $appType);
$stmt->execute();
$stmt->bind_result($appID, $appName, $koreanName);
$resultArray = array();
while($stmt->fetch()) {
$rowArray = array();
$rowArray["appID"] = $appID;
$rowArray["appName"] = $appName;
$rowArray["koreanName"] = $koreanName;
array_push($resultArray, $rowArray);
}
$stmt->close();
return $resultArray;
}
public function getMouseAppList()
{
$query = "
SELECT AppID, AppName, KoreanName
FROM app
WHERE AppType=100 AND Status=1";
$stmt = $this->mysqli->prepare($query);
$stmt->execute();
$stmt->bind_result($appID, $appName, $koreanName);
$resultArray = array();
while($stmt->fetch()) {
$rowArray = array();
$rowArray["appID"] = $appID;
$rowArray["appName"] = $appName;
$rowArray["koreanName"] = $koreanName;
array_push($resultArray, $rowArray);
}
$stmt->close();
return $resultArray;
}
// active app list
public function getActiveAppList($maestroID, $playerID, $appGroup, $language)
{
switch($appGroup) {
case 0: // typing practice
case 1: // typing test
case 3: // typing play
return $this->getTypingActiveAppList($maestroID, $playerID, $appGroup, $language);
case 2:
if($this->writingCollection === null)
$this->writingCollection = new WritingCollection($this->mysqli);
$activeSystemWritingList = $this->writingCollection->getActiveSystemList($maestroID, $language);
return $activeSystemWritingList;
case 4: // mouse play
return $this->getMouseActiveAppList($maestroID, $playerID, $appGroup);
}
}
public function getTypingActiveAppList($maestroID, $playerID, $appGroup, $language)
{
$query = "
SELECT A.AppID
FROM app AS A
INNER JOIN active_app AS AA ON A.AppID = AA.AppID AND A.AppType=? AND AA.MaestroID=?";
$stmt = $this->mysqli->prepare($query);
$appType = $this->getTypingAppType($appGroup, $language);
$stmt->bind_param("ii", $appType, $maestroID);
$stmt->execute();
$stmt->bind_result($appID);
$resultArray = array();
while($stmt->fetch()) {
$rowArray = array();
$rowArray["appID"] = $appID;
array_push($resultArray, $rowArray);
}
$stmt->close();
return $resultArray;
}
public function getMouseActiveAppList($maestroID)
{
$query = "
SELECT A.AppID
FROM app AS A
INNER JOIN active_app AS AA ON A.AppID = AA.AppID AND A.AppType=100 AND AA.MaestroID=?";
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($appID);
$resultArray = array();
while($stmt->fetch()) {
$rowArray = array();
$rowArray["appID"] = $appID;
array_push($resultArray, $rowArray);
}
$stmt->close();
return $resultArray;
}
// highest record list
public function getHighestRecordList($maestroID, $playerID, $appGroup, $appList)
{
switch($appGroup) {
case 0: // typing practice
case 1: // typing test
case 3: // typing play
case 4: // mouse play
return $this->getTypingHighestRecordList($maestroID, $playerID, $appList);
// case 2:
// return $this->getWritingHighestRecordList($maestroID, $playerID, $appList);
}
}
public function getWritingHighestRecordList($maestroID, $playerID, $appList)
{
if($this->writingCollection === null)
$this->writingCollection = new WritingCollection($this->mysqli);
$writingIDs = array();
foreach($appList as $app)
$writingIDs[] = $app["writingID"];
$recordMap = $this->writingCollection->getWritingHighestRecordMap($maestroID, $playerID, $writingIDs);
$highestRecordArray = array();
foreach($writingIDs as $writingID) {
$highestRecord = array();
$highestRecord["writingID"] = $writingID;
$highestRecord["highestRecord"] = isset($recordMap[$writingID]) ? $recordMap[$writingID] : 0;
array_push($highestRecordArray, $highestRecord);
}
return $highestRecordArray;
}
public function getTypingHighestRecordList($maestroID, $playerID, $appList)
{
$appIDs = array();
foreach($appList as $app)
$appIDs[] = $app["appID"];
$recordMap = $this->getTypingHighestRecordMap($maestroID, $playerID, $appIDs);
$highestRecordArray = array();
foreach($appIDs as $appID) {
$highestRecord = array();
$highestRecord["appID"] = $appID;
$highestRecord["highestRecord"] = isset($recordMap[$appID]) ? $recordMap[$appID] : 0;
array_push($highestRecordArray, $highestRecord);
}
return $highestRecordArray;
}
private function getTypingHighestRecordMap($maestroID, $playerID, $appIDs)
{
$recordMap = array();
if(count($appIDs) === 0)
return $recordMap;
// MAX + GROUP BY: UNIQUE 키가 없는 DB에서도 앱당 1행. COALESCE를 쓰면 FLOAT가 DOUBLE로 바뀌어 소수점이 길어짐
$placeholders = implode(",", array_fill(0, count($appIDs), "?"));
$query = "
SELECT AppID, MAX(HighestRecord)
FROM app_highest_record
WHERE MaestroID=? AND PlayerID=? AND AppID IN (" . $placeholders . ")
GROUP BY AppID";
$params = array_merge(array($maestroID, $playerID), $appIDs);
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param(str_repeat("i", count($params)), ...$params);
$stmt->execute();
$stmt->bind_result($appID, $highestRecord);
while($stmt->fetch())
$recordMap[$appID] = $highestRecord;
$stmt->close();
return $recordMap;
}
/*
public function getSystemWritingList()
{
$writer = "system";
$query = "
SELECT WritingID, Language, Name, Filename, LetterCount
FROM writing
WHERE Writer = ?";
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param("s", $writer);
$stmt->execute();
$stmt->bind_result($writingID, $language, $name, $filename, $letterCount);
$resultArray = array();
while($stmt->fetch()) {
$rowArray = array();
$rowArray["writingID"] = $writingID;
$rowArray["language"] = $language;
$rowArray["name"] = $name;
$rowArray["filename"] = $filename;
$rowArray["letterCount"] = $letterCount;
array_push($resultArray, $rowArray);
}
$stmt->close();
return $resultArray;
}
public function getWritingInfo($writingID)
{
$query = "
SELECT Name, Filename, Writer, WriterID
FROM writing
WHERE WritingID = ?";
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param("i", $writingID);
$stmt->execute();
$stmt->bind_result($name, $filename, $writer, $writerID);
$stmt->fetch();
$stmt->close();
$rowArray = array();
$rowArray["name"] = $name;
$rowArray["filename"] = $filename;
$rowArray["writer"] = $writer;
$rowArray["writerID"] = $writerID;
return $rowArray;
}
*/
public function getAllowEditEntercode($maestroID) {
$query = "SELECT AllowEditEnterCode FROM maestro WHERE MaestroID = ?";
$stmt = $this->mysqli->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($allowEditEntercode);
$stmt->fetch();
$stmt->close();
return $allowEditEntercode;
}
}
?>