コード例 #1
0
 public function download(Database $db, Request $request)
 {
     $filter = [];
     if ($keyword = $request->query('keyword')) {
         $filter = ['(name like :keyword or username like :keyword)', ':keyword' => '%' . $keyword . '%'];
     }
     $data = $db->select('name,username,level', 'user', $filter);
     $filename = 'user-report';
     $header = ['Name', 'Username', 'Level'];
     $delimiter = ';';
     $delay = false;
     return $this->csv($filename, $header, $data, $delimiter, $delay);
 }
コード例 #2
0
 public function main(User $user, Database $db, Request $request, HTML $html, $page = 1)
 {
     if (false === is_numeric($page)) {
         return $this->notFound(['message' => "Halaman '{$page}' tidak ditemukan!"]);
     }
     $filter = ['id <> :self', ':self' => $user->get('id')];
     if ($keyword = $request->query('keyword')) {
         $filter[0] .= ' and (name like :keyword or username like :keyword)';
         $filter[':keyword'] = '%' . $keyword . '%';
     }
     $subset = $db->paginate('user', $filter, null, is_numeric($page) ? $page : 1);
     $pagination = $html->pagination($subset, ['route' => $this->homeUrl . '/{page}', 'params' => ['page' => $page]]);
     return $this->render('user/list', ['subset' => $subset, 'homeUrl' => $this->homeUrl, 'keyword' => $keyword, 'pagination' => $pagination, 'createUrl' => $this->homeUrl . '/create', 'updateUrl' => $this->homeUrl . '/update/{id}', 'deleteUrl' => $this->homeUrl . '/delete/{id}', 'detailUrl' => $this->homeUrl . '/detail/{id}']);
 }