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

[Timepoint/Create Timepoint] Add timepoint language feature #4976

Merged
merged 18 commits into from
Feb 26, 2020
5 changes: 4 additions & 1 deletion SQL/0000-00-00-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ CREATE TABLE `language` (
UNIQUE KEY (`language_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO language (language_code, language_label) VALUES ('en-CA', 'English');
INSERT INTO language (language_code, language_label) VALUES
('en-CA', 'English');

CREATE TABLE `users` (
`ID` int(10) unsigned NOT NULL auto_increment,
Expand Down Expand Up @@ -210,6 +211,7 @@ CREATE TABLE `session` (
`MRIQCFirstChangeTime` datetime DEFAULT NULL,
`MRIQCLastChangeTime` datetime DEFAULT NULL,
`MRICaveat` enum('true','false') NOT NULL DEFAULT 'false',
`languageID` integer unsigned DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `session_candVisit` (`CandID`,`VisitNo`),
KEY `FK_session_2` (`CenterID`),
Expand All @@ -218,6 +220,7 @@ CREATE TABLE `session` (
CONSTRAINT `FK_session_1` FOREIGN KEY (`CandID`) REFERENCES `candidate` (`CandID`),
CONSTRAINT `FK_session_2` FOREIGN KEY (`CenterID`) REFERENCES `psc` (`CenterID`),
CONSTRAINT `FK_session_3` FOREIGN KEY (`SubprojectID`) REFERENCES `subproject` (`SubprojectID`),
CONSTRAINT `FK_session_4` FOREIGN KEY (`languageID`) REFERENCES `language` (`language_id`),
CONSTRAINT `FK_session_ProjectID` FOREIGN KEY (`ProjectID`) REFERENCES `Project` (`ProjectID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Table holding session information';

Expand Down
3 changes: 3 additions & 0 deletions SQL/New_patches/2019_07_05_Add_Language_feature.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE `session`
ADD COLUMN `languageID` integer unsigned DEFAULT NULL,
ADD CONSTRAINT `FK_session_4` FOREIGN KEY (`languageID`) REFERENCES `language` (`language_id`);
31 changes: 27 additions & 4 deletions modules/create_timepoint/php/create_timepoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class Create_Timepoint extends \NDB_Form
$values['subprojectID'],
$values['visitLabel'] ?? null,
$site,
$project
$project,
$values['languageID'] ?? null
);

$this->tpl_data['success'] = true;
Expand Down Expand Up @@ -188,7 +189,7 @@ class Create_Timepoint extends \NDB_Form
&& $visitLabel['generation'] !== 'sequence'
) {
throw new \DeprecatedException(
"User generated Visit Labels are no ".
"User generated Visit Labels are no " .
"longer supported in Loris."
);
}
Expand All @@ -202,10 +203,25 @@ class Create_Timepoint extends \NDB_Form
$this->addSelect('visitLabel', 'Visit label', $labelOptions);
$this->addRule('visitLabel', 'Visit label is required', 'required');

$languages = \Utility::getLanguageList();
if (count($languages) > 1) {
array_unshift($languages, null);
$this->addSelect(
'languageID',
'Language',
$languages
);
$this->addRule(
'languageID',
'Language is required',
'required'
);
}

// List of sites for the user
$user_list_of_sites = $user->getCenterIDs();
$num_sites = count($user_list_of_sites);
if ($num_sites >1) {
if ($num_sites > 1) {
$this->tpl_data['pscLabelAdded'] = true;
$psc_labelOptions = [null => ''];
foreach ($user_list_of_sites as $key => $siteID) {
Expand All @@ -228,7 +244,7 @@ class Create_Timepoint extends \NDB_Form

// List projects
$user_list_of_projects = $user->getProjectIDs();
if (count($user_list_of_projects) >1) {
if (count($user_list_of_projects) > 1) {
$this->tpl_data['projectAdded'] = true;
$projectOptions = array(null => '');
foreach ($user_list_of_projects as $key => $projectID) {
Expand All @@ -252,6 +268,7 @@ class Create_Timepoint extends \NDB_Form
If you are an administrator, please assign visits to this subproject in
the config.xml file.";
}

$this->form->addFormRule(array(&$this, '_validate'));

}
Expand Down Expand Up @@ -301,6 +318,12 @@ class Create_Timepoint extends \NDB_Form
$errors['visitLabel'] = $e->getMessage();
}

// validate language
$languages = \Utility::getLanguageList();
if (count($languages) > 1 && empty($val['languageID'])) {
$errors['languageID'] = "A language must be selected.";
}

return $errors;
}

Expand Down
5 changes: 5 additions & 0 deletions modules/create_timepoint/templates/form_create_timepoint.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<div class="col-sm-2">{$form.visitLabel.html}</div>
</div>

<div class="form-group col-sm-12">
<label class="col-sm-2">{$form.languageID.label}</label>
<div class="col-sm-2">{$form.languageID.html}</div>
</div>

<div class="form-group col-sm-12">
<div class="col-sm-2 col-sm-offset-2"><input class="btn btn-primary col-sm-12" name="fire_away" value="Create Time Point" type="submit" /></div>
</div>
Expand Down
26 changes: 18 additions & 8 deletions php/libraries/TimePoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ class TimePoint
/**
* Registers a new timepoint into the session table
*
* @param \Candidate $candidate The Candidate to create this timepoint for
* @param integer $SubprojectID The subprojectID of the new timepoint
* @param string|null $nextVisitLabel The visit label of the timepoint
* being created. If null, consecutive V1, V2,
* etc will be created.
* @param \Site $psc The center of the timepoint
* @param \Project $project The project of the timepoint
* @param \Candidate $candidate The Candidate to create this timepoint for
* @param integer $SubprojectID The subprojectID of the new timepoint
* @param string|null $nextVisitLabel The visit label of the timepoint
* being created. If null,
* consecutive V1, V2, etc will be
* created.
* @param \Site $psc The center of the timepoint
* @param \Project $project The project of the timepoint
* @param integer|null $lang The language id
*
* @throws DatabaseException
*
Expand All @@ -208,7 +210,8 @@ class TimePoint
int $SubprojectID,
?string $nextVisitLabel,
\Site $psc,
\Project $project
\Project $project,
?int $lang = null
): void {

// insert into session set CandID=$candID,
Expand Down Expand Up @@ -237,6 +240,12 @@ class TimePoint
$VisitLabel = "V$visitNo";
}

$language = $lang;
if ($language === null) {
$langList = Utility::getLanguageList();
$language = array_key_first($langList);
}

$insertData = array(
'CandID' => $candidate->getCandID(),
'SubprojectID' => $SubprojectID,
Expand All @@ -250,6 +259,7 @@ class TimePoint
'UserID' => $userID,
'Date_registered' => $today,
'Date_active' => $today,
'languageID' => $language,
);

// insert the data
Expand Down
Loading