Borja,
Thanks for sharing the code. I am in the process of reviewing/testing it. The first thing I found was the following PHP notice.
Notice: Undefined property: stdClass::$pinned in /home/arborrow/Moodle/code/19stable/blocks/dedication/block_dedication.php on line 50
To catch these, I turn debugging mode on and set it to show All reasonable errors (not developer mode). I'll continue to comment as I find others. Generally speaking it is important to check the a variable is set or defined before using it. I find it helpful to initialize variables especially if they are optional params. Let me know if you have questions or need help fixing it. I would probably add the following line around line 14:
$this->instance->pinned = 0; //initialize to zero if not already defined
since you have already checked if it was empty and then set the context, I would then initialize it to zero so that when you use it later you do not get the PHP notice.
Once I did that, I clicked on calculate and received the following PHP Warning:
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 353
Again, this is likely due to not checking for the existence of something before using it in a foreach statement.
I would replace that foreach with something like:
if (!empty($students)) { //if there are no students then there is no need to print them, you could also add an else statement here and output that there are no student enrolled
foreach ($students as $student) {
$name = "<a href='$baseurl&userid=".$student->id."'>".$student->lastname.', '.$student->firstname.'</a>';
$table->data[] = array ($name);
}
}
Other warnings I found were:
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 228
Warning: array_shift() [function.array-shift]: The argument should be an array in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 118
Notice: Trying to get property of non-object in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 119
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 125
All that said, I see nothing preventing the code from being added to CVS. I will create a component in the tracker called Block: Dedication. I will bump your privileges in the tracker so that you can manage issues assigned to you. Any bugs, feature requests, etc. created for the Block: Dedication component in the CONTRIB section of the tracker will automatically be assigned to you. An email will be sent to you letting you know of the issue which helps keep you informed. The next thing to do (if you have not already) is to go to http://moodle.org/cvs/ and request CVS write access for contrib/plugins/blocks/dedication. If you could, comment here that you have done so and I will make sure to go in and approve that request. Once you have CVS write access you can test it by doing some of the above fixes. Generally speaking, I recommend having a tracker issue for any changes you make to your code as it helps with documentation. When you make a commit, there is an opportunity to add a comment describing what that commit is for. I recommend beginning the commit with the tracker issue number. For example, when I add the code to CVS you will see that I begin it with CONTRIB-982. As a result, when I look at this issue I'll be able to see the files that were changed related to this commit. Finally, I would encourage you to review http://docs.moodle.org/en/Development:Guidelines_for_contributed_code and follow the instructions (again, if you have not already done so) to add an entry in the Moodle.org Modules and Plugins database, create a documentation page for the Dedication block, etc. I realize that there are several steps and it can seem like a lot to learn from the beginning but attention to detail especially at the beginning really can make a big difference in helping to ensure that your code is well supported and shared with the community so that they have a positive initial experience with it. Do not hesitate to let me know if you have any questions or need help with these steps as that is part of my role as CONTRIB Coordinator. Thanks again for sharing your time and talent with the community.
Peace - Anthony
p.s. - I noticed there was a 1.6 version; however, I am not going to add that at this time. Most folks are on either 1.8 and 1.9. However, if you want me to add it just let me know and we can create a MOODLE_16_STABLE branch for this block. With CONTRIB code, I usually consider HEAD to be the development version and we start with that. If you find that it would be helpful to also have a 1.9 branch just let me know.
Borja,
Thanks for sharing the code. I am in the process of reviewing/testing it. The first thing I found was the following PHP notice.
Notice: Undefined property: stdClass::$pinned in /home/arborrow/Moodle/code/19stable/blocks/dedication/block_dedication.php on line 50
To catch these, I turn debugging mode on and set it to show All reasonable errors (not developer mode). I'll continue to comment as I find others. Generally speaking it is important to check the a variable is set or defined before using it. I find it helpful to initialize variables especially if they are optional params. Let me know if you have questions or need help fixing it. I would probably add the following line around line 14:
$this->instance->pinned = 0; //initialize to zero if not already defined
since you have already checked if it was empty and then set the context, I would then initialize it to zero so that when you use it later you do not get the PHP notice.
Once I did that, I clicked on calculate and received the following PHP Warning:
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 353
Again, this is likely due to not checking for the existence of something before using it in a foreach statement.
I would replace that foreach with something like:
if (!empty($students)) { //if there are no students then there is no need to print them, you could also add an else statement here and output that there are no student enrolled
foreach ($students as $student) { $name = "<a href='$baseurl&userid=".$student->id."'>".$student->lastname.', '.$student->firstname.'</a>'; $table->data[] = array ($name); }
}
Other warnings I found were:
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 228
Warning: array_shift() [function.array-shift]: The argument should be an array in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 118
Notice: Trying to get property of non-object in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 119
Warning: Invalid argument supplied for foreach() in /home/arborrow/Moodle/code/19stable/blocks/dedication/dedication.php on line 125
All that said, I see nothing preventing the code from being added to CVS. I will create a component in the tracker called Block: Dedication. I will bump your privileges in the tracker so that you can manage issues assigned to you. Any bugs, feature requests, etc. created for the Block: Dedication component in the CONTRIB section of the tracker will automatically be assigned to you. An email will be sent to you letting you know of the issue which helps keep you informed. The next thing to do (if you have not already) is to go to http://moodle.org/cvs/ and request CVS write access for contrib/plugins/blocks/dedication. If you could, comment here that you have done so and I will make sure to go in and approve that request. Once you have CVS write access you can test it by doing some of the above fixes. Generally speaking, I recommend having a tracker issue for any changes you make to your code as it helps with documentation. When you make a commit, there is an opportunity to add a comment describing what that commit is for. I recommend beginning the commit with the tracker issue number. For example, when I add the code to CVS you will see that I begin it with
CONTRIB-982. As a result, when I look at this issue I'll be able to see the files that were changed related to this commit. Finally, I would encourage you to review http://docs.moodle.org/en/Development:Guidelines_for_contributed_code and follow the instructions (again, if you have not already done so) to add an entry in the Moodle.org Modules and Plugins database, create a documentation page for the Dedication block, etc. I realize that there are several steps and it can seem like a lot to learn from the beginning but attention to detail especially at the beginning really can make a big difference in helping to ensure that your code is well supported and shared with the community so that they have a positive initial experience with it. Do not hesitate to let me know if you have any questions or need help with these steps as that is part of my role as CONTRIB Coordinator. Thanks again for sharing your time and talent with the community.Peace - Anthony
p.s. - I noticed there was a 1.6 version; however, I am not going to add that at this time. Most folks are on either 1.8 and 1.9. However, if you want me to add it just let me know and we can create a MOODLE_16_STABLE branch for this block. With CONTRIB code, I usually consider HEAD to be the development version and we start with that. If you find that it would be helpful to also have a 1.9 branch just let me know.
CONTRIB-982. As a result, when I look at this issue I'll be able to see the files that were changed related to this commit. Finally, I would encourage you to review http://docs.moodle.org/en/Development:Guidelines_for_contributed_code and follow the instructions (again, if you have not already done so) to add an entry in the Moodle.org Modules and Plugins database, create a documentation page for the Dedication block, etc. I realize that there are several steps and it can seem like a lot to learn from the beginning but attention to detail especially at the beginning really can make a big difference in helping to ensure that your code is well supported and shared with the community so that they have a positive initial experience with it. Do not hesitate to let me know if you have any questions or need help with these steps as that is part of my role as CONTRIB Coordinator. Thanks again for sharing your time and talent with the community. Peace - Anthony p.s. - I noticed there was a 1.6 version; however, I am not going to add that at this time. Most folks are on either 1.8 and 1.9. However, if you want me to add it just let me know and we can create a MOODLE_16_STABLE branch for this block. With CONTRIB code, I usually consider HEAD to be the development version and we start with that. If you find that it would be helpful to also have a 1.9 branch just let me know.