Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Constants
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
110
0.00% covered (danger)
0.00%
0 / 1
 isImageMimeType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isVideoMimeType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getSlideTypeForMime
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getSourceTable
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Digital Signage Constants
4 *
5 * Defines constants for slide types, sources, and schedule states
6 * to replace magic numbers throughout the digital signage codebase.
7 *
8 * @package BuyerKiosk\DigitalSign
9 * @since December 2025
10 */
11
12namespace BuyerKiosk\DigitalSign;
13
14class Constants
15{
16    // ============================================
17    // Slide Types (stored in dsSlides.type, dsLoop.type)
18    // ============================================
19
20    /** Image slide (gif, jpg, png) */
21    public const SLIDE_TYPE_IMAGE = 0;
22
23    /** Video slide (mp4, webm) */
24    public const SLIDE_TYPE_VIDEO = 1;
25
26    /** Queue display slide (live queue data) */
27    public const SLIDE_TYPE_QUEUE = 3;
28
29    // ============================================
30    // Slide Sources / Uploaders (stored in dsLoop.slideUploader)
31    // ============================================
32
33    /** Store-specific slide (from dsSlides table in store DB) */
34    public const SOURCE_STORE = 0;
35
36    /** Corporate slide (from corpSlides table in global DB) */
37    public const SOURCE_CORPORATE = 1;
38
39    /** Hipbone/partner slide (from hbSlides table in global DB) */
40    public const SOURCE_HIPBONE = 2;
41
42    // ============================================
43    // Schedule States (stored in dsLoop.scheduled)
44    // ============================================
45
46    /** Slide is currently active and visible */
47    public const SCHEDULE_ACTIVE = 0;
48
49    /** Slide is scheduled for future activation */
50    public const SCHEDULE_PENDING = 1;
51
52    // ============================================
53    // Enabled States (stored in dsSlides.enabled)
54    // ============================================
55
56    /** Slide is disabled/hidden */
57    public const ENABLED_NO = 0;
58
59    /** Slide is enabled/visible */
60    public const ENABLED_YES = 1;
61
62    // ============================================
63    // Permission Keys
64    // ============================================
65
66    /** Permission required to manage digital signage */
67    public const PERMISSION_DIGITAL_SIGNAGE = 'uri_digitalsign';
68
69    // ============================================
70    // Accepted MIME Types
71    // ============================================
72
73    /** Accepted image MIME types */
74    public const MIME_TYPES_IMAGE = [
75        'image/gif',
76        'image/jpeg',
77        'image/png',
78    ];
79
80    /** Accepted video MIME types */
81    public const MIME_TYPES_VIDEO = [
82        'video/mp4',
83        'video/webm',
84    ];
85
86    /** All accepted MIME types */
87    public const MIME_TYPES_ALL = [
88        'image/gif',
89        'image/jpeg',
90        'image/png',
91        'video/mp4',
92        'video/webm',
93    ];
94
95    // ============================================
96    // Default Values
97    // ============================================
98
99    /** Default animation for slides */
100    public const DEFAULT_ANIMATION = 'fadeIn';
101
102    /** Default duration for slides (seconds) */
103    public const DEFAULT_DURATION = 10;
104
105    /** Thumbnail extraction time for videos (seconds) */
106    public const VIDEO_THUMBNAIL_SECOND = 5;
107
108    /** Maximum thumbnail dimension (pixels) */
109    public const THUMBNAIL_MAX_SIZE = 300;
110
111    // ============================================
112    // Helper Methods
113    // ============================================
114
115    /**
116     * Check if a MIME type is an image type
117     *
118     * @param string $mimeType The MIME type to check
119     * @return bool True if image type
120     */
121    public static function isImageMimeType(string $mimeType): bool
122    {
123        return in_array($mimeType, self::MIME_TYPES_IMAGE, true);
124    }
125
126    /**
127     * Check if a MIME type is a video type
128     *
129     * @param string $mimeType The MIME type to check
130     * @return bool True if video type
131     */
132    public static function isVideoMimeType(string $mimeType): bool
133    {
134        return in_array($mimeType, self::MIME_TYPES_VIDEO, true);
135    }
136
137    /**
138     * Get the slide type constant for a MIME type
139     *
140     * @param string $mimeType The MIME type
141     * @return int|null The slide type constant, or null if unknown
142     */
143    public static function getSlideTypeForMime(string $mimeType): ?int
144    {
145        if (self::isImageMimeType($mimeType)) {
146            return self::SLIDE_TYPE_IMAGE;
147        }
148        if (self::isVideoMimeType($mimeType)) {
149            return self::SLIDE_TYPE_VIDEO;
150        }
151        return null;
152    }
153
154    /**
155     * Get source table name for a slideUploader value
156     *
157     * @param int $slideUploader The slideUploader value
158     * @return string|null The table name, or null if unknown
159     */
160    public static function getSourceTable(int $slideUploader): ?string
161    {
162        switch ($slideUploader) {
163            case self::SOURCE_STORE:
164                return 'dsSlides';
165            case self::SOURCE_CORPORATE:
166                return 'corpSlides';
167            case self::SOURCE_HIPBONE:
168                return 'hbSlides';
169            default:
170                return null;
171        }
172    }
173}