getPostsの磨き

このコミットが含まれているのは:
テクニカル諏訪子 2020-02-24 22:06:45 +09:00
コミット dd896ddd78
4個のファイルの変更10行の追加106行の削除

ファイルの表示

@ -30,7 +30,7 @@ class HomeController extends Controller {
}
public function index () {
$res = $this->objSite->getPosts();
$res = $this->objSite->getPosts(1);
return view('pages.site.index', ['res' => $res, 'menu' => $this->menu, 'user' => $this->user]);
}

ファイルの表示

@ -22,111 +22,19 @@ class SiteController extends Controller {
$this->objPermission = new PermissionController();
}
public function getPosts () {
public function getPosts ($ispost=1) {
$kero_token = (isset($_COOKIE['kero_token']) ? $_COOKIE['kero_token'] : '');
$check = $this->objAuth->checkLegit($kero_token);
$ucol = $this->objUser->getGroupColours();
$valid = $this->objAuth->getPermissions($kero_token);
if ($valid['blg_editpost']) {
$get = DB::table('blg_content')
->join('users', 'blg_content.user_id', '=', 'users.id')
->join('usr_details', 'usr_details.user_id', '=', 'blg_content.user_id')
->join('usr_profile', 'usr_profile.user_id', '=', 'blg_content.user_id')
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_content.user_id')
->where('isPost', 1)
->orderBy('publish_date', 'desc')
->get(array(
'blg_content.id',
'blg_content.user_id',
'title',
'slug',
'post_date',
'publish_date',
'public_status',
'message',
'username',
'perm_id',
'gender',
'avatar',
'name_style',
'display_name'
));
}
else {
$get = DB::table('blg_content')
->join('users', 'blg_content.user_id', '=', 'users.id')
->join('usr_details', 'usr_details.user_id', '=', 'blg_content.user_id')
->join('usr_profile', 'usr_profile.user_id', '=', 'blg_content.user_id')
->join('usr_perm_id', 'usr_perm_id.user_id', '=', 'blg_content.user_id')
->where('public_status', 0)
->where('isPost', 1)
->orderBy('publish_date', 'desc')
->get(array(
'blg_content.id',
'blg_content.user_id',
'title',
'slug',
'post_date',
'publish_date',
'public_status',
'message',
'username',
'perm_id',
'gender',
'avatar',
'name_style',
'display_name'
));
}
$res = array();
$key = 0;
$get = DB::table('blg_content')->where('isPost', $ispost)->orderBy('publish_date', 'desc')->get();
setlocale(LC_ALL, 'ja_JP.utf8');
foreach ($get as $i) {
$showName = '';
$showCol = '';
$showGroupName = '';
foreach ($get as $g) { if ($valid['blg_addpost'] == 0 && $valid['blg_editpost'] == 0 && $g->public_status != 0) unset($g); }
if (!empty($i->display_name)) $showName = $i->display_name;
else $showName = $i->username;
if (!empty($i->name_style)) {
$showCol = $i->name_style;
}
else {
foreach ($ucol as $j) {
if ($j->id == $i->perm_id) {
if ($i->gender == 1) $showCol = $j->colour_m;
else if ($i->gender == 2) $showCol = $j->colour_f;
else $showCol = $j->colour_u;
}
}
}
$gname = $this->objUser->getGroupName($i->user_id);
$showGroupName = $gname[0]->name;
array_push($res, [
'key' => $key,
'id' => $i->id,
'user_id' => $i->user_id,
'title' => $i->title,
'slug' => $i->slug,
'post_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->post_date),
'publish_date' => strftime('%Y/%m/%d(%a) %H:%M:%S %Z', $i->publish_date),
'public_status' => $i->public_status,
'message' => $i->message,
'avatar' => $i->avatar,
'showcol' => $showCol,
'showname' => $showName
]);
$key++;
}
return $res;
return $get;
}
public function getPost ($slug, $kero) {
@ -212,8 +120,6 @@ class SiteController extends Controller {
$gname = $this->objUser->getGroupName($i->user_id);
$showGroupName = $gname[0]->name;
$comment = $this->getComments($i->id);
array_push($res, [
'id' => $i->id,
'user_id' => $i->user_id,
@ -226,8 +132,7 @@ class SiteController extends Controller {
'gender' => $i->gender,
'avatar' => $i->avatar,
'showcol' => $showCol,
'showname' => $showName,
'comment' => $comment
'showname' => $showName
]);
}
@ -272,7 +177,6 @@ class SiteController extends Controller {
if (!empty($i->display_name)) $showName = $i->display_name;
else $showName = $i->username;
if (empty($i->avatar) || $i->avatar == '') $i->avatar = 'assets/avatars/haznoavaz.png';
if (!empty($i->name_style)) $showCol = $i->name_style;
else {

ファイルの表示

@ -55,7 +55,7 @@
<div class="row">
<div class="col-sm-3">
<div class="nav flex-column nav-pills sidemenu">
<a href="/" class="nav-link {{ ($_SERVER['REQUEST_URI'] == '/sa' ? 'bara' : 'bar') }}">トップ</a>
<a href="/" class="nav-link {{ ($_SERVER['REQUEST_URI'] == '/' ? 'bara' : 'bar') }}">トップ</a>
@foreach ($menu as $m)
<a href="/{{ $m['slug'] }}" class="nav-link {{ ($_SERVER['REQUEST_URI'] == '/'.$m['slug'] ? 'bara' : 'bar') }}">{{ $m['title'] }}</a>
@endforeach

ファイルの表示

@ -3,9 +3,9 @@
@section('content')
@foreach ($res as $r)
<div class="within {{ ($r['public_status'] !== 0 ? ' wny' : '') }}">
<div class="bar {{ ($r['public_status'] !== 0 ? ' bny' : '') }}">
<a href="/blog/{{ $r['slug'] }}">{{ $r['title'] }}</a>
<div class="within {{ ($r->public_status !== 0 ? ' wny' : '') }}">
<div class="bar {{ ($r->public_status !== 0 ? ' bny' : '') }}">
<a href="/blog/{{ $r->slug }}">{{ $r->title }}</a>
</div>
</div>
@endforeach