Assignment.php 2.4 KB
Newer Older
1 2 3 4 5 6 7
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

8
namespace yii\rbac;
9 10 11 12 13

use Yii;
use yii\base\Object;

/**
14 15 16
 * Assignment represents an assignment of a role to a user.
 * It includes additional assignment information such as [[bizRule]] and [[data]].
 * Do not create a Assignment instance using the 'new' operator.
17
 * Instead, call [[Manager::assign()]].
18 19 20 21 22
 *
 * @property mixed $userId User ID (see [[User::id]]).
 * @property string $itemName The authorization item name.
 * @property string $bizRule The business rule associated with this assignment.
 * @property mixed $data Additional data for this assignment.
23 24 25 26 27
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @author Alexander Kochetov <creocoder@gmail.com>
 * @since 2.0
 */
28
class Assignment extends Object
29 30 31
{
	private $_auth;
	private $_userId;
32
	private $_itemName;
33 34 35 36 37
	private $_bizRule;
	private $_data;

	/**
	 * Constructor.
38
	 * @param Manager $auth the authorization manager
39
	 * @param mixed $userId user ID (see [[User::id]])
40
	 * @param string $itemName authorization item name
41 42 43
	 * @param string $bizRule the business rule associated with this assignment
	 * @param mixed $data additional data for this assignment
	 */
44
	public function __construct($auth, $userId, $itemName, $bizRule = null, $data = null)
45 46 47
	{
		$this->_auth = $auth;
		$this->_userId = $userId;
48
		$this->_itemName = $itemName;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
		$this->_bizRule = $bizRule;
		$this->_data = $data;
	}

	/**
	 * @return mixed user ID (see [[User::id]])
	 */
	public function getUserId()
	{
		return $this->_userId;
	}

	/**
	 * @return string the authorization item name
	 */
	public function getItemName()
	{
		return $this->_itemName;
	}

	/**
	 * @return string the business rule associated with this assignment
	 */
	public function getBizRule()
	{
		return $this->_bizRule;
	}

	/**
	 * @param string $value the business rule associated with this assignment
	 */
	public function setBizRule($value)
	{
		if ($this->_bizRule !== $value) {
			$this->_bizRule = $value;
84
			$this->_auth->saveAssignment($this);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
		}
	}

	/**
	 * @return mixed additional data for this assignment
	 */
	public function getData()
	{
		return $this->_data;
	}

	/**
	 * @param mixed $value additional data for this assignment
	 */
	public function setData($value)
	{
		if ($this->_data !== $value) {
			$this->_data = $value;
103
			$this->_auth->saveAssignment($this);
104 105 106
		}
	}
}