dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxContentMediaUsageScope.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxContent;
3
11if (!class_exists(dbxContentMediaUsageScope::class, false)) {
12final class dbxContentMediaUsageScope {
13
14 public static function language(string $lng = ''): string {
15 $lng = strtolower(trim($lng));
16 if ($lng === '' || $lng === 'undef') {
17 $lng = class_exists(dbxContentLng::class) ? dbxContentLng::current() : 'de';
18 }
19 $lng = preg_replace('/[^a-z0-9_-]+/', '', $lng) ?: 'de';
20 return substr($lng, 0, 12);
21 }
22
23 public static function sql(string $lng = ''): string {
24 return "content_lng = '" . str_replace("'", "''", self::language($lng)) . "'";
25 }
26
27 public static function withLanguage(string $where = '', string $lng = ''): string {
28 $scope = self::sql($lng);
29 $where = trim($where);
30 return $where === '' ? $scope : '(' . $where . ') AND ' . $scope;
31 }
32
33 public static function content(int $contentId, string $lng = ''): string {
34 return self::withLanguage('content_id = ' . max(0, $contentId), $lng);
35 }
36
37 public static function folder(int $folderId, string $lng = ''): string {
38 return self::withLanguage('folder_id = ' . max(0, $folderId), $lng);
39 }
40
41 public static function targetKey(int $contentId, int $folderId, string $lng = ''): string {
42 $prefix = self::language($lng) . ':';
43 return $contentId > 0
44 ? $prefix . 'content:' . $contentId
45 : $prefix . 'folder:' . max(0, $folderId);
46 }
47}
48}