summaryrefslogtreecommitdiff
path: root/app/controllers/indexController.php
blob: e7e3797ef91d876e61c23ecb09082f5ce2f5ecc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

class indexController extends ActionController {
	public function indexAction () {
		$entryDAO = new EntryDAO ();
		$catDAO = new CategoryDAO ();
		
		$mode = Session::param ('mode', $this->view->conf->defaultView ());
		$get = Request::param ('get');
		$order = $this->view->conf->sortOrder ();
		
		// Récupère les flux par catégorie, favoris ou tous
		if ($get == 'favoris') {
			$entries = $entryDAO->listFavorites ($mode, $order);
		} elseif ($get != false) {
			$entries = $entryDAO->listByCategory ($get, $mode, $order);
		}
		
		// Cas où on ne choisie ni catégorie ni les favoris
		// ou si la catégorie ne correspond à aucune
		if (!isset ($entries)) {
			$entries = $entryDAO->listEntries ($mode, $order);
		}
		
		// Gestion pagination
		$page = Request::param ('page', 1);
		$this->view->entryPaginator = new Paginator ($entries);
		$this->view->entryPaginator->_nbItemsPerPage ($this->view->conf->postsPerPage ());
		$this->view->entryPaginator->_currentPage ($page);
		
		$this->view->cat_aside = $catDAO->listCategories ();
	}
	
	public function changeModeAction () {
		$mode = Request::param ('mode');
		
		if ($mode == 'not_read') {
			Session::_param ('mode', 'not_read');
		} else {
			Session::_param ('mode', 'all');
		}
		
		Request::forward (array (), true);
	}
}