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

Hotfix 3.1.8 #30

Merged
merged 8 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -111,7 +111,7 @@ public function showOneInventory($id, Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
88 changes: 81 additions & 7 deletions api/app/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Http\Controllers;

use App\Models\Media;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Http\Controllers\TaxonomyController;

class MediaController extends Controller{

Expand Down Expand Up @@ -34,9 +36,44 @@ public function __construct(){
* path="/api/v2/media",
* operationId="showAllMedia",
* tags={""},
* @OA\Parameter(
* name="tid",
* in="query",
* description="Display media filtered by target taxon ID (PK key of taxon)",
* required=false,
* @OA\Schema(type="integer")
* ),
* @OA\Parameter(
* name="includeSynonyms",
* in="query",
* description="Include media linked to synonyms of target taxon (0 = false, 1 = true)",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Parameter(
* name="includeChildren",
* in="query",
* description="Include media linked to direct children of target taxon (0 = false, 1 = true)",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Parameter(
* name="limit",
* in="query",
* description="Controls the number of results in the page.",
* required=false,
* @OA\Schema(type="integer", default=100)
* ),
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
* @OA\Response(
* response="200",
* description="Returns list of media records",
* description="Success: Returns list of media records",
* @OA\JsonContent()
* ),
* @OA\Response(
Expand All @@ -45,8 +82,44 @@ public function __construct(){
* ),
* )
*/
public function showAllMedia(){
return response()->json(Media::skip(0)->take(100)->get());
public function showAllMedia(Request $request){

$this->validate($request, [
'tid' => 'integer',
'includeSynonyms' => 'integer',
'includeChildren' => 'integer',
'limit' => 'integer',
'offset' => 'integer'
]);
$tid = $request->input('tid');
$includeSynonyms = $request->input('includeSynonyms');
$includeChildren = $request->input('includeChildren');
$limit = $request->input('limit',100);
$offset = $request->input('offset',0);

$mediaModel = Media::query();
if($tid){
$tidArr = array($tid);
if($includeSynonyms){
$tidArr = TaxonomyController::getSynonyms($tid);
}
if($includeChildren){
$tidArr = array_merge($tidArr, TaxonomyController::getChildren($tid));
}
$mediaModel->whereIn('tid', $tidArr);
}
$fullCnt = $mediaModel->count();
$result = $mediaModel->skip($offset)->take($limit)->get();

$eor = false;
$retObj = [
'offset' => (int)$offset,
'limit' => (int)$limit,
'endOfRecords' => $eor,
'count' => $fullCnt,
'results' => $result
];
return response()->json($retObj);
}

/**
Expand All @@ -63,7 +136,7 @@ public function showAllMedia(){
* ),
* @OA\Response(
* response="200",
* description="Returns single media record",
* description="Success: Returns single media record",
* @OA\JsonContent(type="application/json")
* ),
* @OA\Response(
Expand Down Expand Up @@ -233,7 +306,7 @@ public function showOneMedia($id){
* ),
* @OA\Response(
* response="201",
* description="Returns JSON object of the of media record that was created"
* description="Success: Returns JSON object of the of media record that was created"
* ),
* @OA\Response(
* response="400",
Expand Down Expand Up @@ -424,7 +497,7 @@ public function insert(Request $request){
* ),
* @OA\Response(
* response="200",
* description="Returns full JSON object of the of media record that was edited"
* description="Success: Returns full JSON object of the of media record that was edited"
* ),
* @OA\Response(
* response="400",
Expand Down Expand Up @@ -472,7 +545,7 @@ public function update($id, Request $request){
* ),
* @OA\Response(
* response="204",
* description="Record deleted successfully"
* description="Success: Record deleted successfully"
* ),
* @OA\Response(
* response="400",
Expand All @@ -496,6 +569,7 @@ public function delete($id, Request $request){
return response()->json(['status' => 'failure', 'error' => 'Unauthorized'], 401);
}

//Support functions
private function adjustInputData(&$data){
if(!empty($data['mediumUrl'])){
//remap mediumUrl to url field
Expand Down
6 changes: 3 additions & 3 deletions api/app/Http/Controllers/OccurrenceAnnotationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -112,7 +112,7 @@ public function showAllAnnotations(Request $request){
$fullCnt = 0;
$result = null;
if($type == 'internal'){
$annotation = DB::table('omoccuredits as e')->select('e.*', 'o.occurrenceID')
$annotation = DB::table('omoccuredits as e')->select('e.*', 'o.occurrenceID', 'o.recordID')
->join('omoccurrences as o', 'e.occid', '=', 'o.occid')
->where('o.collid', $collid);
if($fieldName){
Expand All @@ -129,7 +129,7 @@ public function showAllAnnotations(Request $request){
$result = $this->formatInternalResults($result);
}
elseif($type == 'external'){
$annotation = DB::table('omoccurrevisions as r')->select('r.*', 'o.occurrenceID')
$annotation = DB::table('omoccurrevisions as r')->select('r.*', 'o.occurrenceID', 'o.recordID')
->join('omoccurrences as o', 'o.occid', '=', 'r.occid')
->where('o.collid', $collid);
if($source){
Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/OccurrenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
28 changes: 24 additions & 4 deletions api/app/Http/Controllers/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -76,7 +76,7 @@ public function showAllTaxa(Request $request){
* @OA\Parameter(
* name="taxon",
* in="query",
* description="Taxon searh term",
* description="Taxon search term",
* required=true,
* @OA\Schema(type="string")
* ),
Expand All @@ -101,7 +101,7 @@ public function showAllTaxa(Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -241,7 +241,7 @@ public function showOneTaxon($id, Request $request){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down Expand Up @@ -282,4 +282,24 @@ public function showAllDescriptions($id, Request $request){
return response()->json($retObj);
}

//Support functions
public static function getSynonyms(Int $tid){
$synonymResult = DB::table('taxstatus as ts')
->join('taxstatus as s', 'ts.tidaccepted', '=', 's.tidaccepted')
->where('ts.tid', $tid)->where('ts.taxauthid', 1)->where('s.taxauthid', 1)->pluck('s.tid');
return $synonymResult->toArray();
}

public static function getChildren(Int $tid){
//Direct accepted children only
$childrenResult = DB::table('taxstatus as c')
->join('taxstatus as a', 'c.parenttid', '=', 'a.tidaccepted')
->where('a.tid', $tid)->where('c.taxauthid', 1)->where('a.taxauthid', 1)->whereColumn('c.tid', 'c.tidaccepted')->pluck('c.tid');
/*
SELECT c.tid
FROM taxstatus c INNER JOIN taxstatus a ON c.parenttid = a.tidaccepted
WHERE a.tid = 61943 AND c.taxauthid = 1 AND a.taxauthid = 1 AND c.tid = c.tidaccepted;
*/
return $childrenResult->toArray();
}
}
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/TaxonomyDescriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(){
* @OA\Parameter(
* name="offset",
* in="query",
* description="Determines the offset for the search results. A limit of 200 and offset of 100, will get the third page of 100 results.",
* description="Determines the starting point for the search results. A limit of 100 and offset of 200, will display 100 records starting the 200th record.",
* required=false,
* @OA\Schema(type="integer", default=0)
* ),
Expand Down
4 changes: 4 additions & 0 deletions api/app/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function occurrence() {
return $this->belongsTo(Occurrence::class, 'occid', 'occid');
}

public function Taxonomy() {
return $this->belongsTo(Taxonomy::class, 'tid', 'tid');
}

//Accessor functions
public function getUrlAttribute($value){
if(substr($value, 0, 1) == '/') $value = $this->serverDomain . $value;
Expand Down
Loading