Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
workshop_random_allocator Class Reference

Allocates the submissions randomly. More...

Inheritance diagram for workshop_random_allocator:
workshop_allocator

Public Member Functions

 __construct (workshop $workshop)
 
 execute (workshop_random_allocator_setting $settings, workshop_allocation_result $result)
 Executes the allocation based on the given settings. More...
 
 init ()
 Allocate submissions as requested by user. More...
 
 ui ()
 Returns the HTML code to print the user interface. More...
 

Static Public Member Functions

static available_numofreviews_list ()
 Return an array of possible numbers of reviews to be done. More...
 
static delete_instance ($workshopid)
 Delete all data related to a given workshop module instance. More...
 

Public Attributes

const MSG_SUCCESS = 1
 constants used to pass status messages between init() and ui()
 

Protected Member Functions

 add_new_allocations (array $newallocations, array $dataauthors, array $datareviewers)
 Creates new assessment records. More...
 
 convert_assessments_to_links ($assessments)
 Extracts the information about reviews from the authors' and reviewers' perspectives. More...
 
 filter_current_assessments (&$newallocations, $assessments)
 Filter new allocations so that they do not contain an already existing assessment. More...
 
 get_author_ids ($newallocations)
 Extracts unique list of authors' IDs from the structure of new allocations. More...
 
 get_element_with_lowest_workload ($workload)
 Selects an element with the lowest workload. More...
 
 get_unique_allocations ($newallocations)
 Removes duplicate allocations. More...
 
 get_unkept_assessments ($assessments, $newallocations, $keepselfassessments)
 Returns the list of assessments to remove. More...
 
 index_submissions_by_authors ($submissions)
 Flips the structure of submission so it is indexed by authorid attribute. More...
 
 random_allocation ($authors, $reviewers, $assessments, $result, array $options)
 Allocates submission reviews randomly. More...
 
 self_allocation ($authors=array(), $reviewers=array(), $assessments=array())
 Allocates submissions to their authors for review. More...
 
 shuffle_assoc (&$array)
 Shuffle the order of array elements preserving the key=>values. More...
 

Protected Attributes

 $mform
 mform with settings
 
 $workshop
 workshop instance
 

Detailed Description

Allocates the submissions randomly.

Constructor & Destructor Documentation

◆ __construct()

workshop_random_allocator::__construct ( workshop  $workshop)
Parameters
workshop$workshopWorkshop API object

Member Function Documentation

◆ add_new_allocations()

workshop_random_allocator::add_new_allocations ( array  $newallocations,
array  $dataauthors,
array  $datareviewers 
)
protected

Creates new assessment records.

Parameters
array$newallocationspairs 'reviewerid' => 'authorid'
array$dataauthorsauthors by group, group [0] contains all authors
array$datareviewersreviewers by group, group [0] contains all reviewers
Return values
bool

◆ available_numofreviews_list()

static workshop_random_allocator::available_numofreviews_list ( )
static

Return an array of possible numbers of reviews to be done.

Should contain numbers 1, 2, 3, ... 10 and possibly others up to a reasonable value

Return values
arrayof integers

◆ convert_assessments_to_links()

workshop_random_allocator::convert_assessments_to_links (   $assessments)
protected

Extracts the information about reviews from the authors' and reviewers' perspectives.

Parameters
array$assessmentsarray of assessments as returned by workshop::get_all_assessments()
Return values
arrayof two arrays

◆ delete_instance()

static workshop_random_allocator::delete_instance (   $workshopid)
static

Delete all data related to a given workshop module instance.

This plugin does not store any data.

See also
workshop_delete_instance()
Parameters
int$workshopidid of the workshop module instance being deleted
Return values
void

Implements workshop_allocator.

◆ execute()

workshop_random_allocator::execute ( workshop_random_allocator_setting  $settings,
workshop_allocation_result  $result 
)

Executes the allocation based on the given settings.

Parameters
workshop_random_allocator_setting$setting
workshop_allocation_resultallocation result logger

◆ filter_current_assessments()

workshop_random_allocator::filter_current_assessments ( $newallocations,
  $assessments 
)
protected

Filter new allocations so that they do not contain an already existing assessment.

