public function run() { $userPref = EventsUserPreference::model()->findByPk($this->userId); if (is_null($userPref)) { $userPref = new EventsUserPreference(); $userPref->user_id = $this->userId; $userPref->save(); } $formUserPref = new CForm('application.modules.cal.views.main.formUserPref', $userPref); echo $formUserPref; }
/** * Render event calendar page. */ public function actionBrowse() { if (isset($_POST['currentUser'])) { Yii::app()->user->setState('cal_uid', $_POST['currentUser']); } else { Yii::app()->user->setState('cal_uid', $this->uid); } $curUser = Yii::app()->user->getState('cal_uid'); if (!in_array('events', Yii::app()->db->getSchema()->tableNames)) { $this->tableCreate(); } $this->registerScript(); // select user's prefference /e-mail, mobile alert/ $userPref = EventsUserPreference::model()->findByPk($curUser); if (is_null($userPref)) { $userPref = new EventsUserPreference(); $userPref->user_id = $curUser; $userPref->save(); } // select user's preffered events $criteria = new CDbCriteria(array('condition' => 'user_id=' . $curUser)); $events = EventsHelper::model()->findAll($criteria); $this->render('application.components.views.calendar.browse', array('imagesUrl' => $this->imagesUrl, 'userPref' => $userPref, 'events' => $events)); }