31
31
require_once ($ CFG ->libdir . "/gradelib.php " );
32
32
33
33
// Constants.
34
- define ('TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE ' , 41943040 );
34
+ define ('TURNITINTOOLTWO_MAX_FILE_UPLOAD_SIZE ' , 104857600 );
35
35
define ('TURNITINTOOLTWO_DEFAULT_PSEUDO_DOMAIN ' , '@tiimoodle.com ' );
36
36
define ('TURNITINTOOLTWO_DEFAULT_PSEUDO_FIRSTNAME ' , get_string ('defaultcoursestudent ' ));
37
37
define ('TURNITINTOOLTWO_SUBMISSION_GET_LIMIT ' , 100 );
69
69
* @param int $cmid Course module id
70
70
*/
71
71
function turnitintooltwo_add_to_log ($ courseid , $ eventname , $ link , $ desc , $ cmid , $ userid = 0 ) {
72
- global $ CFG , $ USER ;
73
- if ( ( property_exists ( $ CFG , 'branch ' ) AND ( $ CFG ->branch < 27 ) ) || ( !property_exists ( $ CFG , 'branch ' ) ) ) {
74
- add_to_log ($ courseid , "turnitintooltwo " , $ eventname , $ link , $ desc , $ cmid );
75
- } else {
76
- $ eventname = str_replace (' ' , '_ ' , $ eventname );
77
- $ eventpath = '\mod_turnitintooltwo\event \\' .$ eventname ;
78
-
79
- $ data = array (
80
- 'objectid ' => $ cmid ,
81
- 'context ' => ( $ cmid == 0 ) ? context_course::instance ($ courseid ) : context_module::instance ($ cmid ),
82
- 'other ' => array ('desc ' => $ desc )
83
- );
84
- if (!empty ($ userid ) && ($ userid != $ USER ->id )) {
85
- $ data ['relateduserid ' ] = $ userid ;
86
- }
87
- $ event = $ eventpath ::create ($ data );
88
- $ event ->trigger ();
72
+ global $ USER ;
73
+
74
+
75
+ $ eventname = str_replace (' ' , '_ ' , $ eventname );
76
+ $ eventpath = '\mod_turnitintooltwo\event \\' .$ eventname ;
77
+
78
+ $ data = array (
79
+ 'objectid ' => $ cmid ,
80
+ 'context ' => ( $ cmid == 0 ) ? context_course::instance ($ courseid ) : context_module::instance ($ cmid ),
81
+ 'other ' => array ('desc ' => $ desc )
82
+ );
83
+ if (!empty ($ userid ) && ($ userid != $ USER ->id )) {
84
+ $ data ['relateduserid ' ] = $ userid ;
89
85
}
86
+ $ event = $ eventpath ::create ($ data );
87
+ $ event ->trigger ();
90
88
}
91
89
92
90
/**
@@ -115,18 +113,10 @@ function turnitintooltwo_supports($feature) {
115
113
* @return int the plugin version for use within the plugin.
116
114
*/
117
115
function turnitintooltwo_get_version () {
118
- global $ DB , $ CFG ;
119
- $ pluginversion = '' ;
120
-
121
- if ($ CFG ->branch >= 26 ) {
122
- $ module = $ DB ->get_record ('config_plugins ' , array ('plugin ' => 'mod_turnitintooltwo ' , 'name ' => 'version ' ));
123
- $ pluginversion = $ module ->value ;
124
- } else {
125
- $ module = $ DB ->get_record ('modules ' , array ('name ' => 'turnitintooltwo ' ));
126
- $ pluginversion = $ module ->version ;
127
- }
116
+ global $ DB ;
117
+ $ version = $ DB ->get_record ('config_plugins ' , array ('plugin ' => 'mod_turnitintooltwo ' , 'name ' => 'version ' ));
128
118
129
- return $ pluginversion ;
119
+ return $ version -> value ;
130
120
}
131
121
132
122
/**
@@ -351,6 +341,11 @@ function turnitintooltwo_duplicate_recycle($courseid, $action, $renewdates = nul
351
341
352
342
foreach ($ parts as $ part ) {
353
343
$ partsarray [$ courseid ][$ turnitintooltwo ->id ][$ part ->id ]['tiiassignid ' ] = $ part ->tiiassignid ;
344
+
345
+ if ($ action == "UNTOUCHED " ) {
346
+ $ turnitintooltwoassignment = new turnitintooltwo_assignment ($ turnitintooltwo ->id );
347
+ turnitintooltwo_update_event ($ turnitintooltwoassignment ->turnitintooltwo , $ part );
348
+ }
354
349
}
355
350
356
351
/* Set legacy to 0 for all TII2s so that we can have all recreated assignments on the same TII class.
@@ -368,6 +363,11 @@ function turnitintooltwo_duplicate_recycle($courseid, $action, $renewdates = nul
368
363
}
369
364
}
370
365
366
+ // We don't want to go any further if Turnitin Assignments aren't going to be touched.
367
+ if ($ action == "UNTOUCHED " ) {
368
+ return array ();
369
+ }
370
+
371
371
$ currentcourse = turnitintooltwo_assignment::get_course_data ($ courseid );
372
372
if ($ action == "NEWCLASS " ) {
373
373
// Delete Turnitin class link.
@@ -577,15 +577,20 @@ function turnitintooltwo_reset_part_update($part, $i) {
577
577
* @return array The Result of the turnitintooltwo_duplicate_recycle call
578
578
*/
579
579
function turnitintooltwo_reset_userdata ($ data ) {
580
- $ status = array ();
581
-
582
580
$ renew_dates = isset ($ data ->renew_assignment_dates ) ? 1 : null ;
583
581
584
- if ($ data ->reset_turnitintooltwo == 0 ) {
585
- $ status = turnitintooltwo_duplicate_recycle ($ data ->courseid , 'NEWCLASS ' , $ renew_dates );
586
- } else if ($ data ->reset_turnitintooltwo == 1 ) {
587
- $ status = turnitintooltwo_duplicate_recycle ($ data ->courseid , 'OLDCLASS ' , $ renew_dates );
582
+ $ action = 'UNTOUCHED ' ;
583
+ switch ($ data ->reset_turnitintooltwo ) {
584
+ case 0 :
585
+ $ action = 'NEWCLASS ' ;
586
+ break ;
587
+ case 1 :
588
+ $ action = 'OLDCLASS ' ;
589
+ break ;
588
590
}
591
+
592
+ $ status = turnitintooltwo_duplicate_recycle ($ data ->courseid , $ action , $ renew_dates );
593
+
589
594
return $ status ;
590
595
}
591
596
@@ -1719,22 +1724,33 @@ function turnitintooltwo_override_repository($submitpapersto) {
1719
1724
*/
1720
1725
function mod_turnitintooltwo_core_calendar_provide_event_action (calendar_event $ event ,
1721
1726
\core_calendar \action_factory $ factory ) {
1727
+ global $ DB , $ USER ;
1722
1728
$ cm = get_fast_modinfo ($ event ->courseid )->instances ['turnitintooltwo ' ][$ event ->instance ];
1723
-
1724
- if (!empty ($ cm ->customdata ['timeclose ' ]) && $ cm ->customdata ['timeclose ' ] < time ()) {
1725
- // The assignment has closed so the user can no longer submit anything.
1726
- return null ;
1727
- }
1729
+ $ isinstructor = (has_capability ('mod/turnitintooltwo:grade ' , context_module::instance ($ cm ->id )));
1728
1730
1729
1731
// Restore object from cached values in $cm, we only need id, timeclose and timeopen.
1730
1732
$ customdata = $ cm ->customdata ?: [];
1731
1733
$ customdata ['id ' ] = $ cm ->instance ;
1732
1734
$ data = (object )($ customdata + ['timeclose ' => 0 , 'timeopen ' => 0 ]);
1735
+ $ assignmentpart = $ DB ->get_record ('turnitintooltwo_parts ' , array ('turnitintooltwoid ' => $ customdata ['id ' ]), 'max(dtpost) ' );
1736
+
1737
+ // Check whether the logged in user has a submission, should always be false for Instructors.
1738
+ $ hassubmission = false ;
1739
+ if (!$ isinstructor ) {
1740
+ $ queryparams = array ('userid ' => $ USER ->id , 'turnitintooltwoid ' => $ customdata ['id ' ]);
1741
+ $ hassubmission = $ DB ->get_records ('turnitintooltwo_submissions ' , $ queryparams );
1742
+ }
1743
+
1744
+ if ((!empty ($ cm ->customdata ['timeclose ' ]) && $ cm ->customdata ['timeclose ' ] < time ()) ||
1745
+ $ assignmentpart ->max < time () || !empty ($ hassubmission )) {
1746
+ // The assignment has closed so the user can no longer submit anything.
1747
+ return null ;
1748
+ }
1733
1749
1734
1750
// Check that the activity is open.
1735
1751
list ($ actionable , $ warnings ) = mod_turnitintooltwo_get_availability_status ($ data , true , context_module::instance ($ cm ->id ));
1736
1752
1737
- $ identifier = (has_capability ( ' mod/turnitintooltwo:grade ' , context_module:: instance ( $ cm -> id )) ) ? 'allsubmissions ' : 'addsubmission ' ;
1753
+ $ identifier = ($ isinstructor ) ? 'allsubmissions ' : 'addsubmission ' ;
1738
1754
return $ factory ->create_instance (
1739
1755
get_string ($ identifier , 'turnitintooltwo ' ),
1740
1756
new \moodle_url ('/mod/turnitintooltwo/view.php ' , array ('id ' => $ cm ->id )),
@@ -1791,14 +1807,15 @@ function turnitintooltwo_update_event($turnitintooltwo, $part, $courseparam = fa
1791
1807
$ dbparams [] = $ turnitintooltwo ->course ;
1792
1808
}
1793
1809
try {
1794
- // Update event for assignment part.
1810
+ // Create event data.
1811
+ $ updatedevent = new stdClass ();
1812
+ $ updatedevent ->userid = $ USER ->id ;
1813
+ $ updatedevent ->name = $ turnitintooltwo ->name ." - " .$ part ->partname ;
1814
+ $ updatedevent ->timestart = $ part ->dtdue ;
1815
+
1816
+ // Create/Update event for assignment part.
1795
1817
if ($ event = $ DB ->get_record_select ("event " , $ dbselect , $ dbparams )) {
1796
- // Update the event.
1797
- $ updatedevent = new stdClass ();
1798
1818
$ updatedevent ->id = $ event ->id ;
1799
- $ updatedevent ->userid = $ USER ->id ;
1800
- $ updatedevent ->name = $ turnitintooltwo ->name ." - " .$ part ->partname ;
1801
- $ updatedevent ->timestart = $ part ->dtdue ;
1802
1819
1803
1820
if ($ CFG ->branch >= 33 ) {
1804
1821
$ updatedevent ->timesort = $ part ->dtdue ;
@@ -1811,6 +1828,9 @@ function turnitintooltwo_update_event($turnitintooltwo, $part, $courseparam = fa
1811
1828
}
1812
1829
1813
1830
$ DB ->update_record ('event ' , $ updatedevent );
1831
+ } else {
1832
+ $ turnitintooltwoassignment = new turnitintooltwo_assignment ($ turnitintooltwo ->id );
1833
+ $ turnitintooltwoassignment ->create_event ($ turnitintooltwo ->id , $ part ->partname , $ part ->dtdue );
1814
1834
}
1815
1835
} catch (Exception $ e ) {
1816
1836
turnitintooltwo_comms::handle_exceptions ($ e , 'turnitintooltwoupdateerror ' , false );
0 commit comments