/** * @return NotifyUser */ public static function loadDefault($commentableType = null) { if ($nu = NotifyUser::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'commentable_type' => $commentableType))) { return $nu; } $nu = new self(); $nu->user_id = Yii::app()->user->id; $nu->commentable_type = $commentableType; return $nu; }
public function run() { $uid = Yii::app()->user->id; if (!$uid || !$this->commentableType) { return; } $this->notifyUser = $nu = NotifyUser::loadDefault($this->commentableType); $cr = new CDbCriteria(); $cr->condition = "t.user_id = ? AND t.commentable_type = ?"; $cr->params = array($uid, $this->commentableType); $cr->with = 'item'; $this->subProvider = new CActiveDataProvider('NotifySubscription', array('criteria' => $cr, 'pagination' => array('pageSize' => 5))); $this->render('notifySubscription'); }
/** * изменение настроек подписки пользователя */ public function actionUserSettings() { $postNU = @$_POST['NotifyUser']; $nu = NotifyUser::loadDefault(@$postNU['commentable_type']); if (!empty($postNU)) { // todo: filter notify_all option (admin-only) $nu->attributes = $_POST['NotifyUser']; } if ($nu->save()) { Yii::app()->user->setFlash('user-notify', YCommentsModule::t('Settings saved')); } else { Yii::app()->user->setFlash('user-notify', print_r($nu->getErrors(), true)); } $this->widget('ycomments.widgets.NotifySubscriptionWidget', array('commentableType' => $nu->commentable_type)); }