odea/application/controllers/PreferencesController.php

57 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
class PreferencesController extends Zend_Controller_Action
{
public function saveAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$fields = $this->getRequest()->getParam('fields');
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-01-06 12:43:52 +01:00
$db = Zend_Registry::get('db');
2012-01-06 12:43:52 +01:00
$prefsModel = new Application_Model_Prefs($db);
$data = array(
'login' => $user->username,
'json' => json_encode($this->getNotActivated(json_decode($fields))),
);
$sql = $prefsModel->select()->where('login = ?', $user->username);
$rows = $prefsModel->fetchAll($sql);
if (count($rows)>0) {
$prefsModel->update($data, 'login = '.$user->unsername);
} else {
$prefsModel->insert($data);
}
$this->_redirect('./');
}
public function getNotActivated($fields)
{
foreach($fields as $name => $field)
{
if(!$field['activated']) {
$desactivated[] = array($name => "");
}
}
return ($desactivated);
}
/**
* Place un marqueur d'activation du mode de personnalisation dans la session Utilisateur
* On retourne ensuite dans index/index pour permettre le choix des préférences d'affichage
*/
public function activeAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//@todo : Vérifier que l'utilisateur à le droit de customiser
$user->customisation = true;
$auth->getStorage()->write($user);
$this->_redirect('./');
}
}