<?php

class UserSettingsController extends Controller {
    
    const userMonitorKey = "userMonitor";

    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }
    
    public function accessRules()
    {
        return array(
            array('allow',
                'actions' => array('set'),
                'users' => array('@'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }
    
    public function actionSet() {
        
        $user =  Yii::app()->user->getRealUserInstance();
        $settings = @$_POST['UserSettings'];
        
        if (isset($settings) && isset($settings[self::userMonitorKey]) && $user !== null) {
            $value = $settings[self::userMonitorKey];
            $user->userMonitor = $value;
            Yii::app()->user->setState(self::userMonitorKey, $value);
            $user->save();
        }
    }

}