| 
									
										
										
										
											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='') { | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // time period drill-down
 | 
					
						
							|  |  |  |         // FIXME make it similar to the bash version
 | 
					
						
							|  |  |  |         if (empty($from_time)) { | 
					
						
							|  |  |  |             $from_time = '0000-01-01'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (empty($until_time)) { | 
					
						
							|  |  |  |             $until_time = '9999-12-31'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $from_time = htmlspecialchars(strip_tags($from_time)); | 
					
						
							|  |  |  |         $until_time = htmlspecialchars(strip_tags($until_time)); | 
					
						
							| 
									
										
										
										
											2024-08-21 19:11:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // list of jitsi component events
 | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |         $sql = "SELECT jitsi_component, loglevel, time, component_id, event_type, event_param
 | 
					
						
							|  |  |  |                 FROM jitsi_components | 
					
						
							|  |  |  |                 WHERE LOWER(jitsi_component) = LOWER(%s) | 
					
						
							|  |  |  |                 AND component_id = %s";
 | 
					
						
							| 
									
										
										
										
											2024-10-03 14:31:39 +00:00
										 |  |  |         if ($event_type != '' && $event_type != 'event_type') { | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |             $sql .= " AND event_type LIKE '%%%s%%'"; | 
					
						
							| 
									
										
										
										
											2024-10-03 14:31:39 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-01-26 12:39:10 +00:00
										 |  |  |         $sql .= " AND (time >= '%s 00:00:00' AND time <= '%s 23:59:59') ORDER BY time"; | 
					
						
							| 
									
										
										
										
											2024-08-23 09:44:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-15 18:49:20 +00:00
										 |  |  |         if ($items_per_page) { | 
					
						
							|  |  |  |             $items_per_page = (int)$items_per_page; | 
					
						
							|  |  |  |             $sql .= ' LIMIT ' . $offset . ',' . $items_per_page; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-03 14:31:39 +00:00
										 |  |  |         // FIXME this needs to be done with bound params instead of sprintf
 | 
					
						
							|  |  |  |         if ($event_type != '' && $event_type != 'event_type') { | 
					
						
							|  |  |  |             $sql = sprintf($sql, $jitsi_component, $component_id, $event_type, $from_time, $until_time); | 
					
						
							|  |  |  |             $sql = str_replace("LIKE '%'", "LIKE '%", $sql); | 
					
						
							|  |  |  |             $sql = str_replace("'%'\nAND", "%' AND", $sql); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $sql = sprintf($sql, $jitsi_component, $component_id, $from_time, $until_time); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $query = $this->db->prepare($sql); | 
					
						
							| 
									
										
										
										
											2024-08-22 08:59:48 +00:00
										 |  |  |         $query->execute(); | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $query->fetchAll(PDO::FETCH_ASSOC); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) { | 
					
						
							|  |  |  |         // time period drill-down
 | 
					
						
							|  |  |  |         if (empty($from_time)) { | 
					
						
							|  |  |  |             $from_time = '0000-01-01'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (empty($until_time)) { | 
					
						
							|  |  |  |             $until_time = '9999-12-31'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $from_time = htmlspecialchars(strip_tags($from_time)); | 
					
						
							|  |  |  |         $until_time = htmlspecialchars(strip_tags($until_time)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Build the query
 | 
					
						
							|  |  |  |         $sql = "SELECT COUNT(*) as total
 | 
					
						
							|  |  |  |                 FROM jitsi_events | 
					
						
							|  |  |  |                 WHERE time >= :from_time | 
					
						
							|  |  |  |                 AND time <= :until_time | 
					
						
							|  |  |  |                 AND LOWER(jitsi_component) = LOWER(:jitsi_component) | 
					
						
							|  |  |  |                 AND component_id) = :component_id | 
					
						
							|  |  |  |                 AND LOWER(event_type) = LOWER(:event_type)";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $stmt = $this->db->prepare($sql); | 
					
						
							|  |  |  |             $stmt->bindParam(':from_time', $from_time); | 
					
						
							|  |  |  |             $stmt->bindParam(':until_time', $until_time); | 
					
						
							|  |  |  |             $stmt->bindParam(':jitsi_component', $jitsi_component); | 
					
						
							|  |  |  |             $stmt->bindParam(':component_id', $component_id); | 
					
						
							|  |  |  |             $stmt->bindParam(':event_type', $event_type); | 
					
						
							|  |  |  |             $stmt->execute(); | 
					
						
							|  |  |  |             $result = $stmt->fetch(PDO::FETCH_ASSOC); | 
					
						
							|  |  |  |             return (int)$result['total']; | 
					
						
							|  |  |  |         } catch (PDOException $e) { | 
					
						
							|  |  |  |             error_log("Error in getComponentCount: " . $e->getMessage()); | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-07-08 09:17:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |