Working on profile comments.
このコミットが含まれているのは:
コミット
fbf4ebd79f
|
@ -552,4 +552,222 @@ class UserController extends Controller {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getComments ($id, Request $request) { // /api/rpc/user/comment/get/id
|
||||
$cols = $this->getGroupColours()->toArray();
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_viewcomment'] == 1) {
|
||||
$come = array();
|
||||
$get = DB::table('usr_comments')
|
||||
->where('profile_id', $id)
|
||||
->where('reply_id', 0)
|
||||
->orderBy('usr_comments.postdate', 'asc')
|
||||
->get(array(
|
||||
'usr_comments.id as come_id',
|
||||
'user_id',
|
||||
'postdate',
|
||||
'message',
|
||||
'isEdit',
|
||||
'isDel'
|
||||
));
|
||||
|
||||
// Foreach, new getter but check on replies, and only if isDel is 0.
|
||||
foreach ($get as $g) {
|
||||
$user = $this->getUser($g->user_id, $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
|
||||
if ($user[0]->display_name !== '') {
|
||||
$showName = $user[0]->display_name;
|
||||
}
|
||||
else {
|
||||
$showName = $user[0]->username;
|
||||
}
|
||||
|
||||
if ($user[0]->name_style !== '') {
|
||||
$showCol = $user[0]->name_style;
|
||||
}
|
||||
else {
|
||||
foreach($cols as $cl) {
|
||||
if ($cl->id === $user[0]->perm_id) {
|
||||
if ($user[0]->gender === 1) $showCol = $cl->colour_m;
|
||||
else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
|
||||
else $showCol = $cl->colour_u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rep = DB::table('usr_comments')
|
||||
->where('reply_id', $g->come_id)
|
||||
->orderBy('usr_comments.postdate', 'asc')
|
||||
->get(array(
|
||||
'usr_comments.id as come_id',
|
||||
'user_id',
|
||||
'postdate',
|
||||
'message',
|
||||
'isEdit',
|
||||
'isDel'
|
||||
));
|
||||
|
||||
$come[] = array(
|
||||
'come_id' => $g->come_id,
|
||||
'user_id' => $g->user_id,
|
||||
'name' => $showName,
|
||||
'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'col' => $showCol,
|
||||
'message' => $g->message,
|
||||
'postdate' => $g->postdate,
|
||||
'isEdit' => $g->isEdit,
|
||||
'isDel' => $g->isDel
|
||||
);
|
||||
|
||||
foreach($rep as $r) {
|
||||
$user = $this->getUser($r->user_id, $request)->toArray();
|
||||
$showName = "";
|
||||
$showCol = "";
|
||||
|
||||
if ($user[0]->display_name !== '') {
|
||||
$showName = $user[0]->display_name;
|
||||
}
|
||||
else {
|
||||
$showName = $user[0]->username;
|
||||
}
|
||||
|
||||
if ($user[0]->name_style !== '') {
|
||||
$showCol = $user[0]->name_style;
|
||||
}
|
||||
else {
|
||||
foreach($cols as $cl) {
|
||||
if ($cl->id === $user[0]->perm_id) {
|
||||
if ($user[0]->gender === 1) $showCol = $cl->colour_m;
|
||||
else if ($user[0]->gender === 2) $showCol = $cl->colour_f;
|
||||
else $showCol = $cl->colour_u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$come[] = array(
|
||||
'reply_to' => $g->come_id,
|
||||
'come_id' => $r->come_id,
|
||||
'user_id' => $r->user_id,
|
||||
'name' => $showName,
|
||||
'avatar' => ($user[0]->avatar != '' ? $user[0]->avatar : 'assets/avatars/haznoavaz.png'),
|
||||
'col' => $showCol,
|
||||
'message' => $r->message,
|
||||
'postdate' => $r->postdate,
|
||||
'isEdit' => $r->isEdit,
|
||||
'isDel' => $r->isDel
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $come;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
|
||||
public function addComment (Request $request) { // /api/rpc/user/comment/add
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_addcomment'] == 1) {
|
||||
$add = DB::table('usr_comments')
|
||||
->insert([
|
||||
'user_id' => $request->user_id,
|
||||
'profile_id' => $request->profile_id,
|
||||
'reply_id' => ($request->reply_id > 0 ? $request->reply_id : 0),
|
||||
'postdate' => time(),
|
||||
'message' => $request->message,
|
||||
'isEdit' => 0,
|
||||
'isDel' => 0
|
||||
]);
|
||||
|
||||
return \Response::json($add);
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function editComment (Request $request) { // /api/rpc/user/comment/edit
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_editowncomment'] == 1) {
|
||||
DB::table('usr_comments')
|
||||
->where('profile_id', $request->profile_id)
|
||||
->update([
|
||||
'message' => $request->message,
|
||||
'isEdit' => 1
|
||||
]);
|
||||
|
||||
return 'Success!';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteComment (Request $request) { // /api/rpc/user/comment/delete
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_delcomment'] == 1) {
|
||||
DB::table('usr_comments')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'isDel' => 1
|
||||
]);
|
||||
|
||||
return 'Success!';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function undeleteComment (Request $request) { // /api/rpc/user/comment/undelete
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
||||
if ($check == 0) {
|
||||
return 'Err!';
|
||||
}
|
||||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['usr_delcomment'] == 1) {
|
||||
DB::table('usr_comments')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'isDel' => 0
|
||||
]);
|
||||
|
||||
return 'Success!';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,3 +38,11 @@ Route::post('/api/rpc/user/user/updatetotalpostcount', 'UserController@updateTot
|
|||
Route::post('/api/rpc/user/user/updatetotaltopiccount', 'UserController@updateTotalTopicCount');
|
||||
Route::post('/api/rpc/user/user/avatarupload', 'UserController@avatarUpload');
|
||||
Route::post('/api/rpc/user/user/edit', 'UserController@editUser');
|
||||
|
||||
// Comment
|
||||
Route::get('/api/rpc/user/comment/get/{id}', 'UserController@getComments');
|
||||
|
||||
Route::post('/api/rpc/user/comment/add', 'UserController@addComment');
|
||||
Route::post('/api/rpc/user/comment/edit', 'UserController@editComment');
|
||||
Route::post('/api/rpc/user/comment/delete', 'UserController@deleteComment');
|
||||
Route::post('/api/rpc/user/comment/undelete', 'UserController@undeleteComment');
|
新しいイシューから参照