Skip to content

Commit

Permalink
Progression on taxon profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
MuchQuak committed Feb 13, 2025
1 parent a2e8d18 commit a3f92d8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 23 deletions.
68 changes: 66 additions & 2 deletions app/Http/Controllers/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Facades\DB;

class TaxonomyController extends Controller {
Expand All @@ -16,17 +17,78 @@ public static function taxonData(int $tid) {
return $taxon;
}

public static function getParents(int $tid) {
public static function getParents(int $tid) : array {
$parent_tree = DB::select('with RECURSIVE parents as (
SELECT * from taxstatus where tid = ?
UNION ALL
SELECT ts.* from taxstatus as ts, parents as p where ts.tid = p.parenttid and ts.taxauthid = 1 and ts.tid != 1
) SELECT taxa.tid, sciName, parents.family, parenttid, taxa.rankID, rankname
from parents join taxa on taxa.tid = parents.tid join taxonunits on taxonunits.rankid = taxa.rankID and taxa.kingdomName = taxonunits.kingdomName order by taxa.rankID', [$tid]);

return $parent_tree;
}

public static function getDirectChildren(int $tid) {
$query = DB::table('taxa as t')
->join('taxstatus as ts', 'ts.tid', 't.tid')
->leftJoin('media as m', function(JoinClause $query) {
$query->on('m.tid', 't.tid')
->where('m.mediaType', 'image');
})
->join('taxonunits as tu', function(JoinClause $query) {
$query->on('tu.rankid', 't.rankID')
->whereRaw('tu.kingdomName = t.kingdomName');
})->where('ts.taxauthid', 1)
->where('ts.parenttid', $tid)
->groupBy('t.tid')
->select(['t.tid', 'sciName', 'ts.family', 'parenttid', 't.rankID', 'rankname', DB::raw('COALESCE(m.thumbnailUrl, m.url) as thumbnailUrl')]);

$direct_children = $query->get();

foreach ($direct_children as $child) {
if(!$child->thumbnailUrl) {
DB::table('media')->where($child->tid);
}
}

/*
$children = self::getAllChildren($tid);
if(empty($children)) return [];
$direct_children = [];
$url_remap = [];
foreach ($children as $child) {
if($child->parenttid === $tid) {
$direct_children[$child->tid] = $child;
} else {
if($child->parenttid && isset($url_remap[$child->parenttid])) {
$url_remap[$child->tid] = $url_remap[$child->parenttid];
} else {
$url_remap[$child->tid] = $child->parenttid;
}
if($child->thumbnailUrl && !$direct_children[$url_remap[$child->tid]]->thumbnailUrl) {
$direct_children[$url_remap[$child->tid]]->thumbnailUrl = $child->thumbnailUrl;
}
}
}
*/

return $direct_children;
}

// Be very Careful when calling this function can be very slow depending on the tid
public static function getAllChildren(int $tid) : array {
$child_tree = DB::select('with RECURSIVE children as (
SELECT * from taxstatus where parenttid = ?
UNION ALL
SELECT ts.* from taxstatus as ts, children as c where ts.parenttid = c.tid and ts.taxauthid = 1 and ts.tidaccepted = ts.tid
) SELECT taxa.tid, sciName, children.family, parenttid, taxa.rankID, rankname, COALESCE(m.thumbnailUrl, m.url) as thumbnailUrl
from children join taxa on taxa.tid = children.tid left join media as m on m.tid = taxa.tid join taxonunits on taxonunits.rankid = taxa.rankID and taxa.kingdomName = taxonunits.kingdomName group by taxa.tid order by taxa.rankID', [$tid]);

return $child_tree;
}

public static function getCommonNames(int $tid) {
$common_names = DB::table('taxavernaculars')->where('tid', $tid)->select('*')->get();

Expand All @@ -45,6 +107,7 @@ public static function taxon(int $tid) {
$parents = self::getParents($tid);

$common_names = self::getCommonNames($tid);
$children = self::getDirectChildren($tid);

$occurrence_count = self::getTaxonOccurrenceStats($tid);

Expand All @@ -53,6 +116,7 @@ public static function taxon(int $tid) {
'parents' => $parents,
'common_names' => $common_names,
'occurrence_count' => $occurrence_count,
'children' => $children,
]);
}

Expand Down
32 changes: 12 additions & 20 deletions resources/views/core/pages/taxon/profile.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@props(['taxon', 'parents', 'common_names'])
@props(['taxon', 'parents', 'common_names', 'children' => []])
@php
$breadcrumbs = [['title' => 'Home', 'href' => url('')]];
foreach($parents as $parent) {
Expand Down Expand Up @@ -27,6 +27,10 @@
<a href="{{url(config('portal.name'). '/taxa/profile/tpeditor.php?tid=' . $taxon->tid )}}">
<i class="text-xl float-right fas fa-edit cursor-pointer"></i>
</a>

<a href="{{url('media/search?tid=' . $taxon->tid )}}">
See More
</a>
</div>
</div>
<div class="flex-grow">
Expand Down Expand Up @@ -73,28 +77,16 @@
</x-tabs>
</div>

<div class="flex gap-4">
<div>
<img src="https://s3.msi.umn.edu/mbaenrms3fs/images/MIN_JFBM_PLANTS/01003/1003938_tn.jpg" alt="">
</div>

<div>
<img src="https://s3.msi.umn.edu/mbaenrms3fs/images/MIN_JFBM_PLANTS/01003/1003938_tn.jpg" alt="">
</div>

<div>
<img src="https://s3.msi.umn.edu/mbaenrms3fs/images/MIN_JFBM_PLANTS/01003/1003938_tn.jpg" alt="">
</div>

<div>
<img src="https://s3.msi.umn.edu/mbaenrms3fs/images/MIN_JFBM_PLANTS/01003/1003938_tn.jpg" alt="">
</div>
@if(!empty($children))
<div class="flex flex-wrap flex-row gap-3">
@foreach ($children as $child)
<x-image-card :src="$child->thumbnailUrl" :title="$child->sciName" />
@endforeach
</div>

{{-- Todo Ignore the Hero Taxa Image --}}
@if($taxon->tid)
@else
<div class="flex flex-wrap flex-row gap-3">
<x-media.item :allow_empty_trigger="true" :fixed_start="0" />
<x-media.item :allow_empty_trigger="true" :fixed_start="0" :params="['tid' => $taxon->tid, 'taxon_sort_order' => true]"/>
<div id="scroll-loader" class="htmx-indicator">
<div class="stroke-accent w-full h-16 flex justify-center">
<x-icons.loading />
Expand Down
4 changes: 3 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@
| Taxonomy API
|--------------------------------------------------------------------------
*/
Route::group(['prefix' => 'taxonomy'], function () {});
Route::group(['prefix' => 'taxonomy'], function () {
Route::get('{tid}/children', [TaxonomyController::class, 'getDirectChildren']);
});
});

/*
Expand Down

0 comments on commit a3f92d8

Please sign in to comment.