Ver código fonte

:art: formatting

visuddhinanda 1 ano atrás
pai
commit
36856de50b

+ 11 - 38
api-v8/app/Http/Resources/TaskResource.php

@@ -22,40 +22,13 @@ class TaskResource extends JsonResource
      */
     public function toArray($request)
     {
-        /*
-  id: string;
-  title: string;
-  description?: string | null;
-  assignees?: IUser[] | null;
-  assignees_id?: string[] | null;
-  parent?: ITaskData | null;
-  parent_id?: string | null;
-  roles?: string[] | null;
-  executor?: IUser | null;
-  executor_id?: string | null;
-  executor_relation_task?: ITaskData | null;
-  executor_relation_task_id?: string | null;
-  pre_task?: ITaskData | null;
-  pre_task_id?: string | null;
-  is_milestone: boolean;
-  project?: IProject|null;
-  project_id?: string | null;
-  owner?: IStudio;
-  owner_id?: string | null;
-  editor?: IUser;
-  editor_id?: string | null;
-  status?: TTaskStatus;
-  created_at?: string;
-  updated_at?: string;
-  started_at?: string | null;
-  finished_at?: string | null;
-         */
+
         $htmlRender = new MdRender([
             'mode' => 'read',
-            'format'=> 'react',
+            'format' => 'react',
             'footnote' => true,
-            'origin' => $request->get('origin',true),
-            'paragraph' => $request->get('paragraph',false),
+            'origin' => $request->get('origin', true),
+            'paragraph' => $request->get('paragraph', false),
         ]);
         $data = [
             'id' => $this->id,
@@ -73,9 +46,9 @@ class TaskResource extends JsonResource
             'project_id' => $this->project_id,
             'project' => ProjectApi::getById($this->project_id),
             'owner_id' => $this->owner_id,
-            "owner"=> StudioApi::getById($this->owner_id),
+            "owner" => StudioApi::getById($this->owner_id),
             'editor_id' => $this->editor_id,
-            "editor"=> UserApi::getByUuid($this->editor_id),
+            "editor" => UserApi::getByUuid($this->editor_id),
             'order' => $this->order,
             'status' => $this->status,
             'created_at' => $this->created_at,
@@ -83,8 +56,8 @@ class TaskResource extends JsonResource
             'started_at' => $this->started_at,
             'finished_at' => $this->finished_at,
         ];
-        $assignees = TaskAssignee::where('task_id',$this->id)->select('assignee_id')->get();
-        if(count($assignees)>0){
+        $assignees = TaskAssignee::where('task_id', $this->id)->select('assignee_id')->get();
+        if (count($assignees) > 0) {
             $assignees_id = [];
             foreach ($assignees as $key => $value) {
                 $assignees_id[] = $value->assignee_id;
@@ -92,11 +65,11 @@ class TaskResource extends JsonResource
             $data['assignees_id'] = $assignees_id;
             $data['assignees'] = UserApi::getListByUuid($assignees_id);
         }
-        if(!empty($this->description)){
-            $data["html"] = $htmlRender->convert($this->description,[]);
+        if (!empty($this->description)) {
+            $data["html"] = $htmlRender->convert($this->description, []);
         }
 
-        if(Str::isUuid($this->executor_id)){
+        if (Str::isUuid($this->executor_id)) {
             $data["executor"] = UserApi::getByUuid($this->executor_id);
         }
         return $data;

+ 59 - 57
api-v8/app/Http/Resources/TermResource.php

@@ -25,105 +25,107 @@ class TermResource extends JsonResource
     public function toArray($request)
     {
         $data = [
-            "id"=>$this->id,
-            "guid"=>$this->guid,
-            "word"=> $this->word,
-            "word_en"=> $this->word_en,
-            "meaning"=> $this->meaning,
-            "other_meaning"=> $this->other_meaning,
-            "tag"=> $this->tag,
-            "note"=> $this->note,
-            "language"=> $this->language,
-            "channal"=> $this->channal,
+            "id" => $this->id,
+            "guid" => $this->guid,
+            "word" => $this->word,
+            "word_en" => $this->word_en,
+            "meaning" => $this->meaning,
+            "other_meaning" => $this->other_meaning,
+            "tag" => $this->tag,
+            "note" => $this->note,
+            "language" => $this->language,
+            "channal" => $this->channal,
             "studio" => StudioApi::getById($this->owner),
-            "editor"=> UserApi::getById($this->editor_id),
-            "created_at"=> $this->created_at,
-            "updated_at"=> $this->updated_at,
+            "editor" => UserApi::getById($this->editor_id),
+            "created_at" => $this->created_at,
+            "updated_at" => $this->updated_at,
         ];
 
 
-        if($request->has('channel') && !empty($request->get('channel'))){
-            $channels = explode('_',$request->get('channel')) ;
-        }else{
-            if(!empty($this->channal) && Str::isUuid($this->channal)){
+        if ($request->has('channel') && !empty($request->get('channel'))) {
+            $channels = explode('_', $request->get('channel'));
+        } else {
+            if (!empty($this->channal) && Str::isUuid($this->channal)) {
                 $channelId = $this->channal;
                 $data["channel"] = ChannelApi::getById($this->channal);
-            }else{
-                $channelId = ChannelApi::getSysChannel('_community_translation_'.$this->language.'_');
-                if(empty($channelId)){
+            } else {
+                $channelId = ChannelApi::getSysChannel('_community_translation_' . $this->language . '_');
+                if (empty($channelId)) {
                     $channelId = ChannelApi::getSysChannel('_community_translation_zh-hans_');
                 }
             }
-            if(!empty($channelId)){
+            if (!empty($channelId)) {
                 $channels = [$channelId];
-            }else{
+            } else {
                 $channels = [];
             }
         }
 
 
-        if(!empty($this->note)){
+        if (!empty($this->note)) {
             $mdRender = new MdRender(
                 [
-                    'mode'=>$request->get('mode','read'),
-                    'format'=>'react',
-                    'studioId'=>$this->owner,
-                ]);
-            $data["html"]  = $mdRender->convert($this->note,$channels,null);
+                    'mode' => $request->get('mode', 'read'),
+                    'format' => 'react',
+                    'studioId' => $this->owner,
+                ]
+            );
+            $data["html"]  = $mdRender->convert($this->note, $channels, null);
             $summaryContent = $this->note;
-        }else if($request->has('community_summary')){
+        } else if ($request->has('community_summary')) {
             $lang = strtolower($this->language);
-            if($lang==='zh'){
-                $lang='zh-hans';
+            if ($lang === 'zh') {
+                $lang = 'zh-hans';
             }
             $community_channel = ChannelApi::getSysChannel("_community_term_{$lang}_");
-            if(empty($community_channel)){
+            if (empty($community_channel)) {
                 $community_channel = ChannelApi::getSysChannel('_community_term_zh-hans_');
             }
-            if(Str::isUuid($community_channel)){
-                            //查找社区解释
-                $community_note = DhammaTerm::where("word",$this->word)
-                                            ->where('channal',$community_channel)
-                                            ->value('note');
-                if(!empty($community_note)){
+            if (Str::isUuid($community_channel)) {
+                //查找社区解释
+                $community_note = DhammaTerm::where("word", $this->word)
+                    ->where('channal', $community_channel)
+                    ->value('note');
+                if (!empty($community_note)) {
                     $summaryContent = $community_note;
                     $data["summary_is_community"] = true;
                 }
             }
         }
-        if(isset($summaryContent)){
+        if (isset($summaryContent)) {
             $mdRender = new MdRender(
                 [
-                    'mode'=>$request->get('mode','read'),
-                    'format'=>'text',
-                    'studioId'=>$this->owner,
-                ]);
-            $data["summary"]  = $mdRender->convert($summaryContent,$channels,null);
+                    'mode' => $request->get('mode', 'read'),
+                    'format' => 'text',
+                    'studioId' => $this->owner,
+                ]
+            );
+            $data["summary"]  = $mdRender->convert($summaryContent, $channels, null);
         }
 
         $user = AuthApi::current($request);
-        if(!$user){
+        if (!$user) {
             $data["role"] = 'reader';
-        }else{
-            if($this->owner === $user['user_uid']){
+        } else {
+            if ($this->owner === $user['user_uid']) {
                 $data["role"] = 'owner';
-            }else if(!empty($this->channal)){
-                $power = ShareApi::getResPower($user['user_uid'],$this->channal);
-                if($power===20){
+            } else if (!empty($this->channal)) {
+                $power = ShareApi::getResPower($user['user_uid'], $this->channal);
+                if ($power === 20) {
                     $data["role"] = 'editor';
-                }else if($power===10){
+                } else if ($power === 10) {
                     $data["role"] = 'reader';
-                }else{
+                } else {
                     $data["role"] = 'unknown';
                 }
             }
         }
-        if($request->has('exp')){
+        if ($request->has('exp')) {
             //毫秒计算的经验值
-            $exp = UserOperationDaily::where('user_id',$this->editor_id)
-                                                ->where('date_int','<=',date_timestamp_get(date_create($this->updated_at))*1000)
-                                                ->sum('duration');
-            $data['exp'] = (int)($exp/1000);
+            $exp = UserOperationDaily::where('user_id', $this->editor_id)
+                ->where('date_int', '<=', date_timestamp_get(date_create($this->updated_at)) * 1000)
+                ->sum('duration');
+            $data['exp'] = (int)($exp / 1000);
         }
         return $data;
     }