Customizing/adding the displayed items

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago - 14 years 8 months ago #1 by John Evergrey
Customizing/adding the displayed items was created by John Evergrey
Hi guys,

I have found a way to show more information about practically anything that is stored in moodle and showing it in Joomla. However I have still a bit problems to link the elements correctly.


For starters I am trying to customize the view where logged in user sees his/hers grades from a specific course. There are currently 2 variables -> finalgrade and itemname, and I would like to add the time, when the graded activity was created or modified.

There are three files which need to be edited in order to work. These are:
in Moodle directory -> auth/joomdle/auth.php from line 1309
auth/joomdle/helpers/externallib.php from line 568
in Joomla directory -> components/com_joomdle/views/coursegrades/tmpl/default.php

Main changes has to be made in auth.php

This is the code I am working on and need some help with it.
Code:
function get_user_grades ($user,$cid) { global $CFG, $DB; $user = utf8_decode ($user); $user = get_complete_user_data ('username', $user); $uid = $user->id; $SQL = "SELECT g.itemid, g.finalgrade,gi.courseid,gi.itemname,gi.id, g.timemodified FROM {$CFG->prefix}grade_items gi JOIN {$CFG->prefix}grade_grades g ON g.itemid = gi.id JOIN {$CFG->prefix}user u ON u.id = g.userid JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id WHERE g.finalgrade IS NOT NULL AND u.id = ? AND gi.courseid = ? GROUP BY g.itemid"; $sum_array = array(); $params = array ($uid, $cid); if ($sums = $DB->get_records_sql($SQL, $params)) { $i = 0; $rdo = array (); foreach ($sums as $sum) { if (! $grade_grade = grade_grade::fetch(array('itemid'=>$sum->id,'userid'=>$uid))) { $grade_grade = new grade_grade(); $grade_grade->userid = $this->user->id; $grade_grade->itemid = $grade_object->id; } $grade_item = $grade_grade->load_grade_item(); $sums2[$i] = $sum; $scale = $grade_item->load_scale(); $formatted_grade = grade_format_gradevalue($sums2[$i]->finalgrade, &$grade_item, true, GRADE_DISPLAY_TYPE_REAL); $timemodified = time(); $sums2[$i]->finalgrade = $formatted_grade; $sums2[$i]->timemodified = $timemodified; $rdo[$i]['itemname'] = $sum->itemname; $rdo[$i]['finalgrade'] = $formatted_grade; $rdo[$i]['timemodified'] = $timemodified; $i++; } return $rdo; return $sums2; } return array(); }

I have created new variable to get the date with the grade. But I am not sure how to tell it what to show exactly. The finalgrade variable above the timemodified is clear and I know what it does so I am looking for a way to tell the timemodified variable to show the time the item was modified. Now it's only showing current time.

Thank you for your answers.
Last edit: 14 years 8 months ago by John Evergrey.

Please Log in or Create an account to join the conversation.

More
14 years 8 months ago #2 by Chris
Replied by Chris on topic Re: Customizing/adding the displayed items
Hi there,

Antonio is on holidays at the moment. Thus you will need to wait for a few more weeks before he is able to reply on programming related assistance.

Chris

Please Log in or Create an account to join the conversation.

More
14 years 8 months ago #3 by Antonio Durán
Replied by Antonio Durán on topic Re: Customizing/adding the displayed items
Hi.

It seems you did it correctly, not sure why it won't show the right time...

Have you re-checked that the date in timemodified field in grades tables is set?
I looked at my db and it contains NULL.

Please Log in or Create an account to join the conversation.

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago #4 by John Evergrey
Replied by John Evergrey on topic Re: Customizing/adding the displayed items
Hi,

I have checked the db and in both tables - grade_grades and grade_items in Moodle I have timemodified values expressed like 1322014102. So I think that it should work.

However I know that my example which I posted above is not correct because of this line:

$timemodified = time();

that tells Joomdle to display current time. I am looking for something like this:

$formatted_grade = grade_format_gradevalue($sums2[$i]->finalgrade, &$grade_item, true, GRADE_DISPLAY_TYPE_REAL);

where you specifically say what grade and in which format will be displayed.

Thank you for your answer Antonio, I much appreciate it!!!

V.

Please Log in or Create an account to join the conversation.

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago #5 by John Evergrey
Replied by John Evergrey on topic Re: Customizing/adding the displayed items
Hey,

I figured it out!!! It is working now! Here is the only line which needed to be added:

