| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-29 16:51:52 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * class Component | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Provides methods to interact with Jitsi component events in the database. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | class Component { | 
					
						
							| 
									
										
										
										
											2024-11-29 16:51:52 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @var PDO|null $db The database connection instance. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  |     private $db; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-29 16:51:52 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Component constructor. | 
					
						
							|  |  |  |      * Initializes the database connection. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param object $database The database object to initialize the connection. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  |     public function __construct($database) { | 
					
						
							|  |  |  |         $this->db = $database->getConnection(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-29 16:51:52 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Retrieves Jitsi component events based on various filters. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param string $jitsi_component The Jitsi component name. | 
					
						
							|  |  |  |      * @param int $component_id The component ID. | 
					
						
							|  |  |  |      * @param string $event_type The type of event to filter by. | 
					
						
							|  |  |  |      * @param string $from_time The start date in 'YYYY-MM-DD' format. | 
					
						
							|  |  |  |      * @param string $until_time The end date in 'YYYY-MM-DD' format. | 
					
						
							|  |  |  |      * @param int $offset The offset for pagination. | 
					
						
							|  |  |  |      * @param int $items_per_page The number of items to retrieve per page. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array The list of Jitsi component events or an empty array if no results. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2024-10-03 14:31:39 +00:00
										 |  |  |     public function jitsiComponents($jitsi_component, $component_id, $event_type, $from_time, $until_time, $offset=0, $items_per_page='') { | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |         global $logObject; | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             // Add time part to dates if not present
 | 
					
						
							|  |  |  |             if (strlen($from_time) <= 10) { | 
					
						
							|  |  |  |                 $from_time .= ' 00:00:00'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (strlen($until_time) <= 10) { | 
					
						
							|  |  |  |                 $until_time .= ' 23:59:59'; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             // list of jitsi component events
 | 
					
						
							|  |  |  |             $sql = "SELECT jitsi_component, loglevel, time, component_id, event_type, event_param
 | 
					
						
							|  |  |  |                     FROM jitsi_components | 
					
						
							|  |  |  |                     WHERE time >= :from_time  | 
					
						
							|  |  |  |                     AND time <= :until_time";
 | 
					
						
							| 
									
										
										
										
											2024-08-23 09:44:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             // Only add component and event filters if they're not the default values
 | 
					
						
							|  |  |  |             if ($jitsi_component !== 'jitsi_component') { | 
					
						
							|  |  |  |                 $sql .= " AND LOWER(jitsi_component) = LOWER(:jitsi_component)"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($component_id !== 'component_id') { | 
					
						
							|  |  |  |                 $sql .= " AND component_id = :component_id"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($event_type !== 'event_type') { | 
					
						
							|  |  |  |                 $sql .= " AND event_type LIKE :event_type"; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-09-15 18:49:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             $sql .= " ORDER BY time"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($items_per_page) { | 
					
						
							|  |  |  |                 $sql .= ' LIMIT :offset, :items_per_page'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $stmt = $this->db->prepare($sql); | 
					
						
							| 
									
										
										
										
											2025-02-23 11:51:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             // Bind parameters only if they're not default values
 | 
					
						
							|  |  |  |             if ($jitsi_component !== 'jitsi_component') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':jitsi_component', trim($jitsi_component, "'")); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($component_id !== 'component_id') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':component_id', trim($component_id, "'")); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($event_type !== 'event_type') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':event_type', '%' . trim($event_type, "'") . '%'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $stmt->bindParam(':from_time', $from_time); | 
					
						
							|  |  |  |             $stmt->bindParam(':until_time', $until_time); | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             if ($items_per_page) { | 
					
						
							|  |  |  |                 $stmt->bindParam(':offset', $offset, PDO::PARAM_INT); | 
					
						
							|  |  |  |                 $stmt->bindParam(':items_per_page', $items_per_page, PDO::PARAM_INT); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             $stmt->execute(); | 
					
						
							|  |  |  |             $result = $stmt->fetchAll(PDO::FETCH_ASSOC); | 
					
						
							| 
									
										
										
										
											2025-02-23 11:51:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             if (!empty($result)) { | 
					
						
							|  |  |  |                 $logObject->insertLog(0, "Retrieved " . count($result) . " Jitsi component events"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return $result; | 
					
						
							|  |  |  |         } catch (PDOException $e) { | 
					
						
							|  |  |  |             $logObject->insertLog(0, "Failed to retrieve Jitsi component events: " . $e->getMessage()); | 
					
						
							|  |  |  |             return []; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Gets the total count of components events matching the filter criteria | 
					
						
							|  |  |  |      *  | 
					
						
							|  |  |  |      * @param string $jitsi_component The Jitsi component name. | 
					
						
							|  |  |  |      * @param int $component_id The component ID. | 
					
						
							|  |  |  |      * @param string $event_type The type of event to filter by. | 
					
						
							|  |  |  |      * @param string $from_time The start date in 'YYYY-MM-DD' format. | 
					
						
							|  |  |  |      * @param string $until_time The end date in 'YYYY-MM-DD' format. | 
					
						
							|  |  |  |      *  | 
					
						
							|  |  |  |      * @return int The total count of matching components | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getComponentEventsCount($jitsi_component, $component_id, $event_type, $from_time, $until_time) { | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |         global $logObject; | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             // Add time part to dates if not present
 | 
					
						
							|  |  |  |             if (strlen($from_time) <= 10) { | 
					
						
							|  |  |  |                 $from_time .= ' 00:00:00'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (strlen($until_time) <= 10) { | 
					
						
							|  |  |  |                 $until_time .= ' 23:59:59'; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Build the query
 | 
					
						
							|  |  |  |             $sql = "SELECT COUNT(*) as total
 | 
					
						
							|  |  |  |                     FROM jitsi_components | 
					
						
							|  |  |  |                     WHERE time >= :from_time | 
					
						
							|  |  |  |                     AND time <= :until_time";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // Only add component and event filters if they're not the default values
 | 
					
						
							|  |  |  |             if ($jitsi_component !== 'jitsi_component') { | 
					
						
							|  |  |  |                 $sql .= " AND LOWER(jitsi_component) = LOWER(:jitsi_component)"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($component_id !== 'component_id') { | 
					
						
							|  |  |  |                 $sql .= " AND component_id = :component_id"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($event_type !== 'event_type') { | 
					
						
							|  |  |  |                 $sql .= " AND event_type LIKE :event_type"; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |             $stmt = $this->db->prepare($sql); | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // Bind parameters only if they're not default values
 | 
					
						
							|  |  |  |             if ($jitsi_component !== 'jitsi_component') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':jitsi_component', trim($jitsi_component, "'")); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($component_id !== 'component_id') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':component_id', trim($component_id, "'")); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if ($event_type !== 'event_type') { | 
					
						
							|  |  |  |                 $stmt->bindValue(':event_type', '%' . trim($event_type, "'") . '%'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |             $stmt->bindParam(':from_time', $from_time); | 
					
						
							|  |  |  |             $stmt->bindParam(':until_time', $until_time); | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |             $stmt->execute(); | 
					
						
							|  |  |  |             $result = $stmt->fetch(PDO::FETCH_ASSOC); | 
					
						
							|  |  |  |             return (int)$result['total']; | 
					
						
							|  |  |  |         } catch (PDOException $e) { | 
					
						
							| 
									
										
										
										
											2025-02-23 11:15:46 +00:00
										 |  |  |             $logObject->insertLog(0, "Failed to retrieve component events count: " . $e->getMessage()); | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |