Assignments.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace common\modules\rbac\widgets;
  3. use common\modules\rbac\components\DbManager;
  4. use common\modules\rbac\models\Assignment;
  5. use Yii;
  6. use yii\base\InvalidConfigException;
  7. use yii\base\Widget;
  8. class Assignments extends Widget
  9. {
  10. /** @var integer ID of the user to whom auth items will be assigned. */
  11. public $userId;
  12. /** @var DbManager */
  13. protected $manager;
  14. /** @inheritdoc */
  15. public function init()
  16. {
  17. parent::init();
  18. $this->manager = Yii::$app->authManager;
  19. if ($this->userId === null) {
  20. throw new InvalidConfigException('You should set ' . __CLASS__ . '::$userId');
  21. }
  22. }
  23. /** @inheritdoc */
  24. public function run()
  25. {
  26. $model = Yii::createObject([
  27. 'class' => Assignment::className(),
  28. 'user_id' => $this->userId,
  29. ]);
  30. if ($model->load(\Yii::$app->request->post())) {
  31. $model->updateAssignments();
  32. }
  33. return $this->render('form', [
  34. 'model' => $model,
  35. ]);
  36. }
  37. }