2012-01-04 12:29:07 +01:00
|
|
|
<?php
|
2012-01-06 12:01:01 +01:00
|
|
|
class PreferencesController extends Zend_Controller_Action
|
2012-01-04 12:29:07 +01:00
|
|
|
{
|
2012-01-06 12:01:01 +01:00
|
|
|
public function saveAction()
|
2012-01-04 12:29:07 +01:00
|
|
|
{
|
|
|
|
$this->_helper->layout()->disableLayout();
|
|
|
|
$this->_helper->viewRenderer->setNoRender();
|
|
|
|
|
2012-01-06 12:01:01 +01:00
|
|
|
$fields = $this->getRequest()->getParam('fields');
|
2012-01-04 12:29:07 +01:00
|
|
|
$auth = Zend_Auth::getInstance();
|
2012-01-06 12:01:01 +01:00
|
|
|
$user = $auth->getIdentity();
|
2012-01-11 11:48:22 +01:00
|
|
|
|
2012-01-06 12:43:52 +01:00
|
|
|
$db = Zend_Registry::get('db');
|
2012-01-11 11:48:22 +01:00
|
|
|
|
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);
|
|
|
|
}
|
2012-01-06 12:01:01 +01:00
|
|
|
$this->_redirect('./');
|
2012-01-04 12:29:07 +01:00
|
|
|
}
|
|
|
|
|
2012-01-06 12:01:01 +01:00
|
|
|
public function getNotActivated($fields)
|
2012-01-04 12:29:07 +01:00
|
|
|
{
|
2012-01-06 12:01:01 +01:00
|
|
|
foreach($fields as $name => $field)
|
2012-01-04 12:29:07 +01:00
|
|
|
{
|
2012-01-06 12:01:01 +01:00
|
|
|
if(!$field['activated']) {
|
|
|
|
$desactivated[] = array($name => "");
|
|
|
|
}
|
2012-01-04 12:29:07 +01:00
|
|
|
}
|
2012-01-06 12:01:01 +01:00
|
|
|
return ($desactivated);
|
2012-01-04 12:29:07 +01:00
|
|
|
}
|
2012-01-12 14:47:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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('./');
|
|
|
|
}
|
|
|
|
|
2012-01-04 12:29:07 +01:00
|
|
|
}
|