generalId = $generalId; $this->nationId = $nationId; $this->year = $year; $this->month = $month; $this->autoFlush = $autoFlush; } public function __destruct(){ if($this->autoFlush){ $this->flush(); } } public function rollback(){ $this->generalHistoryLog = []; $this->generalActionLog = []; $this->generalBattleResultLog = []; $this->generalBattleDetailLog = []; $this->nationalHistoryLog = []; $this->globalHistoryLog = []; $this->globalActionLog = []; } public function flush(){ $db = DB::db(); if($this->generalHistoryLog){ $rawText = join('
', $this->generalHistoryLog).'
'; $db->update('general', [ 'history'=>$db->sqleval('concat(%s, history)', $rawText) ], 'no=%i', $this->generalId); $this->generalHistoryLog = []; } if($this->generalActionLog){ pushGenLog(['no'=>$this->generalId], $this->generalActionLog); $this->generalActionLog = []; } if($this->generalBattleResultLog){ pushGenLog(['no'=>$this->generalId], $this->generalBattleResultLog); $this->generalBattleResultLog = []; } if($this->generalBattleDetailLog){ pushGenLog(['no'=>$this->generalId], $this->generalBattleDetailLog); $this->generalBattleDetailLog = []; } if($this->nationId && $this->nationalHistoryLog){ $rawText = join('
', $this->nationalHistoryLog).'
'; $db->update('nation', [ 'history'=>$db->sqleval('concat(%s, history)', $rawText) ], 'nation=%i', $this->nationId); $this->nationalHistoryLog = []; } if($this->globalHistoryLog){ pushWorldHistory($this->globalHistoryLog, $this->year, $this->month); $this->globalHistoryLog = []; } if($this->globalActionLog){ pushGeneralPublicRecord($this->globalActionLog, $this->year, $this->month); $this->globalActionLog = []; } } public function pushGeneralHistoryLog($text, int $formatType = self::YEAR_MONTH){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGeneralHistoryLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->generalHistoryLog[] = $text; } public function pushGeneralActionLog($text, int $formatType = self::MONTH){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGeneralActionLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->generalActionLog[] = $text; } public function pushGeneralBattleResultLog($text, int $formatType = self::RAWTEXT){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGeneralBattleResultLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->generalBattleResultLog[] = $text; } public function pushGeneralBattleDetailLog($text, int $formatType = self::RAWTEXT){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGeneralBattleDetailLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->generalBattleDetailLog[] = $text; } public function pushNationalHistoryLog($text, int $formatType = self::RAWTEXT){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushNationalHistoryLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->nationalHistoryLog[] = $text; } public function pushGlobalActionLog($text, int $formatType = self::MONTH){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGlobalActionLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->globalActionLog[] = $text; } public function pushGlobalHistoryLog($text, int $formatType = self::YEAR_MONTH){ if(!$text){ return; } if(is_array($text)){ foreach($text as $textItem){ $this->pushGlobalHistoryLog($textItem); } return; } $text = $this->formatText($text, $formatType); $this->globalHistoryLog[] = $text; } public function formatText(string $text, int $formatType):string{ if($formatType === self::RAWTEXT){ return $text; } if($formatType === self::PLAIN){ return "●{$text}"; } if($formatType === self::YEAR_MONTH){ return "●{$this->year}년 {$this->month}월:{$text}"; } if($formatType === self::YEAR){ return "●{$this->year}년:{$text}"; } if($formatType === self::MONTH){ return "●{$this->month}월:{$text}"; } if($formatType === self::EVENT_PLAIN){ return "◆{$text}"; } if($formatType === self::EVENT_YEAR_MONTH){ return "◆{$this->year}년 {$this->month}월:{$text}"; } if($formatType === self::NOTICE){ return "★{$text}"; } if($formatType === self::NOTICE_YEAR_MONTH){ return "★{$this->year}년 {$this->month}월:{$text}"; } return $text; } }