mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Mostly working on the view.php UI plus some changes
This commit is contained in:
parent
b13142daee
commit
b761e6d9c6
18 changed files with 535 additions and 147 deletions
|
@ -42,10 +42,11 @@ interface workshop_allocator {
|
|||
*
|
||||
* This method is called soon after the allocator is constructed and before any output
|
||||
* is generated. Therefore is may process any data submitted and do other tasks.
|
||||
* It should not generate any output
|
||||
* It should not generate any output. However if it does so, the output is rendered
|
||||
* using the method {@link moodle_mod_workshop_renderer::allocation_init_result()}
|
||||
*
|
||||
* @throws moodle_exception
|
||||
* @return mixed void or optional HTML string
|
||||
* @return void|string
|
||||
*/
|
||||
public function init();
|
||||
|
||||
|
@ -53,13 +54,9 @@ interface workshop_allocator {
|
|||
* Print HTML to be displayed as the user interface
|
||||
*
|
||||
* If a form is part of the UI, the caller should have called $PAGE->set_url(...)
|
||||
* The methods must produce output instead of just returning it so mform->display() can
|
||||
* be used there. This should be changed once we make quickforms deprecated and then,
|
||||
* this method will just return the required HTML code.
|
||||
*
|
||||
* @param stdClass $wsoutput workshop module renderer can be used
|
||||
* @return void
|
||||
* @return string HTML code to be echoed
|
||||
*/
|
||||
public function ui(moodle_mod_workshop_renderer $wsoutput);
|
||||
|
||||
public function ui();
|
||||
}
|
||||
|
|
|
@ -28,22 +28,20 @@ defined('MOODLE_INTERNAL') || die();
|
|||
require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition
|
||||
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php'); // workshop internal API
|
||||
|
||||
/**
|
||||
* These constants are used to pass status messages between init() and ui()
|
||||
*/
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_ADDED', 1);
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_NOSUBMISSION', 2);
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_EXISTS', 3);
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_CONFIRM_DEL', 4);
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_DELETED', 5);
|
||||
define('WORKSHOP_ALLOCATION_MANUAL_MSG_DELETE_ERROR', 6);
|
||||
|
||||
/**
|
||||
* Allows users to allocate submissions for review manually
|
||||
*/
|
||||
class workshop_manual_allocator implements workshop_allocator {
|
||||
|
||||
/** workshop instance */
|
||||
/** constants that are used to pass status messages between init() and ui() */
|
||||
const MSG_ADDED = 1;
|
||||
const MSG_NOSUBMISSION = 2;
|
||||
const MSG_EXISTS = 3;
|
||||
const MSG_CONFIRM_DEL = 4;
|
||||
const MSG_DELETED = 5;
|
||||
const MSG_DELETE_ERROR = 6;
|
||||
|
||||
/** @var workshop instance */
|
||||
protected $workshop;
|
||||
|
||||
/**
|
||||
|
@ -72,18 +70,18 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
$submission = $this->workshop->get_submission_by_author($authorid);
|
||||
if (!$submission) {
|
||||
// nothing submitted by the given user
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_NOSUBMISSION;
|
||||
$m[] = self::MSG_NOSUBMISSION;
|
||||
$m[] = $authorid;
|
||||
|
||||
} else {
|
||||
// ok, we have the submission
|
||||
$res = $this->workshop->add_allocation($submission, $reviewerid);
|
||||
if ($res == WORKSHOP_ALLOCATION_EXISTS) {
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_EXISTS;
|
||||
if ($res == workshop::ALLOCATION_EXISTS) {
|
||||
$m[] = self::MSG_EXISTS;
|
||||
$m[] = $submission->userid;
|
||||
$m[] = $reviewerid;
|
||||
} else {
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_ADDED;
|
||||
$m[] = self::MSG_ADDED;
|
||||
$m[] = $submission->userid;
|
||||
$m[] = $reviewerid;
|
||||
}
|
||||
|
@ -100,7 +98,7 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
$assessment = $this->workshop->get_assessment_by_id($assessmentid);
|
||||
if ($assessment) {
|
||||
if (!$confirmed) {
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_CONFIRM_DEL;
|
||||
$m[] = self::MSG_CONFIRM_DEL;
|
||||
$m[] = $assessment->id;
|
||||
$m[] = $assessment->authorid;
|
||||
$m[] = $assessment->reviewerid;
|
||||
|
@ -111,11 +109,11 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
}
|
||||
} else {
|
||||
if($this->workshop->delete_assessment($assessment->id)) {
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_DELETED;
|
||||
$m[] = self::MSG_DELETED;
|
||||
$m[] = $assessment->authorid;
|
||||
$m[] = $assessment->reviewerid;
|
||||
} else {
|
||||
$m[] = WORKSHOP_ALLOCATION_MANUAL_MSG_DELETE_ERROR;
|
||||
$m[] = self::MSG_DELETE_ERROR;
|
||||
$m[] = $assessment->authorid;
|
||||
$m[] = $assessment->reviewerid;
|
||||
}
|
||||
|
@ -130,9 +128,10 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
/**
|
||||
* Prints user interface - current allocation and a form to edit it
|
||||
*/
|
||||
public function ui(moodle_mod_workshop_renderer $wsoutput) {
|
||||
public function ui() {
|
||||
global $PAGE;
|
||||
global $CFG; // bacause we include other libs here
|
||||
global $OUTPUT;
|
||||
|
||||
$hlauthorid = -1; // highlight this author
|
||||
$hlreviewerid = -1; // highlight this reviewer
|
||||
|
@ -142,24 +141,24 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
if ($m) {
|
||||
$m = explode('-', $m); // unserialize
|
||||
switch ($m[0]) {
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_ADDED:
|
||||
case self::MSG_ADDED:
|
||||
$hlauthorid = $m[1];
|
||||
$hlreviewerid = $m[2];
|
||||
$msg->text = get_string('allocationadded', 'workshopallocation_manual');
|
||||
$msg->sty = 'ok';
|
||||
break;
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_EXISTS:
|
||||
case self::MSG_EXISTS:
|
||||
$hlauthorid = $m[1];
|
||||
$hlreviewerid = $m[2];
|
||||
$msg->text = get_string('allocationexists', 'workshopallocation_manual');
|
||||
$msg->sty = 'info';
|
||||
break;
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_NOSUBMISSION:
|
||||
case self::MSG_NOSUBMISSION:
|
||||
$hlauthorid = $m[1];
|
||||
$msg->text = get_string('nosubmissionfound', 'workshop');
|
||||
$msg->sty = 'error';
|
||||
break;
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_CONFIRM_DEL:
|
||||
case self::MSG_CONFIRM_DEL:
|
||||
$hlauthorid = $m[2];
|
||||
$hlreviewerid = $m[3];
|
||||
if ($m[4] == 0) {
|
||||
|
@ -170,55 +169,58 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
$msg->sty = 'error';
|
||||
}
|
||||
break;
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_DELETED:
|
||||
case self::MSG_DELETED:
|
||||
$hlauthorid = $m[1];
|
||||
$hlreviewerid = $m[2];
|
||||
$msg->text = get_string('assessmentdeleted', 'workshop');
|
||||
$msg->sty = 'ok';
|
||||
break;
|
||||
case WORKSHOP_ALLOCATION_MANUAL_MSG_DELETE_ERROR:
|
||||
case self::MSG_DELETE_ERROR:
|
||||
$hlauthorid = $m[1];
|
||||
$hlreviewerid = $m[2];
|
||||
$msg->text = get_string('assessmentnotdeleted', 'workshop');
|
||||
$msg->sty = 'error';
|
||||
break;
|
||||
}
|
||||
if ($m[0] == WORKSHOP_ALLOCATION_MANUAL_MSG_CONFIRM_DEL) {
|
||||
$handler = $PAGE->url->out_action();
|
||||
$msg->extra = print_single_button($handler, array('mode' => 'del', 'what' => $m[1], 'confirm' => 1),
|
||||
get_string('iamsure', 'workshop'), 'post', '', true);
|
||||
if ($m[0] == self::MSG_CONFIRM_DEL) {
|
||||
$form = new html_form();
|
||||
$form->url = new moodle_url($PAGE->url, array('mode' => 'del', 'what' => $m[1], 'confirm' => 1));
|
||||
$form->button = new html_button();
|
||||
$form->button->text = get_string('iamsure', 'workshop');
|
||||
$form->method = 'post';
|
||||
$msg->extra = $OUTPUT->button($form);
|
||||
}
|
||||
}
|
||||
|
||||
$peer = array(); // singular chosen due to readibility
|
||||
$peers = array();
|
||||
$rs = $this->workshop->get_allocations_recordset();
|
||||
foreach ($rs as $allocation) {
|
||||
$currentuserid = $allocation->authorid;
|
||||
if (!isset($peer[$currentuserid])) {
|
||||
$peer[$currentuserid] = new stdClass();
|
||||
$peer[$currentuserid]->id = $allocation->authorid;
|
||||
$peer[$currentuserid]->firstname = $allocation->authorfirstname;
|
||||
$peer[$currentuserid]->lastname = $allocation->authorlastname;
|
||||
$peer[$currentuserid]->picture = $allocation->authorpicture;
|
||||
$peer[$currentuserid]->imagealt = $allocation->authorimagealt;
|
||||
$peer[$currentuserid]->submissionid = $allocation->submissionid;
|
||||
$peer[$currentuserid]->submissiontitle = $allocation->submissiontitle;
|
||||
$peer[$currentuserid]->submissiongrade = $allocation->submissiongrade;
|
||||
$peer[$currentuserid]->reviewedby = array(); // users who are reviewing this user's submission
|
||||
$peer[$currentuserid]->reviewerof = array(); // users whom submission is being reviewed by this user
|
||||
if (!isset($peers[$currentuserid])) {
|
||||
$peers[$currentuserid] = new stdClass();
|
||||
$peers[$currentuserid]->id = $allocation->authorid;
|
||||
$peers[$currentuserid]->firstname = $allocation->authorfirstname;
|
||||
$peers[$currentuserid]->lastname = $allocation->authorlastname;
|
||||
$peers[$currentuserid]->picture = $allocation->authorpicture;
|
||||
$peers[$currentuserid]->imagealt = $allocation->authorimagealt;
|
||||
$peers[$currentuserid]->submissionid = $allocation->submissionid;
|
||||
$peers[$currentuserid]->submissiontitle = $allocation->submissiontitle;
|
||||
$peers[$currentuserid]->submissiongrade = $allocation->submissiongrade;
|
||||
$peers[$currentuserid]->reviewedby = array(); // users who are reviewing this user's submission
|
||||
$peers[$currentuserid]->reviewerof = array(); // users whom submission is being reviewed by this user
|
||||
}
|
||||
if (!empty($allocation->reviewerid)) {
|
||||
// example: "submission of user with id 45 is reviewed by user with id 87 in the assessment record 12"
|
||||
$peer[$currentuserid]->reviewedby[$allocation->reviewerid] = $allocation->assessmentid;
|
||||
$peers[$currentuserid]->reviewedby[$allocation->reviewerid] = $allocation->assessmentid;
|
||||
}
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
foreach ($peer as $author) {
|
||||
foreach ($peers as $author) {
|
||||
foreach ($author->reviewedby as $reviewerid => $assessmentid) {
|
||||
if (isset($peer[$reviewerid])) {
|
||||
if (isset($peers[$reviewerid])) {
|
||||
// example: "user with id 87 is reviewer of the work submitted by user id 45 in the assessment record 12"
|
||||
$peer[$reviewerid]->reviewerof[$author->id] = $assessmentid;
|
||||
$peers[$reviewerid]->reviewerof[$author->id] = $assessmentid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,8 +229,7 @@ class workshop_manual_allocator implements workshop_allocator {
|
|||
// Here, we do not use neither the core renderer nor the workshop one but use an own one
|
||||
require_once(dirname(__FILE__) . '/renderer.php');
|
||||
$uioutput = $PAGE->theme->get_renderer('workshopallocation_manual', $PAGE);
|
||||
echo $uioutput->display_allocations($this->workshop, $peer, $hlauthorid, $hlreviewerid, $msg);
|
||||
return $uioutput->display_allocations($this->workshop, $peers, $hlauthorid, $hlreviewerid, $msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,22 +31,18 @@ require_once(dirname(dirname(__FILE__)) . '/lib.php'); // inter
|
|||
require_once(dirname(dirname(dirname(__FILE__))) . '/locallib.php'); // workshop internal API
|
||||
require_once(dirname(__FILE__) . '/settings_form.php'); // settings form
|
||||
|
||||
/**
|
||||
* Constants used to pass status messages between init() and ui()
|
||||
*/
|
||||
define('WORKSHOP_ALLOCATION_RANDOM_MSG_SUCCESS', 1);
|
||||
|
||||
/**
|
||||
* Constants used in allocation settings form
|
||||
*/
|
||||
define('WORKSHOP_USERTYPE_AUTHOR', 1);
|
||||
define('WORKSHOP_USERTYPE_REVIEWER', 2);
|
||||
|
||||
/**
|
||||
* Allocates the submissions randomly
|
||||
*/
|
||||
class workshop_random_allocator implements workshop_allocator {
|
||||
|
||||
/** constants used to pass status messages between init() and ui() */
|
||||
const MSG_SUCCESS = 1;
|
||||
|
||||
/** constants used in allocation settings form */
|
||||
const USERTYPE_AUTHOR = 1;
|
||||
const USERTYPE_REVIEWER = 2;
|
||||
|
||||
/** workshop instance */
|
||||
protected $workshop;
|
||||
|
||||
|
@ -157,21 +153,30 @@ class workshop_random_allocator implements workshop_allocator {
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints user interface
|
||||
* Returns the HTML code to print the user interface
|
||||
*/
|
||||
public function ui(moodle_mod_workshop_renderer $wsoutput) {
|
||||
global $OUTPUT;
|
||||
public function ui() {
|
||||
global $OUTPUT, $PAGE;
|
||||
|
||||
$m = optional_param('m', null, PARAM_INT); // status message code
|
||||
$msg = new stdClass();
|
||||
if ($m == WORKSHOP_ALLOCATION_RANDOM_MSG_SUCCESS) {
|
||||
if ($m == self::MSG_SUCCESS) {
|
||||
$msg = (object)array('text' => get_string('randomallocationdone', 'workshopallocation_random'), 'sty' => 'ok');
|
||||
}
|
||||
|
||||
echo $OUTPUT->container_start('random-allocator');
|
||||
echo $wsoutput->status_message($msg);
|
||||
$out = '';
|
||||
$out .= $OUTPUT->container_start('random-allocator');
|
||||
$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
|
||||
$out .= $wsoutput->status_message($msg);
|
||||
// the nasty hack follows to bypass the sad fact that moodle quickforms do not allow to actually
|
||||
// return the HTML content, just to display it
|
||||
ob_start();
|
||||
$this->mform->display();
|
||||
echo $OUTPUT->container_end();
|
||||
$out .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
$out .= $OUTPUT->container_end();
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,7 +237,7 @@ class workshop_random_allocator implements workshop_allocator {
|
|||
}
|
||||
$submission = $submissions[$authorid];
|
||||
$status = $this->workshop->add_allocation($submission, $reviewerid, true);
|
||||
if (WORKSHOP_ALLOCATION_EXISTS == $status) {
|
||||
if (workshop::ALLOCATION_EXISTS == $status) {
|
||||
debugging('newallocations array contains existing allocation, this should not happen');
|
||||
}
|
||||
}
|
||||
|
@ -342,14 +347,14 @@ class workshop_random_allocator implements workshop_allocator {
|
|||
// nothing to be done
|
||||
return array();
|
||||
}
|
||||
if (WORKSHOP_USERTYPE_AUTHOR == $numper) {
|
||||
if (self::USERTYPE_AUTHOR == $numper) {
|
||||
// circles are authors, squares are reviewers
|
||||
$o[] = 'info::Trying to allocate ' . $numofreviews . ' review(s) per author'; // todo translate
|
||||
$allcircles = $authors;
|
||||
$allsquares = $reviewers;
|
||||
// get current workload
|
||||
list($circlelinks, $squarelinks) = $this->convert_assessments_to_links($assessments);
|
||||
} elseif (WORKSHOP_USERTYPE_REVIEWER == $numper) {
|
||||
} elseif (self::USERTYPE_REVIEWER == $numper) {
|
||||
// circles are reviewers, squares are authors
|
||||
$o[] = 'info::trying to allocate ' . $numofreviews . ' review(s) per reviewer'; // todo translate
|
||||
$allcircles = $reviewers;
|
||||
|
@ -458,7 +463,7 @@ class workshop_random_allocator implements workshop_allocator {
|
|||
} // end of processing circles in the group
|
||||
} // end of processing circle groups
|
||||
$returned = array();
|
||||
if (WORKSHOP_USERTYPE_AUTHOR == $numper) {
|
||||
if (self::USERTYPE_AUTHOR == $numper) {
|
||||
// circles are authors, squares are reviewers
|
||||
foreach ($circlelinks as $circleid => $squares) {
|
||||
foreach ($squares as $squareid) {
|
||||
|
@ -466,7 +471,7 @@ class workshop_random_allocator implements workshop_allocator {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (WORKSHOP_USERTYPE_REVIEWER == $numper) {
|
||||
if (self::USERTYPE_REVIEWER == $numper) {
|
||||
// circles are reviewers, squares are authors
|
||||
foreach ($circlelinks as $circleid => $squares) {
|
||||
foreach ($squares as $squareid) {
|
||||
|
|
|
@ -60,14 +60,16 @@ class workshop_random_allocator_form extends moodleform {
|
|||
}
|
||||
$mform->addElement('static', 'groupmode', get_string('groupmode', 'group'), $grouplabel);
|
||||
|
||||
$options_numofreviewes = array(0=>0,1=>1, 2=>2, 3=>3, 4=>4);
|
||||
$options_numper = array(WORKSHOP_USERTYPE_AUTHOR => get_string('numperauthor', 'workshopallocation_random'),
|
||||
WORKSHOP_USERTYPE_REVIEWER => get_string('numperreviewer', 'workshopallocation_random'));
|
||||
$options_numofreviewes = array(0=>0,1=>1, 2=>2, 3=>3, 4=>4); // todo
|
||||
$options_numper = array(
|
||||
workshop_random_allocator::USERTYPE_AUTHOR => get_string('numperauthor', 'workshopallocation_random'),
|
||||
workshop_random_allocator::USERTYPE_REVIEWER => get_string('numperreviewer', 'workshopallocation_random')
|
||||
);
|
||||
$grpnumofreviews = array();
|
||||
$grpnumofreviews[] = $mform->createElement('select', 'numofreviews', '', $options_numofreviewes);
|
||||
$mform->setDefault('numofreviews', 4);
|
||||
$grpnumofreviews[] = $mform->createElement('select', 'numper', '', $options_numper);
|
||||
$mform->setDefault('numper', WORKSHOP_USERTYPE_AUTHOR);
|
||||
$mform->setDefault('numper', workshop_random_allocator::USERTYPE_AUTHOR);
|
||||
$mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshop'), array(' '), false);
|
||||
|
||||
$mform->addElement('advcheckbox', 'removecurrent', get_string('removecurrentallocations', 'workshopallocation_random'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue