• Tidak ada hasil yang ditemukan

e m p t y F i e l d = ” p s d i s p l a y ” ; i d = t h i s . i d ;

}

i f ( i p A r r a y . l e n g t h != 4 ) { i n v a l i d I P = t r u e ; i d = t h i s . i d ; } e l s e {

f o r ( i = 0 ; i < i p A r r a y . l e n g t h ; i ++) { i p A r r a y [ i ] = i p A r r a y [ i ] . t r i m ( ) ;

i f ( ! $ . i s N u m e r i c ( i p A r r a y [ i ] ) | | i p A r r a y [ i ] < 0 | | i p A r r a y [ i ] > 2 5 5 ) {

i n v a l i d I P = t r u e ; i d = t h i s . i d ; }

}

i p = i p A r r a y . j o i n ( ” . ” ) ;

$(”#”+ t h i s . i d . r e p l a c e ( ” t y p e ” , ” i p ” ) ) . v a l ( i p ) ; }

} e l s e {

i d = t h i s . i d ; }

}) ;

i f ( e m p t y F i e l d != n u l l && i d != n u l l ) { a l e r t ( ” Empty f i e l d ( s ) ” ) ;

v a r i n d e x = i d . s u b s t r i n g ( i d . i n d e x O f ( ” ” ) + 1 , i d . l a s t I n d e x O f ( ” ” ) ) ; t o g g l e S e l e c t e d ( document . g e t E l e m e n t B y I d ( ” d r a g g a b l e ”+ i n d e x ) ) ; window . o n b e f o r e u n l o a d = f u n c t i o n ( ) {

r e t u r n ” E v e r y t h i n g w i l l be l o s t i f you don ’ t s a v e y o u r work . ” }

e v e n t . p r e v e n t D e f a u l t ( ) ; } e l s e i f ( i n v a l i d I P ) {

a l e r t ( ” I n v a l i d IP A d d r e s s ” ) ;

v a r i n d e x = i d . s u b s t r i n g ( i d . i n d e x O f ( ” ” ) + 1 , i d . l a s t I n d e x O f ( ” ” ) ) ; t o g g l e S e l e c t e d ( document . g e t E l e m e n t B y I d ( ” d r a g g a b l e ”+ i n d e x ) ) ; window . o n b e f o r e u n l o a d = f u n c t i o n ( ) {

r e t u r n ” E v e r y t h i n g w i l l be l o s t i f you don ’ t s a v e y o u r work . ” }

e v e n t . p r e v e n t D e f a u l t ( ) ; } e l s e i f ( i d != n u l l ) {

a l e r t ( ” No D e v i c e Type ” ) ;

v a r i n d e x = i d . s u b s t r i n g ( i d . i n d e x O f ( ” ” ) + 1 , i d . l a s t I n d e x O f ( ” ” ) ) ; t o g g l e S e l e c t e d ( document . g e t E l e m e n t B y I d ( ” d r a g g a b l e ”+ i n d e x ) ) ; window . o n b e f o r e u n l o a d = f u n c t i o n ( ) {

r e t u r n ” E v e r y t h i n g w i l l be l o s t i f you don ’ t s a v e y o u r work . ” }

e v e n t . p r e v e n t D e f a u l t ( ) ; } e l s e i f ( ! T S P r e s e n t ) {

a l e r t ( ” T e r m i n a l S e r v e r n o t f o u n d ” ) ; window . o n b e f o r e u n l o a d = f u n c t i o n ( ) {

r e t u r n ” E v e r y t h i n g w i l l be l o s t i f you don ’ t s a v e y o u r work . ” }

e v e n t . p r e v e n t D e f a u l t ( ) ; }

r e t u r n ; }

f u n c t i o n a c t i v a t e ( t a b ) {

$(”#”+ t a b+”−t a b ” ) . show ( ) . s i b l i n g s ( ) . h i d e ( ) ;

$(”#”+ t a b+”−l i n k ” ) . a d d C l a s s ( ” a c t i v e ” ) . s i b l i n g s ( ) . r e m o v e C l a s s ( ” a c t i v e ” ) ; }

f u n c t i o n d e s e l e c t A l l D e v i c e s ( ) {

$(”# c o n t a i n e r d i v ” ) . e a c h ( f u n c t i o n ( ) {

$ ( t h i s ) . r e m o v e C l a s s ( ” s e l e c t e d ” ) ;

v a r i n d e x = t h i s . i d . s u b s t r ( 9 , t h i s . i d . l e n g t h ) ;

$(”# d e l e t e ”+ i n d e x ) . h i d e ( ) ;

$(”# u l ”+ i n d e x ) . h i d e ( ) ; v i e w ( n u l l , t h i s . i d ) ; }) ;

}

p u b l i c f u n c t i o n r u l e s ( ) {

r e t u r n a r r a y (

// e m p l o y e e i d , p a s s w o r d , r e t y p e p a s s w o r d , f i r s t name , and p a s s w o r d a r e r e q u i r e d

a r r a y ( ’ e m p l o y e e i d , p a s s , r e t y p e , f i r s t n a m e , l a s t n a m e ’ , ’ r e q u i r e d ’ ) , // p a s s w o r d n e e d s t o be v a l i d a t e d

a r r a y ( ’ p a s s ’ , ’ v a l i d ’ ) , ) ;

} /∗∗

∗ V a l i d a t e s t h e p a s s w o r d and r e t y p e .

∗ T h i s i s t h e ’ v a l i d ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n v a l i d ( $ a t t r i b u t e , $params ) {

i f ( s t r l e n ( $ t h i s−>p a s s ) < 6 )

$ t h i s−>a d d E r r o r ( ’ p a s s ’ , ’ P a s s w o r d must be a t l e a s t s i x ( 6 ) c h a r a c t e r s l o n g . ’ ) ;

i f ( $ t h i s−>p a s s !== $ t h i s−>r e t y p e )

$ t h i s−>a d d E r r o r ( ’ p a s s ’ , ’ P a s s w o r d s d i d n o t match . ’ ) ; }

/∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ e m p l o y e e i d ’=>’ Employee ID ’ ,

’ p a s s ’=>’ Password ’ ,

’ r e t y p e ’=>’ R e t y p e Password ’ , ) ;

} }

Listing 7: Cable Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” c a b l e ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ c a b l e ’ :

∗ @ p r o p e r t y i n t e g e r $ i d

∗ @ p r o p e r t y s t r i n g $ c o u r s e c o d e

∗ @ p r o p e r t y s t r i n g $ d e v i c e n a m e

∗ @ p r o p e r t y i n t e g e r $ t y p e

∗ @ p r o p e r t y s t r i n g $ p a t h

∗ @ p r o p e r t y s t r i n g $ t r a n s f o r m

∗ @ p r o p e r t y s t r i n g $ p o r t a

∗ @ p r o p e r t y s t r i n g $ p o r t b

∗ @ p r o p e r t y s t r i n g $ p o r t a c o o r

∗ @ p r o p e r t y s t r i n g $ p o r t b c o o r

∗ @ p r o p e r t y s t r i n g $ c o l o r

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y C o u r s e $ c o u r s e C o d e

∗ @ p r o p e r t y D e v i c e $ d e v i c e N a m e

∗/

c l a s s C a b l e M o d e l e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ c a b l e ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ c o u r s e c o d e , t y p e , path ’ , ’ r e q u i r e d ’ ) , a r r a y ( ’ t y p e ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) ,

a r r a y ( ’ c o u r s e c o d e , d e v i c e n a m e , t r a n s f o r m ’ , ’ l e n g t h ’ , ’ max’=>64) , a r r a y ( ’ path , p o r t a c o o r , p o r t b c o o r ’ , ’ l e n g t h ’ , ’ max’=>128) , a r r a y ( ’ p o r t a , p o r t b ’ , ’ l e n g t h ’ , ’ max’=>16) ,

a r r a y ( ’ c o l o r ’ , ’ l e n g t h ’ , ’ max’=>32) , // The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ i d , c o u r s e c o d e , d e v i c e n a m e , t y p e , path , t r a n s f o r m , p o r t a ,

p o r t b , p o r t a c o o r , p o r t b c o o r , c o l o r ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ c o u r s e M o d e l ’ => a r r a y ( s e l f : : BELONGS TO, ’ CourseModel ’ , ’ c o u r s e c o d e ’ ) ,

’ d e v i c e M o d e l ’ => a r r a y ( s e l f : : BELONGS TO, ’ D e v i c e M o d e l ’ , ’ d e v i c e n a m e ’ ) ,

) ; }

/∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ i d ’ => ’ ID ’ ,

’ c o u r s e c o d e ’ => ’ C o u r s e Code ’ ,

’ d e v i c e n a m e ’ => ’ D e v i c e Name ’ ,

’ t y p e ’ => ’ Type ’ ,

’ path ’ => ’ Path ’ ,

’ t r a n s f o r m ’ => ’ T r a n s f o r m ’ ,

’ p o r t a ’ => ’ P o r t A’ ,

’ p o r t b ’ => ’ P o r t B ’ ,

’ p o r t a c o o r ’ => ’ P o r t A Coor ’ ,

’ p o r t b c o o r ’ => ’ P o r t B Coor ’ ,

’ c o l o r ’ => ’ C o l o r ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ i d ’ , $ t h i s−>i d ) ;

$ c r i t e r i a−>compare ( ’ c o u r s e c o d e ’ , $ t h i s−>c o u r s e c o d e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ d e v i c e n a m e ’ , $ t h i s−>d e v i c e n a m e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ t y p e ’ , $ t h i s−>t y p e ) ;

$ c r i t e r i a−>compare ( ’ path ’ , $ t h i s−>path , t r u e ) ;

$ c r i t e r i a−>compare ( ’ t r a n s f o r m ’ , $ t h i s−>t r a n s f o r m , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p o r t a ’ , $ t h i s−>p o r t a , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p o r t b ’ , $ t h i s−>p o r t b , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p o r t a c o o r ’ , $ t h i s−>p o r t a c o o r , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p o r t b c o o r ’ , $ t h i s−>p o r t b c o o r , t r u e ) ;

$ c r i t e r i a−>compare ( ’ c o l o r ’ , $ t h i s−>c o l o r , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n C a b l e M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 8: Change Password Form

<?php /∗∗

∗ ChangePasswordForm c l a s s .

∗ ChangePasswordForm i s t h e d a t a s t r u c t u r e f o r k e e p i n g

∗ u s e r c h a n g e p a s s w o r d f o r m d a t a . I t i s u s e d by t h e ’ c h a n g e P a s s ’ a c t i o n o f ’ U s e r C o n t r o l l e r ’ .

∗/

c l a s s ChangePasswordForm e x t e n d s CFormModel {

p u b l i c $ c u r r e n t P a s s , $newPass , $ r e t y p e ; /∗∗

∗ D e c l a r e s t h e v a l i d a t i o n r u l e s .

∗ The r u l e s s t a t e t h a t u s e r n a m e and p a s s w o r d a r e r e q u i r e d ,

∗ and p a s s w o r d n e e d s t o be a u t h e n t i c a t e d .

∗/

p u b l i c f u n c t i o n r u l e s ( )

{

r e t u r n a r r a y (

// c u r r e n t p a s s w o r d , new p a s s w o r d , and r e t y p e p a s s w o r d a r e r e q u i r e d a r r a y ( ’ c u r r e n t P a s s , newPass , r e t y p e ’ , ’ r e q u i r e d ’ ) ,

// c u r r e n t p a s s w o r d n e e d s t o be a u t h e n t i c a t e d a r r a y ( ’ c u r r e n t P a s s ’ , ’ a u t h e n t i c a t e ’ ) ,

// new p a s s w o r d n e e d s t o be v a l i d a t e d a r r a y ( ’ newPass ’ , ’ v a l i d ’ ) ,

) ; }

/∗∗

∗ A u t h e n t i c a t e s t h e c u r r e n t p a s s w o r d .

∗ T h i s i s t h e ’ a u t h e n t i c a t e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n a u t h e n t i c a t e ( $ a t t r i b u t e , $params ) {

$ u s e r = U s e r M o d e l : : model ( )−>f i n d B y P k ( Y i i : : app ( )−>u s e r−>i d ) ; i f ( ! p a s s w o r d v e r i f y ( $ t h i s−>c u r r e n t P a s s , $ u s e r−>p a s s ) )

$ t h i s−>a d d E r r o r ( ’ c u r r e n t P a s s ’ , ’ I n v a l i d P a s s w o r d . ’ ) ; }

/∗∗

∗ V a l i d a t e s t h e new p a s s w o r d .

∗ T h i s i s t h e ’ a u t h e n t i c a t e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n v a l i d ( $ a t t r i b u t e , $params ) {

i f ( s t r l e n ( $ t h i s−>newPass ) < 6 )

$ t h i s−>a d d E r r o r ( ’ newPass ’ , ’ P a s s w o r d must be a t l e a s t s i x ( 6 ) c h a r a c t e r s l o n g . ’ ) ;

i f ( $ t h i s−>r e t y p e !== $ t h i s−>newPass )

$ t h i s−>a d d E r r o r ( ’ r e t y p e ’ , ’ P a s s w o r d s d i d n o t match ’ ) ; }

/∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ c u r r e n t P a s s ’=>’ C u r r e n t Password ’ ,

’ newPass ’=>’New Password ’ ,

’ r e t y p e ’=>’ R e t y p e New Password ’ , ) ;

} }

Listing 9: Class Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” c l a s s ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ c l a s s ’ :

