Skip to content

Commit 31f092b

Browse files
committed
Merge pull request #481 from moodlehq/mod_quiz
Mod quiz
2 parents 2959209 + 25a9b0b commit 31f092b

File tree

196 files changed

+16304
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+16304
-134
lines changed

gulpfile.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ gulp.task('watch', function() {
103103
gulp.task('build', function(done) {
104104
var dependencies = ["'mm.core'"],
105105
componentRegex = /core\/components\/([^\/]+)\/main.js/,
106-
pluginRegex = /addons\/([^\/]+)\/main.js/;
106+
pluginRegex = /addons\/([^\/]+)\/main.js/,
107+
subpluginRegex = /addons\/([^\/]+)\/([^\/]+)\/main.js/;
107108

108109
gulp.src(paths.js)
109110
.pipe(gulpSlash())
@@ -113,6 +114,10 @@ gulp.task('build', function(done) {
113114
dependencies.push("'mm.core." + file.path.match(componentRegex)[1] + "'");
114115
} else if (pluginRegex.test(file.path)) {
115116
dependencies.push("'mm.addons." + file.path.match(pluginRegex)[1] + "'");
117+
} else if (subpluginRegex.test(file.path)) {
118+
// It's a subplugin, use plugin_subplugin to identify it.
119+
var matches = file.path.match(subpluginRegex);
120+
dependencies.push("'mm.addons." + matches[1] + '_' + matches[2] + "'");
116121
}
117122
}))
118123

@@ -144,7 +149,7 @@ gulp.task('lang', function() {
144149
return fs.readdirSync(dir)
145150
.filter(function(file) {
146151
return file.indexOf('.json') > -1;
147-
})
152+
});
148153
}
149154

150155
/**
@@ -181,8 +186,13 @@ gulp.task('lang', function() {
181186

182187
} else if (filepath.indexOf('addons') == 0) {
183188

184-
var pluginName = filepath.replace('addons/', '');
185-
pluginName = pluginName.substr(0, pluginName.indexOf('/'));
189+
var split = filepath.split('/'),
190+
pluginName = split[1];
191+
192+
// Check if it's a subplugin. If so, we'll use plugin_subplugin.
193+
if (split[2] != 'lang') {
194+
pluginName = pluginName + '_' + split[2];
195+
}
186196
addProperties(merged, data[filepath], 'mma.'+pluginName+'.');
187197

188198
} else if (filepath.indexOf('core/assets/countries') == 0) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.mod_quiz')
16+
17+
/**
18+
* Handler for delaybetweenattempts quiz access rule.
19+
*
20+
* @module mm.addons.mod_quiz
21+
* @ngdoc service
22+
* @name $mmaQuizAccessDelayBetweenAttemptsHandler
23+
*/
24+
.factory('$mmaQuizAccessDelayBetweenAttemptsHandler', function() {
25+
26+
var self = {};
27+
28+
/**
29+
* Whether or not the rule is enabled for the site.
30+
*
31+
* @return {Boolean}
32+
*/
33+
self.isEnabled = function() {
34+
return true;
35+
};
36+
37+
/**
38+
* Check if a preflight check is required.
39+
*
40+
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
41+
* @return {Boolean} True if preflight check required.
42+
*/
43+
self.isPreflightCheckRequired = function(attempt) {
44+
return false;
45+
};
46+
47+
return self;
48+
})
49+
50+
.run(function($mmAddonManager) {
51+
// Use addon manager to inject $mmaModQuizAccessRulesDelegate. This is to provide an example for remote addons,
52+
// since they cannot assume that the quiz addon will be packaged in custom apps.
53+
var $mmaModQuizAccessRulesDelegate = $mmAddonManager.get('$mmaModQuizAccessRulesDelegate');
54+
if ($mmaModQuizAccessRulesDelegate) {
55+
$mmaModQuizAccessRulesDelegate.registerHandler('mmaQuizAccessDelayBetweenAttempts', 'quizaccess_delaybetweenattempts',
56+
'$mmaQuizAccessDelayBetweenAttemptsHandler');
57+
}
58+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.mod_quiz')
16+
17+
/**
18+
* Handler for ipaddress quiz access rule.
19+
*
20+
* @module mm.addons.mod_quiz
21+
* @ngdoc service
22+
* @name $mmaQuizAccessIpAddressHandler
23+
*/
24+
.factory('$mmaQuizAccessIpAddressHandler', function() {
25+
26+
var self = {};
27+
28+
/**
29+
* Whether or not the rule is enabled for the site.
30+
*
31+
* @return {Boolean}
32+
*/
33+
self.isEnabled = function() {
34+
return true;
35+
};
36+
37+
/**
38+
* Check if a preflight check is required.
39+
*
40+
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
41+
* @return {Boolean} True if preflight check required.
42+
*/
43+
self.isPreflightCheckRequired = function(attempt) {
44+
return false;
45+
};
46+
47+
return self;
48+
})
49+
50+
.run(function($mmAddonManager) {
51+
// Use addon manager to inject $mmaModQuizAccessRulesDelegate. This is to provide an example for remote addons,
52+
// since they cannot assume that the quiz addon will be packaged in custom apps.
53+
var $mmaModQuizAccessRulesDelegate = $mmAddonManager.get('$mmaModQuizAccessRulesDelegate');
54+
if ($mmaModQuizAccessRulesDelegate) {
55+
$mmaModQuizAccessRulesDelegate.registerHandler('mmaQuizAccessIpAddress', 'quizaccess_ipaddress',
56+
'$mmaQuizAccessIpAddressHandler');
57+
}
58+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.mod_quiz')
16+
17+
/**
18+
* Handler for numattempts quiz access rule.
19+
*
20+
* @module mm.addons.mod_quiz
21+
* @ngdoc service
22+
* @name $mmaQuizAccessNumAttemptsHandler
23+
*/
24+
.factory('$mmaQuizAccessNumAttemptsHandler', function() {
25+
26+
var self = {};
27+
28+
/**
29+
* Whether or not the rule is enabled for the site.
30+
*
31+
* @return {Boolean}
32+
*/
33+
self.isEnabled = function() {
34+
return true;
35+
};
36+
37+
/**
38+
* Check if a preflight check is required.
39+
*
40+
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
41+
* @return {Boolean} True if preflight check required.
42+
*/
43+
self.isPreflightCheckRequired = function(attempt) {
44+
return false;
45+
};
46+
47+
return self;
48+
})
49+
50+
.run(function($mmAddonManager) {
51+
// Use addon manager to inject $mmaModQuizAccessRulesDelegate. This is to provide an example for remote addons,
52+
// since they cannot assume that the quiz addon will be packaged in custom apps.
53+
var $mmaModQuizAccessRulesDelegate = $mmAddonManager.get('$mmaModQuizAccessRulesDelegate');
54+
if ($mmaModQuizAccessRulesDelegate) {
55+
$mmaModQuizAccessRulesDelegate.registerHandler('mmaQuizAccessNumAttempts', 'quizaccess_numattempts',
56+
'$mmaQuizAccessNumAttemptsHandler');
57+
}
58+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.mod_quiz')
16+
17+
/**
18+
* Directive to render offline attempt preflight.
19+
*
20+
* @module mm.addons.mod_quiz
21+
* @ngdoc directive
22+
* @name mmaQuizAccessOfflineAttemptsPreflight
23+
*/
24+
.directive('mmaQuizAccessOfflineAttemptsPreflight', function() {
25+
return {
26+
restrict: 'A',
27+
priority: 100,
28+
templateUrl: 'addons/mod_quiz/accessrules/offlineattempts/template.html'
29+
};
30+
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.addons.mod_quiz')
16+
17+
/**
18+
* Handler for offline attempts quiz access rule.
19+
*
20+
* @module mm.addons.mod_quiz
21+
* @ngdoc service
22+
* @name $mmaQuizAccessOfflineAttemptsHandler
23+
*/
24+
.factory('$mmaQuizAccessOfflineAttemptsHandler', function(mmaModQuizSyncTime) {
25+
26+
var self = {};
27+
28+
/**
29+
* Whether or not the rule is enabled for the site.
30+
*
31+
* @return {Boolean}
32+
*/
33+
self.isEnabled = function() {
34+
return true;
35+
};
36+
37+
/**
38+
* Check if a preflight check is required.
39+
*
40+
* @param {Object} [attempt] Attempt to continue. Not defined if starting a new attempt.
41+
* @return {Boolean} True if preflight check required.
42+
*/
43+
self.isPreflightCheckRequired = function(attempt) {
44+
if (!attempt) {
45+
return true;
46+
}
47+
48+
// Show warning if last sync was a while ago.
49+
return new Date().getTime() - mmaModQuizSyncTime > attempt.quizSyncTime;
50+
};
51+
52+
/**
53+
* Get fixed preflight data (data that doesn't require user interaction).
54+
*
55+
* @module mm.addons.mod_quiz
56+
* @ngdoc method
57+
* @name $mmaModQuizAccessRulesDelegate#getFixedPreflightData
58+
* @param {Object} attempt Attempt.
59+
* @param {Object} preflightData Object where to store the preflight data.
60+
* @return {Void}
61+
*/
62+
self.getFixedPreflightData = function(attempt, preflightData) {
63+
preflightData.confirmdatasaved = 1;
64+
};
65+
66+
/**
67+
* Get the name of the directive to be rendered in the preflight form.
68+
*
69+
* @return {String} Directive name.
70+
*/
71+
self.getPreflightDirectiveName = function() {
72+
return 'mma-quiz-access-offline-attempts-preflight';
73+
};
74+
75+
return self;
76+
})
77+
78+
.run(function($mmAddonManager) {
79+
// Use addon manager to inject $mmaModQuizAccessRulesDelegate. This is to provide an example for remote addons,
80+
// since they cannot assume that the quiz addon will be packaged in custom apps.
81+
var $mmaModQuizAccessRulesDelegate = $mmAddonManager.get('$mmaModQuizAccessRulesDelegate');
82+
if ($mmaModQuizAccessRulesDelegate) {
83+
$mmaModQuizAccessRulesDelegate.registerHandler('mmaQuizAccessOfflineAttempts', 'quizaccess_offlineattempts',
84+
'$mmaQuizAccessOfflineAttemptsHandler');
85+
}
86+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="item item-text-wrap" ng-init="preflightData.confirmdatasaved = 1">
2+
<p class="item-heading">{{ 'mm.settings.synchronization' | translate }}</p>
3+
<p>{{ 'mma.mod_quiz.confirmcontinueoffline' | translate:{$a: quiz.syncTimeReadable} }}</p>
4+
</div>

0 commit comments

Comments
 (0)