api/src/Topxia/Api/Resource/Thread.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Topxia\Api\Resource;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
class Thread extends BaseResource
{
/**
* @todo 有问题,要重写。
*/
public function create(Application $app, Request $request)
{
try {
$data = $request->request->all();
if (!isset($data['type'])) {
$data['type'] = 'question';
}
$targetType = $data['targetType'];
$targetId = $data['targetId'];
if (empty($targetId) || empty($targetType)) {
return $this->error('500', '创建问答失败,缺失数据');
}
if ('lesson' == $targetType) {
$lesson = $this->getCourseService()->getLesson($targetId);
if (empty($lesson)) {
return $this->error('500', '课时不存在');
}
$data['courseId'] = $lesson['courseId'];
$data['lessonId'] = $targetId;
} else {
$data['courseId'] = $targetId;
}
unset($data['targetId']);
unset($data['targetType']);
$thread = $this->getThreadService()->createThread($data);
if (!empty($thread)) {
return array('threadId' => $thread['id']);
}
} catch (\Exception $e) {
return $this->error('500', $e->getMessage());
}
return $this->error('500', '发帖错误');
}
protected function getThreadService()
{
return $this->getServiceKernel()->createService('Course:ThreadService');
}
protected function getCourseService()
{
return $this->getServiceKernel()->createService('Course:CourseService');
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。