Parameters
mixed$newallocationsarray of ('reviewerid' => 'authorid') tuples
array$assessmentsarray of assessment records
Return values
void

◆ get_author_ids()

workshop_random_allocator::get_author_ids (   $newallocations)
protected

Extracts unique list of authors' IDs from the structure of new allocations.

Parameters
array$newallocationsof pairs 'reviewerid' => 'authorid'
Return values
arrayof authorids

◆ get_element_with_lowest_workload()

workshop_random_allocator::get_element_with_lowest_workload (   $workload)
protected

Selects an element with the lowest workload.

If there are more elements with the same workload, choose one of them randomly. This may be used to select a group or user.

Parameters
array$workload[groupid] => (int)workload
Return values
mixedint|bool id of the selected element or false if it is impossible to choose

◆ get_unique_allocations()

workshop_random_allocator::get_unique_allocations (   $newallocations)
protected

Removes duplicate allocations.

Parameters
mixed$newallocationsarray of 'reviewerid' => 'authorid' pairs
Return values
array

◆ get_unkept_assessments()

workshop_random_allocator::get_unkept_assessments (   $assessments,
  $newallocations,
  $keepselfassessments 
)
protected

Returns the list of assessments to remove.

If user selects "removecurrentallocations", we should remove all current assessment records and insert new ones. But this would needlessly waste table ids. Instead, let us find only those assessments that have not been re-allocated in this run of allocation. So, the once-allocated submissions are kept with their original id.

Parameters
array$assessmentslist of current assessments
mixed$newallocationsarray of 'reviewerid' => 'authorid' pairs
bool$keepselfassessmentsdo not remove already allocated self assessments
Return values
arrayof assessments ids to be removed

◆ index_submissions_by_authors()

workshop_random_allocator::index_submissions_by_authors (   $submissions)
protected

Flips the structure of submission so it is indexed by authorid attribute.

It is the caller's responsibility to make sure the submissions are not teacher examples so no user is the author of more submissions.

Parameters
string$submissionsarray indexed by submission id
Return values
arrayindexed by author id

◆ init()

workshop_random_allocator::init ( )

Allocate submissions as requested by user.

Return values
workshop_allocation_result

Implements workshop_allocator.

◆ random_allocation()

workshop_random_allocator::random_allocation (   $authors,
  $reviewers,
  $assessments,
  $result,
array  $options 
)
protected

Allocates submission reviews randomly.

The algorithm of this function has been described at http://moodle.org/mod/forum/discuss.php?d=128473 Please see the PDF attached to the post before you study the implementation. The goal of the function is to connect each "circle" (circles are representing either authors or reviewers) with a required number of "squares" (the other type than circles are).

The passed $options array must provide keys: (int)numofreviews - number of reviews to be allocated to each circle (int)numper - what user type the circles represent. (bool)excludesamegroup - whether to prevent peer submissions from the same group in visible group mode

Parameters
array$authorsstructure of grouped authors
array$reviewersstructure of grouped reviewers
array$assessmentscurrently assigned assessments to be kept
workshop_allocation_result$resultallocation result logger
array$optionsallocation options
Return values
arrayarray of (reviewerid => authorid) pairs

◆ self_allocation()

workshop_random_allocator::self_allocation (   $authors = array(),
  $reviewers = array(),
  $assessments = array() 
)
protected

Allocates submissions to their authors for review.

If the submission has already been allocated, it is skipped. If the author is not found among reviewers, the submission is not assigned.

Parameters
array$authorsgrouped of {
See also
workshop::get_potential_authors()}
Parameters
array$reviewersgrouped by {
See also
workshop::get_potential_reviewers()}
Parameters
array$assessmentsas returned by {
See also
workshop::get_all_assessments()}
Return values
arrayof new allocations to be created, array of array(reviewerid => authorid)

◆ shuffle_assoc()

workshop_random_allocator::shuffle_assoc ( $array)
protected

Shuffle the order of array elements preserving the key=>values.

Parameters
array$arrayto be shuffled
Return values
true

◆ ui()

workshop_random_allocator::ui ( )

Returns the HTML code to print the user interface.

Implements workshop_allocator.


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