ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
ilExAssignmentTeam Class Reference

Exercise assignment team. More...

+ Collaboration diagram for ilExAssignmentTeam:

Public Member Functions

 __construct ($a_id=null)
 
 getId ()
 
 getMembers ()
 Get members of assignment team. More...
 
 getMembersOfAllTeams ()
 Get members for all teams of assignment. More...
 
 addTeamMember ($a_user_id, $a_exc_ref_id=null)
 Add new member to team. More...
 
 removeTeamMember ($a_user_id, $a_exc_ref_id=null)
 Remove member from team. More...
 
 writeLog ($a_action, $a_details=null)
 
 getLog ()
 Get all log entries for team. More...
 
 sendNotification ($a_exc_ref_id, $a_user_id, $a_action)
 Send notification about team status. More...
 

Static Public Member Functions

static getInstanceByUserId ($a_assignment_id, $a_user_id, $a_create_on_demand=false)
 
static getInstancesFromMap ($a_assignment_id)
 
static getTeamId ($a_assignment_id, $a_user_id, $a_create_on_demand=false)
 Get team id for member id. More...
 
static getAssignmentTeamMap ($a_ass_id)
 Get team structure for assignment. More...
 
static writeTeamLog ($a_team_id, $a_action, $a_details=null)
 Add entry to team log. More...
 
static getAdoptableTeamAssignments ($a_exercise_id, $a_exclude_ass_id=null, $a_user_id=null)
 
static adoptTeams ($a_source_ass_id, $a_target_ass_id, $a_user_id=null, $a_exc_ref_id=null)
 
static getAdoptableGroups ($a_exc_ref_id)
 
static getGroupMembersMap ($a_exc_ref_id)
 

Data Fields

const TEAM_LOG_CREATE_TEAM = 1
 
const TEAM_LOG_ADD_MEMBER = 2
 
const TEAM_LOG_REMOVE_MEMBER = 3
 
const TEAM_LOG_ADD_FILE = 4
 
const TEAM_LOG_REMOVE_FILE = 5
 

Protected Member Functions

 read ($a_id)
 
 cleanLog ()
 Remove obsolete log entries. More...
 

Protected Attributes

 $id
 
 $assignment_id
 
 $members = array()
 

Detailed Description

Exercise assignment team.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 10 of file class.ilExAssignmentTeam.php.

Constructor & Destructor Documentation

◆ __construct()

ilExAssignmentTeam::__construct (   $a_id = null)

Definition at line 22 of file class.ilExAssignmentTeam.php.

References read().

23  {
24  if($a_id)
25  {
26  $this->read($a_id);
27  }
28  }
+ Here is the call graph for this function:

Member Function Documentation

◆ addTeamMember()

ilExAssignmentTeam::addTeamMember (   $a_user_id,
  $a_exc_ref_id = null 
)

Add new member to team.

Parameters
int$a_user_id
int$a_exc_ref_id

Definition at line 159 of file class.ilExAssignmentTeam.php.

References $ilDB, ilObjUser\_lookupFullname(), getMembersOfAllTeams(), read(), sendNotification(), and writeLog().

160  {
161  global $ilDB;
162 
163  if(!$this->id)
164  {
165  return false;
166  }
167 
168  // must not be in any team already
169  if(!in_array($a_user_id, $this->getMembersOfAllTeams()))
170  {
171  $fields = array("id" => array("integer", $this->id),
172  "ass_id" => array("integer", $this->assignment_id),
173  "user_id" => array("integer", $a_user_id));
174  $ilDB->insert("il_exc_team", $fields);
175 
176  if($a_exc_ref_id)
177  {
178  $this->sendNotification($a_exc_ref_id, $a_user_id, "add");
179  }
180 
181  $this->writeLog(self::TEAM_LOG_ADD_MEMBER,
182  ilObjUser::_lookupFullname($a_user_id));
183 
184  $this->read($this->id);
185 
186  return true;
187  }
188 
189  return false;
190  }
_lookupFullname($a_user_id)
Lookup Full Name.
sendNotification($a_exc_ref_id, $a_user_id, $a_action)
Send notification about team status.
getMembersOfAllTeams()
Get members for all teams of assignment.
global $ilDB
writeLog($a_action, $a_details=null)
+ Here is the call graph for this function:

