|
|
@@ -12,7 +12,7 @@ use Illuminate\Support\Facades\Log;
|
|
|
use App\Http\Api\DictApi;
|
|
|
use App\Http\Api\AuthApi;
|
|
|
|
|
|
-require_once __DIR__."/../../../public/app/dict/grm_abbr.php";
|
|
|
+require_once __DIR__ . "/../../../public/app/dict/grm_abbr.php";
|
|
|
|
|
|
|
|
|
class DictController extends Controller
|
|
|
@@ -32,21 +32,21 @@ class DictController extends Controller
|
|
|
$dictListOutput = [];
|
|
|
$caseListOutput = [];
|
|
|
$wordDataPass = [];
|
|
|
- $indexCol = ['word','note','dict_id'];
|
|
|
+ $indexCol = ['word', 'note', 'dict_id'];
|
|
|
$words = [];
|
|
|
$word_base = [];
|
|
|
$searched = [];
|
|
|
$words[$request->get('word')] = [];
|
|
|
- $userLang = $request->get('lang',"zh");
|
|
|
+ $userLang = $request->get('lang', "zh");
|
|
|
|
|
|
/**
|
|
|
* 临时代码判断是否在缅汉字典群里面。在群里的用户可以产看缅汉字典pdf
|
|
|
*/
|
|
|
$user = AuthApi::current($request);
|
|
|
- if($user){
|
|
|
- $inMyHanGroup = GroupMember::where('group_id','905af467-1bde-4d2c-8dc7-49cfb74e0b09')
|
|
|
- ->where('user_id',$user['user_uid'])->exists();
|
|
|
- }else{
|
|
|
+ if ($user) {
|
|
|
+ $inMyHanGroup = GroupMember::where('group_id', '905af467-1bde-4d2c-8dc7-49cfb74e0b09')
|
|
|
+ ->where('user_id', $user['user_uid'])->exists();
|
|
|
+ } else {
|
|
|
$inMyHanGroup = false;
|
|
|
}
|
|
|
|
|
|
@@ -54,8 +54,8 @@ class DictController extends Controller
|
|
|
// The environment is local
|
|
|
$inMyHanGroup = true;
|
|
|
}
|
|
|
- $resultCount=0;
|
|
|
- for ($i=0; $i < 2; $i++) {
|
|
|
+ $resultCount = 0;
|
|
|
+ for ($i = 0; $i < 2; $i++) {
|
|
|
# code...
|
|
|
$word_base = [];
|
|
|
$wordDataOutput = [];
|
|
|
@@ -63,23 +63,23 @@ class DictController extends Controller
|
|
|
# code...
|
|
|
$searched[] = $word;
|
|
|
$table = UserDict::select($indexCol)
|
|
|
- ->where('word',$word)
|
|
|
- ->where('source','_PAPER_');
|
|
|
- if(!$inMyHanGroup){
|
|
|
- $table = $table->where('dict_id','<>','8ae6e0f5-f04c-49fc-a355-4885cc08b4b3');
|
|
|
+ ->where('word', $word)
|
|
|
+ ->where('source', '_PAPER_');
|
|
|
+ if (!$inMyHanGroup) {
|
|
|
+ $table = $table->where('dict_id', '<>', '8ae6e0f5-f04c-49fc-a355-4885cc08b4b3');
|
|
|
//测试代码
|
|
|
//$table = $table->where('dict_id','<>','ac9b7b73-b9c0-4d31-a5c9-7c6dc5a2c187');
|
|
|
}
|
|
|
$result = $table->get();
|
|
|
$resultCount += count($result);
|
|
|
$anchor = $word;
|
|
|
- $wordData=[
|
|
|
- 'word'=> $word,
|
|
|
- 'factors'=> "",
|
|
|
- 'parents'=> "",
|
|
|
- 'case'=> [],
|
|
|
- 'grammar'=>$case,
|
|
|
- 'anchor'=> $anchor,
|
|
|
+ $wordData = [
|
|
|
+ 'word' => $word,
|
|
|
+ 'factors' => "",
|
|
|
+ 'parents' => "",
|
|
|
+ 'case' => [],
|
|
|
+ 'grammar' => $case,
|
|
|
+ 'anchor' => $anchor,
|
|
|
'dict' => [],
|
|
|
];
|
|
|
/**
|
|
|
@@ -88,11 +88,11 @@ class DictController extends Controller
|
|
|
* 将查询的结果放置在对应的容器中。
|
|
|
* 最后将结果扁平化
|
|
|
* 准备字典容器
|
|
|
- * $wordDict = [
|
|
|
- * "zh"=>[
|
|
|
- * "0d79e8e8-1430-4c99-a0f1-b74f2b4b26d8"=>[];
|
|
|
- * ]
|
|
|
- * ]
|
|
|
+ * $wordDict = [
|
|
|
+ * "zh"=>[
|
|
|
+ * "0d79e8e8-1430-4c99-a0f1-b74f2b4b26d8"=>[];
|
|
|
+ * ]
|
|
|
+ * ]
|
|
|
*/
|
|
|
|
|
|
foreach (DictApi::langOrder($userLang) as $langId) {
|
|
|
@@ -103,34 +103,35 @@ class DictController extends Controller
|
|
|
}
|
|
|
$wordDict[$langId] = $dictContainer;
|
|
|
}
|
|
|
- $dictList=[
|
|
|
- 'href'=> '#'.$anchor,
|
|
|
- 'title'=> "{$word}",
|
|
|
+ $dictList = [
|
|
|
+ 'href' => '#' . $anchor,
|
|
|
+ 'title' => "{$word}",
|
|
|
'children' => [],
|
|
|
];
|
|
|
foreach ($result as $key => $value) {
|
|
|
# code...
|
|
|
- $dictInfo= DictInfo::find($value->dict_id);
|
|
|
- $dict_lang = explode('-',$dictInfo->dest_lang);
|
|
|
+ $dictInfo = DictInfo::find($value->dict_id);
|
|
|
+ $dict_lang = explode('-', $dictInfo->dest_lang);
|
|
|
$anchor = "{$word}-{$dictInfo->shortname}";
|
|
|
$currData = [
|
|
|
- 'dictname'=> $dictInfo->name,
|
|
|
- 'shortname'=> $dictInfo->shortname,
|
|
|
- 'description'=>$dictInfo->description,
|
|
|
- 'dict_id' => $value->dict_id,
|
|
|
- 'lang' => $dict_lang[0],
|
|
|
- 'word'=> $word,
|
|
|
- 'note'=> $this->GrmAbbr($value->note,0),
|
|
|
- 'anchor'=> $anchor,
|
|
|
+ 'dictname' => $dictInfo->name,
|
|
|
+ 'shortname' => $dictInfo->shortname,
|
|
|
+ 'description' => $dictInfo->description,
|
|
|
+ 'meta' => json_decode($dictInfo->meta),
|
|
|
+ 'dict_id' => $value->dict_id,
|
|
|
+ 'lang' => $dict_lang[0],
|
|
|
+ 'word' => $word,
|
|
|
+ 'note' => $this->GrmAbbr($value->note, 0),
|
|
|
+ 'anchor' => $anchor,
|
|
|
];
|
|
|
- if(isset($wordDict[$dict_lang[0]])){
|
|
|
- if(isset($wordDict[$dict_lang[0]][$value->dict_id])){
|
|
|
- array_push($wordDict[$dict_lang[0]][$value->dict_id],$currData);
|
|
|
- }else{
|
|
|
- array_push($wordDict[$dict_lang[0]]["others"],$currData);
|
|
|
+ if (isset($wordDict[$dict_lang[0]])) {
|
|
|
+ if (isset($wordDict[$dict_lang[0]][$value->dict_id])) {
|
|
|
+ array_push($wordDict[$dict_lang[0]][$value->dict_id], $currData);
|
|
|
+ } else {
|
|
|
+ array_push($wordDict[$dict_lang[0]]["others"], $currData);
|
|
|
}
|
|
|
- }else{
|
|
|
- array_push($wordDict['others']['others'],$currData);
|
|
|
+ } else {
|
|
|
+ array_push($wordDict['others']['others'], $currData);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
@@ -143,82 +144,81 @@ class DictController extends Controller
|
|
|
foreach ($dictId as $oneData) {
|
|
|
# code...
|
|
|
$wordData['dict'][] = $oneData;
|
|
|
- if(isset($dictList['children']) && count($dictList['children'])>0){
|
|
|
+ if (isset($dictList['children']) && count($dictList['children']) > 0) {
|
|
|
$lastHref = end($dictList['children'])['href'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$lastHref = '';
|
|
|
}
|
|
|
- $currHref = '#'.$oneData['anchor'];
|
|
|
- if($lastHref !== $currHref){
|
|
|
+ $currHref = '#' . $oneData['anchor'];
|
|
|
+ if ($lastHref !== $currHref) {
|
|
|
$dictList['children'][] = [
|
|
|
- 'href'=> $currHref,
|
|
|
- 'title'=> $oneData['shortname'],
|
|
|
+ 'href' => $currHref,
|
|
|
+ 'title' => $oneData['shortname'],
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $wordDataOutput[]=$wordData;
|
|
|
- $dictListOutput[]=$dictList;
|
|
|
+ $wordDataOutput[] = $wordData;
|
|
|
+ $dictListOutput[] = $dictList;
|
|
|
|
|
|
//TODO 加变格查询
|
|
|
$case = new CaseMan();
|
|
|
$parent = $case->WordToBase($word);
|
|
|
foreach ($parent as $base => $case) {
|
|
|
# code...
|
|
|
- if(!in_array($base,$searched)){
|
|
|
+ if (!in_array($base, $searched)) {
|
|
|
$word_base[$base] = $case;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $wordDataPass[] = ['pass'=>$i+1,'words'=>$wordDataOutput];
|
|
|
+ $wordDataPass[] = ['pass' => $i + 1, 'words' => $wordDataOutput];
|
|
|
|
|
|
- if(count($word_base)===0){
|
|
|
+ if (count($word_base) === 0) {
|
|
|
break;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$words = $word_base;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- if($resultCount<2){
|
|
|
+ if ($resultCount < 2) {
|
|
|
//查询内文
|
|
|
$wordDataOutput = [];
|
|
|
$table = UserDict::select($indexCol)
|
|
|
- ->where('note','like','%'.$word.'%')
|
|
|
- ->where('language','<>','my')
|
|
|
- ->take(5)
|
|
|
- ->get();
|
|
|
+ ->where('note', 'like', '%' . $word . '%')
|
|
|
+ ->where('language', '<>', 'my')
|
|
|
+ ->take(5)
|
|
|
+ ->get();
|
|
|
$resultCount += count($table);
|
|
|
- $wordData=[
|
|
|
- 'word'=> $word,
|
|
|
- 'factors'=> "",
|
|
|
- 'parents'=> "",
|
|
|
- 'case'=> [],
|
|
|
- 'grammar'=>[],
|
|
|
- 'anchor'=> $anchor,
|
|
|
+ $wordData = [
|
|
|
+ 'word' => $word,
|
|
|
+ 'factors' => "",
|
|
|
+ 'parents' => "",
|
|
|
+ 'case' => [],
|
|
|
+ 'grammar' => [],
|
|
|
+ 'anchor' => $anchor,
|
|
|
'dict' => [],
|
|
|
];
|
|
|
foreach ($table as $key => $value) {
|
|
|
- $dictInfo= DictInfo::find($value->dict_id);
|
|
|
- $dict_lang = explode('-',$dictInfo->dest_lang);
|
|
|
- $anchor = "{$word}-{$dictInfo->shortname}";
|
|
|
+ $dictInfo = DictInfo::find($value->dict_id);
|
|
|
+ $dict_lang = explode('-', $dictInfo->dest_lang);
|
|
|
+ $anchor = "{$word}-{$dictInfo->shortname}";
|
|
|
$currData = [
|
|
|
- 'dictname'=> $dictInfo->name,
|
|
|
- 'shortname'=> $dictInfo->shortname,
|
|
|
- 'description'=>$dictInfo->description,
|
|
|
+ 'dictname' => $dictInfo->name,
|
|
|
+ 'shortname' => $dictInfo->shortname,
|
|
|
+ 'description' => $dictInfo->description,
|
|
|
'dict_id' => $value->dict_id,
|
|
|
'lang' => $dict_lang[0],
|
|
|
- 'word'=> $word,
|
|
|
- 'note'=> $this->GrmAbbr($value->note,0),
|
|
|
- 'anchor'=> $anchor,
|
|
|
+ 'word' => $word,
|
|
|
+ 'note' => $this->GrmAbbr($value->note, 0),
|
|
|
+ 'anchor' => $anchor,
|
|
|
];
|
|
|
$wordData['dict'][] = $currData;
|
|
|
}
|
|
|
$wordDataOutput[] = $wordData;
|
|
|
- $wordDataPass[] = ['pass'=>0,'words'=>$wordDataOutput];
|
|
|
+ $wordDataPass[] = ['pass' => 0, 'words' => $wordDataOutput];
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -277,24 +277,25 @@ class DictController extends Controller
|
|
|
//
|
|
|
}
|
|
|
|
|
|
- private function GrmAbbr($input,$dictid){
|
|
|
+ private function GrmAbbr($input, $dictid)
|
|
|
+ {
|
|
|
$mean = $input;
|
|
|
$replaced = array();
|
|
|
foreach (GRM_ABBR as $key => $value) {
|
|
|
- if(in_array($value["abbr"],$replaced)){
|
|
|
+ if (in_array($value["abbr"], $replaced)) {
|
|
|
continue;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$replaced[] = $value["abbr"];
|
|
|
}
|
|
|
- if($dictid !== 0){
|
|
|
- if($value["dictid"]=== $dictid && strpos($input,$value["abbr"]."|") == false){
|
|
|
- $mean = str_ireplace($value["abbr"],"|@{$value["abbr"]}-{$value["replace"]}",$mean);
|
|
|
+ if ($dictid !== 0) {
|
|
|
+ if ($value["dictid"] === $dictid && strpos($input, $value["abbr"] . "|") == false) {
|
|
|
+ $mean = str_ireplace($value["abbr"], "|@{$value["abbr"]}-{$value["replace"]}", $mean);
|
|
|
}
|
|
|
- }else{
|
|
|
- if( strpos($mean,"|@".$value["abbr"]) == false){
|
|
|
- $props=base64_encode(\json_encode(['text'=>$value["abbr"],'gid'=>$value["replace"]]));
|
|
|
+ } else {
|
|
|
+ if (strpos($mean, "|@" . $value["abbr"]) == false) {
|
|
|
+ $props = base64_encode(\json_encode(['text' => $value["abbr"], 'gid' => $value["replace"]]));
|
|
|
$tpl = "<MdTpl name='grammar-pop' tpl='grammar-pop' props='{$props}'></MdTpl>";
|
|
|
- $mean = str_ireplace($value["abbr"],$tpl,$mean);
|
|
|
+ $mean = str_ireplace($value["abbr"], $tpl, $mean);
|
|
|
}
|
|
|
}
|
|
|
}
|