∗ @ p r o p e r t y i n t e g e r $ i d

∗ @ p r o p e r t y s t r i n g $ c o u r s e c o d e

∗ @ p r o p e r t y s t r i n g $ p a s s

∗ @ p r o p e r t y s t r i n g $ p r o f

∗ @ p r o p e r t y s t r i n g $ t s i p

∗ @ p r o p e r t y s t r i n g $ t s u s e r

∗ @ p r o p e r t y s t r i n g $ t s p a s s

∗ @ p r o p e r t y i n t e g e r $ n u m o f s t u d e n t s

∗ @ p r o p e r t y s t r i n g $ h a s p o d s

∗ @ p r o p e r t y s t r i n g $ e x p

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y U s e r $ p r o f e s s o r

∗ @ p r o p e r t y C o u r s e $ c o u r s e C o d e

∗ @ p r o p e r t y Pod [ ] $ p o d s

∗/

c l a s s C l a s s M o d e l e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ c l a s s ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ c o u r s e c o d e , p a s s , p r o f , t s i p , t s u s e r , t s p a s s , n u m o f s t u d e n t s , exp ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ n u m o f s t u d e n t s ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) , a r r a y ( ’ c o u r s e c o d e ’ , ’ l e n g t h ’ , ’ max’=>64) ,

a r r a y ( ’ p a s s , p r o f , t s i p , t s u s e r , t s p a s s ’ , ’ l e n g t h ’ , ’ max’=>32) ,

a r r a y ( ’ h a s p o d s ’ , ’ l e n g t h ’ , ’ max’=>3) , a r r a y ( ’ c o u r s e c o d e ’ , ’ nonZero ’ ) , a r r a y ( ’ t s i p ’ , ’ v a l i d I P ’ ) , a r r a y ( ’ exp ’ , ’ f u t u r e ’ ) ,

// The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ i d , c o u r s e c o d e , p a s s , p r o f , t s i p , t s u s e r , t s p a s s ,

n u m o f s t u d e n t s , h a s p o d s , exp ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ C h e c k s w h e t h e r t h e c o u r s e c o d e i s empty .

∗ T h i s i s t h e ’ nonZero ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n n o n Z e r o ( $ a t t r i b u t e , $params ) {

i f ( $ t h i s−>c o u r s e c o d e === ’ 0 ’ )

$ t h i s−>a d d E r r o r ( ’ c o u r s e c o d e ’ , ’ C o u r s e Code c a n n o t be b l a n k ’ ) ; }

/∗∗

∗ C h e c k s w h e t h e r t h e t e r m i n a l s e r v e r IP a d d r e s s i s v a l i d .

∗ T h i s i s t h e ’ v a l i d I P ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n v a l i d I P ( $ a t t r i b u t e , $params ) {

$ i p a d d r = e x p l o d e ( ” . ” , $ t h i s−>t s i p ) ; i f ( c o u n t ( $ i p a d d r ) != 4 ) {

$ t h i s−>a d d E r r o r ( ’ t s i p ’ , ’ I n v a l i d IP A d d r e s s l e n g t h ’ ) ; } e l s e {

f o r e a c h ( $ i p a d d r a s $ i p ) {

$ i p = t r i m ( $ i p ) ;

i f ( ! i s n u m e r i c ( $ i p ) | | $ i p < 0 | | $ i p > 2 5 5 )

$ t h i s−>a d d E r r o r ( ’ t s i p ’ , ’ I n v a l i d IP A d d r e s s ’ ) ; e l s e

$ i p = i n t v a l ( $ i p ) ; }

$ t h i s−>t s i p = i m p l o d e ( ” . ” , $ i p a d d r ) ; }

} /∗∗

∗ C h e c k s w h e t h e r t h e E x p i r a t i o n Date i s s e t i n t h e f u t u r e .

∗ T h i s i s t h e ’ f u t u r e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n f u t u r e ( $ a t t r i b u t e , $params ) {

i f ( d a t e ( $ t h i s−>exp ) < d a t e ( ”Y−m−d ” ) )

$ t h i s−>a d d E r r o r ( ’ exp ’ , ’ E x p i r a t i o n Date must be s e t i n t h e f u t u r e ’ ) ; }

/∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ p r o f e s s o r ’ => a r r a y ( s e l f : : BELONGS TO, ’ UserModel ’ , ’ p r o f ’ ) ,

’ c o u r s e ’ => a r r a y ( s e l f : : BELONGS TO, ’ CourseModel ’ , ’ c o u r s e c o d e ’ ) ,

