Skip to content

Commit

Permalink
MDL-41158 mod_workshop: Workshop submission alternate name field fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed Nov 12, 2013
1 parent 29fa62c commit 3263a35
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 68 deletions.
8 changes: 4 additions & 4 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,10 @@ function ismoving($courseid) {
function fullname($user, $override=false) {
global $CFG, $SESSION;

if (!isset($user->firstname) and !isset($user->lastname)) {
return '';
}

// Get all of the name fields.
$allnames = get_all_user_name_fields();
if ($CFG->debugdeveloper) {
Expand All @@ -3580,10 +3584,6 @@ function fullname($user, $override=false) {
}
}

if (!isset($user->firstname) and !isset($user->lastname)) {
return '';
}

if (!$override) {
if (!empty($CFG->forcefirstname)) {
$user->firstname = $CFG->forcefirstname;
Expand Down
45 changes: 18 additions & 27 deletions mod/workshop/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,12 @@ function workshop_user_complete($course, $user, $mod, $workshop) {
function workshop_print_recent_activity($course, $viewfullnames, $timestart) {
global $CFG, $USER, $DB, $OUTPUT;

$authoramefields = get_all_user_name_fields(true, 'author', null, 'author');
$reviewerfields = get_all_user_name_fields(true, 'reviewer', null, 'reviewer');

$sql = "SELECT s.id AS submissionid, s.title AS submissiontitle, s.timemodified AS submissionmodified,
author.id AS authorid, author.lastname AS authorlastname, author.firstname AS authorfirstname,
a.id AS assessmentid, a.timemodified AS assessmentmodified,
reviewer.id AS reviewerid, reviewer.lastname AS reviewerlastname, reviewer.firstname AS reviewerfirstname,
cm.id AS cmid
author.id AS authorid, $authoramefields, a.id AS assessmentid, a.timemodified AS assessmentmodified,
reviewer.id AS reviewerid, $reviewerfields, cm.id AS cmid
FROM {workshop} w
INNER JOIN {course_modules} cm ON cm.instance = w.id
INNER JOIN {modules} md ON md.id = cm.module
Expand Down Expand Up @@ -404,15 +405,11 @@ function workshop_print_recent_activity($course, $viewfullnames, $timestart) {
// remember all user names we can use later
if (empty($users[$activity->authorid])) {
$u = new stdclass();
$u->lastname = $activity->authorlastname;
$u->firstname = $activity->authorfirstname;
$users[$activity->authorid] = $u;
$users[$activity->authorid] = username_load_fields_from_object($u, $activity, 'author');
}
if ($activity->reviewerid and empty($users[$activity->reviewerid])) {
$u = new stdclass();
$u->lastname = $activity->reviewerlastname;
$u->firstname = $activity->reviewerfirstname;
$users[$activity->reviewerid] = $u;
$users[$activity->reviewerid] = username_load_fields_from_object($u, $activity, 'reviewer');
}
}

Expand Down Expand Up @@ -620,12 +617,14 @@ function workshop_get_recent_mod_activity(&$activities, &$index, $timestart, $co
$params['submissionmodified'] = $timestart;
$params['assessmentmodified'] = $timestart;

$authornamefields = get_all_user_name_fields(true, 'author', null, 'author');
$reviewerfields = get_all_user_name_fields(true, 'reviewer', null, 'reviewer');

$sql = "SELECT s.id AS submissionid, s.title AS submissiontitle, s.timemodified AS submissionmodified,
author.id AS authorid, author.lastname AS authorlastname, author.firstname AS authorfirstname,
author.picture AS authorpicture, author.imagealt AS authorimagealt, author.email AS authoremail,
a.id AS assessmentid, a.timemodified AS assessmentmodified,
reviewer.id AS reviewerid, reviewer.lastname AS reviewerlastname, reviewer.firstname AS reviewerfirstname,
reviewer.picture AS reviewerpicture, reviewer.imagealt AS reviewerimagealt, reviewer.email AS revieweremail
author.id AS authorid, $authornamefields, author.picture AS authorpicture, author.imagealt AS authorimagealt,
author.email AS authoremail, a.id AS assessmentid, a.timemodified AS assessmentmodified,
reviewer.id AS reviewerid, $reviewerfields, reviewer.picture AS reviewerpicture,
reviewer.imagealt AS reviewerimagealt, reviewer.email AS revieweremail
FROM {workshop_submissions} s
INNER JOIN {workshop} w ON s.workshopid = w.id
INNER JOIN {user} author ON s.authorid = author.id
Expand Down Expand Up @@ -662,22 +661,14 @@ function workshop_get_recent_mod_activity(&$activities, &$index, $timestart, $co
// remember all user names we can use later
if (empty($users[$activity->authorid])) {
$u = new stdclass();
$u->id = $activity->authorid;
$u->lastname = $activity->authorlastname;
$u->firstname = $activity->authorfirstname;
$u->picture = $activity->authorpicture;
$u->imagealt = $activity->authorimagealt;
$u->email = $activity->authoremail;
$additionalfields = explode(',', user_picture::fields());
$u = username_load_fields_from_object($u, $activity, 'author', $additionalfields);
$users[$activity->authorid] = $u;
}
if ($activity->reviewerid and empty($users[$activity->reviewerid])) {
$u = new stdclass();
$u->id = $activity->reviewerid;
$u->lastname = $activity->reviewerlastname;
$u->firstname = $activity->reviewerfirstname;
$u->picture = $activity->reviewerpicture;
$u->imagealt = $activity->reviewerimagealt;
$u->email = $activity->revieweremail;
$additionalfields = explode(',', user_picture::fields());
$u = username_load_fields_from_object($u, $activity, 'reviewer', $additionalfields);
$users[$activity->reviewerid] = $u;
}
}
Expand Down
22 changes: 16 additions & 6 deletions mod/workshop/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3075,9 +3075,10 @@ public function __construct(workshop $workshop, stdClass $submission, $showautho
* Usually this is called by the contructor but can be called explicitely, too.
*/
public function anonymize() {
foreach (array('authorid', 'authorfirstname', 'authorlastname',
'authorpicture', 'authorimagealt', 'authoremail') as $field) {
unset($this->{$field});
$authorfields = explode(',', user_picture::fields());
foreach ($authorfields as $field) {
$prefixedusernamefield = 'author' . $field;
unset($this->{$prefixedusernamefield});
}
$this->anonymous = true;
}
Expand Down Expand Up @@ -3115,6 +3116,14 @@ class workshop_submission_summary extends workshop_submission_base implements re
public $authorfirstname;
/** @var string */
public $authorlastname;
/** @var string */
public $authorfirstnamephonetic;
/** @var string */
public $authorlastnamephonetic;
/** @var string */
public $authormiddlename;
/** @var string */
public $authoralternatename;
/** @var int */
public $authorpicture;
/** @var string */
Expand All @@ -3130,7 +3139,8 @@ class workshop_submission_summary extends workshop_submission_base implements re
*/
protected $fields = array(
'id', 'title', 'timecreated', 'timemodified',
'authorid', 'authorfirstname', 'authorlastname', 'authorpicture',
'authorid', 'authorfirstname', 'authorlastname', 'authorfirstnamephonetic', 'authorlastnamephonetic',
'authormiddlename', 'authoralternatename', 'authorpicture',
'authorimagealt', 'authoremail');
}

Expand All @@ -3156,8 +3166,8 @@ class workshop_submission extends workshop_submission_summary implements rendera
*/
protected $fields = array(
'id', 'title', 'timecreated', 'timemodified', 'content', 'contentformat', 'contenttrust',
'attachment', 'authorid', 'authorfirstname', 'authorlastname', 'authorpicture',
'authorimagealt', 'authoremail');
'attachment', 'authorid', 'authorfirstname', 'authorlastname', 'authorfirstnamephonetic', 'authorlastnamephonetic',
'authormiddlename', 'authoralternatename', 'authorpicture', 'authorimagealt', 'authoremail');
}

/**
Expand Down
18 changes: 5 additions & 13 deletions mod/workshop/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,9 @@ protected function render_workshop_submission(workshop_submission $submission) {
$o .= $this->output->heading($title, 3);

if (!$anonymous) {
$author = new stdclass();
$author->id = $submission->authorid;
$author->firstname = $submission->authorfirstname;
$author->lastname = $submission->authorlastname;
$author->picture = $submission->authorpicture;
$author->imagealt = $submission->authorimagealt;
$author->email = $submission->authoremail;
$author = new stdclass();
$additionalfields = explode(',', user_picture::fields());
$author = username_load_fields_from_object($author, $submission, 'author', $additionalfields);
$userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
$userurl = new moodle_url('/user/view.php',
array('id' => $author->id, 'course' => $this->page->course->id));
Expand Down Expand Up @@ -185,12 +181,8 @@ protected function render_workshop_submission_summary(workshop_submission_summar

if (!$anonymous) {
$author = new stdClass();
$author->id = $summary->authorid;
$author->firstname = $summary->authorfirstname;
$author->lastname = $summary->authorlastname;
$author->picture = $summary->authorpicture;
$author->imagealt = $summary->authorimagealt;
$author->email = $summary->authoremail;
$additionalfields = explode(',', user_picture::fields());
$author = username_load_fields_from_object($author, $summary, 'author', $additionalfields);
$userpic = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
$userurl = new moodle_url('/user/view.php',
array('id' => $author->id, 'course' => $this->page->course->id));
Expand Down
33 changes: 15 additions & 18 deletions mod/workshop/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,11 @@
$submission->title = $assessment->submissiontitle;
$submission->timecreated = $assessment->submissioncreated;
$submission->timemodified = $assessment->submissionmodified;
$submission->authorid = $assessment->authorid;
$submission->authorfirstname = $assessment->authorfirstname;
$submission->authorlastname = $assessment->authorlastname;
$submission->authorpicture = $assessment->authorpicture;
$submission->authorimagealt = $assessment->authorimagealt;
$submission->authoremail = $assessment->authoremail;
$userpicturefields = explode(',', user_picture::fields());
foreach ($userpicturefields as $userpicturefield) {
$prefixedusernamefield = 'author' . $userpicturefield;
$submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
}

// transform the submission object into renderable component
$submission = $workshop->prepare_submission_summary($submission, $shownames);
Expand Down Expand Up @@ -513,12 +512,11 @@
$submission->title = $assessment->submissiontitle;
$submission->timecreated = $assessment->submissioncreated;
$submission->timemodified = $assessment->submissionmodified;
$submission->authorid = $assessment->authorid;
$submission->authorfirstname = $assessment->authorfirstname;
$submission->authorlastname = $assessment->authorlastname;
$submission->authorpicture = $assessment->authorpicture;
$submission->authorimagealt = $assessment->authorimagealt;
$submission->authoremail = $assessment->authoremail;
$userpicturefields = explode(',', user_picture::fields());
foreach ($userpicturefields as $userpicturefield) {
$prefixedusernamefield = 'author' . $userpicturefield;
$submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
}

if (is_null($assessment->grade)) {
$class = ' notgraded';
Expand Down Expand Up @@ -621,12 +619,11 @@
$submission->title = $assessment->submissiontitle;
$submission->timecreated = $assessment->submissioncreated;
$submission->timemodified = $assessment->submissionmodified;
$submission->authorid = $assessment->authorid;
$submission->authorfirstname = $assessment->authorfirstname;
$submission->authorlastname = $assessment->authorlastname;
$submission->authorpicture = $assessment->authorpicture;
$submission->authorimagealt = $assessment->authorimagealt;
$submission->authoremail = $assessment->authoremail;
$userpicturefields = explode(',', user_picture::fields());
foreach ($userpicturefields as $userpicturefield) {
$prefixedusernamefield = 'author' . $userpicturefield;
$submission->$prefixedusernamefield = $assessment->$prefixedusernamefield;
}

if (is_null($assessment->grade)) {
$class = ' notgraded';
Expand Down

0 comments on commit 3263a35

Please sign in to comment.