Skip to content

Commit

Permalink
Occurrence Dataset Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
egbot committed May 22, 2024
1 parent 17b9844 commit 6580a7a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 72 deletions.
45 changes: 18 additions & 27 deletions classes/OccurrenceDataset.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
<?php
include_once($SERVER_ROOT.'/config/dbconnection.php');
include_once($SERVER_ROOT.'/classes/DwcArchiverCore.php');
include_once($SERVER_ROOT.'/classes/Manager.php');

class OccurrenceDataset {
class OccurrenceDataset extends Manager {

private $conn;
private $collArr = array();
private $datasetId = 0;
private $errorArr = array();

public function __construct($type = 'write'){
$this->conn = MySQLiConnectionFactory::getCon($type);
parent::__construct(null, $type);
}

public function __destruct(){
if(!($this->conn === null)) $this->conn->close();
parent::__destruct();
}

public function getPublicDatasets(){
// Tests if field `category` exists in table
$sqlFields = 'SHOW COLUMNS FROM omoccurdatasets LIKE "category"';
$fields = $this->conn->query($sqlFields);
$catExists = $fields->num_rows?TRUE:FALSE;
$fields->free();
$retArr = array();
$sql = '';
if ($catExists) {
$sql = 'SELECT datasetid, category, name, notes, description, uid, sortsequence, initialtimestamp, ispublic FROM omoccurdatasets WHERE ispublic=1 ORDER BY category,name';

} else {
$sql = 'SELECT datasetid, name, notes, description, uid, sortsequence, initialtimestamp, ispublic FROM omoccurdatasets WHERE ispublic=1 ORDER BY name';
}
$rs = $this->conn->query($sql);
while($r = $rs->fetch_assoc()){
$retArr[] = $r;
}
$rs->free();
return $retArr;
}
public function getPublicDatasets(){
$retArr = array();
$sql = 'SELECT datasetID, category, name, notes, description, uid, sortSequence, initialTimestamp, ispublic FROM omoccurdatasets WHERE ispublic=1 ORDER BY category, name';
if($rs = $this->conn->query($sql)){
while($r = $rs->fetch_object()){
$category = 0;
if($r->category) $category = $this->cleanOutStr($r->category);
$retArr[$category][$r->datasetID] = $this->cleanOutArray($r);
}
$rs->free();
}
return $retArr;
}

public function getPublicDatasetMetadata($dsid){
$retArr = array();
Expand Down Expand Up @@ -71,7 +62,7 @@ public function getDatasetMetadata($dsid){
$retArr['uid'] = $r->uid;
$retArr['sort'] = $r->sortsequence;
$retArr['ts'] = $r->initialtimestamp;
$retArr['ispublic'] = $r->ispublic;
$retArr['ispublic'] = $r->ispublic;
}
$rs->free();
//Get roles for current user
Expand Down
24 changes: 12 additions & 12 deletions collections/datasets/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
menubar: '',
toolbar: ['undo redo | bold italic underline | link | alignleft aligncenter alignright | formatselect | bullist numlist | indent outdent | blockquote | image'],
branding: false,
default_link_target: "_blank",
default_link_target: "_blank",
paste_as_text: true
});
</script>
Expand Down Expand Up @@ -119,7 +119,7 @@ function validateAddForm(f){
?>
<div>
<div style="float:right;margin:10px;" title="<?php echo (isset($LANG['CRT_NEW_DAT']) ? $LANG['CRT_NEW_DAT'] : 'Create New Dataset') ?>" >
<a href="#" onclick="toggle('adddiv');return false;"><img src="../../images/add.png" style="width:1.5em;" alt="<?php echo (isset($LANG['ADD_BUTTON']) ? $LANG['ADD_BUTTON'] : 'Add Button') ?>"/> </a>
<a href="#" onclick="toggle('adddiv');return false;"><img src="../../images/add.png" style="width:1.5em;" alt="<?php echo (isset($LANG['ADD_BUTTON']) ? $LANG['ADD_BUTTON'] : 'Add Button') ?>"/> </a>
</div>
<h1 class="page-heading"> <?php echo (isset($LANG['OCC_DAT_MNG']) ? $LANG['OCC_DAT_MNG'] : 'Occurrence Dataset Manager') ?> </h1>
<div> <?php echo (isset($LANG['TOOL_DESCR']) ? $LANG['TOOL_DESCR'] : 'These tools will allow you to define and manage dataset profiles. Once a profile is created, you can link occurrence records via the occurrence search and display pages.') ?> </div>
Expand All @@ -131,20 +131,20 @@ function validateAddForm(f){
<p><b> <?php echo (isset($LANG['NAME']) ? $LANG['NAME'] : 'Name') ?> </b></p>
<input name="name" type="text" style="width:90%" />
</div>
<div>
<p>
<input type="checkbox" name="ispublic" id="ispublic" value="1" />
<b> <?php echo (isset($LANG['PUB_VIS']) ? $LANG['PUB_VIS'] : 'Publicly Visible') ?> </b>
</p>
</div>
<div>
<p>
<input type="checkbox" name="ispublic" id="ispublic" value="1" />
<b> <?php echo (isset($LANG['PUB_VIS']) ? $LANG['PUB_VIS'] : 'Publicly Visible') ?> </b>
</p>
</div>
<div>
<p><b> <?php echo (isset($LANG['NOTES']) ? $LANG['NOTES'] : 'Notes (Internal usage, not displayed publicly)') ?></b></p>
<input name="notes" type="text" style="width:90%;" />
</div>
<div>
<p><b> <?php echo (isset($LANG['DESCR']) ? $LANG['DESCR'] : 'Description (Displayed publicly)') ?> </b> </p>
<textarea name="description" id="description" cols="100" rows="10"></textarea>
</div>
<div>
<p><b> <?php echo (isset($LANG['DESCR']) ? $LANG['DESCR'] : 'Description (Displayed publicly)') ?> </b> </p>
<textarea name="description" id="description" cols="100" rows="10"></textarea>
</div>
<div style="margin:15px">
<button name="submitaction" type="submit" value="createNewDataset"> <?php echo (isset($LANG['CRT_NEW_DAT']) ? $LANG['CRT_NEW_DAT'] : 'Create New Dataset') ?> </button>
</div>
Expand Down
41 changes: 12 additions & 29 deletions collections/datasets/publiclist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,38 @@
header('Content-Type: text/html; charset='.$CHARSET);

$datasetManager = new OccurrenceDataset();
$dArr = $datasetManager->getPublicDatasets();
?>
<!DOCTYPE html>
<html lang="<?php echo $LANG_TAG ?>">
<head>
<title>Public Datasets List</title>
<title><?= $LANG['PUB_DAT_LIST'] ?></title>
<?php
include_once($SERVER_ROOT.'/includes/head.php');
?>
</head>
<body>
<?php
$displayLeftMenu = true;
include($SERVER_ROOT.'/includes/header.php');
?>
<div class="navpath">
<a href="<?php echo htmlspecialchars($CLIENT_ROOT, ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE); ?>/index.php"> <?php echo htmlspecialchars($LANG['H_HOME'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) ?> </a> &gt;&gt;
<b> <?php echo htmlspecialchars($LANG['PUB_DAT_LIST'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) ?> </b>
<a href="<?= $CLIENT_ROOT ?>/index.php"> <?= $LANG['H_HOME'] ?> </a> &gt;&gt;
<b> <?= $LANG['PUB_DAT_LIST'] ?> </b>
</div>
<!-- This is inner text! -->
<div role="main" id="innertext">
<h1 class="page-heading"><?php echo htmlspecialchars($LANG['PUB_DAT_LIST'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) ?></h1>
<h1 class="page-heading"><?= $LANG['PUB_DAT_LIST'] ?></h1>
<ul>
<?php
if($dArr){
$catArr = array();
// Creates categories array
foreach($dArr as $row) {
if (array_key_exists('category', $row)) {
($row['category']) ? array_push($catArr, $row['category']) : array_push($catArr, NULL);
}
else {
echo '<li><a href="public.php?datasetid=' . htmlspecialchars($row['datasetid'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '">' . htmlspecialchars($row['name'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a></li>';
}
}
if (count($catArr) > 1) {
$catArr = array_unique($catArr);
foreach($catArr as $cat) {
echo ($cat) ? '<h3>'.$cat.'</h3>' : '';
foreach($dArr as $row){
if ($cat === $row['category']) {
echo '<li><a href="public.php?datasetid=' . htmlspecialchars($row['datasetid'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '">' . htmlspecialchars($row['name'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a></li>';
}
}
if($datasetArr = $datasetManager->getPublicDatasets()){
foreach($datasetArr as $category => $categoryArr) {
if($category) echo '<h3>' . $category . '</h3>';
foreach($categoryArr as $dsID => $dsObject){
echo '<li><a href="public.php?datasetid=' . $dsID . '">' . $dsObject->name . '</a></li>';
}
}
else {
echo '<li><a href="public.php?datasetid=' . htmlspecialchars($row['datasetid'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '">' . htmlspecialchars($row['name'], ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE) . '</a></li>';
}
}
else{
echo $LANG['NO_DATASETS'];
}
?>
</ul>
Expand Down
5 changes: 3 additions & 2 deletions content/lang/collections/datasets/publiclist.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
------------------
*/

$LANG['PUB_DAT_LIST'] = 'Public Datasets List';

$LANG['HOME'] = 'Home';
$LANG['PUB_DAT_LIST'] = 'Public Datasets List';
$LANG['NO_DATASETS'] = 'There are no public datasets';
?>
3 changes: 2 additions & 1 deletion content/lang/collections/datasets/publiclist.es.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
------------------
*/

$LANG['HOME'] = 'Inicio';
$LANG['PUB_DAT_LIST'] = 'Lista de conjuntos de datos públicos';

$LANG['NO_DATASETS'] = 'No hay conjuntos de datos';
?>
3 changes: 2 additions & 1 deletion content/lang/collections/datasets/publiclist.fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
------------------
*/

$LANG['HOME'] = 'Accueil';
$LANG['PUB_DAT_LIST'] = 'Liste des ensembles de données publics';

$LANG['NO_DATASETS'] = "Il n'y a pas d'ensembles de données publics";
?>

0 comments on commit 6580a7a

Please sign in to comment.