| 
									
										
										
										
											2023-07-10 19:57:16 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Publicsearch extends CI_Model { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function search($slug, $callsign) { | 
					
						
							| 
									
										
										
										
											2023-07-13 22:43:17 +08:00
										 |  |  | 		if ($this->public_search_enabled($slug)) { | 
					
						
							|  |  |  | 			$userid = $this->get_userid_for_slug($slug); | 
					
						
							| 
									
										
										
										
											2023-07-14 13:53:54 +08:00
										 |  |  | 			$this->db->like('COL_CALL', $callsign); | 
					
						
							| 
									
										
										
										
											2023-07-13 22:43:17 +08:00
										 |  |  | 			$this->db->join('station_profile', 'station_profile.station_id = '.$this->config->item('table_name').'.station_id'); | 
					
						
							|  |  |  | 			$this->db->join('lotw_users', 'lotw_users.callsign = '.$this->config->item('table_name').'.col_call', 'left outer'); | 
					
						
							|  |  |  | 			$this->db->where('station_profile.user_id', $userid); | 
					
						
							|  |  |  | 			$this->db->order_by('COL_TIME_ON', 'DESC'); | 
					
						
							|  |  |  | 			$query = $this->db->get($this->config->item('table_name')); | 
					
						
							|  |  |  | 			return $query; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2023-07-10 19:57:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function get_userid_for_slug($slug) { | 
					
						
							|  |  |  | 		$this->db->select('user_id'); | 
					
						
							|  |  |  | 		$this->db->where('public_slug', $slug); | 
					
						
							| 
									
										
										
										
											2023-07-13 22:43:17 +08:00
										 |  |  | 		$query = $this->db->get('station_logbooks'); | 
					
						
							| 
									
										
										
										
											2023-07-10 19:57:16 +08:00
										 |  |  | 		return $query->result_array()[0]['user_id']; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-13 22:43:17 +08:00
										 |  |  | 	function public_search_enabled($slug) { | 
					
						
							|  |  |  | 		$this->db->select('public_search'); | 
					
						
							|  |  |  | 		$this->db->where('public_slug', $slug); | 
					
						
							|  |  |  | 		$query = $this->db->get('station_logbooks'); | 
					
						
							|  |  |  | 		if ($query->result_array()[0]['public_search'] == 1) { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 19:57:16 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |