36 lines
1,008 B
PHP
36 lines
1,008 B
PHP
<?php
|
|
|
|
// UPDATE TRACKS INDEX OF ALL RELEASE EACH TIME SOMETHING HAPPENS WITH A RELEASE
|
|
|
|
// Each time something happens with a page
|
|
kirby()->hook('panel.page.*', function($page, $oldPage = null) {
|
|
// If the page is a release
|
|
if($page->intendedTemplate() == 'release') {
|
|
|
|
// Get all artists
|
|
$artists = site()->index()->filterBy('intendedTemplate', 'artist');
|
|
|
|
// For each artist
|
|
foreach ($artists as $key => $a) {
|
|
$index = 0;
|
|
|
|
// For each release of the artist
|
|
foreach ($a->children()->published() as $key => $p) {
|
|
// Get all tracks of the release
|
|
$tracks = $p->tracklist()->toStructure();
|
|
|
|
// For each track
|
|
foreach ($tracks as $key => $t) {
|
|
|
|
// If the track has and audio file
|
|
if($file = $t->audioFile()->toFile()) {
|
|
// Update the track index
|
|
$file->update(['trackIndex' => $index]);
|
|
$index++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
});
|