ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilExcRandomAssignmentManager Class Reference

Manages random mandatory assignments of an exercise. More...

+ Collaboration diagram for ilExcRandomAssignmentManager:

Public Member Functions

 __construct (ilObjExercise $exc, ilExcRandomAssignmentDBRepository $rand_ass_repo, ilObjUser $user=null, ilLanguage $lng=null)
 Constructor. More...
 
 canBeDeactivated ()
 Checks if the random assignment can be activated (if no learner has already submitted stuff) More...
 
 getDeniedDeactivationReasons ()
 Get reasons for denied deactivation. More...
 
 isActivated ()
 Is random assignment activated? More...
 
 getTotalNumberOfAssignments ()
 Get total number of assignments. More...
 
 getNumberOfMandatoryAssignments ()
 Get total number of mandatory assignments. More...
 
 needsStart ()
 Needs current user to start the exercise (by selecting the random assignments)? More...
 
 getMandatoryAssignmentsOfUser ($user_id)
 Get mandatory assignments of user. More...
 
 startExercise ()
 Start exercise. More...
 
 isAssignmentVisible (int $ass_id, int $user_id)
 Is assignment visible for user. More...
 

Data Fields

const DENIED_SUBMISSIONS = "has_submissions"
 
const DENIED_PEER_REVIEWS = "has_peer_reviews"
 
const DENIED_TEAM_ASSIGNMENTS = "has_team_assignments"
 

Protected Member Functions

 getAssignmentSelection ()
 Get random assignment selection. More...
 

Protected Attributes

 $exc
 
 $exc_id
 
 $user
 
 $rand_ass_repo
 
 $lng
 
 $submission_repo
 

Detailed Description

Manages random mandatory assignments of an exercise.

(business logic)

Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilExcRandomAssignmentManager::__construct ( ilObjExercise  $exc,
ilExcRandomAssignmentDBRepository  $rand_ass_repo,
ilObjUser  $user = null,
ilLanguage  $lng = null 
)

Constructor.

Definition at line 51 of file class.ilExcRandomAssignmentManager.php.

References $DIC, $exc, $lng, $rand_ass_repo, $user, ilExAssignment\getInstancesByExercise(), and user().

56  {
57  global $DIC;
58 
59  $this->exc = $exc;
60  $this->exc_id = $this->exc->getId();
61  $this->user = (is_null($user))
62  ? $DIC->user()
63  : $user;
64  $this->rand_ass_repo = $rand_ass_repo;
65  $this->lng = (is_null($lng))
66  ? $DIC->language()
67  : $lng;
68 
69  $this->submission_repo = new ilExcSubmissionRepository($DIC->database());
70  }
user()
Definition: user.php:4
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

Member Function Documentation

◆ canBeDeactivated()

ilExcRandomAssignmentManager::canBeDeactivated ( )

Checks if the random assignment can be activated (if no learner has already submitted stuff)

Returns
bool

Definition at line 126 of file class.ilExcRandomAssignmentManager.php.

127  {
128  return !$this->hasAnySubmission();
129  }

◆ getAssignmentSelection()

ilExcRandomAssignmentManager::getAssignmentSelection ( )
protected

Get random assignment selection.

Definition at line 236 of file class.ilExcRandomAssignmentManager.php.

References $i, ilExAssignment\getInstancesByExercise(), and getNumberOfMandatoryAssignments().

Referenced by startExercise().

237  {
238  $ass_ids = array_map(function ($i) {
239  return $i->getId();
240  }, ilExAssignment::getInstancesByExercise($this->exc_id));
241 
242  $selected = [];
243  for ($i = 0; $i < $this->getNumberOfMandatoryAssignments(); $i++) {
244  $j = rand(0, count($ass_ids) - 1);
245  $selected[] = current(array_splice($ass_ids, $j, 1));
246  }
247 
248  return $selected;
249  }
getNumberOfMandatoryAssignments()
Get total number of mandatory assignments.
static getInstancesByExercise($a_exc_id)
$i
Definition: metadata.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDeniedDeactivationReasons()

ilExcRandomAssignmentManager::getDeniedDeactivationReasons ( )

Get reasons for denied deactivation.

Returns
string[]

Definition at line 136 of file class.ilExcRandomAssignmentManager.php.

References $lng.

137  {
138  $lng = $this->lng;
139  $lng->loadLanguageModule("exc");
140  $reasons = [];
141  if ($this->hasAnySubmission()) {
142  $reasons[self::DENIED_SUBMISSIONS] = $lng->txt("exc_denied_has_submissions");
143  }
144  return $reasons;
145  }

◆ getMandatoryAssignmentsOfUser()

ilExcRandomAssignmentManager::getMandatoryAssignmentsOfUser (   $user_id)

Get mandatory assignments of user.

Parameters
int$user_id
Returns
int[] assignment ids

Definition at line 213 of file class.ilExcRandomAssignmentManager.php.

Referenced by isAssignmentVisible().

