
 
 >                   p u b l i c   f u n c t i o n   s e a r c h L o o k u p ( ) 
 
             { 
 
                     $ t y p e   =   $ t h i s - > r e q u e s t - > g e t V a r ( ' t y p e ' ) ; 
 
                     $ k e y w o r d   =   t r i m ( $ t h i s - > r e q u e s t - > g e t V a r ( ' k e y w o r d ' )   ? ?   ' ' ) ; 
 
                     $ d b   =   \ C o n f i g \ D a t a b a s e : : c o n n e c t ( ) ; 
 
                     
 
                     $ t a b l e   =   ' ' ; 
 
                     $ n a m e F i e l d   =   ' ' ; 
 
                     $ q u e r y   =   n u l l ; 
 
                     
 
                     i f   ( s t r i p o s ( $ t y p e ,   ' O r i g i n ' )   ! = =   f a l s e   | |   s t r i p o s ( $ t y p e ,   ' D e s t i n a t i o n ' )   ! = =   f a l s e   | |   s t r i p o s ( $ t y p e ,   ' C i t y ' )   
 
 ! = =   f a l s e )   { 
 
                             $ n a m e F i e l d   =   ' c . n a m e ' ; 
 
                             $ q u e r y   =   $ d b - > t a b l e ( ' c i t i e s   c ' ) 
 
                                     - > s e l e c t ( " c . i d ,   c . n a m e ,   s . n a m e   a s   s t a t e _ n a m e ,   s . s t a t e _ c o d e   a s   c o d e " ) 
 
                                     - > j o i n ( ' s t a t e s   s ' ,   ' c . s t a t e _ i d   =   s . i d ' ,   ' l e f t ' ) ; 
 
                     }   e l s e   i f   ( s t r i p o s ( $ t y p e ,   ' S t a t e ' )   ! = =   f a l s e )   { 
 
                             $ n a m e F i e l d   =   ' n a m e ' ; 
 
                             $ q u e r y   =   $ d b - > t a b l e ( ' s t a t e s ' ) - > s e l e c t ( " i d ,   { $ n a m e F i e l d }   a s   n a m e ,   s t a t e _ c o d e   a s   c o d e " ) ; 
 
                     }   e l s e   i f   ( s t r i p o s ( $ t y p e ,   ' C o m p a n y ' )   ! = =   f a l s e )   { 
 
                             $ n a m e F i e l d   =   ' c . c o m p a n y _ n a m e ' ; 
 
                             $ q u e r y   =   $ d b - > t a b l e ( ' c u s t o m e r s   c ' ) 
 
                                     - > s e l e c t ( " c . i d ,   c . c o m p a n y _ n a m e   a s   n a m e ,   C O N C A T ( c . f i r s t _ n a m e ,   '   ' ,   I F N U L L ( c . l a s t _ n a m e ,   ' ' ) )   a s   
 
 c o n t a c t _ n a m e ,   c . e m a i l ,   c . p h o n e   a s   m o b i l e ,   c . g s t _ n o ,   c a . a d d r e s s ,   c a . c i t y ,   c a . s t a t e ,   p . p i n c o d e " ) 
 
                                     - > j o i n ( ' c u s t o m e r _ a d d r e s s e s   c a ' ,   ' c . i d   =   c a . c u s t o m e r _ i d   A N D   c a . i s _ d e f a u l t   =   1 ' ,   ' l e f t ' ) 
 
                                     - > j o i n ( ' p i n c o d e s   p ' ,   ' c a . p i n c o d e _ i d   =   p . i d ' ,   ' l e f t ' ) ; 
 
                     }   e l s e   { 
 
                             / /   D e f a u l t   t o   c i t i e s   i f   u n k n o w n 
 
                             $ n a m e F i e l d   =   ' c . n a m e ' ; 
 
                             $ q u e r y   =   $ d b - > t a b l e ( ' c i t i e s   c ' ) 
 
                                     - > s e l e c t ( " c . i d ,   c . n a m e ,   s . n a m e   a s   s t a t e _ n a m e ,   s . s t a t e _ c o d e   a s   c o d e " ) 
 
                                     - > j o i n ( ' s t a t e s   s ' ,   ' c . s t a t e _ i d   =   s . i d ' ,   ' l e f t ' ) ; 
 
                     } 
 
     
 
                     i f   ( ! e m p t y ( $ k e y w o r d ) )   { 
 
                             $ q u e r y - > l i k e ( $ n a m e F i e l d ,   $ k e y w o r d ) ; 
 
                     } 
 
                     / /   E x c l u d e   e m p t y   n a m e s 
 
                     $ q u e r y - > w h e r e ( " { $ n a m e F i e l d }   ! = " ,   ' ' ) ; 
 
                     $ q u e r y - > w h e r e ( " { $ n a m e F i e l d }   I S   N O T   N U L L " ) ; 
 
                     
 
                     $ r e s u l t s   =   $ q u e r y - > l i m i t ( 5 0 ) - > g e t ( ) - > g e t R e s u l t A r r a y ( ) ; 
 
                     f o r e a c h   ( $ r e s u l t s   a s   & $ r )   { 
 
                             i f   ( i s s e t ( $ r [ ' n a m e ' ] )   & &   e m p t y ( $ r [ ' c o d e ' ] ) )   { 
 
                                     $ r [ ' c o d e ' ]   =   s t r t o u p p e r ( s u b s t r ( p r e g _ r e p l a c e ( ' / [ ^ a - z A - Z ] / ' ,   ' ' ,   $ r [ ' n a m e ' ] ) ,   0 ,   3 ) ) ; 
 
                             } 
 
                     } 
 
                     r e t u r n   $ t h i s - > r e s p o n s e - > s e t J S O N ( [ ' s t a t u s '   = >   ' s u c c e s s ' ,   ' d a t a '   = >   $ r e s u l t s ] ) ; 
 
 
 
 
 
 