function paginationAction($id)
 {
     $totalpage = "";
     //tinh xem minh co khoan bao nhieu page
     $per_page = 3;
     //tong so item tren mot trang
     $record = count(News::getAll());
     //tong so hang cua csdl
     if ($record > $per_page) {
         $totalpage = ceil($record / $per_page);
     } else {
         $totalpage = 1;
     }
     $start = ($id - 1) * $per_page;
     //tinh so dong bat dau trong co so du lieu tu page nhap vao
     $end_page = $totalpage - 1;
     $html = "<div class='pagi'><ul>";
     for ($i = 1; $i <= $totalpage; $i++) {
         if ($id == $i) {
             $html .= "<li class='current'><a href='/page/{$i}'> {$i} </a></li>";
         } else {
             $html .= "<li ><a href='/page/{$i}'> {$i} </a></li>";
         }
     }
     $html .= '</ul></div>';
     $data['news'] = News::getPaginate($start, $per_page);
     $data['html'] = $html;
     $data['tag'] = News::getAllTag();
     return $this->render('news/mainpage.html.twig', $data);
 }
 public function updateAction($id)
 {
     if ($this->getPostData()) {
         $news = $this->getPostData();
         $news['img'] = "img/news/" . $_FILES['image']['name'];
         $path = 'img/news/' . $_FILES['image']['name'];
         // Đường dẫn chưa file upload
         move_uploaded_file($_FILES['image']['tmp_name'], $path);
         //end img upload
         $news['slug'] = $this->app['slugify']->slugify($news['name']);
         //xoa gia tri hien tai cua bang post_tag
         News::deletePostTag($id);
         News::add_tag($id, $news['tag']);
         News::updateNews($id, $news);
         return $this->redirect('viewnews');
     }
     $data = array();
     $data['news'] = News::getById($id);
     return $this->render('admin/updatenews.html.twig', $data);
 }
Example #3
0
 function showList()
 {
     $this->beforeLogin();
     $today = date('Y-m-d');
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $user = $_SESSION['user']['name'];
     $subscribes = \App\Model\Subscribe::whereUser($user)->whereStatus(0)->get();
     $subscribeIds = [];
     foreach ($subscribes as $v) {
         $subscribeIds[] = $v->source;
     }
     $newsListOfToday = \App\Model\News::where('gmt_create', '>', $today)->whereIn('source', $subscribeIds)->orderBy('id', 'desc')->get();
     foreach ($newsListOfToday as &$v) {
         $v->source = \App\Model\Source::whereId($v->source)->first();
     }
     $newsListOfYesterday = \App\Model\News::where('gmt_create', '>', $yesterday)->whereIn('source', $subscribeIds)->where('gmt_create', '<', $today)->orderBy('id', 'desc')->get();
     foreach ($newsListOfYesterday as &$v) {
         $v->source = \App\Model\Source::whereId($v->source)->first();
     }
     return view('home/index', ['newsListOfToday' => $newsListOfToday, 'newsListOfYesterday' => $newsListOfYesterday, 'today' => date('m-d'), 'yesterday' => date('m-d', strtotime('-1 day'))]);
 }
Example #4
0
 /**
  * Show detail of a news
  * GET
  *
  * @param int $id
  * @param string $title
  * @return Response
  */
 public function showNews($id, $title)
 {
     $blog = NewsManager::find($id);
     return view('news.detail', compact('blog'));
 }
Example #5
0
 /**
  * Display a listing of the resource.
  * Hiển thị bài viết có status =1 (sidebar-right)
  * @return Response
  */
 public function prd()
 {
     return Response::json(News::orderBy('id', 'desc')->where('news_status', '1')->get());
 }
 public function getPaginate($start, $limit)
 {
     return News::skip($start)->take($limit)->get();
 }
Example #7
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     // $news = News::find($id);
     // if ($news) {
     // 	$news->delete();
     // } else {
     // 	return abort(404);
     // }
     // return redirect('admin/news');
     $news = News::find($id);
     $news->delete();
 }