Skip to content

Commit

Permalink
Merge pull request #6 from BioKIC/master
Browse files Browse the repository at this point in the history
pull request
  • Loading branch information
mandrewj committed Nov 12, 2020
2 parents 02e977e + 0caab58 commit b90ca9d
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 312 deletions.
20 changes: 11 additions & 9 deletions classes/DwcArchiverCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,37 +277,39 @@ private function applyConditions(){
$sqlFrag .= $taxaManager->getTaxonWhereFrag();
}
else{
if($field == 'datelastmodified') $field = 'IFNULL(o.modified,o.datelastmodified)';
else $field = 'o.'.$field;
$sqlFrag2 = '';
foreach($condArr as $cond => $valueArr){
if($cond == 'NULL'){
$sqlFrag2 .= 'AND (o.'.$field.' IS NULL) ';
$sqlFrag2 .= 'AND ('.$field.' IS NULL) ';
}
elseif($cond == 'NOTNULL'){
$sqlFrag2 .= 'AND (o.'.$field.' IS NOT NULL) ';
$sqlFrag2 .= 'AND ('.$field.' IS NOT NULL) ';
}
elseif($cond == 'EQUALS'){
$sqlFrag2 .= 'AND (o.'.$field.' IN("'.implode('","',$valueArr).'")) ';
$sqlFrag2 .= 'AND ('.$field.' IN("'.implode('","',$valueArr).'")) ';
}
elseif($cond == 'NOTEQUALS'){
$sqlFrag2 .= 'AND (o.'.$field.' NOT IN("'.implode('","',$valueArr).'")) ';
$sqlFrag2 .= 'AND ('.$field.' NOT IN("'.implode('","',$valueArr).'")) ';
}
else{
$sqlFrag3 = '';
foreach($valueArr as $value){
if($cond == 'STARTS'){
$sqlFrag3 .= 'OR (o.'.$field.' LIKE "'.$value.'%") ';
$sqlFrag3 .= 'OR ('.$field.' LIKE "'.$value.'%") ';
}
elseif($cond == 'LIKE'){
$sqlFrag3 .= 'OR (o.'.$field.' LIKE "%'.$value.'%") ';
$sqlFrag3 .= 'OR ('.$field.' LIKE "%'.$value.'%") ';
}
elseif($cond == 'NOTLIKE'){
$sqlFrag3 .= 'OR (o.'.$field.' NOT LIKE "%'.$value.'%") ';
$sqlFrag3 .= 'OR ('.$field.' NOT LIKE "%'.$value.'%") ';
}
elseif($cond == 'LESSTHAN'){
$sqlFrag3 .= 'OR (o.'.$field.' < "'.$value.'") ';
$sqlFrag3 .= 'OR ('.$field.' < "'.$value.'") ';
}
elseif($cond == 'GREATERTHAN'){
$sqlFrag3 .= 'OR (o.'.$field.' > "'.$value.'") ';
$sqlFrag3 .= 'OR ('.$field.' > "'.$value.'") ';
}
}
$sqlFrag2 .= 'AND ('.substr($sqlFrag3,3).') ';
Expand Down
169 changes: 137 additions & 32 deletions classes/OccurrenceLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,38 +262,161 @@ private function setLabelFieldArr(){
'identificationQualifier'=>'o.identificationqualifier', 'typeStatus'=>'o.typestatus', 'recordedBy'=>'o.recordedby', 'recordNumber'=>'o.recordnumber', 'associatedCollectors'=>'o.associatedcollectors',
'eventDate'=>'DATE_FORMAT(o.eventdate,"%e %M %Y") AS eventdate', 'year'=>'o.year', 'month'=>'o.month', 'day'=>'o.day', 'monthName'=>'DATE_FORMAT(o.eventdate,"%M") AS monthname',
'verbatimEventDate'=>'o.verbatimeventdate', 'habitat'=>'o.habitat', 'substrate'=>'o.substrate', 'occurrenceRemarks'=>'o.occurrenceremarks', 'associatedTaxa'=>'o.associatedtaxa',
'verbatimAttributes'=>'o.verbatimattributes', 'reproductiveCondition'=>'o.reproductivecondition', 'cultivationStatus'=>'o.cultivationstatus', 'establishmentMeans'=>'o.establishmentmeans',
'dynamicProperties'=>'o.dynamicproperties','verbatimAttributes'=>'o.verbatimattributes', 'behavior'=>'behavior', 'reproductiveCondition'=>'o.reproductivecondition', 'cultivationStatus'=>'o.cultivationstatus',
'establishmentMeans'=>'o.establishmentmeans','lifeStage'=>'lifestage','sex'=>'sex','individualCount'=>'individualcount','samplingProtocol'=>'samplingprotocol','preparations'=>'preparations',
'country'=>'o.country', 'stateProvince'=>'o.stateprovince', 'county'=>'o.county', 'municipality'=>'o.municipality', 'locality'=>'o.locality', 'decimalLatitude'=>'o.decimallatitude',
'decimalLongitude'=>'o.decimallongitude', 'geodeticDatum'=>'o.geodeticdatum', 'coordinateUncertaintyInMeters'=>'o.coordinateuncertaintyinmeters', 'verbatimCoordinates'=>'o.verbatimcoordinates',
'elevationInMeters'=>'CONCAT_WS(" - ",o.minimumelevationinmeters,o.maximumelevationinmeters) AS elevationinmeters', 'verbatimElevation'=>'o.verbatimelevation',
'disposition'=>'o.disposition', 'duplicateQuantity'=>'o.duplicatequantity', 'dateLastModified'=>'o.datelastmodified');
'minimumDepthInMeters'=>'minimumdepthinmeters', 'maximumDepthInMeters'=>'maximumdepthinmeters', 'verbatimDepth'=>'verbatimdepth',
'disposition'=>'o.disposition', 'storageLocation'=>'storagelocation', 'duplicateQuantity'=>'o.duplicatequantity', 'dateLastModified'=>'o.datelastmodified');
}
}

