1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-17 22:45:54 +02:00

MDL-63844 enrolmentdetails: add time-enrolled field

This commit is contained in:
Rohan Khajuria 2018-11-27 12:42:18 -08:00 committed by Amaia Anabitarte
parent 33a388eff7
commit 6676f20214
7 changed files with 33 additions and 6 deletions

@ -1 +1 @@
define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){var a=this;b(j.UNENROL).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename"),enrolinstancename:i.data("enrolinstancename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(c,e){var f=c[0],i=c[1];e.setTitle(f),e.setBody(i),e.setSaveButtonText(f),e.getRoot().on(g.save,function(){var c={ueid:b(h).attr("rel")};d.preventDefault(),a.submitUnenrolFormAjax(e,c)}),e.getRoot().on(g.hidden,function(){e.destroy()}),e.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("<div>").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.submitUnenrolFormAjax=function(a,b){var c={methodname:"core_enrol_unenrol_user_enrolment",args:b};i.call([c])[0].done(function(b){b.result?(a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload()):e.alert(b.errors[0].key,b.errors[0].message)}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}});
define(["core/templates","jquery","core/str","core/config","core/notification","core/modal_factory","core/modal_events","core/fragment","core/ajax"],function(a,b,c,d,e,f,g,h,i){var j={EDIT_ENROLMENT:'[data-action="editenrolment"]',SHOW_DETAILS:'[data-action="showdetails"]',UNENROL:'[data-action="unenrol"]'},k=function(a){this.contextid=a.contextid,this.courseid=a.courseid,this.bindEditEnrol(),this.bindUnenrol(),this.bindStatusDetails()};return k.prototype.courseid=0,k.prototype.bindEditEnrol=function(){var a=this;b(j.EDIT_ENROLMENT).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=i.data("fullname"),k=h.attr("rel");b.when(c.get_string("edituserenrolment","enrol",j)).then(function(a){return f.create({large:!0,title:a,type:f.types.SAVE_CANCEL})}).done(function(b){b.getRoot().on(g.save,function(c){c.preventDefault(),a.submitEditFormAjax(b)}),b.getRoot().on(g.hidden,function(){b.destroy()}),b.setBody(a.getBody(k)),b.show()}).fail(e.exception)})},k.prototype.bindUnenrol=function(){var a=this;b(j.UNENROL).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),j=[{key:"unenrol",component:"enrol"},{key:"unenrolconfirm",component:"enrol",param:{user:i.data("fullname"),course:i.data("coursename"),enrolinstancename:i.data("enrolinstancename")}}],k=f.create({type:f.types.SAVE_CANCEL});b.when(c.get_strings(j),k).done(function(c,e){var f=c[0],i=c[1];e.setTitle(f),e.setBody(i),e.setSaveButtonText(f),e.getRoot().on(g.save,function(){var c={ueid:b(h).attr("rel")};d.preventDefault(),a.submitUnenrolFormAjax(e,c)}),e.getRoot().on(g.hidden,function(){e.destroy()}),e.show()}).fail(e.exception)})},k.prototype.bindStatusDetails=function(){b(j.SHOW_DETAILS).click(function(d){d.preventDefault();var h=b(this),i=h.parent(),k={fullname:i.data("fullname"),coursename:i.data("coursename"),enrolinstancename:i.data("enrolinstancename"),status:i.data("status"),statusclass:i.find("span").attr("class"),timestart:i.data("timestart"),timeend:i.data("timeend"),timeenrolled:i.data("timeenrolled")},l=[{key:"enroldetails",component:"enrol"}],m=h.next(j.EDIT_ENROLMENT);m.length&&(k.editenrollink=b("<div>").append(m.clone()).html());var n=c.get_strings(l),o=f.create({large:!0,type:f.types.CANCEL});b.when(n,o).done(function(c,d){var e=a.render("core_user/status_details",k);d.setTitle(c[0]),d.setBody(e),m.length&&d.getRoot().on("click",j.EDIT_ENROLMENT,function(a){a.preventDefault(),d.hide(),b(m).trigger("click")}),d.show(),d.getRoot().on(g.hidden,function(){d.destroy()})}).fail(e.exception)})},k.prototype.submitEditFormAjax=function(a){var c=this,d=a.getRoot().find("form"),f=b(d).find('[name="ue"]').val(),g=b(d).find('[name="status"]').val(),h={courseid:this.courseid,ueid:f,status:g},j=b(d).find('[name="timestart[enabled]"]');if(j.is(":checked")){var k=b(d).find('[name="timestart[year]"]').val(),l=b(d).find('[name="timestart[month]"]').val()-1,m=b(d).find('[name="timestart[day]"]').val(),n=b(d).find('[name="timestart[hour]"]').val(),o=b(d).find('[name="timestart[minute]"]').val(),p=new Date(k,l,m,n,o);h.timestart=p.getTime()/1e3}var q=b(d).find('[name="timeend[enabled]"]');if(q.is(":checked")){var r=b(d).find('[name="timeend[year]"]').val(),s=b(d).find('[name="timeend[month]"]').val()-1,t=b(d).find('[name="timeend[day]"]').val(),u=b(d).find('[name="timeend[hour]"]').val(),v=b(d).find('[name="timeend[minute]"]').val(),w=new Date(r,s,t,u,v);h.timeend=w.getTime()/1e3}var x={methodname:"core_enrol_edit_user_enrolment",args:h};i.call([x])[0].done(function(b){if(b.result)a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload();else{var e=JSON.stringify(d.serialize());a.setBody(c.getBody(f,e))}}).fail(e.exception)},k.prototype.submitUnenrolFormAjax=function(a,b){var c={methodname:"core_enrol_unenrol_user_enrolment",args:b};i.call([c])[0].done(function(b){b.result?(a.hide(),"undefined"!=typeof window.M.core_formchangechecker&&window.M.core_formchangechecker.reset_form_dirty_state(),window.location.reload()):e.alert(b.errors[0].key,b.errors[0].message)}).fail(e.exception)},k.prototype.getBody=function(a,b){var c={ueid:a};return"undefined"!=typeof b&&(c.formdata=b),h.loadFragment("enrol","user_enrolment_form",this.contextid,c).fail(e.exception)},{init:function(a){new k(a)}}});

