Hello,
The best option to control content of "my" section and prevent users from changing settings is:
- Add in config.php this line:
$CFG->forcedefaultmymoodle = true;
Best regards,
Iban Cardona.
Iban Cardona i Subiela
Tuesday 25 July 2017
Thursday 13 July 2017
Moodle: Change course name in breadcrumb
Hello,
If you want to modify the text of the a course in the breadcrumb you can do this (tested in Moodle 3.2):
Add this function in your file lib.php of your local plugin:
function local_yourlocalplugin_extend_navigation(global_navigation $nav) {
global $COURSE, $CFG;
if (isset($COURSE->id) && $COURSE->id > 0) {
$coursenode = $nav->find($COURSE->id, navigation_node::TYPE_COURSE);
if ($coursenode) {
$coursenode->text .= ' My extra text';
}
}
}
Best regards!
If you want to modify the text of the a course in the breadcrumb you can do this (tested in Moodle 3.2):
Add this function in your file lib.php of your local plugin:
function local_yourlocalplugin_extend_navigation(global_navigation $nav) {
global $COURSE, $CFG;
if (isset($COURSE->id) && $COURSE->id > 0) {
$coursenode = $nav->find($COURSE->id, navigation_node::TYPE_COURSE);
if ($coursenode) {
$coursenode->text .= ' My extra text';
}
}
}
Best regards!
Monday 15 May 2017
Moodle & PHPUnit: Capture events
Hello,
If you want to tests events in Moodle using PHPUnit, the best method is:
public function test_creationg_event() {
$this->resetAfterTest();
$event_sink = $this->redirectEvents();
$course = $this->getDataGenerator()->create_course();
$events = $event_sink->get_events();
$event_sink->close();
$event = $events[0];
$this->assertInstanceOf('\core\event\course_created', $event);
}
Best regards!
If you want to tests events in Moodle using PHPUnit, the best method is:
public function test_creationg_event() {
$this->resetAfterTest();
$event_sink = $this->redirectEvents();
$course = $this->getDataGenerator()->create_course();
$events = $event_sink->get_events();
$event_sink->close();
$event = $events[0];
$this->assertInstanceOf('\core\event\course_created', $event);
}
Best regards!
Tuesday 25 April 2017
Moodle: Block settings not shown for students
Hello,
If you want to disable (not shown) settings block for students in Moodle, you can do it changing the renderer in your theme. This code is valid only for themes not based on Boost.
Add this function in the core_renderer class of your theme:
public function block(block_contents $bc, $region) {
global $DB;
$idblock = isset($bc->attributes['id']) ? $bc->attributes['id'] : '';
$arr_aux = explode('inst', $idblock);
if (isset($arr_aux[1])) {
$block_instance = $DB->get_record('block_instances', array('id' => $arr_aux[1]));
$context_course = context_course::instance($this->page->course->id);
if (isset($block_instance->blockname) && $block_instance->blockname == 'settings') {
if (!has_capability('moodle/grade:viewall', $context_course)) {
return '';
}
}
}
return parent::block($bc, $region);
}
Best regards,
Iban Cardona.
If you want to disable (not shown) settings block for students in Moodle, you can do it changing the renderer in your theme. This code is valid only for themes not based on Boost.
Add this function in the core_renderer class of your theme:
public function block(block_contents $bc, $region) {
global $DB;
$idblock = isset($bc->attributes['id']) ? $bc->attributes['id'] : '';
$arr_aux = explode('inst', $idblock);
if (isset($arr_aux[1])) {
$block_instance = $DB->get_record('block_instances', array('id' => $arr_aux[1]));
$context_course = context_course::instance($this->page->course->id);
if (isset($block_instance->blockname) && $block_instance->blockname == 'settings') {
if (!has_capability('moodle/grade:viewall', $context_course)) {
return '';
}
}
}
return parent::block($bc, $region);
}
Best regards,
Iban Cardona.
Wednesday 22 February 2017
Moodle: moodle_form inside module: Edit or new?
Hello,
Sometimes inside a custom Moodle module we need to know if we are editing or creating a new module (activity or resource) instance... Here the solution:
function definition() {
global $CFG, $DB;
$mform =& $this->_form;
if (is_numeric($this->_instance) && $this->_instance && $mymodule = $DB->get_record("mymodule", array("id"=>$this->_instance))) {
$mform->addElement('header', 'general', 'Editing');
} else {
$mform->addElement('header', 'general', 'Creating');
}
...
Best regards,
Iban Cardona.
Sometimes inside a custom Moodle module we need to know if we are editing or creating a new module (activity or resource) instance... Here the solution:
function definition() {
global $CFG, $DB;
$mform =& $this->_form;
if (is_numeric($this->_instance) && $this->_instance && $mymodule = $DB->get_record("mymodule", array("id"=>$this->_instance))) {
$mform->addElement('header', 'general', 'Editing');
} else {
$mform->addElement('header', 'general', 'Creating');
}
...
Best regards,
Iban Cardona.
Saturday 7 January 2017
Moodle: Download exact commit from git
Hello,
If you want to manage a source code from Moodle of a specific commit, you need to do:
Best regards!
If you want to manage a source code from Moodle of a specific commit, you need to do:
- Install git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- Find the commit to download in https://github.com/moodle/moodle . In my case I found this: https://github.com/moodle/moodle/commit/89117976b8afd75c588b8b3908f763aab2edfb6a#diff-5bbd3ccd25214f9956eea7e9f714bc08
- Download the Moodle code: git clone https://github.com/moodle/moodle.git my_moodle
- Copy the ID of the commit: 89117976b8afd75c588b8b3908f763aab2edfb6a
- Checkout the commit:
- cd my_moodle
- git checkout 89117976b8afd75c588b8b3908f763aab2edfb6a
Best regards!
Monday 22 August 2016
Laravel : Get SQL of a DB object
Hello,
How to print SQL (Select statement) of DB Object in Laravel:
$sql = DB::table('users');
echo $sql->toSql();
Best regards,
Iban Cardona.
How to print SQL (Select statement) of DB Object in Laravel:
$sql = DB::table('users');
echo $sql->toSql();
Best regards,
Iban Cardona.
Subscribe to:
Posts (Atom)