public function getLabelFormatArr($index){
if(is_numeric($index) && $this->collArr['dynprops']){
$dymPropArr = json_decode($this->collArr['dynprops'],true);
if(isset($dymPropArr['labelFormats'][$index])){
return $dymPropArr['labelFormats'][$index];
public function getLabelBlock($blockArr,$occArr){
$outStr = '';
foreach($blockArr as $bArr){
if(array_key_exists('divBlock', $bArr)){
$outStr .= $this->getDivBlock($bArr['divBlock'],$occArr);
}
elseif(array_key_exists('fieldBlock', $bArr)){
$delimiter = (isset($bArr['delimiter'])?$bArr['delimiter']:'');
$cnt = 0;
$fieldDivStr = '';
foreach($bArr['fieldBlock'] as $fieldArr){
$fieldName = $fieldArr['field'];
$fieldValue = trim($occArr[$fieldName]);
if($fieldValue){
if($delimiter && $cnt) $fieldDivStr .= $delimiter;
$fieldDivStr .= '<span class="'.$fieldName.'" '.(isset($fieldArr['style'])?'style="'.$fieldArr['style'].'"':'').'>';
if(isset($fieldArr['prefix']) && $fieldArr['prefix']){
$fieldDivStr .= '<span class="'.$fieldName.'Prefix" '.(isset($fieldArr['prefixStyle'])?'style="'.$fieldArr['prefixStyle'].'"':'').'>'.$fieldArr['prefix'].'</span>';
}
$fieldDivStr .= $fieldValue;
if(isset($fieldArr['suffix']) && $fieldArr['suffix']){
$fieldDivStr .= '<span class="'.$fieldName.'Suffix" '.(isset($fieldArr['suffixStyle'])?'style="'.$fieldArr['suffixStyle'].'"':'').'>'.$fieldArr['suffix'].'</span>';
}
$fieldDivStr .= '</span>';
$cnt++;
}
}
if($fieldDivStr) $outStr .= '<div class="fieldBlockDiv" '.(isset($bArr['style'])?'style="'.$bArr['style'].'"':'').'>'.$fieldDivStr.'</div>';
}
}
return $outStr;
}

private function getDivBlock($divArr,$occArr){
if(array_key_exists('blocks', $divArr)){
if($blockStr = $this->getLabelBlock($divArr['blocks'],$occArr)){
return '<div '.(isset($divArr['className'])?'class="'.$divArr['className'].'"':'').' '.(isset($divArr['style'])?'style="'.$divArr['style'].'"':'').'>'.$blockStr.'</div>'."\n";
}
}
return '';
}

public function getLabelFormatArr($labelCat, $labelIndex){
if(is_numeric($labelIndex)){
if($labelCat == 'global'){
if(file_exists($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php')){
include($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php');
if(isset($LABEL_FORMAT_JSON)){
if($labelFormatArr = json_decode($LABEL_FORMAT_JSON,true)){
if(isset($labelFormatArr['labelFormats'][$labelIndex])){
return $labelFormatArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning global format: index does not exist';
}
else $this->errorArr[] = 'ERROR returning global format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning global format: $LABEL_FORMAT_JSON does not exist';
}
else $this->errorArr[] = 'ERROR returning global format: /content/collections/reports/labeljson.php does not exist';
return false;
}
elseif($labelCat == 'coll'){
if($this->collArr['dynprops']){
if($dymPropArr = json_decode($this->collArr['dynprops'],true)){
if(isset($dymPropArr['labelFormats'][$labelIndex])){
return $dymPropArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning collection format: labelFormats or index does not exist';
}
else $this->errorArr[] = 'ERROR returning collection format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning collection format: dynamicProperties not defined';
}
elseif($labelCat == 'user'){
$dynPropStr = '';
$sql = 'SELECT dynamicProperties FROM users WHERE uid = '.$GLOBALS['SYMB_UID'];
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$dynPropStr = $r->dynamicProperties;
}
$rs->free();
if($dynPropStr){
if($dymPropArr = json_decode($dynPropStr,true)){
if(isset($dymPropArr['labelFormats'][$labelIndex])){
return $dymPropArr['labelFormats'][$labelIndex];
}
else $this->errorArr[] = 'ERROR returning user format: labelFormats or index does not exist';
}
else $this->errorArr[] = 'ERROR returning user format: issue parsing JSON string';
}
else $this->errorArr[] = 'ERROR returning user format: dynamicProperties not defined';
}
}
return false;
}

public function getLabelFormatAnnotatedArr(){
$labelFormatArr = array();
//Add global portal defined label formats
if(file_exists($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php')){
include($GLOBALS['SERVER_ROOT'].'/content/collections/reports/labeljson.php');
if(isset($LABEL_FORMAT_JSON)){
if($globalFormatArr = json_decode($LABEL_FORMAT_JSON,true)){
if(isset($globalFormatArr['labelFormats'])){
foreach($globalFormatArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['g'][$k] = $labelObj;
}
}
}
}
}
//Add collection defined label formats
if($this->collArr['dynprops']){
if($dymPropArr = json_decode($this->collArr['dynprops'],true)){
if($collFormatArr = json_decode($this->collArr['dynprops'],true)){
if(isset($collFormatArr['labelFormats'])){
foreach($collFormatArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['c'][$k] = $labelObj;
}
}
}
}
//Add label formats associated with user profile
/*
$dynPropStr = '';
$sql = 'SELECT dynamicProperties FROM users WHERE uid = '.$GLOBALS['SYMB_UID'];
$rs = $this->conn->query($sql);
if($r = $rs->fetch_object()){
$dynPropStr = $r->dynamicProperties;
}
$rs->free();
if($dynPropStr){
if($dymPropArr = json_decode($dynPropStr,true)){
if(isset($dymPropArr['labelFormats'])){
$labelFormatArr = $dymPropArr['labelFormats'];
foreach($labelFormatArr as $k => $labelObj){
unset($labelFormatArr[$k]['blocks']);
foreach($dymPropArr['labelFormats'] as $k => $labelObj){
unset($labelObj['labelBlocks']);
$labelFormatArr['u'][$k] = $labelObj;
}
if($labelFormatArr) return $labelFormatArr;
else return false;
}
}
}
return null;
*/
return $labelFormatArr;
}

//Annotation functions
Expand Down Expand Up @@ -460,24 +583,6 @@ public function getErrorArr(){
return $this->errorArr;
}

//Misc functions
function parseCSS($fileName){
global $SERVER_ROOT;
if(!$fileName) $fileName = 'defaultlabels.css';
$fh = fopen($SERVER_ROOT.'/collections/reports/css/'.$fileName);
$retArr = array();
preg_match_all('/(.+?)\s?\{\s?(.+?)\s?\}/', $css, $matches);
foreach($matches[0] AS $i => $original){
foreach(explode(';', $matches[2][$i]) AS $attr){
if (strlen(trim($attr)) > 0){
list($name, $value) = explode(':', $attr);
$retArr[$matches[1][$i]][trim($name)] = trim($value);
}
}
}
return $retArr;
}

//Internal cleaning functions
private function cleanInStr($str){
$newStr = trim($str);
Expand Down
2 changes: 1 addition & 1 deletion classes/TaxonomyUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ public function getTaxAuthorityName(){

public function getKingdomArr(){
$retArr = array();
$rs = $this->conn->query('SELECT tid, sciname FROM taxa WHERE rankid = 10');
$rs = $this->conn->query('SELECT tid, sciname FROM taxa WHERE rankid = 10 ORDER BY sciname');
while($r = $rs->fetch_object()){
$retArr[$r->tid] = $r->sciname;
}
Expand Down
38 changes: 19 additions & 19 deletions classes/WordCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
include_once($SERVER_ROOT.'/config/dbconnection.php');

class WordCloud{

private $conn;
private $frequencyArr = array();
private $commonWordArr = array();
private $commonWordArr = array();

//custom parameters
private $displayedWordCount;
private $tagUrl;
private $tagUrl;
private $backgroundImage;
private $backgroundColor;
private $cloudWidth;
Expand All @@ -18,11 +18,11 @@ class WordCloud{

public function __construct(){
$this->conn = MySQLiConnectionFactory::getCon("readonly");

$this->displayedWordCount = 100;
if($GLOBALS['charset'] == 'ISO-8859-1') $this->supportUtf8 = false;
$this->tagUrl = "http://www.google.com/search?hl=en&q=";

$this->backgroundColor = "#000";
$this->wordColors[0] = "#5122CC";
$this->wordColors[1] = "#229926";
Expand All @@ -34,7 +34,7 @@ public function __construct(){
$this->wordColors[7] = "#B23B3B";
$this->wordColors[8] = "#229938";
$this->wordColors[9] = "#419922";

$commonWordStr = "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,arent," .
"as,at,be,because,been,but,by,can,cant,cannot,could,couldve,couldnt,dear,did,didnt,do,does,doesnt," .
"dont,either,else,ever,every,for,from,get,got,had,has,hasnt,have,he,her,him,his,how,however," .
Expand All @@ -55,7 +55,7 @@ public function buildWordFile($collectionId = 0,$csMode = 0){
$sqlFrag = 'FROM omoccurrences o INNER JOIN images i ON o.occid = i.occid '.
'INNER JOIN specprocessorrawlabels r ON i.imgid = r.imgid ';
if($csMode){
$sqlFrag .= 'INNER JOIN omcrowdsourcequeue q ON o.occid = q.occid ';
$sqlFrag .= 'INNER JOIN omcrowdsourcequeue q ON o.occid = q.occid ';
}
$sqlColl = 'SELECT DISTINCT c.collid, c.collectionname '.$sqlFrag.
'INNER JOIN omcollections c ON c.collid = o.collid ';
Expand Down Expand Up @@ -87,8 +87,8 @@ public function buildWordFile($collectionId = 0,$csMode = 0){
echo $cloudStr.'<br/><br/>';
//Write word out to text file
$wcPath = $GLOBALS['serverRoot'];
if(substr($wcPath,-1) != '/' && substr($wcPath,-1) != "\\") $wcPath .= '/';
$wcPath .= 'temp/wordclouds/ocrcloud'.$collid.'.html';
if(substr($wcPath,-1) != '/' && substr($wcPath,-1) != "\\") $wcPath .= '/';
$wcPath .= 'content/collections/wordclouds/ocrcloud'.$collid.'.html';
if(file_exists($wcPath)){
$wcFH = fopen($wcPath, 'a');
if(!$wcFH = fopen($wcPath, 'a')) {
Expand Down Expand Up @@ -124,9 +124,9 @@ public function addTagsFromText($seedText){
$seedText = preg_replace('/\s+/',' ',$seedText);
$seedText = trim($seedText);

//Remove common words
//Remove common words
$wordArr = array_diff(explode(" ", $seedText),$this->commonWordArr);

foreach ($wordArr as $key => $value){
$this->addTag($value);
}
Expand All @@ -150,24 +150,24 @@ public function getWordCloud(){
if($this->frequencyArr){
arsort($this->frequencyArr);
$topTags = array_slice($this->frequencyArr, 0, $this->displayedWordCount);

/* randomize the order of elements */
uasort($topTags, 'randomSort');

$maxCount = max($this->frequencyArr);
foreach ($topTags as $tag => $useCount){
$grade = $this->gradeFrequency(($useCount * 100) / $maxCount);
$retStr .= ('<a href="'. $this->tagUrl.urlencode($tag).'" title="More info on '.
$tag.'" style="color:'.$this->wordColors[$grade].';">'.
'<span style="color:'.$this->wordColors[$grade].'; letter-spacing:3px; '.
'padding:4px; font-family:Tahoma; font-weight:900; font-size:'.
'padding:4px; font-family:Tahoma; font-weight:900; font-size:'.
(0.6 + 0.1 * $grade).'em">'.$tag.'</span></a> ');
}
$retStr .= '</div></div><br />';
}
return $retStr;
}

private function gradeFrequency($frequency){
$grade = 0;
if ($frequency >= 90)
Expand All @@ -188,15 +188,15 @@ private function gradeFrequency($frequency){
$grade = 2;
else if ($frequency >= 5)
$grade = 1;

return $grade;
}

//Setters and getters
public function setDisplayedWordCount($cnt){
$this->displayedWordCount = $cnt;
}

public function setSearchURL($searchURL){
$this->tagUrl = $searchURL;
}
Expand Down
Loading

0 comments on commit b90ca9d

Please sign in to comment.