◆ adoptTeams()

static ilExAssignmentTeam::adoptTeams (   $a_source_ass_id,
  $a_target_ass_id,
  $a_user_id = null,
  $a_exc_ref_id = null 
)
static

Definition at line 423 of file class.ilExAssignmentTeam.php.

References getId().

Referenced by ilExAssignmentEditorGUI\adoptTeamAssignmentsObject(), and ilExSubmissionTeamGUI\createAdoptedTeamObject().

424  {
425  $teams = array();
426 
427  $old_team = null;
428  foreach(self::getAssignmentTeamMap($a_source_ass_id) as $user_id => $team_id)
429  {
430  $teams[$team_id][] = $user_id;
431 
432  if($a_user_id && $user_id == $a_user_id)
433  {
434  $old_team = $team_id;
435  }
436  }
437 
438  if($a_user_id)
439  {
440  // no existing team (in source) or user already in team (in current)
441  if(!$old_team ||
442  self::getInstanceByUserId($a_target_ass_id, $a_user_id)->getId())
443  {
444  return;
445  }
446  }
447 
448  $current_map = self::getAssignmentTeamMap($a_target_ass_id);
449 
450  foreach($teams as $team_id => $user_ids)
451  {
452  if(!$old_team || $team_id == $old_team)
453  {
454  // only not assigned users
455  $missing = array();
456  foreach($user_ids as $user_id)
457  {
458  if(!array_key_exists($user_id, $current_map))
459  {
460  $missing[] = $user_id;
461  }
462  }
463 
464  if(sizeof($missing))
465  {
466  // create new team
467  $first = array_shift($missing);
468  $new_team = self::getInstanceByUserId($a_target_ass_id, $first, true);
469 
470  if($a_exc_ref_id)
471  {
472  // getTeamId() does NOT send notification
473  $new_team->sendNotification($a_exc_ref_id, $first, "add");
474  }
475 
476  foreach($missing as $user_id)
477  {
478  $new_team->addTeamMember($user_id, $a_exc_ref_id);
479  }
480  }
481  }
482  }
483  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanLog()

ilExAssignmentTeam::cleanLog ( )
protected

Remove obsolete log entries.

As there is no proper team deletion event, we are doing it this way

Definition at line 304 of file class.ilExAssignmentTeam.php.

References $ilDB, and $row.

Referenced by getLog().

305  {
306  global $ilDB;
307 
308  // #18179
309 
310  $teams = array();
311  $set = $ilDB->query("SELECT DISTINCT(id)".
312  " FROM il_exc_team");
313  while($row = $ilDB->fetchAssoc($set))
314  {
315  $teams[] = $row["id"];
316  }
317 
318  $set = $ilDB->query("SELECT DISTINCT(team_id)".
319  " FROM il_exc_team_log");
320  while($row = $ilDB->fetchAssoc($set))
321  {
322  $team_id = $row["team_id"];
323  if(!in_array($team_id, $teams))
324  {
325  $ilDB->manipulate("DELETE FROM il_exc_team_log".
326  " WHERE team_id = ".$ilDB->quote($team_id, "integer"));
327  }
328  }
329  }
global $ilDB
+ Here is the caller graph for this function:

◆ getAdoptableGroups()

static ilExAssignmentTeam::getAdoptableGroups (   $a_exc_ref_id)
static

Definition at line 489 of file class.ilExAssignmentTeam.php.

References $res.

Referenced by ilExerciseManagementGUI\membersObject().

490  {
491  global $tree;
492 
493  $res = array();
494 
495  $parent_ref_id = $tree->getParentId($a_exc_ref_id);
496  if($parent_ref_id)
497  {
498  foreach($tree->getChildsByType($parent_ref_id, "grp") as $group)
499  {
500  $res[] = $group["obj_id"];
501  }
502  }
503 
504  return $res;
505  }
+ Here is the caller graph for this function:

◆ getAdoptableTeamAssignments()

static ilExAssignmentTeam::getAdoptableTeamAssignments (   $a_exercise_id,
  $a_exclude_ass_id = null,
  $a_user_id = null 
)
static

Definition at line 365 of file class.ilExAssignmentTeam.php.

References $data, $res, $row, ilExAssignment\getAssignmentDataOfExercise(), ilUtil\sortArray(), and ilExAssignment\TYPE_UPLOAD_TEAM.

Referenced by ilExAssignmentEditorGUI\adoptTeamAssignmentsFormObject(), ilExSubmissionTeamGUI\createTeamObject(), and ilExAssignmentEditorGUI\saveAssignmentObject().

366  {
367  $res = array();
368 
370  foreach($data as $row)
371  {
372  if($a_exclude_ass_id && $row["id"] == $a_exclude_ass_id)
373  {
374  continue;
375  }
376 
377  if($row["type"] == ilExAssignment::TYPE_UPLOAD_TEAM)
378  {
379  $map = self::getAssignmentTeamMap($row["id"]);
380 
381  if($a_user_id && !array_key_exists($a_user_id, $map))
382  {
383  continue;
384  }
385 
386  if(sizeof($map))
387  {
388  $user_team = null;
389  if($a_user_id)
390  {
391  $user_team_id = $map[$a_user_id];
392  $user_team = array();
393  foreach($map as $user_id => $team_id)
394  {
395  if($user_id != $a_user_id &&
396  $user_team_id == $team_id)
397  {
398  $user_team[] = $user_id;
399  }
400  }
401  }
402 
403  if(!$a_user_id ||
404  sizeof($user_team))
405  {
406  $res[$row["id"]] = array(
407  "title" => $row["title"],
408  "teams" => sizeof(array_flip($map)),
409  );
410 
411  if($a_user_id)
412  {
413  $res[$row["id"]]["user_team"] = $user_team;
414  }
415  }
416  }
417  }
418  }
419 
420  return ilUtil::sortArray($res, "title", "asc", false, true);
421  }
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
$data
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAssignmentTeamMap()

static ilExAssignmentTeam::getAssignmentTeamMap (   $a_ass_id)
static

Get team structure for assignment.

Parameters
int$a_ass_id
Returns
array

Definition at line 230 of file class.ilExAssignmentTeam.php.

References $ilDB, and $row.

Referenced by ilExerciseMemberTableGUI\__construct(), ilExSubmissionTeamGUI\createTeamObject(), ilExerciseManagementGUI\createTeamsFromGroupsObject(), and ilExSubmission\downloadAllAssignmentFiles().

231  {
232  global $ilDB;
233 
234  $map = array();
235 
236  $sql = "SELECT * FROM il_exc_team".
237  " WHERE ass_id = ".$ilDB->quote($a_ass_id, "integer");
238  $set = $ilDB->query($sql);
239  while($row = $ilDB->fetchAssoc($set))
240  {
241  $map[$row["user_id"]] = $row["id"];
242  }
243 
244  return $map;
245  }
global $ilDB
+ Here is the caller graph for this function:

◆ getGroupMembersMap()

static ilExAssignmentTeam::getGroupMembersMap (   $a_exc_ref_id)
static

Definition at line 507 of file class.ilExAssignmentTeam.php.

References $res, ilObject\_lookupTitle(), and ilUtil\sortArray().

Referenced by ilExerciseManagementGUI\createTeamsFromGroupsObject(), and ilExerciseManagementGUI\initGroupForm().

508  {
509  $res = array();
510 
511  include_once "Modules/Group/classes/class.ilGroupParticipants.php";
512  foreach(self::getAdoptableGroups($a_exc_ref_id) as $grp_obj_id)
513  {
514  $members_obj = new ilGroupParticipants($grp_obj_id);
515 
516  $res[$grp_obj_id] = array(
517  "title" => ilObject::_lookupTitle($grp_obj_id)
518  ,"members" => $members_obj->getMembers()
519  );
520  }
521 
522  return ilUtil::sortArray($res, "title", "asc", false, true);
523  }
static _lookupTitle($a_id)
lookup object title
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getId()

ilExAssignmentTeam::getId ( )

Definition at line 56 of file class.ilExAssignmentTeam.php.

References $id.

Referenced by adoptTeams().

57  {
58  return $this->id;
59  }
+ Here is the caller graph for this function:

◆ getInstanceByUserId()

static ilExAssignmentTeam::getInstanceByUserId (   $a_assignment_id,
  $a_user_id,
  $a_create_on_demand = false 
)
static

Definition at line 30 of file class.ilExAssignmentTeam.php.

References $id.

Referenced by ilExSubmission\__construct(), ilExerciseManagementGUI\createTeamsFromGroupsObject(), ilExerciseManagementGUI\createTeamsObject(), and ilExerciseManagementGUI\dissolveTeamsObject().

31  {
32  $id = self::getTeamId($a_assignment_id, $a_user_id, $a_create_on_demand);
33  return new self($id);
34  }
+ Here is the caller graph for this function:

◆ getInstancesFromMap()

static ilExAssignmentTeam::getInstancesFromMap (   $a_assignment_id)
static

Definition at line 36 of file class.ilExAssignmentTeam.php.

References $members, and $res.

Referenced by ilExerciseMemberTableGUI\__construct().

37  {
38  $teams = array();
39  foreach(self::getAssignmentTeamMap($a_assignment_id) as $user_id => $team_id)
40  {
41  $teams[$team_id][] = $user_id;
42  }
43 
44  $res = array();
45  foreach($teams as $team_id => $members)
46  {
47  $team = new self();
48  $team->id = $team_id;
49  $team->members = $members;
50  $res[$team_id] = $team;
51  }
52 
53  return $res;
54  }
+ Here is the caller graph for this function:

◆ getLog()

ilExAssignmentTeam::getLog ( )

Get all log entries for team.

Parameters
int$a_team_id
Returns
array

Definition at line 280 of file class.ilExAssignmentTeam.php.

References $ilDB, $res, $row, and cleanLog().

281  {
282  global $ilDB;
283 
284  $this->cleanLog();
285 
286  $res = array();
287 
288  $sql = "SELECT * FROM il_exc_team_log".
289  " WHERE team_id = ".$ilDB->quote($this->id, "integer").
290  " ORDER BY tstamp DESC";
291  $set = $ilDB->query($sql);
292  while($row = $ilDB->fetchAssoc($set))
293  {
294  $res[] = $row;
295  }
296  return $res;
297  }
cleanLog()
Remove obsolete log entries.
global $ilDB
+ Here is the call graph for this function:

◆ getMembers()

ilExAssignmentTeam::getMembers ( )

Get members of assignment team.

Returns
array

Definition at line 125 of file class.ilExAssignmentTeam.php.

References $members.

126  {
127  return $this->members;
128  }

◆ getMembersOfAllTeams()

ilExAssignmentTeam::getMembersOfAllTeams ( )

Get members for all teams of assignment.

Returns
array

Definition at line 135 of file class.ilExAssignmentTeam.php.

References $ilDB, and $row.

Referenced by addTeamMember().

136  {
137  global $ilDB;
138 
139  $ids = array();
140 
141  $sql = "SELECT user_id".
142  " FROM il_exc_team".
143  " WHERE ass_id = ".$ilDB->quote($this->assignment_id, "integer");
144  $set = $ilDB->query($sql);
145  while($row = $ilDB->fetchAssoc($set))
146  {
147  $ids[] = $row["user_id"];
148  }
149 
150  return $ids;
151  }
global $ilDB
+ Here is the caller graph for this function:

◆ getTeamId()

static ilExAssignmentTeam::getTeamId (   $a_assignment_id,
  $a_user_id,
  $a_create_on_demand = false 
)
static

Get team id for member id.

team will be created if no team yet

Parameters
int$a_user_id
bool$a_create_on_demand
Returns
int

Definition at line 92 of file class.ilExAssignmentTeam.php.

References $id, $ilDB, $row, and ilObjUser\_lookupFullname().

Referenced by ilExSubmissionTeamGUI\createAdoptedTeamObject(), ilExSubmissionTeamGUI\createSingleMemberTeamObject(), and ilExSubmissionTeamGUI\createTeamObject().

93  {
94  global $ilDB;
95 
96  $sql = "SELECT id FROM il_exc_team".
97  " WHERE ass_id = ".$ilDB->quote($a_assignment_id, "integer").
98  " AND user_id = ".$ilDB->quote($a_user_id, "integer");
99  $set = $ilDB->query($sql);
100  $row = $ilDB->fetchAssoc($set);
101  $id = $row["id"];
102 
103  if(!$id && $a_create_on_demand)
104  {
105  $id = $ilDB->nextId("il_exc_team");
106 
107  $fields = array("id" => array("integer", $id),
108  "ass_id" => array("integer", $a_assignment_id),
109  "user_id" => array("integer", $a_user_id));
110  $ilDB->insert("il_exc_team", $fields);
111 
112  self::writeTeamLog($id, self::TEAM_LOG_CREATE_TEAM);
113  self::writeTeamLog($id, self::TEAM_LOG_ADD_MEMBER,
114  ilObjUser::_lookupFullname($a_user_id));
115  }
116 
117  return $id;
118  }
_lookupFullname($a_user_id)
Lookup Full Name.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilExAssignmentTeam::read (   $a_id)
protected

Definition at line 61 of file class.ilExAssignmentTeam.php.

References $ilDB, and $row.

Referenced by __construct(), addTeamMember(), and removeTeamMember().

62  {
63  global $ilDB;
64 
65  // #18094
66  $this->members = array();
67 
68  $sql = "SELECT * FROM il_exc_team".
69  " WHERE id = ".$ilDB->quote($a_id, "integer");
70  $set = $ilDB->query($sql);
71  if($ilDB->numRows($set))
72  {
73  $this->id = $a_id;
74 
75  while($row = $ilDB->fetchAssoc($set))
76  {
77  $this->assignment_id = $row["ass_id"];
78  $this->members[] = $row["user_id"];
79  }
80  }
81  }
global $ilDB
+ Here is the caller graph for this function:

◆ removeTeamMember()

ilExAssignmentTeam::removeTeamMember (   $a_user_id,
  $a_exc_ref_id = null 
)

Remove member from team.

Parameters
int$a_user_id
int$a_exc_ref_id

Definition at line 198 of file class.ilExAssignmentTeam.php.

References $ilDB, ilObjUser\_lookupFullname(), read(), sendNotification(), and writeLog().

199  {
200  global $ilDB;
201 
202  if(!$this->id)
203  {
204  return;
205  }
206 
207  $sql = "DELETE FROM il_exc_team".
208  " WHERE ass_id = ".$ilDB->quote($this->assignment_id, "integer").
209  " AND id = ".$ilDB->quote($this->id, "integer").
210  " AND user_id = ".$ilDB->quote($a_user_id, "integer");
211  $ilDB->manipulate($sql);
212 
213  if($a_exc_ref_id)
214  {
215  $this->sendNotification($a_exc_ref_id, $a_user_id, "rmv");
216  }
217 
218  $this->writeLog(self::TEAM_LOG_REMOVE_MEMBER,
219  ilObjUser::_lookupFullname($a_user_id));
220 
221  $this->read($this->id);
222  }
_lookupFullname($a_user_id)
Lookup Full Name.
sendNotification($a_exc_ref_id, $a_user_id, $a_action)
Send notification about team status.
global $ilDB
writeLog($a_action, $a_details=null)
+ Here is the call graph for this function:

◆ sendNotification()

ilExAssignmentTeam::sendNotification (   $a_exc_ref_id,
  $a_user_id,
  $a_action 
)

Send notification about team status.

Parameters
int$a_exc_ref_id
int$a_user_id
string$a_action

Definition at line 338 of file class.ilExAssignmentTeam.php.

References $ilUser.

Referenced by addTeamMember(), and removeTeamMember().

339  {
340  global $ilUser;
341 
342  // no need to notify current user
343  if(!$a_exc_ref_id ||
344  $ilUser->getId() == $a_user_id)
345  {
346  return;
347  }
348 
349  $ass = new ilExAssignment($this->assignment_id);
350 
351  include_once "./Services/Notification/classes/class.ilSystemNotification.php";
352  $ntf = new ilSystemNotification();
353  $ntf->setLangModules(array("exc"));
354  $ntf->setRefId($a_exc_ref_id);
355  $ntf->setChangedByUserId($ilUser->getId());
356  $ntf->setSubjectLangId('exc_team_notification_subject_'.$a_action);
357  $ntf->setIntroductionLangId('exc_team_notification_body_'.$a_action);
358  $ntf->addAdditionalInfo("exc_assignment", $ass->getTitle());
359  $ntf->setGotoLangId('exc_team_notification_link');
360  $ntf->setReasonLangId('exc_team_notification_reason');
361  $ntf->sendMail(array($a_user_id));
362  }
Exercise assignment.
global $ilUser
Definition: imgupload.php:15
Wrapper classes for system notifications.
+ Here is the caller graph for this function:

◆ writeLog()

ilExAssignmentTeam::writeLog (   $a_action,
  $a_details = null 
)

Definition at line 247 of file class.ilExAssignmentTeam.php.

Referenced by addTeamMember(), and removeTeamMember().

248  {
249  self::writeTeamLog($this->id, $a_action, $a_details);
250  }
+ Here is the caller graph for this function:

◆ writeTeamLog()

static ilExAssignmentTeam::writeTeamLog (   $a_team_id,
  $a_action,
  $a_details = null 
)
static

Add entry to team log.

Parameters
int$a_team_id
int$a_action
string$a_details

Definition at line 259 of file class.ilExAssignmentTeam.php.

References $ilDB, and $ilUser.

260  {
261  global $ilDB, $ilUser;
262 
263  $fields = array(
264  "team_id" => array("integer", $a_team_id),
265  "user_id" => array("integer", $ilUser->getId()),
266  "action" => array("integer", $a_action),
267  "details" => array("text", $a_details),
268  "tstamp" => array("integer", time())
269  );
270 
271  $ilDB->insert("il_exc_team_log", $fields);
272  }
global $ilUser
Definition: imgupload.php:15
global $ilDB

Field Documentation

◆ $assignment_id

ilExAssignmentTeam::$assignment_id
protected

Definition at line 13 of file class.ilExAssignmentTeam.php.

◆ $id

ilExAssignmentTeam::$id
protected

Definition at line 12 of file class.ilExAssignmentTeam.php.

Referenced by getId(), getInstanceByUserId(), and getTeamId().

◆ $members

ilExAssignmentTeam::$members = array()
protected

Definition at line 14 of file class.ilExAssignmentTeam.php.

Referenced by getInstancesFromMap(), and getMembers().

◆ TEAM_LOG_ADD_FILE

const ilExAssignmentTeam::TEAM_LOG_ADD_FILE = 4

◆ TEAM_LOG_ADD_MEMBER

const ilExAssignmentTeam::TEAM_LOG_ADD_MEMBER = 2

Definition at line 17 of file class.ilExAssignmentTeam.php.

Referenced by ilExAssignmentTeamLogTableGUI\getItems().

◆ TEAM_LOG_CREATE_TEAM

const ilExAssignmentTeam::TEAM_LOG_CREATE_TEAM = 1

Definition at line 16 of file class.ilExAssignmentTeam.php.

Referenced by ilExAssignmentTeamLogTableGUI\getItems().

◆ TEAM_LOG_REMOVE_FILE

const ilExAssignmentTeam::TEAM_LOG_REMOVE_FILE = 5

◆ TEAM_LOG_REMOVE_MEMBER

const ilExAssignmentTeam::TEAM_LOG_REMOVE_MEMBER = 3

Definition at line 18 of file class.ilExAssignmentTeam.php.

Referenced by ilExAssignmentTeamLogTableGUI\getItems().


The documentation for this class was generated from the following file: