Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flag] Add flag editors table #9478

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
20 changes: 18 additions & 2 deletions SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ CREATE TABLE `flag` (
`Administration` enum('None','Partial','All') default NULL,
`Validity` enum('Questionable','Invalid','Valid') default NULL,
`Exclusion` enum('Fail','Pass') default NULL,
`UserID` varchar(255) default NULL,
`Testdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`DataID` int(10) unsigned default NULL,
PRIMARY KEY (`CommentID`),
Expand All @@ -309,12 +308,29 @@ CREATE TABLE `flag` (
KEY `flag_Data_entry` (`Data_entry`),
KEY `flag_Validity` (`Validity`),
KEY `flag_Administration` (`Administration`),
KEY `flag_UserID` (`UserID`),
CONSTRAINT `FK_flag_1` FOREIGN KEY (`SessionID`) REFERENCES `session` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_flag_3` FOREIGN KEY (`DataID`) REFERENCES `instrument_data` (`ID`),
CONSTRAINT `FK_ibfk_1` FOREIGN KEY (`TestID`) REFERENCES `test_names` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `flag_editors` (
`userID` int(10) unsigned NOT NULL default '0',
`CommentID` VARCHAR(255) NOT NULL default '',
`editDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`userID`,`CommentID`),
KEY `FK_flag_editors_2` (`CommentID`),
CONSTRAINT `FK_flag_editors_2`
FOREIGN KEY (`CommentID`)
REFERENCES `flag` (`CommentID`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `FK_flag_editors_1`
FOREIGN KEY (`userID`)
REFERENCES `users` (`ID`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `history` (
`id` int(11) NOT NULL auto_increment,
`tbl` varchar(255) NOT NULL default '',
Expand Down
22 changes: 22 additions & 0 deletions SQL/New_patches/2024_11_18_Save_Flag_Editors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE `flag_editors` (
`userID` int(10) unsigned NOT NULL default '0',
`CommentID` VARCHAR(255) NOT NULL default '',
`editDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`userID`,`CommentID`),
KEY `FK_flag_editors_2` (`CommentID`),
CONSTRAINT `FK_flag_editors_2`
FOREIGN KEY (`CommentID`)
REFERENCES `flag` (`CommentID`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `FK_flag_editors_1`
FOREIGN KEY (`userID`)
REFERENCES `users` (`ID`)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO flag_editors (userID, CommentID)
SELECT users.ID, CommentID from flag JOIN users ON flag.UserID = users.UserID;

ALTER TABLE flag DROP COLUMN UserID;
8 changes: 0 additions & 8 deletions modules/conflict_resolver/jsx/resolved_filterabledatatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ class ResolvedFilterableDataTable extends Component {
name: 'CorrectAnswer',
type: 'text',
}},
{label: 'User 1', show: true, filter: {
name: 'User1',
type: 'text',
}},
{label: 'User 2', show: true, filter: {
name: 'User2',
type: 'text',
}},
{label: 'Resolver', show: true, filter: {
name: 'Resolver',
type: 'text',
Expand Down
6 changes: 0 additions & 6 deletions modules/conflict_resolver/php/endpoints/unresolved.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ class Unresolved extends Endpoint implements ETagCalculator
'
REPLACE INTO conflicts_resolved (
UserID,
User1,
User2,
TestName,
ExtraKeyColumn,
ExtraKey1,
Expand All @@ -309,8 +307,6 @@ class Unresolved extends Endpoint implements ETagCalculator
)
SELECT
:v_username,
f1.UserID,
f2.UserID,
cu.TestName,
cu.ExtraKeyColumn,
cu.ExtraKey1,
Expand All @@ -331,8 +327,6 @@ class Unresolved extends Endpoint implements ETagCalculator
UNION DISTINCT
SELECT
:v_username,
cr.User1,
cr.User2,
cr.TestName,
cr.ExtraKeyColumn,
cr.ExtraKey1,
Expand Down
4 changes: 0 additions & 4 deletions modules/conflict_resolver/php/models/resolveddto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class ResolvedDTO implements DataInstance, SiteHaver
protected $value1;
protected $value2;
protected $correctanswer;
protected $user1;
protected $user2;
protected $resolver;
protected $resolutiontimestamp;

Expand All @@ -75,8 +73,6 @@ class ResolvedDTO implements DataInstance, SiteHaver
'Value 1' => $this->value1,
'Value 2' => $this->value2,
'Correct Answer' => $this->correctanswer,
'User 1' => $this->user1,
'User 2' => $this->user2,
'Resolver' => $this->resolver,
'ResolutionTimestamp' => $this->resolutiontimestamp,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class ResolvedProvisioner extends \LORIS\Data\Provisioners\DBObjectProvisioner
ELSE conflicts_resolved.OldValue2
END AS correctanswer,
conflicts_resolved.ResolutionTimestamp as resolutiontimestamp,
conflicts_resolved.User1 as user1,
conflicts_resolved.User2 as user2,
conflicts_resolved.UserID as resolver,
psc.name as site,
session.CenterID as centerid,
Expand Down
25 changes: 23 additions & 2 deletions php/libraries/NDB_BVL_Battery.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,23 @@ class NDB_BVL_Battery
'SessionID' => $sessionData['SessionID'],
'TestID' => $testId,
'CommentID' => $commentID,
'UserID' => $sessionData['UserID'],
]
);

$userID = $DB->pselectOne(
"SELECT ID FROM users WHERE UserID=:uid",
['uid' => $sessionData['UserID'] ?? ""]
);
if (($userID ?? "") != "") {
$DB->insertOnDuplicateUpdate(
"flag_editors",
[
'userID' => $userID,
'CommentID' => $commentID,
],
);
}

// insert the dde into the flag table
if ($DDEEnabled) {
$DB->insert(
Expand All @@ -260,9 +273,17 @@ class NDB_BVL_Battery
'SessionID' => $sessionData['SessionID'],
'TestID' => $testId,
'CommentID' => $ddeCommentID,
'UserID' => $sessionData['UserID'],
]
);
if (($userID ?? "") != "") {
$DB->insertOnDuplicateUpdate(
"flag_editors",
[
'userID' => $userID,
'CommentID' => $ddeCommentID,
],
);
}
}

return $commentID ?? '';
Expand Down
13 changes: 13 additions & 0 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,19 @@ abstract class NDB_BVL_Instrument extends NDB_Page
}
$newData = array_merge($oldData ?? [], $values);

$userID = $db->pselectOne(
"SELECT ID FROM users WHERE UserID=:uid",
['uid' => $newData['UserID'] ?? ""]
);
if (($userID ?? "") != "") {
$db->insertOnDuplicateUpdate(
"flag_editors",
[
'userID' => $userID,
'CommentID' => $this->getCommentID(),
],
);
}
// If there's already a row with the same data, re-use the DataID.
// Otherwise, insert it, then update the DataID on flag.
$jsonencoded = json_encode($newData);
Expand Down
Loading
Loading