visuddhinanda 3 лет назад
Родитель
Сommit
80c33977a7

+ 22 - 0
app/Http/Api/ChannelApi.php

@@ -0,0 +1,22 @@
+<?php
+namespace App\Http\Api;
+use App\Models\Channel;
+
+class ChannelApi{
+    public static function getById($id){
+        $channel = Channel::where("uid",$id)->first();
+        if($channel){
+            return [
+                    'id'=>$id,
+                    'name'=>$channel['name'],
+                    'type'=>$channel['type'],
+                    'studio_id'=>$channel['owner_uid'],
+                ];
+        }else{
+            return false;
+        }
+    }
+    public static function getListByUser(){
+
+    }
+}

+ 18 - 0
app/Http/Api/PaliTextApi.php

@@ -0,0 +1,18 @@
+<?php
+namespace App\Http\Api;
+
+use App\Models\PaliText;
+
+class PaliTextApi{
+    public static function getChapterStartEnd($book,$para){
+        $chapter = PaliText::where('book',$book)
+                        ->where('paragraph',$para)
+                        ->first();
+        if(!$chapter){
+            return false;
+        }
+        $start = $para;
+        $end = $para + $chapter->chapter_len -1;
+        return [$start,$end];
+    }
+}

+ 139 - 0
app/Http/Api/ShareApi.php

@@ -0,0 +1,139 @@
+<?php
+namespace App\Http\Api;
+use App\Models\GroupMember;
+use App\Models\Share;
+use App\Models\Article;
+use App\Models\Channel;
+use App\Models\Collection;
+
+class ShareApi{
+
+    /*
+    获取某用户的可见的协作资源
+    $res_type 见readme.md#资源类型 -1全部类型资源
+    */
+    public static function getResList($user_uid,$res_type=-1){
+        # 找我加入的群
+        $my_group = GroupMember::where("user_id",$user_uid)->select('group_id')->get();
+        $userList[] = $user_uid;
+        foreach ($my_group as $key => $value) {
+            # code...
+            $userList[]=$value["group_id"];
+        }
+
+        if($res_type==-1){
+            #所有类型资源
+            $Fetch =Share::whereIn("cooperator_id",$userList)->select(['res_id','res_type','power'])->get();
+        }
+        else{
+            #指定类型资源
+            $Fetch =Share::whereIn("cooperator_id",$userList)
+                        ->where('res_type',$res_type)
+                        ->select(['res_id','res_type','power'])->get();
+        }
+
+        $resOutput = array();
+        foreach ($Fetch as $key => $value) {
+            # 查重
+            if(isset($resOutput[$value["res_id"]])){
+                if($value["power"]>$resOutput[$value["res_id"]]["power"]){
+                    $resOutput[$value["res_id"]]["power"] = $value["power"];
+                }
+            }
+            else{
+                $resOutput[$value["res_id"]]= array("power"=> $value["power"],"type" => $value["res_type"]);
+            }
+        }
+        $resList=array();
+        foreach ($resOutput as $key => $value) {
+            # code...
+            $resList[]=array("res_id"=>$key,"res_type"=>(int)$value["type"],"power"=>(int)$value["power"]);
+        }
+
+        foreach ($resList as $key => $res) {
+            # 获取资源标题 和所有者
+            $resList[$key]["res_title"]="_unknown_";
+            $resList[$key]["res_owner_id"]="_unknown_";
+            $resList[$key]["type"]="_unknown_";
+            $resList[$key]["status"]="0";
+            $resList[$key]["lang"]="_unknown_";
+
+            switch ($res["res_type"]) {
+                case 1:
+                    # pcs 文档
+                    $resList[$key]["res_title"]="title";
+                    break;
+                case 2:
+                    # channel
+                    $channelInfo = Channel::where('uid',$res["res_id"])->first();
+                    if($channelInfo){
+                        $resList[$key]["res_title"]=$channelInfo["name"];
+                        $resList[$key]["res_owner_id"]=$channelInfo["owner_uid"];
+                        $resList[$key]["type"]=$channelInfo["type"];
+                        $resList[$key]["status"]=$channelInfo["status"];
+                        $resList[$key]["lang"]=$channelInfo["lang"];
+                    }
+                    break;
+                case 3:
+                    # 3 Article 文章
+                    $aInfo = Article::where('uid',$res["res_id"])->first();
+                    if($aInfo){
+                        $resList[$key]["res_title"]=$aInfo["title"];
+                        $resList[$key]["res_owner_id"]=$aInfo["owner"];
+                        $resList[$key]["status"]=$aInfo["status"];
+                        $resList[$key]["lang"]='';
+                    }
+                    break;
+                case 4:
+                    # 4 Collection 文集
+                    $aInfo = Collection::where('uid',$res["res_id"])->first();
+                    if($aInfo){
+                        $resList[$key]["res_title"]=$aInfo["title"];
+                        $resList[$key]["res_owner_id"]=$aInfo["owner"];
+                        $resList[$key]["status"]=$aInfo["status"];
+                        $resList[$key]["lang"]=$aInfo["lang"];
+                    }
+                    break;
+                case 5:
+                    # code...
+                    break;
+
+                default:
+                    # code...
+                    break;
+            }
+        }
+
+        return $resList;
+
+    }
+
+    /**
+     * 获取对某个共享资源的权限
+     */
+    public static function getResPower($user_uid,$res_id){
+            if($userid==='0'){
+                #未登录用户 没有共享资源
+                return 0;
+            }
+            # 找我加入的群
+            $my_group = Group::where("user_id",$user_uid)->select('group_id')->get();
+            $userList[] = $user_uid;
+            foreach ($my_group as $key => $value) {
+                $userList[]=$value["group_id"];
+            }
+            $Fetch =Share::whereIn("cooperator_id",$userList)
+                        ->where('res_id',$res_id)
+                        ->select(['power'])->get();
+            $power=0;
+            foreach ($Fetch as $key => $value) {
+                # code...
+                if((int)$value["power"]>$power){
+                    $power = $value["power"];
+                }
+            }
+            return $power;
+    }
+
+}
+

