Hey texnixe,
sure I will provide the requested data.
Kirby Version: 3.9.5
The block blueprint:
name: Job-Listing
icon: file-spreadsheet
preview: fields
wysiwyg: true
fields:
showControls:
type: toggle
label: User-Filter anzeigen
default: true
controls:
type: object
label: User-Filter
fields:
useSearch:
type: toggle
default: true
label: Suche
useLocation:
type: toggle
default: true
label: Standort
useContract:
type: toggle
default: true
label: Vollzeit/Teilzeit
jobs:
label: Spotlight Jobs
type: pages
max: 3
query: site.index.filterBy('intendedTemplate', 'job')
store: uuid
extends: sections/block-style
the preview: fields
entry refers to a plugin I use to display block fields directly in the panel.
The stored JSON looks like this:
"blocks":[
{
"content":{
"showcontrols":"true",
"controls":{
"usesearch":"true",
"uselocation":"true",
"usecontract":"true"
},
"jobs":[
"page://hDh1qk0Vcu6G1Wk1",
"page://XivvlXA0gMaC8FrB",
"page://RO1rqciRDJOlX4UW"
],
"style":""
},
"id":"a427b13c-28b0-4a42-9d95-8ef9d83f2a28",
"isHidden":false,
"type":"JobListing"
}
],
The pages don’t have a fixed UUID. Not strictly at least: I query the API and check if there is an updated request to the last query. If no I use a cached version as the API is unfortunately quite slow. The API updates maybe once every one or two days. Here is my code for creating the virtual pages:
<?php
use Kirby\Uuid\Uuid;
use Kirby\Toolkit\Date;
use voku\helper\HtmlDomParser;
// removes unessential tags and attributes from job data
function cleanHtml($str) {
if(!empty($str)) {
$parsed = new HtmlDomParser($str);
foreach($parsed->find('*') as $e) {
// remove all inline styles
if($e->hasAttribute('style')) {
$e->setAttribute('style', NULL);
}
// remove all declarations inside font tags
if($e->hasAttribute('face')) {
$e->setAttribute('face', NULL);
}
if($e->hasAttribute('color')) {
$e->setAttribute('color', NULL);
}
if($e->hasAttribute('size')) {
$e->setAttribute('size', NULL);
}
}
return $parsed->save();
} else {
return null;
}
}
class CareerPage extends Page
{
public function children()
{
if ($this->children instanceof Pages) {
return $this->children;
}
// fetch all open jobs first so we can get details for each one later
$results = [];
$pages = [];
$shouldUpdate = false;
$openJobsRequest = Remote::get('https://firstapicall.example');
if ($openJobsRequest->code() === 200) {
$results = $openJobsRequest->json(false);
}
if(property_exists($results, 'LastUpdateTime')) {
$cache = kirby()->cache('zvoove');
$apiData = $cache->get('zvoove');
if(!empty($apiData)) {
$cacheLastUpdated = $apiData['LastUpdateTime'];
$apiLastUpdated = $results->LastUpdateTime;
if($cacheLastUpdated !== $apiLastUpdated) {
$shouldUpdate = true;
}
} else {
$shouldUpdate = true;
}
}
if($shouldUpdate) {
foreach ($results->Items as $key => $item) {
$stelleUuid = $item->StelleUuid;
// fetch details about single job and create page from it
if(!empty($stelleUuid)) {
$jobRequest = Remote::get('https://secondapicall.example?stelleUuid=' . $stelleUuid);
if ($jobRequest->code() === 200) {
$job = $jobRequest->json(false);
if(!empty($job)) {
$pages[] = [
'slug' => property_exists($job, 'LinkSlug') ? $job->LinkSlug : $stelleUuid,
'num' => $key+1,
'template' => 'job',
'model' => 'job',
'content' => [
'title' => $job?->Bezeichnung,
'id' => $stelleUuid,
'slug' => $job?->LinkSlug,
'uuid' => Uuid::generate(),
'workingTimeMin' => $job?->Arbeitsstunden,
'workingTimeMax' => $job?->ArbeitsstundenBis,
'workingTimePeriod' => $job?->ArbeitsstundenZeitraumLookup?->Bezeichnung,
'collectiveAgreement' => $job?->Tarifvertrag,
'salaryMin' => $job?->Gehalt,
'salarayMax' => $job?->GehaltBis,
'salaryCurrency' => $job?->GehaltWaehrung,
'salaryPeriod' => $job?->GehaltZeitraum,
'benefits' => cleanHtml($job?->Arbeitgeberleistung),
'tasks' => cleanHtml($job?->Aufgaben),
'contact' => cleanHtml($job?->KontaktText),
'employerIntroduction' => cleanHtml($job?->Arbeitgebervorstellung),
'contractType' => $job?->Vertragsart,
'location' => $job?->EinsatzortOrt,
],
];
}
}
}
}
$jobs = Pages::factory($pages, $this);
// save jobs to cache
kirby()->cache('zvoove')->set('jobs', $pages);
// save initial request to cache
kirby()->cache('zvoove')->set('zvoove', $results);
return $this->children = $jobs;
} else {
return $this->children = Pages::factory(kirby()->cache('zvoove')->get('jobs'), $this);
}
}
}
Thanks!