diff --git a/modules/behavioural_qc/jsx/tabs_content/behaviouralFeedback.js b/modules/behavioural_qc/jsx/tabs_content/behaviouralFeedback.js index a07018eaec..e003d338d3 100644 --- a/modules/behavioural_qc/jsx/tabs_content/behaviouralFeedback.js +++ b/modules/behavioural_qc/jsx/tabs_content/behaviouralFeedback.js @@ -4,6 +4,26 @@ import Loader from 'jsx/Loader'; import FilterableDataTable from 'jsx/FilterableDataTable'; import {withTranslation} from 'react-i18next'; +/** + * Build a URL with query parameters. + * + * @param {string} baseURL - LORIS base URL. + * @param {string} path - The URL path. + * @param {object} params - Query parameters to append. + * @return {string} the URL with query parameters. + */ +const buildURL = (baseURL, path, params) => { + const query = new URLSearchParams(); + + Object.entries(params).forEach(([key, value]) => { + if (value !== undefined && value !== null && value !== '') { + query.append(key, value); + } + }); + + return baseURL + path + (query.toString() ? '?' + query.toString() : ''); +}; + /** * Behavioural Feedback Component. * @@ -88,6 +108,7 @@ class BehaviouralFeedback extends Component { const labelInstrument = t('Instrument', {ns: 'loris', count: 1}); const labelTestName = t('Test Name', {ns: 'behavioural_qc'}); const labelVisit = t('Visit', {ns: 'loris'}); + const candID = rowData[labelDCCID]; // PSCID column (match English or translated) if (column === 'PSCID' || column === labelPSCID) { @@ -117,26 +138,64 @@ class BehaviouralFeedback extends Component { if (column === 'Feedback Level' || column === labelBVL) { let bvlLink = ''; let bvlLevel = ''; - if (rowData[labelInstrument]) { - bvlLink = this.props.baseURL + - '/instruments/' + - rowData[labelTestName] + - '/?candID=' + rowData[labelDCCID] + - '&sessionID=' + rowData['sessionID'] + - '&commentID=' + rowData['commentID'] + - '&showFeedback=true'; + const feedbackLevel = rowData[labelBVL]; + const sessionID = rowData['sessionID']; + const commentID = rowData['commentID']; + const testName = rowData[labelTestName]; + const instrument = rowData[labelInstrument] || testName || commentID; + const hasSession = sessionID !== undefined + && sessionID !== null + && sessionID !== '' + && sessionID !== 0 + && sessionID !== '0'; + + if (feedbackLevel === 'instrument') { + if (hasSession) { + bvlLink = buildURL( + this.props.baseURL, + '/instrument_list/', + { + candID, + sessionID, + commentID, + showFeedback: true, + } + ); + } else { + bvlLink = buildURL( + this.props.baseURL, + '/' + candID + '/', + {showFeedback: true} + ); + } bvlLevel = labelInstrument + ' : ' - + rowData[labelInstrument]; - } else if (rowData[labelVisit]) { - bvlLink = this.props.baseURL + - '/instrument_list/?candID=' + rowData[labelDCCID] + - '&sessionID=' + rowData['sessionID'] + - '&showFeedback=true'; + + instrument; + } else if (feedbackLevel === 'visit') { + if (hasSession) { + bvlLink = buildURL( + this.props.baseURL, + '/instrument_list/', + { + candID, + sessionID, + showFeedback: true, + } + ); + } else { + bvlLink = buildURL( + this.props.baseURL, + '/' + candID + '/', + {showFeedback: true} + ); + } bvlLevel = labelVisit + ' : ' + rowData[labelVisit]; } else { - bvlLink = this.props.baseURL + '/' + rowData[labelDCCID] - + '/?showFeedback=true'; + bvlLink = buildURL( + this.props.baseURL, + '/' + candID + '/', + {showFeedback: true} + ); bvlLevel = t('Profile', {ns: 'behavioural_qc'}) + ' : ' + rowData[labelPSCID]; } diff --git a/modules/behavioural_qc/php/provisioners/behaviouralprovisioner.class.inc b/modules/behavioural_qc/php/provisioners/behaviouralprovisioner.class.inc index 58d5ac8789..22baab90c2 100644 --- a/modules/behavioural_qc/php/provisioners/behaviouralprovisioner.class.inc +++ b/modules/behavioural_qc/php/provisioners/behaviouralprovisioner.class.inc @@ -1,9 +1,21 @@ + * Alizée Wickenheiser + * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 + * @link https://github.com/aces/Loris-Trunk + */ namespace LORIS\behavioural_qc\Provisioners; /** - * TThis class implements a data provisioner to get all feedback level + * This class implements a data provisioner to get all feedback level * of visits. * * PHP version 7 @@ -49,7 +61,7 @@ class BehaviouralProvisioner extends \LORIS\Data\Provisioners\DBObjectProvisione LEFT JOIN test_names tn ON (tn.ID = f.TestID) WHERE fb.Public = 'Y' - AND fb.Status = 'opened' + AND fb.Status <> 'closed' AND fb.active = 'Y' ", [], diff --git a/modules/instrument_list/php/instrument_list.class.inc b/modules/instrument_list/php/instrument_list.class.inc index 5392373e0a..6d69dfe5f9 100644 --- a/modules/instrument_list/php/instrument_list.class.inc +++ b/modules/instrument_list/php/instrument_list.class.inc @@ -338,7 +338,11 @@ class Instrument_List extends \NDB_Menu_Filter */ function getFeedbackPanel(CandID $candID, ?\SessionID $sessionID): string { - $feedbackPanel = new \BVL_Feedback_Panel($candID, $sessionID); + $feedbackPanel = new \BVL_Feedback_Panel( + $candID, + $sessionID, + $this->commentID ?: null + ); $html = $feedbackPanel->display(); return $html; } diff --git a/php/libraries/NDB_BVL_Feedback.class.inc b/php/libraries/NDB_BVL_Feedback.class.inc index 0adfe4acd8..2b8ee19927 100644 --- a/php/libraries/NDB_BVL_Feedback.class.inc +++ b/php/libraries/NDB_BVL_Feedback.class.inc @@ -564,7 +564,7 @@ class NDB_BVL_Feedback ON (c.ID=ft.CandidateID) LEFT JOIN session as s ON (s.ID = ft.SessionID) - JOIN feedback_bvl_type as ftp + LEFT JOIN feedback_bvl_type as ftp ON (ftp.Feedback_type=ft.Feedback_type)"; if (!empty($this->_feedbackObjectInfo['CommentID'])) { $query .= ", flag as f LEFT JOIN test_names tn ON (tn.ID=f.TestID)"; @@ -574,7 +574,7 @@ class NDB_BVL_Feedback // cause SQL syntax errors on any code paths. // This would make more sense to put in an array and then // call "join($arrayname, ", ") at the end to construct the string. - $query .= " WHERE ftp.Feedback_type = ft.Feedback_type"; + $query .= " WHERE 1=1"; if (!empty($this->_feedbackObjectInfo['CommentID'])) { $query .= " AND ft.SessionID = :SID";