From 1eb3944b8adfc09ae63fd3cd104e2ddf3d6d73c4 Mon Sep 17 00:00:00 2001 From: hide_d Date: Fri, 9 Feb 2018 02:02:38 +0900 Subject: [PATCH] =?UTF-8?q?dictionary(php=EC=97=90=EC=84=A0=20associative?= =?UTF-8?q?=20array)=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=20=EC=A0=84=EC=86=A1=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=EB=A5=BC=20message=EC=97=90=20json=EC=9D=84=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD.=20?= =?UTF-8?q?=EC=99=B8=EA=B5=90=20=EC=84=9C=EC=8B=A0=20=EB=93=B1=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20$option=EC=9D=84=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/func_message.php | 20 ++++++++------------ twe/lib.php | 29 +++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/twe/func_message.php b/twe/func_message.php index 8832b34a..1da51233 100644 --- a/twe/func_message.php +++ b/twe/func_message.php @@ -105,7 +105,7 @@ function getMessage($msgType, $limit=30, $fromTime=NULL){ } } -function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date){ +function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date, $msgOption){ getDB()->insert('message', array( 'address' => $dest, @@ -113,20 +113,16 @@ function sendRawMessage($msgType, $isSender, $mailbox, $src, $dest, $msg, $date) 'src' => $src['id'], 'dest' => $dest['id'], 'time' => $date, - 'src_nation_id' => util::array_get($src['nation_id'], null), - 'src_name' => util::array_get($src['name'], null), - 'src_nation' => util::array_get($src['nation'], null), - 'src_color' => util::array_get($src['color'], null), - 'src_icon' => util::array_get($src['icon'], null), - 'dest_nation_id' => util::array_get($dest['nation_id'], null), - 'dest_name' => util::array_get($dest['name'], null), - 'dest_nation' => util::array_get($dest['nation'], null), - 'dest_color' => util::array_get($dest['color'], null), - 'message' => $msg + 'message' => json_encode(eraseNullValue([ + 'src' => $src, + 'dest' =>$dest, + 'text' => $msg, + 'option' => $msgOption + ])) )); } -function sendMessage($msgType, $src, $dest, $msg, $date = null){ +function sendMessage($msgType, $src, $dest, $msg, $date = null, $msgOption = null){ if($date === null){ $date = $datetime->format('Y-m-d H:i:s'); } diff --git a/twe/lib.php b/twe/lib.php index 08d47efe..e1adc952 100644 --- a/twe/lib.php +++ b/twe/lib.php @@ -249,7 +249,32 @@ function dictToArray($dict, $keys){ return $result; } -function eraseNullKey(&$dict, $depth=512){ +function isDict(&$array){ + if(!is_array($array)){ + //배열이 아니면 dictionary 조차 아님. + return false; + } + $idx = 0; + $jmp = 0; + foreach ($arr as $key=>&$value) { + if(is_string($key)){ + return true; + } + $jmp = $key - $idx - 1; + $idx = $key; + } + + if ($jmp * 5 >= count($array)){ + //빈칸이 많으면 dictionary인걸로. + return true; + } + else{ + return false; + } + +} + +function eraseNullValue(&$dict, $depth=512){ //TODO:Test 추가 if($depth <= 0){ return $dict; @@ -259,7 +284,7 @@ function eraseNullKey(&$dict, $depth=512){ if($value === null){ unset($dict[$key]); } - else if(is_array($value)){ + else if(isDict($value)){ $dict[$key] = eraseNullKey($value, $depth - 1); } }