| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Clubdeuce\WPLib\Components\GoogleMaps; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Clubdeuce\WPGoogleMaps\Location as WPLoc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Class Location_Model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package Clubdeuce\WPLib\Components\GoogleMaps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @method  string address() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @method  string formatted_address() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @method  string state() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @method  string zip_code() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @method  float  latitude() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @method  string location_type() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @method  float  longitude() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @method  string place_id() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @method  array  type() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @method  array  viewport() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class Location_Model extends Model_Base { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var \Clubdeuce\WPGoogleMaps\Location | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     protected $_location; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * Location_Model constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * @param array $args | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 | 4 |  | 	function __construct( $args = array() ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 4 |  | 		$location = new WPLoc( $args ); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 4 |  | 		$args = wp_parse_args( $args, array( | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 4 |  | 			'location' => $location, | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 | 4 |  | 		parent::__construct( $args ); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 | 4 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  | 	function has_location() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  | 		return $this->_has( '_location' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param  string $method_name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 4 |  |     public function __call( $method_name, $args ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 4 |  |         $value = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	    do { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 4 |  | 		    if ( property_exists( $this, "_{$method_name}" ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 2 |  | 			    $property = "_{$method_name}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 2 |  | 			    $value = $this->{$property}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 2 |  | 			    break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		    } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 2 |  | 		    if ( ! isset( $this->_location ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  | 		    	break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		    } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  | 		    $value = call_user_func_array( array( $this->_location, $method_name ), $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  | 	    } while ( false ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 4 |  |         return $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  |