@ -202,7 +202,8 @@ define(['core/templates',
"status": parentContainer.data('status'),
"statusclass": parentContainer.find('span').attr('class'),
"timestart": parentContainer.data('timestart'),
"timeend": parentContainer.data('timeend')
"timeend": parentContainer.data('timeend'),
"timeenrolled": parentContainer.data('timeenrolled')
};
// Get default string for the modal and modal type.

@ -68,6 +68,9 @@ class status_field implements renderable, templatable {
/** @var int $timeend The timestamp when the user's enrolment ends. */
protected $timeend;
/** @var int $timeenrolled The timestamp when the user was enrolled. */
protected $timeenrolled;
/** @var user_enrolment_action[] $enrolactions Array of enrol action objects for the given enrolment method. */
protected $enrolactions;
@ -89,16 +92,18 @@ class status_field implements renderable, templatable {
* @param string $status The user enrolment status.
* @param int|null $timestart The timestamp when the user's enrolment starts.
* @param int|null $timeend The timestamp when the user's enrolment ends.
* @param int|null $timeenrolled The timestamp when the user was enrolled.
* @param user_enrolment_action[] $enrolactions Array of enrol action objects for the given enrolment method.
*/
public function __construct($enrolinstancename, $coursename, $fullname, $status, $timestart = null, $timeend = null,
$enrolactions = []) {
$timeenrolled, $enrolactions = []) {
$this->enrolinstancename = $enrolinstancename;
$this->coursename = $coursename;
$this->fullname = $fullname;
$this->status = $status;
$this->timestart = $timestart;
$this->timeend = $timeend;
$this->timeenrolled = $timeenrolled;
$this->enrolactions = $enrolactions;
}
@ -127,6 +132,9 @@ class status_field implements renderable, templatable {
if ($this->timeend) {
$data->timeend = userdate($this->timeend);
}
if ($this->timeenrolled) {
$data->timeenrolled = userdate($this->timeenrolled);
}
$data->enrolactions = [];
foreach ($this->enrolactions as $enrolaction) {

@ -375,6 +375,7 @@ class participants_table extends \table_sql {
foreach ($userenrolments as $ue) {
$timestart = $ue->timestart;
$timeend = $ue->timeend;
$timeenrolled = $ue->timecreated;
$actions = $ue->enrolmentplugin->get_user_enrolment_actions($manager, $ue);
$instancename = $ue->enrolmentinstancename;
@ -399,7 +400,8 @@ class participants_table extends \table_sql {
break;
}
$statusfield = new status_field($instancename, $coursename, $fullname, $status, $timestart, $timeend, $actions);
$statusfield = new status_field($instancename, $coursename, $fullname, $status, $timestart, $timeend, $timeenrolled,
$actions);
$statusfielddata = $statusfield->set_status($statusval)->export_for_template($OUTPUT);
$enrolstatusoutput .= $OUTPUT->render_from_template('core_user/status_field', $statusfielddata);
}

@ -27,6 +27,7 @@
* statusclass string - The CSS class for the enrolment status.
* timestart string - Optional. The enrolment time start.
* timeend string - Optional. The enrolment time end.
* timeenrolled string - Optional. The time when the user was enrolled.
Example context (json):
{
@ -36,7 +37,8 @@
"status": "Active",
"statusclass": "label label-success",
"timestart": "1 January 2017",
"timeend": "31 January 2018"
"timeend": "31 January 2018",
"timeenrolled": "31 December 2016"
}
}}
<table class="table user-enrol-details">
@ -94,4 +96,14 @@
</td>
</tr>
{{/timeend}}
{{#timeenrolled}}
<tr>
<th>
{{#str}}enroltimecreated, enrol{{/str}}
</th>
<td class="user-enrol-timeenrolled">
{{timeenrolled}}
</td>
</tr>
{{/timeenrolled}}
</table>

@ -29,6 +29,7 @@
* notcurrent boolean - Flag to indicate whether the user's enrolment is active, but not current.
* timestart string - Optional. The enrolment time start.
* timeend string - Optional. The enrolment time end.
* timeenrolled string - Optional. The time when the user was enrolled.
* enrolactions array - Optional. Array of enrol actions consisting of:
* url string - The URL of the enrol action link.
* attributes array - The array of attributes for the enrol action link.
@ -43,6 +44,7 @@
"active": true,
"timestart": "1 January 2017",
"timeend": "31 January 2018",
"timeenrolled": "31 December 2016",
"enrolactions": [
{
"url": "#",
@ -58,7 +60,7 @@
}
}}
<div data-fullname="{{fullname}}" data-coursename="{{coursename}}" data-enrolinstancename="{{enrolinstancename}}"
data-status="{{status}}" data-timestart="{{timestart}}" data-timeend="{{timeend}}">
data-status="{{status}}" data-timestart="{{timestart}}" data-timeend="{{timeend}}" data-timeenrolled="{{timeenrolled}}">
<span class="label {{#active}}label-success{{/active}}{{#suspended}}label-warning{{/suspended}}{{#notcurrent}}label-default{{/notcurrent}}">{{status}}</span>
<a data-action="showdetails" href="#" role="button" tabindex="0">{{!
}}{{#pix}}docs, core, {{enrolinstancename}}{{/pix}}{{!

@ -58,12 +58,14 @@ Feature: Edit user enrolment
And I should see "Student 1" in the "Full name" "table_row"
And I should see "Active" in the "//td[@class='user-enrol-status']" "xpath_element"
And I should see "Manual enrolments" in the "Enrolment method" "table_row"
And I should see "Enrolment created"
And I click on "Cancel" "button" in the "Enrolment details" "dialogue"
And I click on "Manual enrolments" "icon" in the "student2" "table_row"
And I should see "Enrolment details"
And I should see "Student 2" in the "Full name" "table_row"
And I should see "Suspended" in the "//td[@class='user-enrol-status']" "xpath_element"
And I should see "Manual enrolments" in the "Enrolment method" "table_row"
And I should see "Enrolment created"
And "Edit enrolment" "icon" should exist in the "Enrolment method" "table_row"
@javascript