2.6.1 quiz getting rid of items on mod/quiz/view.php

2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -
Number of replies: 8

Please refer to the attachment, it is a cut&paste of mod/quiz/view, and it is shown just after you submit your test questions.

I really want to remove the "Summary of your previous attempts" box and the 3 items above it, and keep the box that says "Overall Feedback". How do I remove these things?

Please don't tell me to just keep them and be quiet. Thank you...   smile

Average of ratings: -
In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Do you always want those things hidden, or only after the student has attempted the quiz?

Anyway, there are two general approaches:

1. add some CSS rules to make the things you want hidden display: none;.

2. Edit the code in mod/quiz/renderer.php to change the output. The method to look for is public function view_page. For example you could change

$output .= $this->view_information($quiz, $cm, $context, $viewobj->infomessages);

to

if ($viewobj->moreattempts || $viewobj->unfinished) {
    $output .= $this->view_information($quiz, $cm, $context, $viewobj->infomessages);
}

to only show that information if the student has an attempt in progress, or is allowed to start a new attempt.

In reply to Tim Hunt

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -

Thank you, that worked wonderfully! I silenced two lines...

 

  /*  $output .= $this->view_information($quiz, $cm, $context, $viewobj->infomessages);*/
       /* $output .= $this->view_table($quiz, $context, $viewobj);*/

 

and that took care of most of it. I have one more issue...

There is a button that says "re-attempt quiz", and I need that to show up if they did not pass, not if they did pass. How can I program it so that they see that button if, and only if, they did not pass the first time?

In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -

In mod/quiz/view there is a sections that starts out with the heading of 

"// Determine whether a start attempt button should be displayed."

and I am thinking/hoping this will be where we fix the problem of the "re-attempt quiz" button showing up on the page that told us they passed the quiz...very confusing for students.

Here is the code, lines 186-215 on mod/quiz/view on my download (2.6.1)...any ideas?

 

// Determine whether a start attempt button should be displayed.
$viewobj->quizhasquestions = (bool) quiz_clean_layout($quiz->questions, true);
$viewobj->preventmessages = array();
if (!$viewobj->quizhasquestions) {
    $viewobj->buttontext = 'Try again';

} else {
    if ($unfinished) {
        if ($canattempt) {
            $viewobj->buttontext = get_string('continueattemptquiz', 'quiz');
        } else if ($canpreview) {
            $viewobj->buttontext = get_string('continuepreview', 'quiz');
        }

    } else {
        if ($canattempt) {
            $viewobj->preventmessages = $viewobj->accessmanager->prevent_new_attempt(
                    $viewobj->numattempts, $viewobj->lastfinishedattempt);
            if ($viewobj->preventmessages) {
                $viewobj->buttontext = '';
            } else if ($viewobj->numattempts == 0) {
                $viewobj->buttontext = get_string('attemptquiznow', 'quiz');
            } else {
                $viewobj->buttontext = get_string('reattemptquiz', 'quiz');
            }

        } else if ($canpreview) {
            $viewobj->buttontext = get_string('previewquiznow', 'quiz');
        }
    }

In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, that is probably the right section of code to change to do what you want. If you set $viewobj->buttontext to the empty string ('') then the button will not appear.

Well, but that point in the code, there is a $mygrade variable. Adding an if statement after the block of code you quoted, setting the text to '' if the grade is high enough, will probably do it. What is hight enough?

Note that the $viewobj->buttontext = 'Try again'; line is not the original code. https://github.com/moodle/moodle/blob/master/mod/quiz/view.php#L189 . Not that it really matters.

In reply to Tim Hunt

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -

Thanks Tim. What does it mean to set $viewobj->buttontext to the empty string ('')? How do I do that? Also, I want that button to show up if they fail the test, but I can put the button script in the overall feedback box for failing, just as I added the certificate button script. Would that make a difference, if it were programmed in the box instead of on the page? They are supposed to have only 2 attempts...would that change things?

 

No, the coding was originally $viewobj->buttontext = ''; and I went into language customization and changed the button text from "re-attempt quiz" to "try again", as it just sounds more social and less robotic. I didn't change that in cpanel.

In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -

I think there needs to be something in there to the effect of "if grade is less than 70%, show the button. 2 attempts only", although I know that is not how the coding actually goes.

 

Before anyone suggests that I hire a programmer, please know that I tried to hire a programmer to do this, and after 3 weeks he messed they system up and I had to reupload fresh ftp files...so I would really rather do this myself with help.

In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Wendi Daniels -

Alright, I think I got part of the coding issue resolved, but I could use your help, Tim Hunt (or other).

 Below is what I did that fixed the button issue, but one issue remains, and that is that they are supposed to have 2 attempts and then a message saying "I'm sorry, but you ran out of attempts". As it is, it seems they have endless attempts even though I have it programmed for no more than 2.

 

Here is what I have done so far...

1) First, I went to the page you see in the first post and clicked on the button I did not like, and then right-clicked on my mouse and then selected "inspect element". I copied the coding as follows:

<div (coding)>
<div id="yui (coding)>

<form id="yui (coding)>
<div id="yui (coding)>

<input id="yui (coding) />

<input value=(coding) />

<input value=(coding) />

</div>
</form>

</div>
</div>

and I pasted this into the "Overall Feedback" box in "Edit Quiz" (select the html button that looks like this "<>")

 

2) After that, I simply silenced the coding in mod/quiz/view as follows (lines 208 and 209 on my copy):

    /*  } else {
                $viewobj->buttontext = get_string('reattemptquiz', 'quiz');*/

 

 

In reply to Wendi Daniels

Re: 2.6.1 quiz getting rid of items on mod/quiz/view.php

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am not sure that trying to put the button in the overall feedback is a good idea. There are probably some ids in there which vary from quiz to quiz, or from login to login. You really need to leave the button being automatically generated, but with the logic you want. I guess we can continue to discuss that in the other thread you started.