/** * Sets the evidence data for the passed in loc var ID * */ function doSetEvidence($geneName, $name, $type, $value) { // init a evidence data element $evidence = null; // init a index $i = 0; // get the user info object from the session $userObj = getUserSessionObj(); // do we have a evidence object if (isset($userObj->Evidence)) { // find the evidence if it exists foreach ($userObj->Evidence as $item) { // is this the one we are looking for if ($item->geneName == $geneName) { // save the evidence $evidence = $item; // no need to continue break; } //increment the index counter $i++; } } // does the evidence already exist if (isset($evidence)) { // overwrite the current value $userObj->Evidence[$i]->value = $value; echo '{"error": "doSetEvidence(' . $geneName . ') - Data overwritten"}'; } else { // create a new evidence object $evidence = new Evidence(); // save the data in the object $evidence->setData($geneName, $name, $value, $type); // and save it to the user object $userObj->Evidence[] = $evidence; // encode and send the data echo '{"data":' . json_encode($evidence) . '}'; } // terminate the data stream die; }