+ 17 - 0
app/Http/Api/SuggestionApi.php

@@ -0,0 +1,17 @@
+<?php
+namespace App\Http\Api;
+
+use App\Models\SentPr;
+use App\Http\Api\PaliTextApi;
+
+class SuggestionApi{
+    public static function getCountBySent($book,$para,$start,$end,$channel,$type="suggestion"){
+        $count['suggestion'] = SentPr::where('book_id',$book)
+                                    ->where('paragraph',$para)
+                                    ->where('word_start',$start)
+                                    ->where('word_end',$end)
+                                    ->where('channel_uid',$channel)
+                                    ->count();
+        return $count;
+    }
+}

+ 130 - 0
app/Http/Controllers/ArticleProgressController.php

@@ -0,0 +1,130 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Channel;
+use App\Models\Sentence;
+use App\Models\PaliSentence;
+use App\Http\Api\PaliTextApi;
+use Illuminate\Support\Arr;
+
+use Illuminate\Http\Request;
+
+class ArticleProgressController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index(Request $request)
+    {
+        //
+        switch ($request->get('view')) {
+            case 'chapter':
+                $chapter = PaliTextApi::getChapterStartEnd($request->get('book'),$request->get('para'));
+                $channels = Sentence::where('book_id',$request->get('book'))
+                                    ->whereBetween('paragraph',$chapter)
+                                    ->where('strlen','>',0)
+                                    ->groupBy('channel_uid')
+                                    ->select('channel_uid')
+                                    ->get();
+                //获取单句长度
+                $sentLen = PaliSentence::where('book',$request->get('book'))
+                            ->whereBetween('paragraph',$chapter)
+                            ->orderBy('word_begin')
+                            ->select(['book','paragraph','word_begin','word_end','length'])
+                            ->get();
+                //获取每个channel的完成度
+                foreach ($channels as $key => $value) {
+                    # code...
+                    $finished = Sentence::where('book_id',$request->get('book'))
+                    ->whereBetween('paragraph',$chapter)
+                    ->where('channel_uid',$value->channel_uid)
+                    ->where('strlen','>',0)
+                    ->select(['strlen','book_id','paragraph','word_start','word_end'])
+                    ->get();
+                    $final=[];
+                    foreach ($sentLen as  $sent) {
+                        # code...
+                        $first = Arr::first($finished, function ($value, $key) use($sent) {
+                            return ($value->book_id==$sent->book &&
+                                    $value->paragraph==$sent->paragraph &&
+                                    $value->word_start==$sent->word_begin &&
+                                    $value->word_end==$sent->word_end);
+                        });
+                        $final[] = [$sent->length,$first?true:false];
+                    }
+                    $value['final'] = $final;
+                }
+                return $this->ok($channels);
+                break;
+        }
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\Channel  $channel
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Channel $channel)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Channel  $channel
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Channel $channel)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\Channel  $channel
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Channel $channel)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\Channel  $channel
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Channel $channel)
+    {
+        //
+    }
+}