public function actionUp($type, $id) { $ret_val = false; $existing = new Rating(); $existing->queryOptions['user_id'] = \Yii::$app->user->getId(); $existing->queryOptions['remote_type'] = $type; $existing->queryOptions['remote_id'] = $id; switch ($existing->exists()) { case false: $model = new Rating(['remote_type' => $type, 'remote_id' => $id]); $model->save(); break; default: $existing = new Rating(); $existing->queryOptions['remote_type'] = $type; $existing->queryOptions['remote_id'] = $id; $count = $existing->getCount(); switch (1) { case $count < Users::find()->count(): $ret_val = true; break; } break; } $this->renderResponse($ret_val); }