diff --git a/htdocs/survey-react.php b/htdocs/survey-react.php index ec6246e740f..82fc70a32be 100644 --- a/htdocs/survey-react.php +++ b/htdocs/survey-react.php @@ -243,8 +243,10 @@ function display() $factory = \NDB_Factory::singleton(); $config = $factory->config(); $json_class = new NDB_BVL_Instrument_JSON(); + $json_class->setup($this->CommentID); $base = $config->getSetting('base'); $json = file_get_contents($base."project/instruments/$this->TestName.json"); + //$json = $json_class->loadInstrumentFile($base."project/instruments/$this->TestName.json"); //TODO $this->updateStatus('In Progress'); $this->tpl_data['lang'] = $json_class->_getLang(); $this->tpl_data['json'] = htmlspecialchars($json); diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index be6bbd6e8b5..fbcc234fa79 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -37,6 +37,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument { $this->commentID = $commentID; $this->page = $page; + parent::setup($commentID, $page); } /** @@ -46,16 +47,35 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument * @return array containing context variables */ function _getContext() { + $timepoint = \TimePoint::singleton($this->getSessionID()); + $candID = $timepoint->getCandID(); + $candidate = \Candidate::singleton($candID); + $dob = $candidate->getCandidateDoB(); + $dobDT = new \DateTime($dob); + $curDate = new \DateTime("now"); + $interval = date_diff($curDate, $dobDT, true); + $ageM = $this->calculateAgeMonths(array('year' => $interval->format("%y"), + 'mon' => $interval->format("%m"), + 'day' => $interval->format("%d"))); + //$ageTEST = $this->getCandidateAge($curDate); //TODO replace the hacky age function with this + $gender = $candidate->getCandidateGender(); return array( - "age_mths" => 200 + "age_mths" => $ageM, + "dob" => $dob, + "gender" => $gender ); } function _getLang() { - // This should grab lang from the timepoint associated with this instrument instance - return 'en-ca'; + //$timepoint = \TimePoint::singleton($this->getSessionID()); + //$candID = $timepoint->getCandID(); + //$candidate = \Candidate::singleton($candID); + //$lang = $candidate->getCandidateLanguage(); + $lang = "en-ca"; + return $lang ? $lang : "en-ca"; } + function _getInstrumentData($db) { $result = $db->pselect( "SELECT * FROM $this->table WHERE CommentID=:CID", @@ -83,6 +103,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $this->instrument = json_decode($json, true); $this->instrument["Elements"] = self::inlineCalcFormulas($this->instrument["Elements"]); $this->table = $this->instrument['Meta']['ShortName']; + $this->testName = $this->table; return $json; } }