Merge branch 'wip-MDL-41158-master-two' of git://github.com/abgreeve/moodle

This commit is contained in:
Sam Hemelryk 2013-11-12 13:20:12 +08:00
commit 0ac5863d86
5 changed files with 58 additions and 68 deletions

View File

@ -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) {
@ -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;

View File

@ -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
@ -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');
}
}
@ -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
@ -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;
}
}

View File

@ -3075,9 +3075,10 @@ abstract class workshop_submission_base {
* 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;
}
@ -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 */
@ -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');
}
@ -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');
}
/**

View File

@ -102,13 +102,9 @@ class mod_workshop_renderer extends plugin_renderer_base {
$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));
@ -185,12 +181,8 @@ class mod_workshop_renderer extends plugin_renderer_base {
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));

View File

@ -387,12 +387,11 @@ case workshop::PHASE_ASSESSMENT:
$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);
@ -513,12 +512,11 @@ case workshop::PHASE_EVALUATION:
$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';
@ -621,12 +619,11 @@ case workshop::PHASE_CLOSED:
$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';