/** * @param $website * * @since 1.0 * @author Choate <*****@*****.**> * @return bool * @throws ForbiddenHttpException */ public static function checkAccess($website) { if (!\Yii::$app->user->id || !WebsiteHasUser::find()->can($website, \Yii::$app->user->id)) { throw new ForbiddenHttpException(\Yii::t('yii', 'You are not allowed to perform this action.')); } return true; }
public function safeDown() { $this->dropTable('IF EXISTS ' . Websites::tableName()); $this->dropTable('IF EXISTS ' . Tasks::tableName()); $this->dropTable('IF EXISTS ' . Deploy::tableName()); $this->dropTable('IF EXISTS ' . DeployHasTasks::tableName()); $this->dropTable('IF EXISTS ' . WebsiteHasUser::tableName()); return true; }
public function actionUpdate($id) { /* @var Websites $model */ $model = Websites::findOne($id); $form = new WebsiteForm(); if ($form->load($_POST) && $form->validate()) { $model->setAttributes($form->getAttributes(null, ['user_id']), false); $model->on(Websites::EVENT_AFTER_UPDATE, function ($event) use($form) { $model = $event->sender; WebsiteHasUser::deleteAll(['website_id' => $model->id]); if ($form->user_id) { WebsiteHasUser::batchInsertByCondition(['user_id'], explode(',', $form->user_id), ['website_id' => $model->id]); } }); $model->update(false); return $this->redirect('index'); } $form->setAttributes($model->getAttributes()); $form->user_id = implode(',', ArrayHelper::getColumn($model->websiteHasUser, 'user_id')); return $this->render('update', ['model' => $form]); }
public function getWebsiteHasUser() { return $this->hasMany(WebsiteHasUser::className(), ['website_id' => 'id']); }