1: <?php
2: /**
3: * CAuthAssignment class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CAuthAssignment represents an assignment of a role to a user.
13: * It includes additional assignment information such as {@link bizRule} and {@link data}.
14: * Do not create a CAuthAssignment instance using the 'new' operator.
15: * Instead, call {@link IAuthManager::assign}.
16: *
17: * @property mixed $userId User ID (see {@link IWebUser::getId}).
18: * @property string $itemName The authorization item name.
19: * @property string $bizRule The business rule associated with this assignment.
20: * @property mixed $data Additional data for this assignment.
21: *
22: * @author Qiang Xue <qiang.xue@gmail.com>
23: * @package system.web.auth
24: * @since 1.0
25: */
26: class CAuthAssignment extends CComponent
27: {
28: private $_auth;
29: private $_itemName;
30: private $_userId;
31: private $_bizRule;
32: private $_data;
33:
34: /**
35: * Constructor.
36: * @param IAuthManager $auth the authorization manager
37: * @param string $itemName authorization item name
38: * @param mixed $userId user ID (see {@link IWebUser::getId})
39: * @param string $bizRule the business rule associated with this assignment
40: * @param mixed $data additional data for this assignment
41: */
42: public function __construct($auth,$itemName,$userId,$bizRule=null,$data=null)
43: {
44: $this->_auth=$auth;
45: $this->_itemName=$itemName;
46: $this->_userId=$userId;
47: $this->_bizRule=$bizRule;
48: $this->_data=$data;
49: }
50:
51: /**
52: * @return mixed user ID (see {@link IWebUser::getId})
53: */
54: public function getUserId()
55: {
56: return $this->_userId;
57: }
58:
59: /**
60: * @return string the authorization item name
61: */
62: public function getItemName()
63: {
64: return $this->_itemName;
65: }
66:
67: /**
68: * @return string the business rule associated with this assignment
69: */
70: public function getBizRule()
71: {
72: return $this->_bizRule;
73: }
74:
75: /**
76: * @param string $value the business rule associated with this assignment
77: */
78: public function setBizRule($value)
79: {
80: if($this->_bizRule!==$value)
81: {
82: $this->_bizRule=$value;
83: $this->_auth->saveAuthAssignment($this);
84: }
85: }
86:
87: /**
88: * @return mixed additional data for this assignment
89: */
90: public function getData()
91: {
92: return $this->_data;
93: }
94:
95: /**
96: * @param mixed $value additional data for this assignment
97: */
98: public function setData($value)
99: {
100: if($this->_data!==$value)
101: {
102: $this->_data=$value;
103: $this->_auth->saveAuthAssignment($this);
104: }
105: }
106: }