designtopack/public/site/plugins/user-projects/index.php

24 lines
845 B
PHP
Raw Normal View History

<?php
Kirby::plugin('adrienpayet/pdc-authorized-projects', [
'userMethods' => [
'currentProjects' => function() {
$listed = page('projects')->children()->listed();
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
return $listed;
}
return $listed->filter(fn($project) => $project->users()->toUsers()->has($this));
},
'archivedProjects' => function() {
$unlisted = page('projects')->children()->unlisted();
if ($this->role() == 'admin' && $this->hasNoAssignedProjects()) {
return $unlisted;
}
return $unlisted->filter(fn($project) => $project->users()->toUsers()->has($this));
},
'hasNoAssignedProjects' => function() {
return page('projects')->children()->filter(fn($p) => $p->users()->toUsers()->has($this))->isEmpty();
},
]
]);