public function validateSecondaryAbilities($attribute, $params) { if ($this->hasErrors($attribute)) { return; } $values = $this->{$attribute}; if (!is_array($values)) { $this->addError($attribute, "{$attribute} must be an array of key-string."); return; } if (count($values) < 1 || count($values) > 3) { $this->addError($attribute, "{$attribute} must be contain 1-3 values, " . count($values) . " given."); return; } foreach ($values as $i => $value) { $value = (string) $value; if ($value == '') { continue; } $ability = Ability::findOne(['key' => $value]); if (!$ability) { $this->addError($attribute, "[{$i}] {$value} is invalid key-string."); } } }
public function getAbilities() { $ret = []; foreach (Ability::find()->all() as $o) { $ret[$o->key] = $o->id; } return (object) $ret; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('users')->delete(); $users = array(array('name' => 'maik', 'email' => '*****@*****.**', 'password' => Hash::make('12345678'), 'created_at' => new DateTime(), 'updated_at' => new DateTime())); DB::table('users')->insert($users); DB::table('abilities')->delete(); $abilities = array(array('id' => '1', 'name' => 'admin_master', 'description' => 'The master of the universe', 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('id' => '2', 'name' => 'post_blog', 'description' => 'Post a blog', 'created_at' => new DateTime(), 'updated_at' => new DateTime())); DB::table('abilities')->insert($abilities); $maik = User::where('name', 'maik')->first(); $ab = Ability::where('name', 'admin_master')->first(); //$abs=[$ab]; $maik->abilities()->attach($ab); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ability::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Edit the given task. * * @param Request $request * @param Task $task * @return Response */ public function edit(Request $request, User $user) { $this->authorize('edit_user', $request->user(), $user); if ($request->user()->can('admin', $request->user())) { //Debugbar::info('siiiii'); $abilities = Ability::all(); $selectedAbilities = $user->abilities; } else { //Debugbar::info('nooooo'); $abilities = []; $selectedAbilities = []; } return view('users.edit', ['user' => $user, 'abilities' => $abilities, 'selectedAbilities' => $selectedAbilities]); }
/** * Destroy the given task. * * @param Request $request * @param Task $task * @return Response */ public function destroy(Request $request, Ability $ability) { $this->authorize('admin', Auth::user()); $ability->delete(); return redirect(route('ability')); }
protected function processGear($key) { if ($this->isTest || !$this->gears instanceof PostGearsForm) { return null; } $gearForm = $this->gears->{$key}; if (!$gearForm instanceof BaseGearForm) { return null; } $gearModel = $gearForm->getGearModel(); // may null $primaryAbility = $gearForm->primary_ability ? Ability::findOne(['key' => $gearForm->primary_ability]) : null; $secondaryAbilityIdList = []; if (is_array($gearForm->secondary_abilities)) { foreach ($gearForm->secondary_abilities as $aKey) { if ($aKey == '') { $secondaryAbilityIdList[] = null; } else { if ($a = Ability::findOne(['key' => $aKey])) { $secondaryAbilityIdList[] = $a->id; } } } } $fingerPrint = GearConfiguration::generateFingerPrint($gearModel ? $gearModel->id : null, $primaryAbility ? $primaryAbility->id : null, $secondaryAbilityIdList); $config = GearConfiguration::findOne(['finger_print' => $fingerPrint]); if (!$config) { $config = new GearConfiguration(); $config->finger_print = $fingerPrint; $config->gear_id = $gearModel ? $gearModel->id : null; $config->primary_ability_id = $primaryAbility ? $primaryAbility->id : null; if (!$config->save()) { throw new \Exception('Could not save gear_counfiguration'); } foreach ($secondaryAbilityIdList as $aId) { $sub = new GearConfigurationSecondary(); $sub->config_id = $config->id; $sub->ability_id = $aId; if (!$sub->save()) { throw new \Exception('Could not save gear_configuration_secondary'); } } } return $config->id; }
public function isSuperAdmin() { return $this->abilities()->get()->filter(function ($item) { return $item->id == Ability::superUser(); })->first(); }
public static function superUser() { //\Debugbar::info(Ability::where('name', 'admin_master')->first()->id); return Ability::where('name', Ability::$master)->first()->id; }
/** * @return \yii\db\ActiveQuery */ public function getWeakness() { return $this->hasOne(Ability::className(), ['id' => 'weakness_id']); }
/** * @return \yii\db\ActiveQuery */ public function getPrimaryAbility() { return $this->hasOne(Ability::className(), ['id' => 'primary_ability_id']); }
/** * Finds the Ability model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ability the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ability::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getAbility() { return $this->hasOne(Ability::className(), ['id' => 'ability_id']); }