ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOrgUnitAssignmentList.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once('Services/OrgUnit/classes/class.ilOrgUnitAssignment.php');
5 
15 {
16  private $org_unit_id = 0;
17 
18  private $assignments = array();
19 
20  public function __construct($org_unit_id)
21  {
22  $this->org_unit_id = (int)$org_unit_id;
23 
24  $this->read();
25  }
26 
27  private function read()
28  {
29  global $ilDB;
30 
31  $query = "SELECT * FROM org_unit_assignments WHERE oa_ou_id = %s";
32 
33  $res = $ilDB->queryF($query, array('integer'), array($this->org_unit_id));
34 
35  $this->assignments = array();
36 
37  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
38  {
39  $assignment = new ilOrgUnitAssignment($row->oa_ou_id, $row->oa_usr_id);
40 
41  $assignment->setReportingAccess($row->oa_reporting_access);
42  $assignment->setCcComplianceInvitation($row->oa_cc_compl_invit);
43  $assignment->setCcComplianceNotify1($row->oa_cc_compl_not1);
44  $assignment->setCcComplianceNotify2($row->oa_cc_compl_not2);
45 
46  $this->assignments[$row->oa_usr_id] = $assignment;
47  }
48 
49  #usort($this->assignments, array($this, 'sortCallback'));
50  }
51 
52  public function sortCallback($a_assignment_a, $a_assignment_b)
53  {
54  $user_a = ilObjectFactory::getInstanceByObjId($a_assignment_a->getUserId());
55  $user_b = ilObjectFactory::getInstanceByObjId($a_assignment_b->getUserId());
56 
57  $user_name_a = $user_a->getLastName().', '.$user_a->getFirstName();
58  $user_name_b = $user_b->getLastName().', '.$user_b->getFirstName();
59 
60  return strcmp($user_name_a, $user_name_b);
61  }
62 
63  public function addAssignment($a_user_id, $a_reporting_access,
64  $a_cc_compl_invit, $a_cc_compl_not1, $a_cc_compl_not2)
65  {
66  if( isset($this->assignments[$user_id]) )
67  throw new ilOrgUnitException('Error: User with id "'.$user_id.'" is allready assigned!');
68 
69  $assignment = new ilOrgUnitAssignment($this->org_unit_id, $a_user_id);
70 
71  $assignment ->setReportingAccess($a_reporting_access)
72  ->setCcComplianceInvitation($a_cc_compl_invit)
73  ->setCcComplianceNotify1($a_cc_compl_not1)
74  ->setCcComplianceNotify2($a_cc_compl_not2)
75  ->create();
76 
77  $this->assignments[$user_id] = $assignment;
78  }
79 
80  public function removeAssignment($a_user_id)
81  {
82  if( !isset($this->assignments[$user_id]) )
83  throw new ilOrgUnitException('Error: User with id "'.$user_id.'" is not assigned!');
84 
85  $this->assignments[$user_id]->delete();
86 
87  unset( $this->assignments[$user_id] );
88  }
89 
90  public function doesAssignmentExist($a_user_id)
91  {
92  return isset($this->assignments[$a_user_id]);
93  }
94 
95  public function hasUserReportingAccess($a_user_id)
96  {
97  return $this->assignments[$a_user_id]->hasReportingAccess();
98  }
99 
100  public function current()
101  {
102  return current($this->assignments);
103  }
104 
105  public function next()
106  {
107  return next($this->assignments);
108  }
109 
110  public function key()
111  {
112  return key($this->assignments);
113  }
114 
115  public function valid()
116  {
117  return key($this->assignments) !== null;
118  }
119 
120  public function rewind()
121  {
122  return reset($this->assignments);
123  }
124 }
125 
126 ?>