’ pods ’ => a r r a y ( s e l f : : HAS MANY, ’ PodModel ’ , ’ c l a s s i d ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ i d ’ => ’ ID ’ ,

’ c o u r s e c o d e ’ => ’ C o u r s e Code ’ ,

’ p a s s ’ => ’ Password ’ ,

’ p r o f ’ => ’ P r o f e s s o r ’ ,

’ t s i p ’ => ’ T e r m i n a l S e r v e r IP A d d r e s s ’ ,

’ t s u s e r ’ => ’ T e r m i n a l S e r v e r Username ’ ,

’ t s p a s s ’ => ’ T e r m i n a l S e r v e r Password ’ ,

’ n u m o f s t u d e n t s ’ => ’ Number Of S t u d e n t s ’ ,

’ h a s p o d s ’ => ’ Has Pods ’ ,

’ exp ’ => ’ E x p i r a t i o n Date ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( )

{

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ i d ’ , $ t h i s−>i d ) ;

$ c r i t e r i a−>compare ( ’ c o u r s e c o d e ’ , $ t h i s−>c o u r s e c o d e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p a s s ’ , $ t h i s−>p a s s , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p r o f ’ , Y i i : : app ( )−>u s e r−>i d , t r u e ) ;

$ c r i t e r i a−>compare ( ’ t s i p ’ , $ t h i s−>t s i p , t r u e ) ;

$ c r i t e r i a−>compare ( ’ t s u s e r ’ , $ t h i s−>t s u s e r , t r u e ) ;

$ c r i t e r i a−>compare ( ’ t s p a s s ’ , $ t h i s−>t s p a s s , t r u e ) ;

$ c r i t e r i a−>compare ( ’ n u m o f s t u d e n t s ’ , $ t h i s−>n u m o f s t u d e n t s ) ;

$ c r i t e r i a−>compare ( ’ h a s p o d s ’ , $ t h i s−>h a s p o d s , t r u e ) ;

$ c r i t e r i a−>compare ( ’ exp ’ , $ t h i s−>exp , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n C l a s s M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 10: Course Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” c o u r s e ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ c o u r s e ’ :

∗ @ p r o p e r t y s t r i n g $ c o d e

∗ @ p r o p e r t y s t r i n g $name

∗ @ p r o p e r t y i n t e g e r $ s t u d e n t s p e r p o d

∗ @ p r o p e r t y s t r i n g $ p a i r e d

∗ @ p r o p e r t y s t r i n g $ h a s t o p o l o g y

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y C l a s s [ ] $ c l a s s e s

∗ @ p r o p e r t y T o p o l o g y [ ] $ t o p o l o g i e s

∗/

c l a s s C o u r s e M o d e l e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ c o u r s e ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ c o d e , name , s t u d e n t s p e r p o d ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ s t u d e n t s p e r p o d ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) , a r r a y ( ’ c o d e ’ , ’ l e n g t h ’ , ’ max’=>64) ,

a r r a y ( ’ p a i r e d , h a s t o p o l o g y ’ , ’ l e n g t h ’ , ’ max’=>3) , a r r a y ( ’ c o d e ’ , ’ u n i q u e ’ ) ,

// The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ c o d e , name , s t u d e n t s p e r p o d , p a i r e d , h a s t o p o l o g y ’ , ’ s a f e ’ , ’

on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ c l a s s e s ’ => a r r a y ( s e l f : : HAS MANY, ’ C l a s s M o d e l ’ , ’ c o u r s e c o d e ’ ) ,

’ t o p o l o g i e s ’ => a r r a y ( s e l f : : HAS MANY, ’ TopologyModel ’ , ’ c o u r s e c o d e ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ c o d e ’ => ’ C o u r s e Code ’ ,

’ name ’ => ’ C o u r s e Name ’ ,

’ s t u d e n t s p e r p o d ’ => ’ S t u d e n t s Pe r Pod ’ ,

’ p a i r e d ’ => ’ P a i r e d ’ ,

’ h a s t o p o l o g y ’ => ’ Has Topolog y ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ c o d e ’ , $ t h i s−>c o d e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ name ’ , $ t h i s−>name , t r u e ) ;

$ c r i t e r i a−>compare ( ’ s t u d e n t s p e r p o d ’ , $ t h i s−>s t u d e n t s p e r p o d ) ;

$ c r i t e r i a−>compare ( ’ p a i r e d ’ , $ t h i s−>p a i r e d , t r u e ) ;

$ c r i t e r i a−>compare ( ’ h a s t o p o l o g y ’ , $ t h i s−>h a s t o p o l o g y , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n C o u r s e M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 11: Database Setup Form

<?php /∗∗

∗ DatabaseForm c l a s s .

∗ DatabaseForm i s t h e d a t a s t r u c t u r e f o r k e e p i n g

∗ d a t a b a s e c o n f i g u r a t i o n f o r m d a t a . I t i s u s e d by t h e ’ d a t a b a s e ’ a c t i o n o f ’ S e t u p C o n t r o l l e r ’ .

∗/

c l a s s DatabaseForm e x t e n d s CFormModel {

p u b l i c $ h o s t , $ u s e r , $ p a s s ; /∗∗

∗ D e c l a r e s t h e v a l i d a t i o n r u l e s .

∗ The r u l e s s t a t e t h a t hostname , username , and p a s s w o r d a r e r e q u i r e d ,

∗ and hostname n e e d s t o be a c c e s s i b l e .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

r e t u r n a r r a y (

// hostname and u s e r n a m e a r e r e q u i r e d a r r a y ( ’ h o s t , u s e r ’ , ’ r e q u i r e d ’ ) , // p a s s w o r d n e e d s t o be a c c e s s i b l e a r r a y ( ’ h o s t ’ , ’ c o n n e c t ’ ) ,

) ; }

/∗∗

∗ V a l i d a t e s t h e h o s t name .

∗ T h i s i s t h e ’ c o n n e c t ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n c o n n e c t ( $ a t t r i b u t e , $params ) { t r y {

new PDO( ’ m y s q l : h o s t = ’ . $ t h i s−>h o s t , $ t h i s−>u s e r , $ t h i s−>p a s s ) ;

$ c o n n e c t i o n = m y s q l i c o n n e c t ( $ t h i s−>h o s t , $ t h i s−>u s e r , $ t h i s−>p a s s ) ;

$ s q l = ’CREATE DATABASE IF NOT EXISTS t r e n d s r l a ’ ; i f ( ! m y s q l i q u e r y ( $ c o n n e c t i o n , $ s q l ) )

$ t h i s−>a d d E r r o r ( ’ u s e r ’ , m y s q l i e r r o r ( $ c o n n e c t i o n ) ) ; } c a t c h ( PDOException $ e ) {

$ t h i s−>a d d E r r o r ( ’ h o s t ’ , ’ I n v a l i d H o s t Name ’ ) ; }

} /∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ h o s t ’=>’ H o s t Name ’ ,

’ u s e r ’=>’ Username ’ ,

’ p a s s ’=>’ Password ’ , ) ;

} }

Listing 12: Device Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” d e v i c e ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ d e v i c e ’ :

∗ @ p r o p e r t y s t r i n g $name

∗ @ p r o p e r t y s t r i n g $ f i l e

∗ @ p r o p e r t y s t r i n g $ c o n n e c t a b l e

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y C a b l e [ ] $ c a b l e s

∗ @ p r o p e r t y T o p o l o g y [ ] $ t o p o l o g i e s

∗/

c l a s s D e v i c e M o d e l e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tableName ( ) {

r e t u r n ’ d e v i c e ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ name , f i l e ’ , ’ r e q u i r e d ’ ) , a r r a y ( ’ name ’ , ’ l e n g t h ’ , ’ max’=>64) , a r r a y ( ’ f i l e ’ , ’ l e n g t h ’ , ’ max’=>128) , a r r a y ( ’ c o n n e c t a b l e ’ , ’ l e n g t h ’ , ’ max’=>3) , a r r a y ( ’ name ’ , ’ u n i q u e ’ ) ,

// The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ name , f i l e , c o n n e c t a b l e ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) ,

) ; }

/∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ c a b l e s ’ => a r r a y ( s e l f : : HAS MANY, ’ CableModel ’ , ’ d e v i c e n a m e ’ ) ,

’ t o p o l o g i e s ’ => a r r a y ( s e l f : : HAS MANY, ’ TopologyModel ’ , ’ d e v i c e n a m e ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ name ’ => ’ D e v i c e Name ’ ,

’ f i l e ’ => ’ Image F i l e ’ ,

’ c o n n e c t a b l e ’ => ’ C o n n e c t a b l e ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( )

{

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ name ’ , $ t h i s−>name , t r u e ) ;

$ c r i t e r i a−>compare ( ’ f i l e ’ , $ t h i s−>f i l e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ c o n n e c t a b l e ’ , $ t h i s−>c o n n e c t a b l e , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n D e v i c e M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 13: Login Form

<?php /∗∗

∗ LoginForm c l a s s .

∗ LoginForm i s t h e d a t a s t r u c t u r e f o r k e e p i n g

∗ u s e r l o g i n f o r m d a t a . I t i s u s e d by t h e ’ l o g i n ’ a c t i o n o f ’ S i t e C o n t r o l l e r ’ .

∗/

c l a s s LoginForm e x t e n d s CFormModel {

p u b l i c $ u s e r n a m e ; p u b l i c $ p a s s w o r d ; p r i v a t e $ i d e n t i t y ; /∗∗

∗ D e c l a r e s t h e v a l i d a t i o n r u l e s .

∗ The r u l e s s t a t e t h a t u s e r n a m e and p a s s w o r d a r e r e q u i r e d ,

∗ and p a s s w o r d n e e d s t o be a u t h e n t i c a t e d .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

r e t u r n a r r a y (

// u s e r n a m e and p a s s w o r d a r e r e q u i r e d a r r a y ( ’ username , p a s s w o r d ’ , ’ r e q u i r e d ’ ) , // p a s s w o r d n e e d s t o be a u t h e n t i c a t e d a r r a y ( ’ p a s s w o r d ’ , ’ a u t h e n t i c a t e ’ ) , ) ;

} /∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ username ’=>’ Employee ID ’ ) ;

} /∗∗

∗ A u t h e n t i c a t e s t h e p a s s w o r d .

∗ T h i s i s t h e ’ a u t h e n t i c a t e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n a u t h e n t i c a t e ( $ a t t r i b u t e , $params ) {

i f ( ! $ t h i s−>h a s E r r o r s ( ) ) {

$ t h i s−> i d e n t i t y =new U s e r I d e n t i t y ( $ t h i s−>username , $ t h i s−>p a s s w o r d ) ; i f ( ! $ t h i s−>i d e n t i t y−>a u t h e n t i c a t e ( ) )

$ t h i s−>a d d E r r o r ( ’ p a s s w o r d ’ , ’ I n c o r r e c t u s e r n a m e o r p a s s w o r d . ’ ) ; }

} /∗∗

∗ L o g s i n t h e u s e r u s i n g t h e g i v e n u s e r n a m e and p a s s w o r d i n t h e model .

∗ @ r e t u r n b o o l e a n w h e t h e r l o g i n i s s u c c e s s f u l

∗/

p u b l i c f u n c t i o n l o g i n ( ) {

i f ( $ t h i s−> i d e n t i t y===n u l l ) {

$ t h i s−> i d e n t i t y =new U s e r I d e n t i t y ( $ t h i s−>username , $ t h i s−>p a s s w o r d ) ;

$ t h i s−> i d e n t i t y−>a u t h e n t i c a t e ( ) ; }

i f ( $ t h i s−> i d e n t i t y−>e r r o r C o d e===U s e r I d e n t i t y : : ERROR NONE) {

Y i i : : app ( )−>u s e r−>l o g i n ( $ t h i s−> i d e n t i t y , 0 ) ; r e t u r n t r u e ;

} e l s e

r e t u r n f a l s e ; }

}

Listing 14: Pod Device Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” p o d d e v i c e ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ p o d d e v i c e ’ :

∗ @ p r o p e r t y i n t e g e r $ i d

∗ @ p r o p e r t y i n t e g e r $ p o d i d

∗ @ p r o p e r t y i n t e g e r $ t o p o l o g y i d

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y Pod $pod

∗ @ p r o p e r t y T o p o l o g y $ t o p o l o g y

∗/

c l a s s P o d D e v i c e M o d e l e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ p o d d e v i c e ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ p o d i d , t o p o l o g y i d ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ p o d i d , t o p o l o g y i d ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) , // The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ i d , p o d i d , t o p o l o g y i d ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) ,

) ; }

/∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ pod ’ => a r r a y ( s e l f : : BELONGS TO, ’ PodModel ’ , ’ p o d i d ’ ) ,

’ t o p o l o g y ’ => a r r a y ( s e l f : : BELONGS TO, ’ TopologyModel ’ , ’ t o p o l o g y i d ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ i d ’ => ’ ID ’ ,

’ p o d i d ’ => ’ Pod ’ ,

’ t o p o l o g y i d ’ => ’ Topol ogy ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ i d ’ , $ t h i s−>i d ) ;

$ c r i t e r i a−>compare ( ’ p o d i d ’ , $ t h i s−>p o d i d ) ;

$ c r i t e r i a−>compare ( ’ t o p o l o g y i d ’ , $ t h i s−>t o p o l o g y i d ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a ,

) ) ; }

/∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n P o d D e v i c e M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 15: Pod Login Form

<?php /∗∗

∗ PodForm c l a s s .

∗ PodForm i s t h e d a t a s t r u c t u r e f o r k e e p i n g

∗ pod l o g i n f o r m d a t a . I t i s u s e d by t h e ’ i n d e x ’ a c t i o n o f ’ S i t e C o n t r o l l e r ’ .

∗/

c l a s s PodForm e x t e n d s CFormModel {

p u b l i c $podNum , $ p a s s , $ c l a s s I D ; /∗∗

∗ D e c l a r e s t h e v a l i d a t i o n r u l e s .

∗ The r u l e s s t a t e t h a t pod number and p a s s w o r d a r e r e q u i r e d ,

∗ and p a s s w o r d n e e d s t o be a u t h e n t i c a t e d .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

r e t u r n a r r a y (

// u s e r n a m e and p a s s w o r d a r e r e q u i r e d a r r a y ( ’ podNum , p a s s , c l a s s I D ’ , ’ r e q u i r e d ’ ) , // p a s s w o r d n e e d s t o be a u t h e n t i c a t e d a r r a y ( ’ p a s s ’ , ’ a u t h e n t i c a t e ’ ) , ) ;

} /∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ podNum’=>’Pod Number ’ ,

’ p a s s ’=>’ Password ’ ,

’ c l a s s I D ’=>’ C l a s s ID ’ , ) ;

} /∗∗

∗ A u t h e n t i c a t e s t h e p a s s w o r d .

∗ T h i s i s t h e ’ a u t h e n t i c a t e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n a u t h e n t i c a t e ( $ a t t r i b u t e , $params ) {

$pod = PodModel : : model ( )−>f i n d B y P k ( $ t h i s−>podNum ) ; i f ( $pod−>p a s s !== $ t h i s−>p a s s )

$ t h i s−>a d d E r r o r ( ’ p a s s ’ , ’ I n c o r r e c t P a s s w o r d . ’ ) ; }

/∗∗

∗ L o g s i n t h e u s e r u s i n g t h e g i v e n pod number and p a s s w o r d i n t h e model .

∗ @ r e t u r n b o o l e a n w h e t h e r l o g i n i s s u c c e s s f u l

∗/

p u b l i c f u n c t i o n l o g i n ( ) {

$pod = PodModel : : model ( )−>f i n d B y P k ( $ t h i s−>podNum ) ; i f ( $pod−>p a s s === $ t h i s−>p a s s )

r e t u r n t r u e ; r e t u r n f a l s e ; }

}

Listing 16: Pod Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” pod ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ pod ’ :

∗ @ p r o p e r t y i n t e g e r $ i d

∗ @ p r o p e r t y i n t e g e r $pod num

∗ @ p r o p e r t y i n t e g e r $ c l a s s i d

∗ @ p r o p e r t y s t r i n g $ p a s s

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y C l a s s $ c l a s s

∗ @ p r o p e r t y P o d D e v i c e [ ] $ p o d D e v i c e s

∗/

c l a s s PodModel e x t e n d s C A c t i v e R e c o r d {

/∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ pod ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ pod num , c l a s s i d , p a s s ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ pod num , c l a s s i d ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) , a r r a y ( ’ p a s s ’ , ’ l e n g t h ’ , ’ max’=>32) ,

a r r a y ( ’ pod num ’ , ’ d o e s N o t E x i s t ’ ) ,

// The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ i d , pod num , c l a s s i d , p a s s ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ C h e c k s w h e t h e r t h e pod number / c l a s s i d c o m b i n a t i o n a l r e a d y e x i s t s .

∗ T h i s i s t h e ’ d o e s N o t E x i s t ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n d o e s N o t E x i s t ( $ a t t r i b u t e , $params ) {

$pod = PodModel : : model ( )−>f i n d B y A t t r i b u t e s ( a r r a y (

’ pod num’=>$ t h i s−>pod num ,

’ c l a s s i d ’=>$ t h i s−>c l a s s i d , ) ) ;

i f ( i s s e t ( $pod ) )

$ t h i s−>a d d E r r o r ( ’ pod num ’ , ’ Pod Number ” ’ . $ t h i s−>pod num . ’ ” h a s a l r e a d y b e e n t a k e n ’ ) ;

} /∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ c l a s s ’ => a r r a y ( s e l f : : BELONGS TO, ’ C l a s s M o d e l ’ , ’ c l a s s i d ’ ) ,

’ p o d D e v i c e s ’ => a r r a y ( s e l f : : HAS MANY, ’ PodDeviceModel ’ , ’ p o d i d ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ i d ’ => ’ ID ’ ,

’ pod num ’ => ’ Pod Number ’ ,

’ c l a s s i d ’ => ’ C l a s s ID ’ ,

’ p a s s ’ => ’ Password ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( $ c l a s s i d ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ i d ’ , $ t h i s−>i d ) ;

$ c r i t e r i a−>compare ( ’ pod num ’ , $ t h i s−>pod num ) ;

$ c r i t e r i a−>compare ( ’ c l a s s i d ’ , $ c l a s s i d ) ;

$ c r i t e r i a−>compare ( ’ p a s s ’ , $ t h i s−>p a s s , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a ,

) ) ; }

/∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n PodModel t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 17: Student Login Form

<?php /∗∗

∗ StudentForm c l a s s .

∗ StudentForm i s t h e d a t a s t r u c t u r e f o r k e e p i n g

∗ s t u d e n t l o g i n f o r m d a t a . I t i s u s e d by t h e ’ i n d e x ’ a c t i o n o f ’ S i t e C o n t r o l l e r ’ .

∗/

c l a s s StudentForm e x t e n d s CFormModel {

p u b l i c $ p r o f , $ s u b j , $ p a s s ; p r i v a t e $ i d e n t i t y ;

/∗∗

∗ D e c l a r e s t h e v a l i d a t i o n r u l e s .

∗ The r u l e s s t a t e t h a t p r o f e s s o r , s u b j e c t , and p a s s w o r d a r e r e q u i r e d ,

∗ and p a s s w o r d n e e d s t o be a u t h e n t i c a t e d .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

r e t u r n a r r a y (

// p a s s w o r d i s r e q u i r e d

a r r a y ( ’ p r o f , s u b j , p a s s ’ , ’ r e q u i r e d ’ ) , // p r o f e s s o r and s u b j e c t a r e r e q u i r e d a r r a y ( ’ p r o f , s u b j ’ , ’ nonZero ’ ) , // p a s s w o r d n e e d s t o be a u t h e n t i c a t e d a r r a y ( ’ p a s s ’ , ’ a u t h e n t i c a t e ’ ) , ) ;

} /∗∗

∗ C h e c k s w h e t h e r t h e p r o f e s s o r o r s u b j e c t i s empty .

∗ T h i s i s t h e ’ nonZero ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n n o n Z e r o ( $ a t t r i b u t e , $params ) {

i f ( $ t h i s−>p r o f === ’ 0 ’ )

$ t h i s−>a d d E r r o r ( ’ p r o f ’ , ’ P r o f e s s o r c a n n o t be b l a n k . ’ ) ; i f ( $ t h i s−>s u b j === ’ 0 ’ )

$ t h i s−>a d d E r r o r ( ’ s u b j ’ , ’ S u b j e c t c a n n o t be b l a n k . ’ ) ; }

/∗∗

∗ D e c l a r e s a t t r i b u t e l a b e l s .

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ p r o f ’=>’ P r o f e s s o r ’ ,

’ s u b j ’=>’ S u b j e c t ’ ,

’ p a s s ’=>’ Password ’ , ) ;

} /∗∗

∗ A u t h e n t i c a t e s t h e p a s s w o r d .

∗ T h i s i s t h e ’ a u t h e n t i c a t e ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n a u t h e n t i c a t e ( $ a t t r i b u t e , $params ) {

i f ( ! $ t h i s−>h a s E r r o r s ( ) ) {

$ t h i s−> i d e n t i t y =new U s e r I d e n t i t y ( $ t h i s−>p r o f , $ t h i s−>p a s s ) ;

$ t h i s−> i d e n t i t y−>s e t S u b j ( $ t h i s−>s u b j ) ; i f ( ! $ t h i s−>i d e n t i t y−>a u t h e n t i c a t e ( ) )

$ t h i s−>a d d E r r o r ( ’ p a s s ’ , ’ I n c o r r e c t p a s s w o r d . ’ ) ; }

} /∗∗

∗ L o g s i n t h e u s e r u s i n g t h e g i v e n p r o f e s s o r , s u b j e c t , and p a s s w o r d i n t h e model .

∗ @ r e t u r n b o o l e a n w h e t h e r l o g i n i s s u c c e s s f u l

∗/

p u b l i c f u n c t i o n l o g i n ( ) {

i f ( $ t h i s−> i d e n t i t y===n u l l ) {

$ t h i s−> i d e n t i t y =new U s e r I d e n t i t y ( $ t h i s−>p r o f , $ t h i s−>p a s s ) ;

$ t h i s−> i d e n t i t y−>s e t S u b j ( $ t h i s−>s u b j ) ;

$ t h i s−> i d e n t i t y−>a u t h e n t i c a t e ( ) ; }

i f ( $ t h i s−> i d e n t i t y−>e r r o r C o d e===U s e r I d e n t i t y : : ERROR NONE) {

Y i i : : app ( )−>u s e r−>l o g i n ( $ t h i s−> i d e n t i t y , 0 ) ; r e t u r n t r u e ;

} e l s e

r e t u r n f a l s e ; }

}

Listing 18: Topology Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” t o p o l o g y ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ t o p o l o g y ’ :

∗ @ p r o p e r t y i n t e g e r $ i d

∗ @ p r o p e r t y s t r i n g $ c o u r s e c o d e

∗ @ p r o p e r t y s t r i n g $ d e v i c e n a m e

∗ @ p r o p e r t y i n t e g e r $x

∗ @ p r o p e r t y i n t e g e r $y

∗ @ p r o p e r t y i n t e g e r $ w i d t h

∗ @ p r o p e r t y i n t e g e r $ h e i g h t

∗ @ p r o p e r t y s t r i n g $ t y p e

∗ @ p r o p e r t y s t r i n g $ i p

∗ @ p r o p e r t y s t r i n g $ h o s t

∗ @ p r o p e r t y s t r i n g $ d i s p l a y

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y P o d D e v i c e [ ] $ p o d D e v i c e s

∗ @ p r o p e r t y D e v i c e $ d e v i c e N a m e

∗ @ p r o p e r t y C o u r s e $ c o u r s e C o d e

∗/

c l a s s T o p o l o g y M o d e l e x t e n d s C A c t i v e R e c o r d {

p u b l i c $ d e v i c e , $ c a b l e ; /∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tableName ( ) {

r e t u r n ’ t o p o l o g y ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ c o u r s e c o d e , d e v i c e n a m e , x , y , width , h e i g h t , t y p e , i p , h o s t , d i s p l a y ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ x , y , width , h e i g h t ’ , ’ n u m e r i c a l ’ , ’ i n t e g e r O n l y ’=>t r u e ) , a r r a y ( ’ c o u r s e c o d e , d e v i c e n a m e ’ , ’ l e n g t h ’ , ’ max’=>64) ,

a r r a y ( ’ t y p e ’ , ’ l e n g t h ’ , ’ max’=>1) , a r r a y ( ’ i p ’ , ’ l e n g t h ’ , ’ max’=>32) ,

a r r a y ( ’ h o s t , d i s p l a y ’ , ’ l e n g t h ’ , ’ max’=>16) , // The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ i d , c o u r s e c o d e , d e v i c e n a m e , x , y , width , h e i g h t , t y p e , i p ,

h o s t , d i s p l a y ’ , ’ s a f e ’ , ’ on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ p o d D e v i c e s ’ => a r r a y ( s e l f : : HAS MANY, ’ PodDeviceModel ’ , ’ t o p o l o g y i d ’ ) ,

’ d e v i c e M o d e l ’ => a r r a y ( s e l f : : BELONGS TO, ’ D e v i c e M o d e l ’ , ’ d e v i c e n a m e ’ ) ,

’ c o u r s e M o d e l ’ => a r r a y ( s e l f : : BELONGS TO, ’ CourseModel ’ , ’ c o u r s e c o d e ’ ) ,

) ; }

/∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ i d ’ => ’ ID ’ ,

’ c o u r s e c o d e ’ => ’ C o u r s e Code ’ ,

’ d e v i c e n a m e ’ => ’ D e v i c e Name ’ ,

’ x ’ => ’X’ ,

’ y ’ => ’Y’ ,

’ width ’ => ’ Width ’ ,

’ h e i g h t ’ => ’ H e i g h t ’ ,

’ t y p e ’ => ’ Type ’ ,

’ i p ’ => ’ IP A d d r e s s ’ ,

’ h o s t ’ => ’ H o s t Name ’ ,

’ d i s p l a y ’ => ’ D i s p l a y Name ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ i d ’ , $ t h i s−>i d ) ;

$ c r i t e r i a−>compare ( ’ c o u r s e c o d e ’ , $ t h i s−>c o u r s e c o d e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ d e v i c e n a m e ’ , $ t h i s−>d e v i c e n a m e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ x ’ , $ t h i s−>x ) ;

$ c r i t e r i a−>compare ( ’ y ’ , $ t h i s−>y ) ;

$ c r i t e r i a−>compare ( ’ width ’ , $ t h i s−>w i d t h ) ;

$ c r i t e r i a−>compare ( ’ h e i g h t ’ , $ t h i s−>h e i g h t ) ;

$ c r i t e r i a−>compare ( ’ t y p e ’ , $ t h i s−>t y p e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ i p ’ , $ t h i s−>i p , t r u e ) ;

$ c r i t e r i a−>compare ( ’ h o s t ’ , $ t h i s−>h o s t , t r u e ) ;

$ c r i t e r i a−>compare ( ’ d i s p l a y ’ , $ t h i s−>d i s p l a y , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n T o p o l o g y M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Listing 19: User Model

<?php /∗∗

∗ T h i s i s t h e model c l a s s f o r t a b l e ” u s e r ” .

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e c o l u m n s i n t a b l e ’ u s e r ’ :

∗ @ p r o p e r t y s t r i n g $ e m p l o y e e i d

∗ @ p r o p e r t y s t r i n g $ p a s s

∗ @ p r o p e r t y s t r i n g $ u s e r t y p e

∗ @ p r o p e r t y s t r i n g $ f i r s t n a m e

∗ @ p r o p e r t y s t r i n g $ l a s t n a m e

∗ The f o l l o w i n g s a r e t h e a v a i l a b l e model r e l a t i o n s :

∗ @ p r o p e r t y C l a s s [ ] $ c l a s s e s

∗/

c l a s s U s e r M o d e l e x t e n d s C A c t i v e R e c o r d {

p u b l i c $name , $ r e t y p e ; /∗∗

∗ @ r e t u r n s t r i n g t h e a s s o c i a t e d d a t a b a s e t a b l e name

∗/

p u b l i c f u n c t i o n tabl eName ( ) {

r e t u r n ’ u s e r ’ ; }

/∗∗

∗ @ r e t u r n a r r a y v a l i d a t i o n r u l e s f o r model a t t r i b u t e s .

∗/

p u b l i c f u n c t i o n r u l e s ( ) {

// NOTE: you s h o u l d o n l y d e f i n e r u l e s f o r t h o s e a t t r i b u t e s t h a t // w i l l r e c e i v e u s e r i n p u t s .

r e t u r n a r r a y (

a r r a y ( ’ e m p l o y e e i d , p a s s , r e t y p e , u s e r t y p e , f i r s t n a m e , l a s t n a m e ’ , ’ r e q u i r e d ’ ) ,

a r r a y ( ’ e m p l o y e e i d ’ , ’ l e n g t h ’ , ’ max’=>32) ,

a r r a y ( ’ p a s s ’ , ’ l e n g t h ’ , ’ max’=>128) , a r r a y ( ’ u s e r t y p e ’ , ’ l e n g t h ’ , ’ max’=>13) ,

a r r a y ( ’ f i r s t n a m e , l a s t n a m e ’ , ’ l e n g t h ’ , ’ max’=>64) , a r r a y ( ’ e m p l o y e e i d ’ , ’ u n i q u e ’ ) ,

a r r a y ( ’ p a s s ’ , ’ v a l i d ’ ) , a r r a y ( ’ u s e r t y p e ’ , ’ nonZero ’ ) ,

// The f o l l o w i n g r u l e i s u s e d by s e a r c h ( ) .

// @todo P l e a s e remove t h o s e a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d . a r r a y ( ’ e m p l o y e e i d , p a s s , u s e r t y p e , f i r s t n a m e , l a s t n a m e , name ’ , ’

s a f e ’ , ’ on ’=>’ s e a r c h ’ ) , ) ;

} /∗∗

∗ V a l i d a t e s t h e p a s s w o r d and r e t y p e .

∗ T h i s i s t h e ’ v a l i d ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n v a l i d ( $ a t t r i b u t e , $params ) {

i f ( s t r l e n ( $ t h i s−>p a s s ) < 6 )

$ t h i s−>a d d E r r o r ( ’ p a s s ’ , ’ P a s s w o r d must be a t l e a s t s i x ( 6 ) c h a r a c t e r s l o n g . ’ ) ;

$ t h i s−>p a s s = p a s s w o r d h a s h ( $ t h i s−>p a s s , PASSWORD DEFAULT) ; i f ( ! p a s s w o r d v e r i f y ( $ t h i s−>r e t y p e , $ t h i s−>p a s s ) )

$ t h i s−>a d d E r r o r ( ’ r e t y p e ’ , ’ P a s s w o r d s d i d n o t match ’ ) ; }

/∗∗

∗ C h e c k s w h e t h e r t h e u s e r t y p e i s empty .

∗ T h i s i s t h e ’ nonZero ’ v a l i d a t o r a s d e c l a r e d i n r u l e s ( ) .

∗/

p u b l i c f u n c t i o n n o n Z e r o ( $ a t t r i b u t e , $params ) {

i f ( $ t h i s−>u s e r t y p e === ’ 0 ’ )

$ t h i s−>a d d E r r o r ( ’ u s e r t y p e ’ , ’ U s e r Type c a n n o t be b l a n k ’ ) ; }

/∗∗

∗ @ r e t u r n a r r a y r e l a t i o n a l r u l e s .

∗/

p u b l i c f u n c t i o n r e l a t i o n s ( ) {

// NOTE: you may n e e d t o a d j u s t t h e r e l a t i o n name and t h e r e l a t e d // c l a s s name f o r t h e r e l a t i o n s a u t o m a t i c a l l y g e n e r a t e d b e l o w . r e t u r n a r r a y (

’ c l a s s e s ’ => a r r a y ( s e l f : : HAS MANY, ’ C l a s s M o d e l ’ , ’ p r o f ’ ) , ) ;

} /∗∗

∗ @ r e t u r n a r r a y c u s t o m i z e d a t t r i b u t e l a b e l s ( name=>l a b e l )

∗/

p u b l i c f u n c t i o n a t t r i b u t e L a b e l s ( ) {

r e t u r n a r r a y (

’ e m p l o y e e i d ’ => ’ Employee ID ’ ,

’ p a s s ’ => ’ Password ’ ,

’ r e t y p e ’ => ’ R e t y p e Password ’ ,

’ u s e r t y p e ’ => ’ U s e r Type ’ ,

’ f i r s t n a m e ’ => ’ F i r s t Name ’ ,

’ l a s t n a m e ’ => ’ L a s t Name ’ , ) ;

} /∗∗

∗ R e t r i e v e s a l i s t o f m o d e l s b a s e d on t h e c u r r e n t s e a r c h / f i l t e r c o n d i t i o n s .

∗ T y p i c a l u s e c a s e :

∗ − I n i t i a l i z e t h e model f i e l d s w i t h v a l u e s f r o m f i l t e r f o r m .

∗ − E x e c u t e t h i s method t o g e t C A c t i v e D a t a P r o v i d e r i n s t a n c e w h i c h w i l l f i l t e r

∗ m o d e l s a c c o r d i n g t o d a t a i n model f i e l d s .

∗ − P a s s d a t a p r o v i d e r t o CGridView , C L i s t V i e w o r any s i m i l a r w i d g e t .

∗ @ r e t u r n C A c t i v e D a t a P r o v i d e r t h e d a t a p r o v i d e r t h a t c a n r e t u r n t h e m o d e l s

∗ b a s e d on t h e s e a r c h / f i l t e r c o n d i t i o n s .

∗/

p u b l i c f u n c t i o n s e a r c h ( ) {

// @todo P l e a s e m o d i f y t h e f o l l o w i n g c o d e t o remove a t t r i b u t e s t h a t s h o u l d n o t be s e a r c h e d .

$ c r i t e r i a =new C D b C r i t e r i a ;

$ c r i t e r i a−>compare ( ’ e m p l o y e e i d ’ , $ t h i s−>e m p l o y e e i d , t r u e ) ;

$ c r i t e r i a−>compare ( ’ p a s s ’ , $ t h i s−>p a s s , t r u e ) ;

$ c r i t e r i a−>compare ( ’ u s e r t y p e ’ , $ t h i s−>u s e r t y p e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ f i r s t n a m e ’ , $ t h i s−>f i r s t n a m e , t r u e ) ;

$ c r i t e r i a−>compare ( ’ l a s t n a m e ’ , $ t h i s−>l a s t n a m e , t r u e ) ;

$ c r i t e r i a−>compare ( ” c o n c a t ( l a s t n a m e , ’ , ’ , f i r s t n a m e ) ” , $ t h i s−>name , t r u e ) ; r e t u r n new C A c t i v e D a t a P r o v i d e r ( $ t h i s , a r r a y (

’ c r i t e r i a ’=>$ c r i t e r i a , ) ) ;

} /∗∗

∗ R e t u r n s t h e s t a t i c model o f t h e s p e c i f i e d AR c l a s s .

∗ P l e a s e n o t e t h a t you s h o u l d h a v e t h i s e x a c t method i n a l l y o u r C A c t i v e R e c o r d

d e s c e n d a n t s !

∗ @param s t r i n g $ c l a s s N a m e a c t i v e r e c o r d c l a s s name .

∗ @ r e t u r n U s e r M o d e l t h e s t a t i c model c l a s s

∗/

p u b l i c s t a t i c f u n c t i o n model ( $ c l a s s N a m e= C L A S S ) {

r e t u r n p a r e n t : : model ( $ c l a s s N a m e ) ; }

}

Dokumen terkait