evergrey Posted August 6, 2011 Share Posted August 6, 2011 Hi guys, I have this problem: I have connected Moodle with Joomla and I ma transferring specific pieces from the database. One of these pieces is the Feedback from grades. The feedback is written in Moodle using JCE editor which stores it in the HTML format When I try to call on the feedback using code: <?php echo $tarea['feedback']; ?> I get an API error because the feedback contains characters like <p>, <li> etc. When I manually remove these it works but all I get is unformatted plain text. Is there a way how to persuade the database, Moodle and anything that needs to be changed, to display the feedback including HTML? Just to clarify things, here are the codes I use to get data from Moodle to Joomla: auth.php 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 ORDER BY g.timecreated DESC"; $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; $rdo[$i]['itemname'] = $sum->itemname; $rdo[$i]['finalgrade'] = $formatted_grade; $rdo[$i]['timecreated'] = $sum->timecreated; $rdo[$i]['feedback'] = $sum->feedback; $rdo[$i]['itemid'] = $sum->itemid; $i++; } return $rdo; return $sums2; } return array(); } This is the translator: externallib.php /* get_user_grades */ public static function get_user_grades_parameters() { return new external_function_parameters( array( 'user' => new external_value(PARAM_TEXT, 'username'), 'id' => new external_value(PARAM_INT, 'course id'), ) ); } public static function get_user_grades_returns() { return new external_multiple_structure( new external_single_structure( array( 'itemname' => new external_value(PARAM_TEXT, 'item name'), 'finalgrade' => new external_value(PARAM_TEXT, 'final grade'), 'timecreated' => new external_value(PARAM_INT, 'timecreated'), 'feedback' => new external_value(PARAM_TEXT, 'feedback'), 'itemid' => new external_value(PARAM_INT, 'itemid'), ) ) ); } public static function get_user_grades($user, $id) { global $CFG, $DB; $params = self::validate_parameters(self::get_user_grades_parameters(), array('user' => $user, 'id'=>$id)); $auth = new auth_plugin_joomdle (); $return = $auth->get_user_grades ($user, $id); return $return; } and this is the code to display it in Joomla: <?php echo $tarea['feedback']; ?> Thanks in advance for your answers!! Quote Link to comment https://forums.phpfreaks.com/topic/244021-storing-html-in-the-database-moodle-joomla/ Share on other sites More sharing options...
MasterACE14 Posted August 6, 2011 Share Posted August 6, 2011 could try using htmlentities() on $tarea['feedback'] : <?php echo htmlentities($tarea['feedback']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244021-storing-html-in-the-database-moodle-joomla/#findComment-1253142 Share on other sites More sharing options...
evergrey Posted August 6, 2011 Author Share Posted August 6, 2011 Thank you for your quick answer, sadly this returns the same error: XML-RPC Error (0): Invalid external api response: feedback (Invalid external api response) Quote Link to comment https://forums.phpfreaks.com/topic/244021-storing-html-in-the-database-moodle-joomla/#findComment-1253146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.