Merge branch 'markread' into 'master'

Markread

See merge request 076/community/076Server!12
このコミットが含まれているのは:
テクニカル諏訪子 2018-04-26 18:05:22 +09:00
コミット ef59d00367
2個のファイルの変更189行の追加15行の削除

ファイルの表示

@ -43,29 +43,110 @@ class BoardController extends Controller {
->get();
}
public function readPost(Request $request) { // /api/rpc/board/post/read
public function checkRead($for, $top, $username, $password) {
$check = $this->objAuth->checkLegit($username, $password);
if ($check == 0) {
$yetToRead = false;
}
else {
$valid = $this->objAuth->getPermissions($username, $password);
if ($valid['for_canview']) {
$isRead = array();
if ($for != 0) {
$isRead = DB::table('for_threads')
->select('id')
->where('for_id', $for)
->get();
}
else {
$isRead[] = array('id' => $top);
}
foreach ($isRead as $r) {
$yetToRead = false;
$rid = 0;
if ($for != 0) {
$rid = $r->id;
}
else {
$rid = $r['id'];
}
$get = DB::table('for_read')
->join('for_posts', 'for_posts.top_id', 'for_read.top_id')
->where('for_read.user_id', $check)
->where('for_read.top_id', $rid)
->get(array(
'for_posts.id',
'for_posts.user_id',
'for_posts.top_id',
'for_posts.post_date',
'for_read.view_time',
));
if (!$get->count()) {
$yetToRead = true;
}
else {
foreach($get as $g) {
if ($g->post_date > $g->view_time) {
$yetToRead = true;
}
else {
$yetToRead = false;
}
}
}
}
}
else {
$yetToRead = false;
}
}
return $yetToRead;
}
public function readTopic(Request $request) { // /api/rpc/board/topic/read
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
return 'Guests can\'t read';
}
else {
$valid = $this->objAuth->getPermissions($request->username, $request->password);
if ($valid['for_canview']) {
$getViews = DB::table('for_threads')
->select('views')
->where('id', $request->id)
$getRead = DB::table('for_read')
->select('view_time')
->where('user_id', $check)
->where('top_id', $request->top_id)
->first();
// id, user_id, for_id, last_read
// $getReadTopic = DB::table('for_readthreads')
$getPost = DB::table('for_posts')
->select('post_date')
->where('top_id', $request->top_id)
->orderBy('post_date', 'desc')
->limit(1)
->first();
// id, user_id, top_id, page_id, last_read
// $getReadPost = DB::table('for_readposts')
// ->select('*')
if ($getRead->view_time < $getPost->post_date) {
DB::table('for_read')
->where('user_id', $check)
->where('top_id', $request->top_id)
->update([
'view_time' => $getPost->post_date
]);
// return $something;
return 'Read.';
}
return '';
}
else {
return 'Permission denied.';
@ -209,18 +290,22 @@ class BoardController extends Controller {
$forS = array();
foreach($for as $f) {
$read = $this->checkRead($f->fid, 0, $request->username, $request->password);
$forS[] = array(
'id' => $f->fid,
'type' => 'forum',
'title' => $f->fctitle.'/'.$f->ftitle
'title' => $f->fctitle.'/'.$f->ftitle,
'read' => $read
);
}
foreach($top as $t) {
$read = $this->checkRead(0, $t->tid, $request->username, $request->password);
$forS[] = array(
'id' => $t->tid,
'type' => 'topic',
'title' => $t->ttitle
'title' => $t->ttitle,
'read' => $read
);
}
@ -1123,6 +1208,52 @@ class BoardController extends Controller {
}
}
public function getReadCategories (Request $request) { // /api/rpc/board/topic/getreadcategories
}
public function getReadForums (Request $request) { // /api/rpc/board/topic/getreadforums
}
public function getReadTopics (Request $request) { // /api/rpc/board/topic/getreadtopics
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($check == 0) {
return 'Err!';
}
else {
$i = 0;
$getTopIdAll = DB::table('for_readposts')
->select('top_id', 'last_read')
->where('user_id', $check)
->get();
$res = array();
foreach($getTopIdAll as $t) {
$res[] = array(
'key' => $i,
'uid' => $check,
'tid' => $t->top_id,
'read' => $t->last_read
);
$i++;
}
return $res;
}
}
public function markForumRead ($id, Request $request) { // /api/rpc/board/topic/markforumread/fid
}
public function markTopicRead ($id, Request $request) { // /api/rpc/board/topic/marktopicread/tid
}
public function undeletePost(Request $request) { // /api/rpc/board/post/undeletepost
$check = $this->objAuth->checkLegit($request->username, $request->password);
@ -1169,6 +1300,7 @@ class BoardController extends Controller {
$resF = array();
foreach($fors as $f) {
$read = $this->checkRead($f['id'], 0, $request->username, $request->password);
$ldet = $this->getLastPostOfForum($f['id']);
$topicsuu = DB::table('for_threads')->where('for_id', $f['id'])->count();
$replysuu = $this->countPostsInForum($f['id']);
@ -1216,7 +1348,8 @@ class BoardController extends Controller {
'f_desc' => $f['description'],
'f_topics' => $topicsuu,
'f_posts' => $replysuu,
'f_last' => $ldet['date']
'f_last' => $ldet['date'],
'f_read' => $read
);
}
@ -1239,6 +1372,7 @@ class BoardController extends Controller {
$res = array();
foreach($fors as $f) {
$read = $this->checkRead($f['id'], 0, $request->username, $request->password);
$ldet = $this->getLastPostOfForum($f['id']);
$topicsuu = DB::table('for_threads')->where('for_id', $f['id'])->count();
$replysuu = $this->countPostsInForum($f['id']);
@ -1286,6 +1420,7 @@ class BoardController extends Controller {
'f_topics' => $topicsuu,
'f_posts' => $replysuu,
'f_last' => $ldet['date'],
'f_read' => $read,
'c_name' => $catname[0]->title,
'u_name' => $showName,
'u_col' => $showCol
@ -1326,6 +1461,7 @@ class BoardController extends Controller {
$i = 0;
foreach($tops as $t) {
$read = $this->checkRead(0, $t->id, $request->username, $request->password);
$replysuu = DB::table('for_posts')->where('top_id', $t->id)->count();
$fplp = $this->getFirstAndLastPosts($t->id);
@ -1395,7 +1531,7 @@ class BoardController extends Controller {
't_sticky' => $t->sticky,
't_lock' => $t->lock,
't_poll' => $t->poll,
't_read' => $t->read,
't_read' => $read,
't_lang_id' => $t->lang_id,
'u_first_uid' => $t->started_by,
'u_last_uid' => $t->last_uid,
@ -1574,6 +1710,7 @@ class BoardController extends Controller {
else $uid = $this->getPostsOfUser($id, $from, $to, $request);
$udat = array();
$key = 0;
$ldate = 0;
foreach ($uid as $i) {
$showName = '';
@ -1635,9 +1772,45 @@ class BoardController extends Controller {
'showgroup' => $showGroupName,
'country' => $i->country,
]);
$ldate = $i->post_date;
$key++;
}
$check = $this->objAuth->checkLegit($request->username, $request->password);
if ($tp == 't' && $check != 0) {
$view = DB::table('for_threads')
->select('views')
->where('id', $id)
->first();
DB::table('for_threads')
->where('id', $id)
->update(['views' => $view->views+1]);
$checkTime = DB::table('for_read')
->select('view_time')
->where('user_id', $check)
->where('top_id', $id)
->first();
if (empty($checkTime)) {
DB::table('for_read')
->insert([
'user_id' => $check,
'top_id' => $id,
'view_time' => $ldate
]);
}
else if ($ldate > $checkTime->view_time) {
DB::table('for_read')
->where('user_id', $check)
->where('top_id', $id)
->update(['view_time' => $ldate]);
}
}
// Assign group names.
return $udat;
}

ファイルの表示

@ -45,6 +45,7 @@ Route::get('/api/rpc/board/topic/gettopiclock/{id}', 'BoardController@getTopicLo
Route::get('/api/rpc/board/topic/getforumidfromtopic/{top_id}', 'BoardController@getForumIdFromTopic');
Route::get('/api/rpc/board/topic/gettopicname/{id}', 'BoardController@getTopicName');
Route::post('/api/rpc/board/topic/read', 'BoardController@readTopic');
Route::post('/api/rpc/board/topic/addtopic', 'BoardController@addTopic');
Route::post('/api/rpc/board/topic/lock', 'BoardController@lockTopic');
Route::post('/api/rpc/board/topic/unlock', 'BoardController@unlockTopic');