General developer forum

Insert a checkbox form in a html_writer::table

 
Picture of Cyril Z.
Insert a checkbox form in a html_writer::table
 
Hi,

I'm a newbie in the Moodle development word. My colleagues ask me to develop a plugin in order to get my hands dirty and understand how Moodle works. The plugin is an admin tool.

In fact I want to display a table using html_writer::table and add to each line checkbox using a "$mform->('checkbox')".

The goal of this development
Dont forget that is an exercice for me. There will be a several lines displaying each plugin activities like in "Plugin Overview" in the "Site administration". What I want is to check or uncheck each plugin in order to activate or deactivate them. I know that is already made in the "Plugin Overview" but what we want is to define the state for all of them and then save the new states when we click the save button. In the current "Plugin Overview" each time we click activate or deactivate a plugin the page is refreshed. We dont want to do the same. We just want to save all the changes in one operation.

My problem
I want to simply add a "$mform->('checkbox')" to each line. It seems to be impossible.

To let you know I tried another way before. First I used a "html_writer_empty('input'..." which makes a checkbox instead of a $mform. But I think it is easier to manipulate a $mform. Is that right ?

My code
I tried to integreate a $mform whithout success in the method called dataProcessing();

function dataProcessing($activities, $mform){
    global $OUTPUT, $DB, $CFG;
    $arrayBack = (array) array();

    foreach($activities as $activity){
        $temp = new stdClass();
       
        ...
...

        if($activity->visible == 1)
            $temp->visible = '<label class="switch">'. html_writer::empty_tag('input', array('id' => $activity->id,'type' => 'checkbox', 'name' => 'fieldname', 'checked'=>'checked')) . '<span class="slider"></span></label>';
        else
            $temp->visible = '<?php echo "$mform->addElement("checkbox", "ratingtime.$activity->id", "try");" ?>';
            //$temp->visible = '<label class="switch">'. html_writer::empty_tag('input', array('id' => $activity->id,'type' => 'checkbox', 'name' => 'fieldname')) . '<span class="slider"></span></label>';
        array_push($arrayBack, $temp);
    }
    return $arrayBack;
}
function displayActivities($activities, $mform){
    $table = new html_table();
    $table->head = array("Activity module", "Version", "Count", "Hide/Show");
    $data = dataProcessing($activities, $mform);  
    $table->data = $data;
    echo html_writer::table($table);
}

I have already looked at this topic but it doesn't really help me : https://moodle.org/mod/forum/discuss.php?d=255722

Thank you in advance for you help.

Have a great day.

 
Average of ratings: -