214  {
215  return $this->rand_ass_repo->getAssignmentsOfUser($user_id, $this->exc_id);
216  }
+ Here is the caller graph for this function:

◆ getNumberOfMandatoryAssignments()

ilExcRandomAssignmentManager::getNumberOfMandatoryAssignments ( )

Get total number of mandatory assignments.

Returns
int

Definition at line 172 of file class.ilExcRandomAssignmentManager.php.

References ilExAssignment\getInstancesByExercise().

Referenced by getAssignmentSelection().

173  {
174  return $this->exc->getNrMandatoryRandom();
175  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTotalNumberOfAssignments()

ilExcRandomAssignmentManager::getTotalNumberOfAssignments ( )

Get total number of assignments.

Returns
int

Definition at line 162 of file class.ilExcRandomAssignmentManager.php.

References ilExAssignment\getInstancesByExercise().

163  {
164  return count(ilExAssignment::getInstancesByExercise($this->exc_id));
165  }
static getInstancesByExercise($a_exc_id)
+ Here is the call graph for this function:

◆ isActivated()

ilExcRandomAssignmentManager::isActivated ( )

Is random assignment activated?

Returns
bool

Definition at line 152 of file class.ilExcRandomAssignmentManager.php.

References ilObjExercise\PASS_MODE_RANDOM.

Referenced by isAssignmentVisible(), and needsStart().

153  {
154  return ($this->exc->getPassMode() == ilObjExercise::PASS_MODE_RANDOM);
155  }
+ Here is the caller graph for this function:

◆ isAssignmentVisible()

ilExcRandomAssignmentManager::isAssignmentVisible ( int  $ass_id,
int  $user_id 
)

Is assignment visible for user.

Parameters
int$ass_id
int$user_id
Returns
bool

Definition at line 258 of file class.ilExcRandomAssignmentManager.php.

References getMandatoryAssignmentsOfUser(), and isActivated().

259  {
260  if ($this->isActivated() && !in_array($ass_id, $this->getMandatoryAssignmentsOfUser($user_id))) {
261  return false;
262  }
263  return true;
264  }
getMandatoryAssignmentsOfUser($user_id)
Get mandatory assignments of user.
isActivated()
Is random assignment activated?
+ Here is the call graph for this function:

◆ needsStart()

ilExcRandomAssignmentManager::needsStart ( )

Needs current user to start the exercise (by selecting the random assignments)?

Returns
bool

Definition at line 196 of file class.ilExcRandomAssignmentManager.php.

References $exc_id, isActivated(), and user().

Referenced by startExercise().

197  {
198  if ($this->isActivated()) {
199  $ass_of_user = $this->rand_ass_repo->getAssignmentsOfUser($this->user->getId(), $this->exc_id);
200  if (count($ass_of_user) == 0) {
201  return true;
202  }
203  }
204  return false;
205  }
user()
Definition: user.php:4
isActivated()
Is random assignment activated?
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startExercise()

ilExcRandomAssignmentManager::startExercise ( )

Start exercise.

Definition at line 222 of file class.ilExcRandomAssignmentManager.php.

References $exc_id, getAssignmentSelection(), needsStart(), and user().

223  {
224  if ($this->needsStart()) {
225  $this->rand_ass_repo->saveAssignmentsOfUser(
226  $this->user->getId(),
228  $this->getAssignmentSelection()
229  );
230  }
231  }
getAssignmentSelection()
Get random assignment selection.
needsStart()
Needs current user to start the exercise (by selecting the random assignments)?
user()
Definition: user.php:4
+ Here is the call graph for this function:

Field Documentation

◆ $exc

ilExcRandomAssignmentManager::$exc
protected

Definition at line 21 of file class.ilExcRandomAssignmentManager.php.

Referenced by __construct().

◆ $exc_id

ilExcRandomAssignmentManager::$exc_id
protected

Definition at line 26 of file class.ilExcRandomAssignmentManager.php.

Referenced by needsStart(), and startExercise().

◆ $lng

ilExcRandomAssignmentManager::$lng
protected

◆ $rand_ass_repo

ilExcRandomAssignmentManager::$rand_ass_repo
protected

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

Referenced by __construct().

◆ $submission_repo

ilExcRandomAssignmentManager::$submission_repo
protected

Definition at line 46 of file class.ilExcRandomAssignmentManager.php.

◆ $user

ilExcRandomAssignmentManager::$user
protected

Definition at line 31 of file class.ilExcRandomAssignmentManager.php.

Referenced by __construct().

◆ DENIED_PEER_REVIEWS

const ilExcRandomAssignmentManager::DENIED_PEER_REVIEWS = "has_peer_reviews"

Definition at line 15 of file class.ilExcRandomAssignmentManager.php.

◆ DENIED_SUBMISSIONS

const ilExcRandomAssignmentManager::DENIED_SUBMISSIONS = "has_submissions"

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

◆ DENIED_TEAM_ASSIGNMENTS

const ilExcRandomAssignmentManager::DENIED_TEAM_ASSIGNMENTS = "has_team_assignments"

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


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