<?php
 namespace App\Http\Controllers\Main; use App\Http\Controllers\BaseController; use App\Util\NoteUtil; use App\Util\TopicUtil; use Illuminate\Support\Facades\Input; use TechOnline\Laravel\Http\Request; use TechOnline\Laravel\Http\Response; use TechSoft\Laravel\Member\MemberUtil; use TechSoft\Laravel\MemberFollow\MemberFollowUtil; class SearchController extends BaseController { public function index() { return Response::send(0, null, null, '/search/note?keyword=' . urlencode(Input::get('keyword'))); } public function note() { $pageSize = 10; $option = []; $option['where'] = []; if ($keyword = trim(Input::get('keyword'))) { $option['whereOperate'] = ['title', 'like', '%' . $keyword . '%']; } else { $keyword = ''; } if (Request::isPost()) { $page = intval(Input::get('page', 1)); $paginateData = NoteUtil::paginateNotes($page, $pageSize, $option); MemberUtil::mergeMemberUsers($paginateData['records']); $html = $this->_viewRender('fragment.noteListItems', [ 'notes' => $paginateData['records'], ]); return Response::send(0, null, [ 'html' => $html, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], ]); } $page = 1; $paginateData = NoteUtil::paginateNotes($page, $pageSize, $option); MemberUtil::mergeMemberUsers($paginateData['records']); return $this->_view('search.index', [ 'keyword' => $keyword, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], 'notes' => $paginateData['records'], ]); } public function topic() { $pageSize = 10; $option = []; $option['where'] = []; if ($keyword = trim(Input::get('keyword'))) { $option['whereOperate'] = ['title', 'like', '%' . $keyword . '%']; } else { $keyword = ''; } if (Request::isPost()) { $page = intval(Input::get('page', 1)); $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $html = $this->_viewRender('fragment.topicListItems', [ 'topics' => $paginateData['records'], ]); return Response::send(0, null, [ 'html' => $html, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], ]); } $page = 1; $paginateData = TopicUtil::paginateTopics($page, $pageSize, $option); TopicUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); return $this->_view('search.index', [ 'keyword' => $keyword, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], 'topics' => $paginateData['records'], ]); } public function user() { $pageSize = 10; $option = []; $option['where'] = []; if ($keyword = trim(Input::get('keyword'))) { $option['whereOperate'] = ['username', 'like', '%' . $keyword . '%']; } else { $keyword = ''; } if (Request::isPost()) { $page = intval(Input::get('page', 1)); $paginateData = MemberUtil::paginate($page, $pageSize, $option); MemberFollowUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); $html = $this->_viewRender('fragment.memberUserListItems', [ 'memberUsers' => $paginateData['records'], ]); return Response::send(0, null, [ 'html' => $html, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], ]); } $page = 1; $paginateData = MemberUtil::paginate($page, $pageSize, $option); MemberFollowUtil::mergeIsFollowed($paginateData['records'], $this->memberUserId()); return $this->_view('search.index', [ 'keyword' => $keyword, 'page' => $page, 'pageSize' => $pageSize, 'total' => $paginateData['total'], 'memberUsers' => $paginateData['records'], ]); } }