Skip to content

Commit 1969e28

Browse files
author
\nrlucke
committed
vips 1.8 ready
1 parent 1d0b97e commit 1969e28

4 files changed

Lines changed: 64 additions & 24 deletions

File tree

blocks/TestBlock/TestBlock.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static function getSubTypes()
3131

3232
public function student_view()
3333
{
34+
global $user;
35+
3436
if (!$this->isAuthorized()) {
3537
return array('inactive' => true);
3638
}
@@ -78,6 +80,8 @@ public function student_view()
7880
);
7981
}
8082

83+
$assignment->recordAssignmentAttempt($user->id);
84+
8185
return array_merge($this->getAttrArray(), array(
8286
'active' => $active,
8387
'version' => $version,
@@ -357,7 +361,14 @@ private function buildExercises()
357361
$solving_allowed = ($now >= $start) && ($now <= $end);
358362
$solved_completely = true;
359363

360-
foreach ($test->getExercises() as $exercise){
364+
if (method_exists($assignment, 'releaseStatus')) {
365+
$released = $assignment->releaseStatus($user->id);
366+
} else {
367+
// use the same scale here as Vips 1.8 would use
368+
$released = $assignment->options['released'] * 2;
369+
}
370+
371+
foreach ($test->getExercises() as $exercise) {
361372
$solution = \VipsSolution::findOneBySQL('exercise_id = ? AND user_id = ?', array($exercise->id, $user->id));
362373
$has_solution = $solution != null;
363374
$correct = false;
@@ -386,7 +397,7 @@ private function buildExercises()
386397
$solved_completely = false;
387398
}
388399
$tries_left = -1;
389-
$max_counter = $this->container['current_courseware']->getMaxTries();
400+
$max_counter = $assignment->options['max_tries'] ?: $this->container['current_courseware']->getMaxTries();
390401
if(!$max_counter) {
391402
// no max counter, do as before
392403
$show_corrected_solution = $correct;
@@ -424,7 +435,7 @@ private function buildExercises()
424435
}
425436

426437
if ($solution != null) {
427-
$rendered_solution = $exercise->getCorrectionTemplate($solution)->render();
438+
$rendered_solution = $exercise->getCorrectionTemplate($solution)->render(['show_solution' => $released == 4 || $show_corrected_solution]);
428439
} else {
429440
$rendered_solution = '';
430441
}
@@ -447,14 +458,16 @@ private function buildExercises()
447458
'has_solution' => $has_solution,
448459
'solution' => $rendered_solution,
449460
'solving_allowed' => $solving_allowed,
461+
'reset_allowed' => $this->vipsVersion('1.8') ? $solving_allowed && $assignment->isResetAllowed() : $solving_allowed, // isResetAllowed() since vips 1.8
450462
'number_of_exercises' => $numberofex,
451463
'exercise_index' => $exindex++,
452464
'correct' => $correct,
453465
'tryagain' => $tryagain,
454466
'exercise_hint' => $exercise->options['hint'],
455467
'corrector_comment' => $corrector_comment,
456468
'sample_solution' => $sample_solution,
457-
'is_corrected' => $solution['corrected'] && ($assignment->options['released'] == 2),
469+
'is_corrected' => $solution['corrected'] && ($released >= 3),
470+
'released' => $released,
458471
'tries_left' => $tries_left,
459472
'tries_pl' => $tries_pl,
460473
'character_picker' => $character_picker

blocks/TestBlock/css/test_block.less

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ section.TestBlock {
1313

1414
.question_title {
1515
font-size: 12pt;
16-
margin-left: 0.25em;
1716
}
1817

1918
.question_description {
2019
padding: 1em 0 1em 0;
21-
margin-left: 0.5em;
2220
}
2321

2422
ul.exercise {
@@ -30,10 +28,6 @@ ul.exercise {
3028
border: solid thin #ccc;
3129
}
3230

33-
.cw-test-content {
34-
padding: 10px;
35-
}
36-
3731
&:not(#exercise1) {
3832
display: none;
3933
}
@@ -45,7 +39,7 @@ ul.exercise {
4539
border: none;
4640
border-bottom: solid thin #ccc;
4741

48-
.exercisenavbutton{
42+
.exercisenavbutton {
4943
position: absolute;
5044
border: none;
5145
height: 20px;
@@ -68,7 +62,7 @@ ul.exercise {
6862
}
6963

7064
.cw-test-content {
71-
padding: 0 10px;
65+
padding: 10px;
7266

7367
.exercise-title {
7468
text-align: center;
@@ -81,17 +75,16 @@ ul.exercise {
8175
font-weight: 400;
8276
}
8377

84-
.answer, label {
78+
.answer, label:not(.undecorated) {
8579
font-size: 14px;
8680
font-weight: normal;
87-
line-height: 32px;
88-
padding-left: 7px;
81+
margin-top: 1.5ex;
8982
text-transform: none;
9083
display: block;
9184
}
9285

93-
.label_text{
94-
margin-left: 7px;
86+
.label_text, .label-text {
87+
margin-top: 1.5ex;
9588
}
9689

9790
select {
@@ -104,7 +97,7 @@ ul.exercise {
10497

10598
p img {
10699
margin-top: 12px;
107-
margin-bttom: 12px;
100+
margin-bottom: 12px;
108101
}
109102

110103
textarea {
@@ -297,8 +290,6 @@ ul.exercise {
297290
font-weight: 600;
298291
}
299292

300-
p {
301-
}
302293
}
303294

304295
}

blocks/TestBlock/js/student_view.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export default StudentView.extend({
221221
jQuery(this).removeClass('hover');
222222
},
223223
receive: function(event, ui) {
224-
var sortable = jQuery(this);
224+
var sortable = jQuery(this).not('.multiple');
225225
var container = sortable.closest('tbody').find('.answer_container');
226226

227227
// default answer container can have more items
@@ -236,6 +236,42 @@ export default StudentView.extend({
236236
}
237237
}
238238
});
239+
this.$('.cloze_item').draggable({
240+
revert: 'invalid'
241+
});
242+
243+
this.$('.cloze_drop').droppable({
244+
accept: '.cloze_item',
245+
tolerance: 'pointer',
246+
classes: {
247+
'ui-droppable-hover': 'hover'
248+
},
249+
drop: function(event, ui) {
250+
var container = jQuery(this).closest('fieldset').find('.cloze_items');
251+
252+
if (!jQuery(this).is(container)) {
253+
jQuery(this).find('.cloze_item').detach().appendTo(container)
254+
.css('opacity', 0).animate({opacity: 1})
255+
}
256+
257+
ui.draggable.closest('.cloze_drop').find('input').val('');
258+
ui.draggable.detach().css({top: 0, left: 0}).appendTo(this);
259+
jQuery(this).find('input').val(ui.draggable.text());
260+
}
261+
});
262+
263+
$('.vips_tabs').each(function() {
264+
if ($(this).hasClass('edit-hidden')) {
265+
jQuery(this).tabs({
266+
active: 1
267+
});
268+
} else {
269+
jQuery(this).tabs({
270+
active: 0
271+
});
272+
273+
}
274+
})
239275
} else {
240276
this.$('.rh_list').sortable({
241277
axis: 'y',

blocks/TestBlock/templates/student_view.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@
8686
{{#show_solution}}
8787
{{> _solution}}
8888
{{#self_test}}
89-
{{#solving_allowed}}
89+
{{#reset_allowed}}
9090
{{> _reset_exercise}}
91-
{{/solving_allowed}}
91+
{{/reset_allowed}}
9292
{{/self_test}}
9393
{{/show_solution}}
9494
{{#exercise_hint}}
@@ -112,7 +112,7 @@
112112
{{#skip_entry}}
113113
{{#correction_available}}
114114
<ul class="exercise" id="exercise{{exercise_index}}">
115-
<li>
115+
<li class="exercise-item">
116116
<div class="exercisetitle">
117117
<button name="exercisenav" class="exercisenavbutton exercisenavback" button-data='{"id":"{{exercise_index}}", "numexes": "{{number_of_exercises}}", "direction": "back" }'></button>
118118
{{#i18n}}Frage{{/i18n}} {{exercise_index}} / {{number_of_exercises}}

0 commit comments

Comments
 (0)