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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?php
/**
* categorie actions.
*
* @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
class categorieActions extends sfActions {
public function executeIndex( sfWebRequest $request) {
// pager
if ($request->getParameter('page')) {
$this->setPage($request->getParameter('page'));
}
$this->obj = $this->getRoute()->getObject();
$this->setObject($this->obj);
$this->stars = Doctrine_Core::getTable('Vehicule')->getStar();
$this->pager = $this->getPager();
//$this->vehicules = $this->getRoute()->getObject()->Vehicule;
}
protected function getPager() {
$pager = new sfDoctrinePager('Vehicule',5);
$pager->setQuery($this->buildQuery());
$pager->setPage($this->getPage());
$pager->init();
return $pager;
}
protected function buildQuery() {
if (null === $this->filters) {
$this->filters = new VehiculeFormFilter();
}
$request = sfContext::getInstance()->getRequest();
$this->filters->bind($this->getFilters());
$query = $this->filters->buildQuery($this->getFilters());
$query->where('date_to >= ?',date('Y-m-d H:i:s',time()))
->orderBy('created_at DESC')
->andWhere('categorie_id = ?', $request->getParameter('id',1));
$this->route = 'categorie';
// $event = $this->dispatcher->filter(new sfEvent($this, 'front.build_query_categorie'), $query);
// $query = $event->getReturnValue();
return $query;
}
protected function getFilters() {
return $this->getUser()->getAttribute('front.vehicule.categorie.form.filters', array(),'front_module');
}
protected function setPage($page) {
$this->getUser()->setAttribute('front.vehicule.categorie.page', $page, 'front_module');
}
protected function setObject($obj){
$this->getUser()->setAttribute('front.vehicule.categorie.object', $obj, 'front_module');
}
protected function getObject(){
return $this->getUser()->getAttribute('front.vehicule.categorie.object', null, 'front_module');
}
protected function getPage() {
return $this->getUser()->getAttribute('front.vehicule.categorie.page', 1, 'front_module');
}
public function executeFilter(sfWebRequest $request) {
$this->setPage(1);
$obj = $this->getObject();
if ($request->hasParameter('_reset')) {
$this->setFilters(array());
$this->redirect('@categorie?libelle='.$obj->libelle.'&id='.$obj->id);
}
$this->filters = new VehiculeFormFilter();
$this->filters->bind($request->getParameter($this->filters->getName()));
if ($this->filters->isValid()) {
$this->getUser()->setAttribute('front.vehicule.categorie.form.filters', $this->filters->getValues(), 'front_module');
$this->redirect('@categorie?libelle='.$obj->libelle.'&id='.$obj->id);
}
$this->obj = $this->getObject();
$this->stars = Doctrine_Core::getTable('Vehicule')->getStar();
$this->pager = $this->getPager();
$this->setTemplate('index');
}
} |
Partager