aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/indexController.php
blob: b8908dee31c8fd494f92ba452e9ca4c3bb977fd2 (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
46
47
48
49
50
51
<?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');
		
		// Récupère les flux par catégorie, favoris ou tous
		if ($get == 'favoris') {
			$entries = $entryDAO->listFavorites ($mode);
		} elseif ($get != false) {
			$entries = $entryDAO->listByCategory ($get, $mode);
		}
		
		// 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);
		}
		
		// Tri par date
		if ($this->view->conf->sortOrder () == 'high_to_low') {
			usort ($entries, 'sortReverseEntriesByDate');
		} else {
			usort ($entries, 'sortEntriesByDate');
		}
		
		// 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);
	}
}