public function actionAdduser() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $user_id = \yii::$app->request->post('id'); $collection_id = \yii::$app->request->post('col'); $member_type_id = \yii::$app->request->post('mem'); $userCollectionModel = UserCollection::findOne(['user_id' => $user_id, 'collection_id' => $collection_id, 'member_type_id' => $member_type_id]); if ($userCollectionModel === null) { $userCollectionModel = new UserCollection(); $userCollectionModel->user_id = $user_id; $userCollectionModel->collection_id = $collection_id; $userCollectionModel->member_type_id = $member_type_id; } $userCollectionModel->status_id = Types::$status['active']['id']; if ($userCollectionModel->save() === false) { return $userCollectionModel->getErrors(); } }
public function actionAdduser() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $user_id = \yii::$app->request->post('id'); $collection_id = \yii::$app->request->post('col'); $member_type_id = \yii::$app->request->post('mem'); if (yii::$app->CollectionComponent->isManager($collection_id) === false) { throw new \yii\web\HttpException(403, yii::t('app', 'No permission to access collection.')); } $userCollectionModel = UserCollection::findOne(['user_id' => $user_id, 'collection_id' => $collection_id, 'member_type_id' => $member_type_id]); if ($userCollectionModel === null) { $userCollectionModel = new UserCollection(); $userCollectionModel->user_id = $user_id; $userCollectionModel->collection_id = $collection_id; $userCollectionModel->member_type_id = $member_type_id; } $userCollectionModel->status_id = Types::$status['active']['id']; if ($userCollectionModel->save() === false) { return $userCollectionModel->getErrors(); } }