Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RUserBehavior.php
1 <?php
2 /**
3  * Rights user behavior class file.
4  *
5  * @author Christoffer Niska <cniska@live.com>
6  * @copyright Copyright &copy; 2010 Christoffer Niska
7  * @since 0.9.10
8  */
9 class RUserBehavior extends CModelBehavior {
10 
11  /**
12  * @property the name of the id column.
13  */
14  public $idColumn;
15  /**
16  * @property the name of the name column.
17  */
18  public $nameColumn;
19 
20  private $_assignments;
21 
22  /**
23  * Returns the value of the owner's id column.
24  * Attribute name is retrived from the module configuration.
25  *
26  * @return string the id.
27  */
28  public function getId()
29  {
30  if ($this->idColumn===null) {
31  $this->idColumn = Rights::module()->userIdColumn;
32  }
33 
34  return $this->owner->{$this->idColumn};
35  }
36 
37  /**
38  * Returns the value of the owner's name column.
39  * Attribute name is retrived from the module configuration.
40  *
41  * @return string the name.
42  */
43  public function getName()
44  {
45  if ($this->nameColumn===null) {
46  $this->nameColumn = Rights::module()->userNameColumn;
47  }
48 
49  return $this->owner->{$this->nameColumn};
50  }
51 
52  /**
53  * Returns a link labeled with the username pointing to the users assignments.
54  *
55  * @return string the link markup.
56  */
57  public function getAssignmentNameLink()
58  {
59  return CHtml::link($this->getName(), array('assignment/user', 'id' => $this->getId()));
60  }
61 
62  /**
63  * Returns a string with names of the authorization items
64  * of the given type that are assigned to this user.
65  *
66  * @param integer $type the item type (0: operation, 1: task, 2: role).
67  *
68  * @return mixed the assigned items.
69  */
70  public function getAssignmentsText($type)
71  {
72  $assignedItems = $this->getAssignments();
73 
74  if (isset($assignedItems[$type])===true) {
75  $items = $assignedItems[$type];
76  $names = array();
77  foreach ($items as $itemname => $item) {
78  $names[] = $item->getNameText();
79  }
80 
81  return implode('<br />', $names);
82  }
83  }
84 
85  /**
86  * Returns the authorization items assigned to the user.
87  *
88  * @return string the assignments markup.
89  */
90  public function getAssignments()
91  {
92  if ($this->_assignments!==null) {
93  return $this->_assignments;
94  } else {
95  $authorizer = Rights::getAuthorizer();
96  $authAssignments = $authorizer->authManager->getAuthAssignments($this->getId());
97  $nestedItems = $authorizer->authManager->getAuthItemsByNames(array_keys($authAssignments), true);
98 
99  $assignments = array();
100  foreach ($nestedItems as $type => $items) {
101  $items = $authorizer->attachAuthItemBehavior($items);
102  $assignments[$type] = array();
103  foreach ($items as $itemName => $item) {
104  $assignments[$type][$itemName] = $item;
105  }
106  }
107 
108  return $this->_assignments = $assignments;
109  }
110  }
111 }