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

jvdkolk’s picture

Issue summary: View changes

Forgot the error :)

jvdkolk’s picture

Issue summary: View changes

Added php code

jvdkolk’s picture

Title: Fatal error: Call to a member function getIdentifier() on a non-object in /var/www/www.wmmrc.nl/drupal/sites/all/modules/closedq » Empty <hotspot/> are the cause

So 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.

HylkeVDS’s picture

Status: Active » Closed (fixed)

I'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.

HylkeVDS’s picture

Issue summary: View changes

Wrong XML provided (ja, goed bezig vanochtend ;)