|
@@ -36,8 +36,8 @@ class ArticleResource extends JsonResource
|
|
|
"title" => $this->title,
|
|
"title" => $this->title,
|
|
|
"subtitle" => $this->subtitle,
|
|
"subtitle" => $this->subtitle,
|
|
|
"summary" => $this->summary,
|
|
"summary" => $this->summary,
|
|
|
- "studio"=> StudioApi::getById($this->owner),
|
|
|
|
|
- "editor"=> UserApi::getById($this->editor_id),
|
|
|
|
|
|
|
+ "studio" => StudioApi::getById($this->owner),
|
|
|
|
|
+ "editor" => UserApi::getById($this->editor_id),
|
|
|
"status" => $this->status,
|
|
"status" => $this->status,
|
|
|
"lang" => $this->lang,
|
|
"lang" => $this->lang,
|
|
|
"parent_uid" => $this->parent,
|
|
"parent_uid" => $this->parent,
|
|
@@ -46,78 +46,84 @@ class ArticleResource extends JsonResource
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$user = AuthApi::current($request);
|
|
$user = AuthApi::current($request);
|
|
|
- if($user){
|
|
|
|
|
- $canEdit = ArticleController::userCanEdit($user['user_uid'],$this);
|
|
|
|
|
- if($canEdit){
|
|
|
|
|
|
|
+ if ($user) {
|
|
|
|
|
+ $canEdit = ArticleController::userCanEdit($user['user_uid'], $this);
|
|
|
|
|
+ if ($canEdit) {
|
|
|
$data['role'] = 'editor';
|
|
$data['role'] = 'editor';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//查询该文章在哪些文集中出现
|
|
//查询该文章在哪些文集中出现
|
|
|
- $collectionCount = ArticleCollection::where('article_id',$this->uid)->count();
|
|
|
|
|
- if($collectionCount>0){
|
|
|
|
|
|
|
+ $collectionCount = ArticleCollection::where('article_id', $this->uid)->count();
|
|
|
|
|
+ if ($collectionCount > 0) {
|
|
|
$data['anthology_count'] = $collectionCount;
|
|
$data['anthology_count'] = $collectionCount;
|
|
|
- $collection = ArticleCollection::where('article_id',$this->uid)->first();
|
|
|
|
|
|
|
+ $collection = ArticleCollection::where('article_id', $this->uid)->first();
|
|
|
$data['anthology_first'] = Collection::find($collection->collect_id);
|
|
$data['anthology_first'] = Collection::find($collection->collect_id);
|
|
|
}
|
|
}
|
|
|
- if($request->has('anthology') && Str::isUuid($request->get('anthology'))){
|
|
|
|
|
- $anthology = Collection::where('uid',$request->get('anthology'))->first();
|
|
|
|
|
|
|
+ if ($request->has('anthology') && Str::isUuid($request->input('anthology'))) {
|
|
|
|
|
+ $anthology = Collection::where('uid', $request->input('anthology'))->first();
|
|
|
}
|
|
}
|
|
|
//渲染简化版标题
|
|
//渲染简化版标题
|
|
|
$channels = [];
|
|
$channels = [];
|
|
|
- if($request->has('channel')){
|
|
|
|
|
|
|
+ if ($request->has('channel')) {
|
|
|
//有channel
|
|
//有channel
|
|
|
- $channels = explode('_',$request->get('channel')) ;
|
|
|
|
|
- }else if(isset($anthology) && $anthology && !empty($anthology->default_channel)){
|
|
|
|
|
|
|
+ $channels = explode('_', $request->input('channel'));
|
|
|
|
|
+ } else if (isset($anthology) && $anthology && !empty($anthology->default_channel)) {
|
|
|
//没有channel,使用文集channel
|
|
//没有channel,使用文集channel
|
|
|
$channels[] = $anthology->default_channel;
|
|
$channels[] = $anthology->default_channel;
|
|
|
}
|
|
}
|
|
|
- $mdRender = new MdRender(['format'=>'simple']);
|
|
|
|
|
|
|
+ $mdRender = new MdRender(['format' => 'simple']);
|
|
|
|
|
|
|
|
//path
|
|
//path
|
|
|
- if($request->has('anthology') && Str::isUuid($request->get('anthology'))){
|
|
|
|
|
|
|
+ if ($request->has('anthology') && Str::isUuid($request->input('anthology'))) {
|
|
|
$data['path'] = array();
|
|
$data['path'] = array();
|
|
|
- if(isset($anthology) && $anthology){
|
|
|
|
|
- $data['path'][] = ['key'=>$anthology->uid,
|
|
|
|
|
- 'title'=>$anthology->title,
|
|
|
|
|
- 'level'=>0];
|
|
|
|
|
|
|
+ if (isset($anthology) && $anthology) {
|
|
|
|
|
+ $data['path'][] = [
|
|
|
|
|
+ 'key' => $anthology->uid,
|
|
|
|
|
+ 'title' => $anthology->title,
|
|
|
|
|
+ 'level' => 0
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$currLevel = -1;
|
|
$currLevel = -1;
|
|
|
- $aList = ArticleCollection::where('collect_id',$request->get('anthology'))
|
|
|
|
|
- ->orderBy('id','desc')
|
|
|
|
|
- ->select(['article_id','title','level'])->get();
|
|
|
|
|
|
|
+ $aList = ArticleCollection::where('collect_id', $request->input('anthology'))
|
|
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
|
|
+ ->select(['article_id', 'title', 'level'])->get();
|
|
|
$path = array();
|
|
$path = array();
|
|
|
foreach ($aList as $article) {
|
|
foreach ($aList as $article) {
|
|
|
- if($article->article_id === $this->uid ||
|
|
|
|
|
- ($currLevel >= 0 && $article->level < $currLevel)){
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ $article->article_id === $this->uid ||
|
|
|
|
|
+ ($currLevel >= 0 && $article->level < $currLevel)
|
|
|
|
|
+ ) {
|
|
|
$currLevel = $article->level;
|
|
$currLevel = $article->level;
|
|
|
- $path[] = ['key'=>$article->article_id,
|
|
|
|
|
- 'title'=>$mdRender->convert($article->title,$channels),
|
|
|
|
|
- 'level'=>$article->level];
|
|
|
|
|
|
|
+ $path[] = [
|
|
|
|
|
+ 'key' => $article->article_id,
|
|
|
|
|
+ 'title' => $mdRender->convert($article->title, $channels),
|
|
|
|
|
+ 'level' => $article->level
|
|
|
|
|
+ ];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- for ($i=count($path)-1; $i >=0 ; $i--) {
|
|
|
|
|
|
|
+ for ($i = count($path) - 1; $i >= 0; $i--) {
|
|
|
$data['path'][] = $path[$i];
|
|
$data['path'][] = $path[$i];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//下级目录
|
|
//下级目录
|
|
|
$level = -1;
|
|
$level = -1;
|
|
|
$subToc = array();
|
|
$subToc = array();
|
|
|
- for ($i=count($aList)-1; $i >=0 ; $i--) {
|
|
|
|
|
|
|
+ for ($i = count($aList) - 1; $i >= 0; $i--) {
|
|
|
$article = $aList[$i];
|
|
$article = $aList[$i];
|
|
|
- if($level>=0){
|
|
|
|
|
- if($article->level>$level){
|
|
|
|
|
- $subToc[] =[
|
|
|
|
|
- "key"=>$article->article_id,
|
|
|
|
|
- "title"=>$mdRender->convert($article->title,$channels),
|
|
|
|
|
- "level"=>$article->level
|
|
|
|
|
|
|
+ if ($level >= 0) {
|
|
|
|
|
+ if ($article->level > $level) {
|
|
|
|
|
+ $subToc[] = [
|
|
|
|
|
+ "key" => $article->article_id,
|
|
|
|
|
+ "title" => $mdRender->convert($article->title, $channels),
|
|
|
|
|
+ "level" => $article->level
|
|
|
];
|
|
];
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if($article->article_id === $this->uid){
|
|
|
|
|
|
|
+ if ($article->article_id === $this->uid) {
|
|
|
$level = $article->level;
|
|
$level = $article->level;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -125,32 +131,34 @@ class ArticleResource extends JsonResource
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- $data['title_text'] = $mdRender->convert($this->title,$channels);
|
|
|
|
|
|
|
+ $data['title_text'] = $mdRender->convert($this->title, $channels);
|
|
|
|
|
|
|
|
//render html
|
|
//render html
|
|
|
$channels = array();
|
|
$channels = array();
|
|
|
- if(isset($this->content) && !empty($this->content)){
|
|
|
|
|
- if($request->has('channel')){
|
|
|
|
|
- $channels = explode('_',$request->get('channel')) ;
|
|
|
|
|
- }else if($request->has('anthology')){
|
|
|
|
|
- $defaultChannel = Collection::where('uid',$request->get('anthology'))
|
|
|
|
|
- ->value('default_channel');
|
|
|
|
|
- if($defaultChannel){
|
|
|
|
|
|
|
+ if (isset($this->content) && !empty($this->content)) {
|
|
|
|
|
+ if ($request->has('channel')) {
|
|
|
|
|
+ $channels = explode('_', $request->input('channel'));
|
|
|
|
|
+ } else if ($request->has('anthology')) {
|
|
|
|
|
+ $defaultChannel = Collection::where('uid', $request->input('anthology'))
|
|
|
|
|
+ ->value('default_channel');
|
|
|
|
|
+ if ($defaultChannel) {
|
|
|
$channels[] = $defaultChannel;
|
|
$channels[] = $defaultChannel;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if(count($channels) === 0){
|
|
|
|
|
|
|
+ if (count($channels) === 0) {
|
|
|
//查找用户默认channel
|
|
//查找用户默认channel
|
|
|
- $studioChannel = Channel::where('owner_uid',$this->owner)
|
|
|
|
|
- ->where('type','translation')
|
|
|
|
|
- ->get();
|
|
|
|
|
- if($studioChannel){
|
|
|
|
|
|
|
+ $studioChannel = Channel::where('owner_uid', $this->owner)
|
|
|
|
|
+ ->where('type', 'translation')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+ if ($studioChannel) {
|
|
|
$channelId = $studioChannel[0]->uid;
|
|
$channelId = $studioChannel[0]->uid;
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
- }else{
|
|
|
|
|
- $channelId = ChannelApi::getSysChannel('_community_translation_'.strtolower($this->lang).'_',
|
|
|
|
|
- '_community_translation_en_');
|
|
|
|
|
- if($channelId){
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $channelId = ChannelApi::getSysChannel(
|
|
|
|
|
+ '_community_translation_' . strtolower($this->lang) . '_',
|
|
|
|
|
+ '_community_translation_en_'
|
|
|
|
|
+ );
|
|
|
|
|
+ if ($channelId) {
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -158,57 +166,63 @@ class ArticleResource extends JsonResource
|
|
|
$data["content"] = $this->content;
|
|
$data["content"] = $this->content;
|
|
|
$data["content_type"] = $this->content_type;
|
|
$data["content_type"] = $this->content_type;
|
|
|
$query_id = null;
|
|
$query_id = null;
|
|
|
- if($request->has('course')){
|
|
|
|
|
- if($request->has('exercise')){
|
|
|
|
|
- $query_id = $request->get('exercise');
|
|
|
|
|
- if($request->has('user')){
|
|
|
|
|
|
|
+ if ($request->has('course')) {
|
|
|
|
|
+ if ($request->has('exercise')) {
|
|
|
|
|
+ $query_id = $request->input('exercise');
|
|
|
|
|
+ if ($request->has('user')) {
|
|
|
/**
|
|
/**
|
|
|
* 显示指定用户作业
|
|
* 显示指定用户作业
|
|
|
* 查询用户在课程中的channel
|
|
* 查询用户在课程中的channel
|
|
|
*/
|
|
*/
|
|
|
- $userId = UserApi::getIdByName($request->get('user'));
|
|
|
|
|
|
|
+ $userId = UserApi::getIdByName($request->input('user'));
|
|
|
|
|
|
|
|
- $userInCourse = CourseMember::where('course_id',$request->get('course'))
|
|
|
|
|
- ->where('user_id',$userId)
|
|
|
|
|
- ->first();
|
|
|
|
|
- if($userInCourse){
|
|
|
|
|
|
|
+ $userInCourse = CourseMember::where('course_id', $request->input('course'))
|
|
|
|
|
+ ->where('user_id', $userId)
|
|
|
|
|
+ ->first();
|
|
|
|
|
+ if ($userInCourse) {
|
|
|
$channelId = $userInCourse->channel_id;
|
|
$channelId = $userInCourse->channel_id;
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
}
|
|
}
|
|
|
- }else if($request->get('view')==="answer"){
|
|
|
|
|
|
|
+ } else if ($request->input('view') === "answer") {
|
|
|
/**
|
|
/**
|
|
|
* 显示答案
|
|
* 显示答案
|
|
|
* 算法:查询course 答案 channel
|
|
* 算法:查询course 答案 channel
|
|
|
*/
|
|
*/
|
|
|
- $channelId = Course::where('id',$request->get('course'))->value('channel_id');
|
|
|
|
|
|
|
+ $channelId = Course::where('id', $request->input('course'))->value('channel_id');
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
//显示答案
|
|
//显示答案
|
|
|
- $channelId = Course::where('id',$request->get('course'))->value('channel_id');
|
|
|
|
|
|
|
+ $channelId = Course::where('id', $request->input('course'))->value('channel_id');
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
}
|
|
}
|
|
|
- }else{
|
|
|
|
|
- $channelId = Course::where('id',$request->get('course'))->value('channel_id');
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $channelId = Course::where('id', $request->input('course'))->value('channel_id');
|
|
|
$channels = [$channelId];
|
|
$channels = [$channelId];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $mode = $request->get('mode','read');
|
|
|
|
|
- $format = $request->get('format','react');
|
|
|
|
|
|
|
+ $mode = $request->input('mode', 'read');
|
|
|
|
|
+ $format = $request->input('format', 'react');
|
|
|
|
|
|
|
|
$htmlRender = new MdRender([
|
|
$htmlRender = new MdRender([
|
|
|
'mode' => $mode,
|
|
'mode' => $mode,
|
|
|
- 'format'=> $format,
|
|
|
|
|
|
|
+ 'format' => $format,
|
|
|
'footnote' => true,
|
|
'footnote' => true,
|
|
|
- 'origin' => $request->get('origin',true),
|
|
|
|
|
- 'paragraph' => $request->get('paragraph',false),
|
|
|
|
|
|
|
+ 'origin' => $request->input('origin', true),
|
|
|
|
|
+ 'paragraph' => $request->input('paragraph', false),
|
|
|
]);
|
|
]);
|
|
|
//Log::debug('article render',['content'=>$this->content,'format'=>$format,'html'=>$html]);
|
|
//Log::debug('article render',['content'=>$this->content,'format'=>$format,'html'=>$html]);
|
|
|
- $data["html"] = $htmlRender->convert($this->content,$channels);
|
|
|
|
|
- if(empty($this->summary)){
|
|
|
|
|
- $data["_summary"] = MdRender::render($this->content,
|
|
|
|
|
- $channels,$query_id,$mode,
|
|
|
|
|
- 'translation','markdown','text');
|
|
|
|
|
|
|
+ $data["html"] = $htmlRender->convert($this->content, $channels);
|
|
|
|
|
+ if (empty($this->summary)) {
|
|
|
|
|
+ $data["_summary"] = MdRender::render(
|
|
|
|
|
+ $this->content,
|
|
|
|
|
+ $channels,
|
|
|
|
|
+ $query_id,
|
|
|
|
|
+ $mode,
|
|
|
|
|
+ 'translation',
|
|
|
|
|
+ 'markdown',
|
|
|
|
|
+ 'text'
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return $data;
|
|
return $data;
|