$rdo[$i] = $sum->timemodified;

And it works. But I am not sure how to translate the tome from database which is in format 13021055705 to something more user-friendly like 2011-03-05.

Thank you so much!!!

Please Log in or Create an account to join the conversation.

More
14 years 8 months ago #6 by Antonio Durán
Replied by Antonio Durán on topic Re: Customizing/adding the displayed items
Good.

You can look here, to see how Joomdle converts moodle dates to human friendly form:
components/com_joomdle/views/courseevents/tmpl/default.php

Please Log in or Create an account to join the conversation.

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago #7 by John Evergrey
Replied by John Evergrey on topic Re: Customizing/adding the displayed items
YES!! That did it. Thank you for the hint :).

Now the only thing left is to add the feedback field and it will be good to go :)

Please Log in or Create an account to join the conversation.

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago - 14 years 8 months ago #8 by John Evergrey
Replied by John Evergrey on topic Re: Customizing/adding the displayed items
Hi Antonio,

I was playing with the code, but I can't seem to make feedback working. I have added the g.feedback to the SQL variable but when typing the same code I used for displaying time I get an API error. I guess I have to use another way to show the feedback. I was trying to write that code and now I don't get any API errors, but the site doesn't display the feedback. Here is the code so you can see:
Code:
function get_user_grades ($user,$cid) { global $CFG, $DB; $user = utf8_decode ($user); $user = get_complete_user_data ('username', $user); $uid = $user->id; $SQL = "SELECT g.itemid, g.finalgrade,gi.courseid,gi.itemname,gi.id, g.timecreated, g.feedback FROM {$CFG->prefix}grade_items gi JOIN {$CFG->prefix}grade_grades g ON g.itemid = gi.id JOIN {$CFG->prefix}user u ON u.id = g.userid JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id WHERE g.finalgrade IS NOT NULL AND u.id = ? AND gi.courseid = ? GROUP BY g.itemid"; $sum_array = array(); $params = array ($uid, $cid); if ($sums = $DB->get_records_sql($SQL, $params)) { $i = 0; $rdo = array (); foreach ($sums as $sum) { if (! $grade_grade = grade_grade::fetch(array('itemid'=>$sum->id,'userid'=>$uid))) { $grade_grade = new grade_grade(); $grade_grade->userid = $this->user->id; $grade_grade->itemid = $grade_object->id; } $grade_item = $grade_grade->load_grade_item(); $sums2[$i] = $sum; $scale = $grade_item->load_scale(); $formatted_grade = grade_format_gradevalue($sums2[$i]->finalgrade, &$grade_item, true, GRADE_DISPLAY_TYPE_REAL); $sums2[$i]->finalgrade = $formatted_grade; $sums2[$i]->feedback = $feedback; $feedback = $sum->feedback; $rdo[$i]['itemname'] = $sum->itemname; $rdo[$i]['finalgrade'] = $formatted_grade; $rdo[$i]['timecreated'] = $sum->timecreated; $rdo[$i]['feedback'] = $feedback; $i++; } return $rdo; return $sums2; } return array(); }

I tried to use similar technique you used for displaying the grade. Can you please help me out with this? Thank you very much!
Last edit: 14 years 8 months ago by John Evergrey. Reason: Adding the piece of code

Please Log in or Create an account to join the conversation.

More
14 years 8 months ago #9 by Antonio Durán
Replied by Antonio Durán on topic Re: Customizing/adding the displayed items
Don't really know what is your problem, but the feedback would be a string or a text, i guess, so you would have to define it like that on the function definition, and show it like text, not like a date.

Please Log in or Create an account to join the conversation.

  • John Evergrey
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
14 years 8 months ago - 14 years 8 months ago #10 by John Evergrey
Replied by John Evergrey on topic Re: Customizing/adding the displayed items
Ok, bu I think that it should be the same as itemname, because that is string too. So how does feedback and itemname differ? There are both strings. The only difference I can see is that the itemname was already in the SQL query and I added the feedback. There may be an error there.

UPDATE: Ok, I got it. There was not problem in the code. The code was correct. The problem was with the text in the feedback. It contained some HTML tags and that was messing it up. Thank you again for your help.

BTW: Do you have any experience with any lightbox plugins which I can use to show the information like final grade and feedback when I click an image or a link?
Last edit: 14 years 8 months ago by John Evergrey. Reason: Problem solved

Please Log in or Create an account to join the conversation.