Hi,
I'm just wondering if the following are possible to do within a block, and how to go about doing them..
When a block is first installed, I want to generate a random string and insert it into a database table. Is it possible to detect when a block is first installed within a course and where would the code go for this?
Is it possible to output the time/date of when cron last ran on the main interface of a block? Ideally this would go in the get_content() function?
Thanks
Update:
I solved the first query of generating a random string to insert into a table.
I am still trying to figure out the following:
Is it possible to output the time/date of when cron last ran on the main interface of a block?
How to determine when a course starts/ends? In the context of a course beginning every academic year (same taught course but different students/maybe different resources), how to determine this and to clean out database from previous year?
Hope this make sense.
I solved the first query of generating a random string to insert into a table.
I am still trying to figure out the following:
Is it possible to output the time/date of when cron last ran on the main interface of a block?
How to determine when a course starts/ends? In the context of a course beginning every academic year (same taught course but different students/maybe different resources), how to determine this and to clean out database from previous year?
Hope this make sense.
Hi Megan, yeah it's possible to output the time/date. Check the data base table where the plugin's cron is store, then select the last run timestamp column. There are PHP functions to convert timestamp to a readable time/date. HTH
Hi Alejandro,
I found the mdl_block data base table which stores plugins and the last cron timestamp column, but my block is not listed in the table. How do I add it to the table? When I run my cron function at the moment, I am usually running it manually from cron.php for testing.
Thanks,
Megan
I found the mdl_block data base table which stores plugins and the last cron timestamp column, but my block is not listed in the table. How do I add it to the table? When I run my cron function at the moment, I am usually running it manually from cron.php for testing.
Thanks,
Megan
I've solved this
Megan,
What version of Moodle are we talking about? In Moodle 2.0 you can have a script called db/install.php in any plugin that runs after installation. I don't think there's such a thing in 1.9 unfortunately
What version of Moodle are we talking about? In Moodle 2.0 you can have a script called db/install.php in any plugin that runs after installation. I don't think there's such a thing in 1.9 unfortunately
I am using 1.9 and so are the party I'm developing for. Thanks anyway
In Moodle 1.9, blocks have an after_install method that is called when the block is installed, and an instance_create method that is called when a block instance is created.
Megan, remember to upgrade your block version (in version.php) when you modify the cron time. That will update the mdl_block table with your new cron time value.
Alejandro, I just have the following in my block.php
function init() {
$this->title = get_string('blockname', 'block_myblock');
$this->version = 2011013000;
$this->cron = 300;
}
I am using Moodle 1.9 so I am not sure I require a version.php
function init() {
$this->title = get_string('blockname', 'block_myblock');
$this->version = 2011013000;
$this->cron = 300;
}
I am using Moodle 1.9 so I am not sure I require a version.php