1
class block_add extends block_base {

    function init() {
        $this->title = get_string('pluginname', 'block_add');

    }

    function applicable_formats() {
        return array('all' => true, 'tag' => false);
    }

    function specialization() {
        $this->title = isset($this->config->title) ? $this->config->title : get_string('newblock', 'block_add');
    }

    function instance_allow_multiple() {
        return true;
    }

    function get_content() {

        global $USER,$DB;

        if ($this->content !== NULL) {
            return $this->content;
        }

        $this->content = new stdClass();
        $this->content->footer= $DB->get_records('role_assignments', ['userid' => $user->id]);
        return $this->content;
    }
    
    function has_config() {return true;}
}

I am a newbie getting stuck at this, kindly help me in this, not getting value from DB in my block, i am new to moodle as well as in php($this->content->footer= $DB->get_records('role_assignments', ['userid' => $user->id]);).

vee
  • 4,506
  • 5
  • 44
  • 81
  • First of all - you need to turn on debugging - https://docs.moodle.org/en/debugging and it would tell you that $user->id is undefined ($USER->id is what you want). Secondly, $this->content->footer only works when it contains text. You cannot pass it an array of objects and expect it to output it successfully. You need to loop through the data returned by $DB->get_records() and format it in some way, before you can output it onto the page. – davosmith Sep 13 '22 at 07:37
  • Does this answer your question? [I want to print all user role by id into my footer](https://stackoverflow.com/questions/73692465/i-want-to-print-all-user-role-by-id-into-my-footer) – Russell England Sep 13 '22 at 08:23

0 Answers0