Closed (fixed)
Project:
Closed Question
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Jul 2011 at 09:16 UTC
Updated:
22 Aug 2011 at 12:53 UTC
The following XML, generated by the Editor, results in a fatal error:
Fatal error: Call to a member function getIdentifier() on a non-object in /var/www/www.wmmrc.nl/drupal/sites/all/modules/closedquestion/question/CqQuestion... on line 187
<?xml version="1.0"?>
<question type="dragdrop">
<text>Drag the items to the corresponding locations on the image.</text>
<matchimg src="[attachurl:P.Q7.png]" height="100" width="100">
<hotspot shape="rect" coords="9,7,401,68" id="h1"/>
<hotspot shape="rect" coords="9,143,401,81" id="h2"/>
<hotspot shape="rect" coords="7,159,401,222" id="h3"/>
<draggable id="d1">Draggable 1</draggable>
<draggable id="d2">Draggable 2</draggable>
<draggable id="d3">Draggable 3</draggable>
<hotspot/>
<hotspot/>
<hotspot/>
<hotspot/>
<draggable id="d4"/>
<draggable id="d5"/>
<draggable id="d6"/>
<draggable id="d7"/>
</matchimg>
<hint mintries="1">A first hint.</hint>
<hint mintries="2">A second hint.</hint>
<hint mintries="3">A third hint.</hint>
<mapping correct="1">
<match hotspot="h1" draggable="d1"/>
<match hotspot="h2" draggable="d2"/>
<match hotspot="h3" draggable="d3"/>
<feedback>Correct. You have put the items at the right locations.</feedback>
</mapping>
<mapping correct="0">
<match hotspot="h.*" draggable="d[0-9]"/>
<feedback>You have at least one draggable on one hotspot.</feedback>
</mapping>
<mapping correct="0">
<match hotspot="h1" draggable="d[0-9]"/>
<feedback>You have at least one draggable on hotspot 1.</feedback>
</mapping>
<mapping correct="0">
<match hotspot="h.*" draggable="d1"/>
<feedback>You have draggable 1 on a hotspot.</feedback>
</mapping>
</question>
The relevant code reads (the error occurs at the if):
case 'hotspot':
$hotspot = cq_Hotspot_from_xml($child, $this);
if (isset($this->hotspots[$hotspot->getIdentifier()])) {
drupal_set_message(t('Hotspot identifier %identifier used more than once!', array('%identifier' => $hotspot->getIdentifier())), 'warning');
}
$this->hotspots[$hotspot->getIdentifier()] = $hotspot;
break;
Comments
Comment #0.0
jvdkolk commentedForgot the error :)
Comment #0.1
jvdkolk commentedAdded php code
Comment #1
jvdkolk commentedSo the editor should forbid empty hotspots to exist / make sure that no empty hotspot will ever exist (mandatory_attributes in the config?)
And the server-side code should - imho - not give a fatal error, but a warning telling the user what to do to solve the problem.
Comment #2
HylkeVDS commentedI've fixed it in dev by adding a check to see of the hotspot is valid. It already gave a warning that the hotspot type was unknown, but that warning was not visible due to the fatal error.
Comment #2.0
HylkeVDS commentedWrong XML provided (ja, goed bezig vanochtend ;)