idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
6,000
|
public function actionDiff ( ) { Yii :: import ( 'gii.components.TextDiff' ) ; $ model = $ this -> prepare ( ) ; if ( isset ( $ _GET [ 'id' ] ) && isset ( $ model -> files [ $ _GET [ 'id' ] ] ) ) { $ file = $ model -> files [ $ _GET [ 'id' ] ] ; if ( ! in_array ( $ file -> type , array ( 'php' , 'txt' , 'js' , 'css' , 'sql' ) ) ) $ diff = false ; elseif ( $ file -> operation === CCodeFile :: OP_OVERWRITE ) $ diff = TextDiff :: compare ( file_get_contents ( $ file -> path ) , $ file -> content ) ; else $ diff = '' ; $ this -> renderPartial ( '/common/diff' , array ( 'file' => $ file , 'diff' => $ diff , ) ) ; } else throw new CHttpException ( 404 , 'Unable to find the code you requested.' ) ; }
|
The code diff action . This action shows up the difference between the newly generated code and the corresponding existing code .
|
6,001
|
public function getViewPath ( ) { if ( $ this -> _viewPath === null ) { $ class = new ReflectionClass ( get_class ( $ this ) ) ; $ this -> _viewPath = dirname ( $ class -> getFileName ( ) ) . DIRECTORY_SEPARATOR . 'views' ; } return $ this -> _viewPath ; }
|
Returns the view path of the generator . The views directory under the directory containing the generator class file will be returned .
|
6,002
|
protected function prepare ( ) { if ( $ this -> codeModel === null ) throw new CException ( get_class ( $ this ) . '.codeModel property must be specified.' ) ; $ modelClass = Yii :: import ( $ this -> codeModel , true ) ; $ model = new $ modelClass ; $ model -> loadStickyAttributes ( ) ; if ( isset ( $ _POST [ $ modelClass ] ) ) { $ model -> attributes = $ _POST [ $ modelClass ] ; $ model -> status = CCodeModel :: STATUS_PREVIEW ; if ( $ model -> validate ( ) ) { $ model -> saveStickyAttributes ( ) ; $ model -> prepare ( ) ; } } return $ model ; }
|
Prepares the code model .
|
6,003
|
public static function format ( $ messages , $ number ) { $ n = preg_match_all ( '/\s*([^#]*)\s*#([^\|]*)\|/' , $ messages . '|' , $ matches ) ; if ( $ n === 0 ) return $ messages ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ expression = $ matches [ 1 ] [ $ i ] ; $ message = $ matches [ 2 ] [ $ i ] ; if ( $ expression === ( string ) ( int ) $ expression ) { if ( $ expression == $ number ) return $ message ; } elseif ( self :: evaluate ( str_replace ( 'n' , '$n' , $ expression ) , $ number ) ) return $ message ; } return $ message ; }
|
Formats a message according to the specified number value .
|
6,004
|
public function actionSuggestTags ( ) { if ( isset ( $ _GET [ 'q' ] ) && ( $ keyword = trim ( $ _GET [ 'q' ] ) ) !== '' ) { $ tags = Tag :: model ( ) -> suggestTags ( $ keyword ) ; if ( $ tags !== array ( ) ) echo implode ( "\n" , $ tags ) ; } }
|
Suggests tags based on the current user input . This is called via AJAX when the user is entering the tags input .
|
6,005
|
protected function newComment ( $ post ) { $ comment = new Comment ; if ( isset ( $ _POST [ 'ajax' ] ) && $ _POST [ 'ajax' ] === 'comment-form' ) { echo CActiveForm :: validate ( $ comment ) ; Yii :: app ( ) -> end ( ) ; } if ( isset ( $ _POST [ 'Comment' ] ) ) { $ comment -> attributes = $ _POST [ 'Comment' ] ; if ( $ post -> addComment ( $ comment ) ) { if ( $ comment -> status == Comment :: STATUS_PENDING ) Yii :: app ( ) -> user -> setFlash ( 'commentSubmitted' , 'Thank you for your comment. Your comment will be posted once it is approved.' ) ; $ this -> refresh ( ) ; } } return $ comment ; }
|
Creates a new comment . This method attempts to create a new comment based on the user input . If the comment is successfully created the browser will be redirected to show the created comment .
|
6,006
|
public function encrypt ( $ data , $ key = null ) { if ( $ key === null ) $ key = $ this -> getEncryptionKey ( ) ; $ this -> validateEncryptionKey ( $ key ) ; $ module = $ this -> openCryptModule ( ) ; srand ( ) ; $ iv = @ mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $ module ) , MCRYPT_RAND ) ; @ mcrypt_generic_init ( $ module , $ key , $ iv ) ; $ encrypted = $ iv . @ mcrypt_generic ( $ module , $ data ) ; @ mcrypt_generic_deinit ( $ module ) ; @ mcrypt_module_close ( $ module ) ; return $ encrypted ; }
|
Encrypts data .
|
6,007
|
public function validateData ( $ data , $ key = null ) { if ( ! is_string ( $ data ) ) return false ; $ len = $ this -> strlen ( $ this -> computeHMAC ( 'test' ) ) ; if ( $ this -> strlen ( $ data ) >= $ len ) { $ hmac = $ this -> substr ( $ data , 0 , $ len ) ; $ data2 = $ this -> substr ( $ data , $ len , $ this -> strlen ( $ data ) ) ; return $ this -> compareString ( $ hmac , $ this -> computeHMAC ( $ data2 , $ key ) ) ? $ data2 : false ; } else return false ; }
|
Validates if data is tampered .
|
6,008
|
public function generateRandomBytes ( $ length , $ cryptographicallyStrong = true ) { $ bytes = '' ; if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ bytes = openssl_random_pseudo_bytes ( $ length , $ strong ) ; if ( $ this -> strlen ( $ bytes ) >= $ length && ( $ strong || ! $ cryptographicallyStrong ) ) return $ this -> substr ( $ bytes , 0 , $ length ) ; } if ( function_exists ( 'mcrypt_create_iv' ) && ( $ bytes = @ mcrypt_create_iv ( $ length , MCRYPT_DEV_URANDOM ) ) !== false && $ this -> strlen ( $ bytes ) >= $ length ) { return $ this -> substr ( $ bytes , 0 , $ length ) ; } if ( ( $ file = @ fopen ( '/dev/urandom' , 'rb' ) ) !== false && ( $ bytes = @ fread ( $ file , $ length ) ) !== false && ( fclose ( $ file ) || true ) && $ this -> strlen ( $ bytes ) >= $ length ) { return $ this -> substr ( $ bytes , 0 , $ length ) ; } $ i = 0 ; while ( $ this -> strlen ( $ bytes ) < $ length && ( $ byte = $ this -> generateSessionRandomBlock ( ) ) !== false && ++ $ i < 3 ) { $ bytes .= $ byte ; } if ( $ this -> strlen ( $ bytes ) >= $ length ) return $ this -> substr ( $ bytes , 0 , $ length ) ; if ( $ cryptographicallyStrong ) return false ; while ( $ this -> strlen ( $ bytes ) < $ length ) $ bytes .= $ this -> generatePseudoRandomBlock ( ) ; return $ this -> substr ( $ bytes , 0 , $ length ) ; }
|
Generates a string of random bytes .
|
6,009
|
public function generateSessionRandomBlock ( ) { ini_set ( 'session.entropy_length' , 20 ) ; if ( ini_get ( 'session.entropy_length' ) != 20 ) return false ; @ session_start ( ) ; @ session_regenerate_id ( ) ; $ bytes = session_id ( ) ; if ( ! $ bytes ) return false ; return sha1 ( $ bytes , true ) ; }
|
Get random bytes from the system entropy source via PHP session manager .
|
6,010
|
private function substr ( $ string , $ start , $ length ) { return $ this -> _mbstring ? mb_substr ( $ string , $ start , $ length , '8bit' ) : substr ( $ string , $ start , $ length ) ; }
|
Returns the portion of string specified by the start and length parameters . If available uses the multibyte string function mb_substr
|
6,011
|
public function unmaskToken ( $ maskedToken ) { $ decoded = base64_decode ( strtr ( $ maskedToken , '-_' , '+/' ) ) ; $ length = $ this -> strlen ( $ decoded ) / 2 ; if ( ! is_int ( $ length ) ) return '' ; return $ this -> substr ( $ decoded , $ length , $ length ) ^ $ this -> substr ( $ decoded , 0 , $ length ) ; }
|
Unmasks a token previously masked by maskToken .
|
6,012
|
public function load ( $ file , $ context ) { $ pattern = '/(msgctxt\s+"(.*?(?<!\\\\))")?\s+' . 'msgid\s+((?:".*(?<!\\\\)"\s*)+)\s+' . 'msgstr\s+((?:".*(?<!\\\\)"\s*)+)/' ; $ matches = array ( ) ; $ n = preg_match_all ( $ pattern , file_get_contents ( $ file ) , $ matches ) ; $ messages = array ( ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ matches [ 2 ] [ $ i ] === $ context ) { $ id = $ this -> decode ( $ matches [ 3 ] [ $ i ] ) ; $ message = $ this -> decode ( $ matches [ 4 ] [ $ i ] ) ; $ messages [ $ id ] = $ message ; } } return $ messages ; }
|
Loads messages from a PO file .
|
6,013
|
protected function generateClassNames ( $ schema , $ pattern = null ) { $ this -> _tables = array ( ) ; foreach ( $ schema -> getTableNames ( ) as $ name ) { if ( $ pattern === null ) $ this -> _tables [ $ name ] = $ this -> generateClassName ( $ this -> removePrefix ( $ name ) ) ; elseif ( preg_match ( $ pattern , $ name , $ matches ) ) { if ( count ( $ matches ) > 1 && ! empty ( $ matches [ 1 ] ) ) $ className = $ this -> generateClassName ( $ matches [ 1 ] ) ; else $ className = $ this -> generateClassName ( $ matches [ 0 ] ) ; $ this -> _tables [ $ name ] = empty ( $ className ) ? $ name : $ className ; } } }
|
Generates the mapping table between table names and class names .
|
6,014
|
public function init ( ) { parent :: init ( ) ; if ( $ this -> name === null ) $ this -> sortable = false ; if ( $ this -> name === null && $ this -> value === null ) throw new CException ( Yii :: t ( 'zii' , 'Either "name" or "value" must be specified for CDataColumn.' ) ) ; }
|
Initializes the column .
|
6,015
|
public function getHeaderCellContent ( ) { if ( $ this -> grid -> enableSorting && $ this -> sortable && $ this -> name !== null ) return $ this -> grid -> dataProvider -> getSort ( ) -> link ( $ this -> name , $ this -> header , array ( 'class' => 'sort-link' ) ) ; elseif ( $ this -> name !== null && $ this -> header === null ) { if ( $ this -> grid -> dataProvider instanceof CActiveDataProvider ) return CHtml :: encode ( $ this -> grid -> dataProvider -> model -> getAttributeLabel ( $ this -> name ) ) ; else return CHtml :: encode ( $ this -> name ) ; } else return parent :: getHeaderCellContent ( ) ; }
|
Returns the header cell content . This method will render a link that can trigger the sorting if the column is sortable .
|
6,016
|
protected function generateDependentData ( ) { if ( $ this -> directory !== null ) return $ this -> generateTimestamps ( $ this -> directory ) ; else throw new CException ( Yii :: t ( 'yii' , 'CDirectoryCacheDependency.directory cannot be empty.' ) ) ; }
|
Generates the data needed to determine if dependency has been changed . This method returns the modification timestamps for files under the directory .
|
6,017
|
public static function getInstance ( $ id ) { static $ locales = array ( ) ; if ( isset ( $ locales [ $ id ] ) ) return $ locales [ $ id ] ; else return $ locales [ $ id ] = new CLocale ( $ id ) ; }
|
Returns the instance of the specified locale . Since the constructor of CLocale is protected you can only use this method to obtain an instance of the specified locale .
|
6,018
|
public function getMonthNames ( $ width = 'wide' , $ standAlone = false ) { if ( $ standAlone ) return isset ( $ this -> _data [ 'monthNamesSA' ] [ $ width ] ) ? $ this -> _data [ 'monthNamesSA' ] [ $ width ] : $ this -> _data [ 'monthNames' ] [ $ width ] ; else return isset ( $ this -> _data [ 'monthNames' ] [ $ width ] ) ? $ this -> _data [ 'monthNames' ] [ $ width ] : $ this -> _data [ 'monthNamesSA' ] [ $ width ] ; }
|
Returns the month names in the specified width .
|
6,019
|
public function getWeekDayNames ( $ width = 'wide' , $ standAlone = false ) { if ( $ standAlone ) return isset ( $ this -> _data [ 'weekDayNamesSA' ] [ $ width ] ) ? $ this -> _data [ 'weekDayNamesSA' ] [ $ width ] : $ this -> _data [ 'weekDayNames' ] [ $ width ] ; else return isset ( $ this -> _data [ 'weekDayNames' ] [ $ width ] ) ? $ this -> _data [ 'weekDayNames' ] [ $ width ] : $ this -> _data [ 'weekDayNamesSA' ] [ $ width ] ; }
|
Returns the week day names in the specified width .
|
6,020
|
public function getLanguageID ( $ id ) { $ id = $ this -> getCanonicalID ( $ id ) ; if ( ( $ underscorePosition = strpos ( $ id , '_' ) ) !== false ) { $ id = substr ( $ id , 0 , $ underscorePosition ) ; } return $ id ; }
|
Converts a locale ID to a language ID . A language ID consists of only the first group of letters before an underscore or dash .
|
6,021
|
public function getScriptID ( $ id ) { $ id = $ this -> getCanonicalID ( $ id ) ; if ( ( $ underscorePosition = strpos ( $ id , '_' ) ) !== false ) { $ subTag = explode ( '_' , $ id ) ; if ( strlen ( $ subTag [ 1 ] ) === 4 ) { $ id = $ subTag [ 1 ] ; } else { $ id = null ; } } else { $ id = null ; } return $ id ; }
|
Converts a locale ID to a script ID . A script ID consists of only the last four characters after an underscore or dash .
|
6,022
|
public function getTerritoryID ( $ id ) { $ id = $ this -> getCanonicalID ( $ id ) ; if ( ( $ underscorePosition = strpos ( $ id , '_' ) ) !== false ) { $ subTag = explode ( '_' , $ id ) ; if ( isset ( $ subTag [ 2 ] ) && strlen ( $ subTag [ 2 ] ) < 4 ) { $ id = $ subTag [ 2 ] ; } elseif ( strlen ( $ subTag [ 1 ] ) < 4 ) { $ id = $ subTag [ 1 ] ; } else { $ id = null ; } } else { $ id = null ; } return $ id ; }
|
Converts a locale ID to a territory ID . A territory ID consists of only the last two to three letter or digits after an underscore or dash .
|
6,023
|
public function __isset ( $ name ) { if ( $ this -> contains ( $ name ) ) return $ this -> itemAt ( $ name ) !== null ; else return parent :: __isset ( $ name ) ; }
|
Checks if a property value is null . This method overrides the parent implementation by checking if the key exists in the collection and contains a non - null value .
|
6,024
|
public function mergeWith ( $ data , $ recursive = true ) { if ( ! $ this -> caseSensitive && ( is_array ( $ data ) || $ data instanceof Traversable ) ) { $ d = array ( ) ; foreach ( $ data as $ key => $ value ) $ d [ strtolower ( $ key ) ] = $ value ; return parent :: mergeWith ( $ d , $ recursive ) ; } parent :: mergeWith ( $ data , $ recursive ) ; }
|
Merges iterable data into the map .
|
6,025
|
public function getPagination ( $ className = 'CPagination' ) { if ( $ this -> _pagination === null ) { $ this -> _pagination = new $ className ; if ( ( $ id = $ this -> getId ( ) ) != '' ) $ this -> _pagination -> pageVar = $ id . '_page' ; } return $ this -> _pagination ; }
|
Returns the pagination object .
|
6,026
|
public function getSort ( $ className = 'CSort' ) { if ( $ this -> _sort === null ) { $ this -> _sort = new $ className ; if ( ( $ id = $ this -> getId ( ) ) != '' ) $ this -> _sort -> sortVar = $ id . '_sort' ; } return $ this -> _sort ; }
|
Returns the sort object .
|
6,027
|
public function getData ( $ refresh = false ) { if ( $ this -> _data === null || $ refresh ) $ this -> _data = $ this -> fetchData ( ) ; return $ this -> _data ; }
|
Returns the data items currently available .
|
6,028
|
public function getKeys ( $ refresh = false ) { if ( $ this -> _keys === null || $ refresh ) $ this -> _keys = $ this -> fetchKeys ( ) ; return $ this -> _keys ; }
|
Returns the key values associated with the data items .
|
6,029
|
public function assign ( $ userId , $ bizRule = null , $ data = null ) { return $ this -> _auth -> assign ( $ this -> _name , $ userId , $ bizRule , $ data ) ; }
|
Assigns this item to a user .
|
6,030
|
public function actionLogin ( ) { $ user = new LoginForm ; if ( Yii :: app ( ) -> request -> isPostRequest ) { if ( isset ( $ _POST [ 'LoginForm' ] ) ) $ user -> setAttributes ( $ _POST [ 'LoginForm' ] ) ; if ( $ user -> validate ( ) ) $ this -> redirect ( Yii :: app ( ) -> user -> returnUrl ) ; } $ this -> render ( 'login' , array ( 'user' => $ user ) ) ; }
|
Displays a login form to login a user .
|
6,031
|
public function hasItemChild ( $ itemName , $ childName ) { return $ this -> db -> createCommand ( ) -> select ( 'parent' ) -> from ( $ this -> itemChildTable ) -> where ( 'parent=:parent AND child=:child' , array ( ':parent' => $ itemName , ':child' => $ childName ) ) -> queryScalar ( ) !== false ; }
|
Returns a value indicating whether a child exists within a parent .
|
6,032
|
public function isAssigned ( $ itemName , $ userId ) { return $ this -> db -> createCommand ( ) -> select ( 'itemname' ) -> from ( $ this -> assignmentTable ) -> where ( 'itemname=:itemname AND userid=:userid' , array ( ':itemname' => $ itemName , ':userid' => $ userId ) ) -> queryScalar ( ) !== false ; }
|
Returns a value indicating whether the item has been assigned to the user .
|
6,033
|
public function getAuthAssignments ( $ userId ) { $ rows = $ this -> db -> createCommand ( ) -> select ( ) -> from ( $ this -> assignmentTable ) -> where ( 'userid=:userid' , array ( ':userid' => $ userId ) ) -> queryAll ( ) ; $ assignments = array ( ) ; foreach ( $ rows as $ row ) { if ( ( $ data = @ unserialize ( $ row [ 'data' ] ) ) === false ) $ data = null ; $ assignments [ $ row [ 'itemname' ] ] = new CAuthAssignment ( $ this , $ row [ 'itemname' ] , $ row [ 'userid' ] , $ row [ 'bizrule' ] , $ data ) ; } return $ assignments ; }
|
Returns the item assignments for the specified user .
|
6,034
|
public function saveAuthAssignment ( $ assignment ) { $ this -> db -> createCommand ( ) -> update ( $ this -> assignmentTable , array ( 'bizrule' => $ assignment -> getBizRule ( ) , 'data' => serialize ( $ assignment -> getData ( ) ) , ) , 'itemname=:itemname AND userid=:userid' , array ( 'itemname' => $ assignment -> getItemName ( ) , 'userid' => $ assignment -> getUserId ( ) ) ) ; }
|
Saves the changes to an authorization assignment .
|
6,035
|
public function clearAll ( ) { $ this -> clearAuthAssignments ( ) ; $ this -> db -> createCommand ( ) -> delete ( $ this -> itemChildTable ) ; $ this -> db -> createCommand ( ) -> delete ( $ this -> itemTable ) ; }
|
Removes all authorization data .
|
6,036
|
public function validateValue ( $ value ) { if ( is_string ( $ value ) && $ this -> validateIDN ) $ value = $ this -> encodeIDN ( $ value ) ; $ valid = is_string ( $ value ) && strlen ( $ value ) <= 254 && ( preg_match ( $ this -> pattern , $ value ) || $ this -> allowName && preg_match ( $ this -> fullPattern , $ value ) ) ; if ( $ valid ) $ domain = rtrim ( substr ( $ value , strpos ( $ value , '@' ) + 1 ) , '>' ) ; if ( $ valid && $ this -> checkMX && function_exists ( 'checkdnsrr' ) ) $ valid = checkdnsrr ( $ domain , 'MX' ) ; if ( $ valid && $ this -> checkPort && function_exists ( 'fsockopen' ) && function_exists ( 'dns_get_record' ) ) $ valid = $ this -> checkMxPorts ( $ domain ) ; return $ valid ; }
|
Validates a static value to see if it is a valid email . This method is provided so that you can call it directly without going through the model validation rule mechanism .
|
6,037
|
public function validateValue ( $ value ) { if ( $ this -> strict ) return $ value === $ this -> trueValue || $ value === $ this -> falseValue ; else return $ value == $ this -> trueValue || $ value == $ this -> falseValue ; }
|
Validates a static value to see if it is a valid boolean . This method is provided so that you can call it directly without going through the model validation rule mechanism .
|
6,038
|
private function parseResponse ( ) { if ( ( $ line = fgets ( $ this -> _socket ) ) === false ) throw new CException ( 'Failed reading data from redis connection socket.' ) ; $ type = $ line [ 0 ] ; $ line = substr ( $ line , 1 , - 2 ) ; switch ( $ type ) { case '+' : return true ; case '-' : throw new CException ( 'Redis error: ' . $ line ) ; case ':' : return $ line ; case '$' : if ( $ line == '-1' ) return null ; $ length = $ line + 2 ; $ data = '' ; while ( $ length > 0 ) { if ( ( $ block = fread ( $ this -> _socket , $ length ) ) === false ) throw new CException ( 'Failed reading data from redis connection socket.' ) ; $ data .= $ block ; $ length -= $ this -> byteLength ( $ block ) ; } return substr ( $ data , 0 , - 2 ) ; case '*' : $ count = ( int ) $ line ; $ data = array ( ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) $ data [ ] = $ this -> parseResponse ( ) ; return $ data ; default : throw new CException ( 'Unable to parse data received from redis.' ) ; } }
|
Reads the result from socket and parses it
|
6,039
|
public static function item ( $ type , $ code ) { if ( ! isset ( self :: $ _items [ $ type ] ) ) self :: loadItems ( $ type ) ; return isset ( self :: $ _items [ $ type ] [ $ code ] ) ? self :: $ _items [ $ type ] [ $ code ] : false ; }
|
Returns the item name for the specified type and code .
|
6,040
|
private static function loadItems ( $ type ) { self :: $ _items [ $ type ] = array ( ) ; $ models = self :: model ( ) -> findAll ( array ( 'condition' => 'type=:type' , 'params' => array ( ':type' => $ type ) , 'order' => 'position' , ) ) ; foreach ( $ models as $ model ) self :: $ _items [ $ type ] [ $ model -> code ] = $ model -> name ; }
|
Loads the lookup items for the specified type from the database .
|
6,041
|
private function getHash ( ) { if ( $ this -> _hash === null ) $ this -> _hash = sha1 ( serialize ( $ this ) ) ; return $ this -> _hash ; }
|
Generates a unique hash that identifies this cache dependency .
|
6,042
|
public function submitted ( $ buttonName = 'submit' , $ loadData = true ) { $ ret = $ this -> clicked ( $ this -> getUniqueId ( ) ) && $ this -> clicked ( $ buttonName ) ; if ( $ ret && $ loadData ) $ this -> loadData ( ) ; return $ ret ; }
|
Returns a value indicating whether this form is submitted .
|
6,043
|
public function clicked ( $ name ) { if ( strcasecmp ( $ this -> getRoot ( ) -> method , 'get' ) ) return isset ( $ _POST [ $ name ] ) ; else return isset ( $ _GET [ $ name ] ) ; }
|
Returns a value indicating whether the specified button is clicked .
|
6,044
|
public function getModel ( $ checkParent = true ) { if ( ! $ checkParent ) return $ this -> _model ; $ form = $ this ; while ( $ form -> _model === null && $ form -> getParent ( ) instanceof self ) $ form = $ form -> getParent ( ) ; return $ form -> _model ; }
|
Returns the model that this form is associated with .
|
6,045
|
public function getModels ( ) { $ models = array ( ) ; if ( $ this -> _model !== null ) $ models [ ] = $ this -> _model ; foreach ( $ this -> getElements ( ) as $ element ) { if ( $ element instanceof self ) $ models = array_merge ( $ models , $ element -> getModels ( ) ) ; } return $ models ; }
|
Returns all models that are associated with this form or its sub - forms .
|
6,046
|
protected function getUniqueId ( ) { if ( isset ( $ this -> attributes [ 'id' ] ) ) return 'yform_' . $ this -> attributes [ 'id' ] ; else return 'yform_' . sprintf ( '%x' , crc32 ( serialize ( array_keys ( $ this -> getElements ( ) -> toArray ( ) ) ) ) ) ; }
|
Returns a unique ID that identifies this form in the current page .
|
6,047
|
private function encodeIDN ( $ value ) { if ( preg_match_all ( '/^(.*):\/\/([^\/]+)(.*)$/' , $ value , $ matches ) ) { if ( function_exists ( 'idn_to_ascii' ) ) $ value = $ matches [ 1 ] [ 0 ] . '://' . idn_to_ascii ( $ matches [ 2 ] [ 0 ] ) . $ matches [ 3 ] [ 0 ] ; else { require_once ( Yii :: getPathOfAlias ( 'system.vendors.Net_IDNA2.Net' ) . DIRECTORY_SEPARATOR . 'IDNA2.php' ) ; $ idna = new Net_IDNA2 ( ) ; $ value = $ matches [ 1 ] [ 0 ] . '://' . @ $ idna -> encode ( $ matches [ 2 ] [ 0 ] ) . $ matches [ 3 ] [ 0 ] ; } } return $ value ; }
|
Converts given IDN to the punycode .
|
6,048
|
private function decodeIDN ( $ value ) { if ( preg_match_all ( '/^(.*):\/\/([^\/]+)(.*)$/' , $ value , $ matches ) ) { if ( function_exists ( 'idn_to_utf8' ) ) $ value = $ matches [ 1 ] [ 0 ] . '://' . idn_to_utf8 ( $ matches [ 2 ] [ 0 ] ) . $ matches [ 3 ] [ 0 ] ; else { require_once ( Yii :: getPathOfAlias ( 'system.vendors.Net_IDNA2.Net' ) . DIRECTORY_SEPARATOR . 'IDNA2.php' ) ; $ idna = new Net_IDNA2 ( ) ; $ value = $ matches [ 1 ] [ 0 ] . '://' . @ $ idna -> decode ( $ matches [ 2 ] [ 0 ] ) . $ matches [ 3 ] [ 0 ] ; } } return $ value ; }
|
Converts given punycode to the IDN .
|
6,049
|
protected function renderMenu ( $ items ) { if ( count ( $ items ) ) { echo CHtml :: openTag ( 'ul' , $ this -> htmlOptions ) . "\n" ; $ this -> renderMenuRecursive ( $ items ) ; echo CHtml :: closeTag ( 'ul' ) ; } }
|
Renders the menu items .
|
6,050
|
protected function renderMenuRecursive ( $ items ) { $ count = 0 ; $ n = count ( $ items ) ; foreach ( $ items as $ item ) { $ count ++ ; $ options = isset ( $ item [ 'itemOptions' ] ) ? $ item [ 'itemOptions' ] : array ( ) ; $ class = array ( ) ; if ( $ item [ 'active' ] && $ this -> activeCssClass != '' ) $ class [ ] = $ this -> activeCssClass ; if ( $ count === 1 && $ this -> firstItemCssClass !== null ) $ class [ ] = $ this -> firstItemCssClass ; if ( $ count === $ n && $ this -> lastItemCssClass !== null ) $ class [ ] = $ this -> lastItemCssClass ; if ( $ this -> itemCssClass !== null ) $ class [ ] = $ this -> itemCssClass ; if ( $ class !== array ( ) ) { if ( empty ( $ options [ 'class' ] ) ) $ options [ 'class' ] = implode ( ' ' , $ class ) ; else $ options [ 'class' ] .= ' ' . implode ( ' ' , $ class ) ; } echo CHtml :: openTag ( 'li' , $ options ) ; $ menu = $ this -> renderMenuItem ( $ item ) ; if ( isset ( $ this -> itemTemplate ) || isset ( $ item [ 'template' ] ) ) { $ template = isset ( $ item [ 'template' ] ) ? $ item [ 'template' ] : $ this -> itemTemplate ; echo strtr ( $ template , array ( '{menu}' => $ menu ) ) ; } else echo $ menu ; if ( isset ( $ item [ 'items' ] ) && count ( $ item [ 'items' ] ) ) { echo "\n" . CHtml :: openTag ( 'ul' , isset ( $ item [ 'submenuOptions' ] ) ? $ item [ 'submenuOptions' ] : $ this -> submenuHtmlOptions ) . "\n" ; $ this -> renderMenuRecursive ( $ item [ 'items' ] ) ; echo CHtml :: closeTag ( 'ul' ) . "\n" ; } echo CHtml :: closeTag ( 'li' ) . "\n" ; } }
|
Recursively renders the menu items .
|
6,051
|
public function applyJoin ( $ sql , $ join ) { if ( $ join == '' ) return $ sql ; if ( strpos ( $ sql , 'UPDATE' ) === 0 && ( $ pos = strpos ( $ sql , 'SET' ) ) !== false ) return substr ( $ sql , 0 , $ pos ) . $ join . ' ' . substr ( $ sql , $ pos ) ; elseif ( strpos ( $ sql , 'DELETE FROM ' ) === 0 ) { $ tableName = substr ( $ sql , 12 ) ; return "DELETE {$tableName} FROM {$tableName} " . $ join ; } else return $ sql . ' ' . $ join ; }
|
Alters the SQL to apply JOIN clause . This method handles the mysql specific syntax where JOIN has to come before SET in UPDATE statement and for DELETE where JOIN has to be after FROM part .
|
6,052
|
protected function validateAttribute ( $ object , $ attribute ) { if ( ! $ this -> setOnEmpty ) $ object -> $ attribute = $ this -> value ; else { $ value = $ object -> $ attribute ; if ( $ value === null || $ value === '' ) $ object -> $ attribute = $ this -> value ; } }
|
Validates the attribute of the object .
|
6,053
|
public function getSort ( $ className = 'CSort' ) { if ( ( $ sort = parent :: getSort ( $ className ) ) !== false ) $ sort -> modelClass = $ this -> modelClass ; return $ sort ; }
|
Returns the sorting object .
|
6,054
|
protected function calculateTotalItemCount ( ) { $ baseCriteria = $ this -> model -> getDbCriteria ( false ) ; if ( $ baseCriteria !== null ) $ baseCriteria = clone $ baseCriteria ; $ count = $ this -> model -> count ( $ this -> getCountCriteria ( ) ) ; $ this -> model -> setDbCriteria ( $ baseCriteria ) ; return $ count ; }
|
Calculates the total number of data items .
|
6,055
|
public function run ( $ args ) { $ this -> _scriptName = $ args [ 0 ] ; array_shift ( $ args ) ; if ( isset ( $ args [ 0 ] ) ) { $ name = $ args [ 0 ] ; array_shift ( $ args ) ; } else $ name = 'help' ; $ oldCommand = $ this -> _command ; if ( ( $ command = $ this -> createCommand ( $ name ) ) === null ) $ command = $ this -> createCommand ( 'help' ) ; $ this -> _command = $ command ; $ command -> init ( ) ; $ exitCode = $ command -> run ( $ args ) ; $ this -> _command = $ oldCommand ; return $ exitCode ; }
|
Executes the requested command .
|
6,056
|
public function findCommands ( $ path ) { if ( ( $ dir = @ opendir ( $ path ) ) === false ) return array ( ) ; $ commands = array ( ) ; while ( ( $ name = readdir ( $ dir ) ) !== false ) { $ file = $ path . DIRECTORY_SEPARATOR . $ name ; if ( ! strcasecmp ( substr ( $ name , - 11 ) , 'Command.php' ) && is_file ( $ file ) ) $ commands [ strtolower ( substr ( $ name , 0 , - 11 ) ) ] = $ file ; } closedir ( $ dir ) ; return $ commands ; }
|
Searches for commands under the specified directory .
|
6,057
|
public function addCommands ( $ path ) { if ( ( $ commands = $ this -> findCommands ( $ path ) ) !== array ( ) ) { foreach ( $ commands as $ name => $ file ) { if ( ! isset ( $ this -> commands [ $ name ] ) ) $ this -> commands [ $ name ] = $ file ; } } }
|
Adds commands from the specified command path . If a command already exists the new one will be ignored .
|
6,058
|
public function init ( ) { parent :: init ( ) ; $ id = $ this -> getId ( ) ; if ( isset ( $ this -> htmlOptions [ 'id' ] ) ) $ id = $ this -> htmlOptions [ 'id' ] ; else $ this -> htmlOptions [ 'id' ] = $ id ; $ options = CJavaScript :: encode ( $ this -> options ) ; Yii :: app ( ) -> getClientScript ( ) -> registerScript ( __CLASS__ . '#' . $ id , "jQuery('#{$id}').dialog($options);" ) ; echo CHtml :: openTag ( $ this -> tagName , $ this -> htmlOptions ) . "\n" ; }
|
Renders the open tag of the dialog . This method also registers the necessary javascript code .
|
6,059
|
public function getLastInsertID ( $ table ) { $ this -> ensureTable ( $ table ) ; if ( $ table -> sequenceName !== null ) return $ this -> _connection -> getLastInsertID ( $ table -> sequenceName ) ; else return null ; }
|
Returns the last insertion ID for the specified table .
|
6,060
|
public function createFindCommand ( $ table , $ criteria , $ alias = 't' ) { $ this -> ensureTable ( $ table ) ; $ select = is_array ( $ criteria -> select ) ? implode ( ', ' , $ criteria -> select ) : $ criteria -> select ; if ( $ criteria -> alias != '' ) $ alias = $ criteria -> alias ; $ alias = $ this -> _schema -> quoteTableName ( $ alias ) ; if ( $ select === '*' && ! empty ( $ criteria -> join ) ) { $ prefix = $ alias . '.' ; $ select = array ( ) ; foreach ( $ table -> getColumnNames ( ) as $ name ) $ select [ ] = $ prefix . $ this -> _schema -> quoteColumnName ( $ name ) ; $ select = implode ( ', ' , $ select ) ; } $ sql = ( $ criteria -> distinct ? 'SELECT DISTINCT' : 'SELECT' ) . " {$select} FROM {$table->rawName} $alias" ; $ sql = $ this -> applyJoin ( $ sql , $ criteria -> join ) ; $ sql = $ this -> applyCondition ( $ sql , $ criteria -> condition ) ; $ sql = $ this -> applyGroup ( $ sql , $ criteria -> group ) ; $ sql = $ this -> applyHaving ( $ sql , $ criteria -> having ) ; $ sql = $ this -> applyOrder ( $ sql , $ criteria -> order ) ; $ sql = $ this -> applyLimit ( $ sql , $ criteria -> limit , $ criteria -> offset ) ; $ command = $ this -> _connection -> createCommand ( $ sql ) ; $ this -> bindValues ( $ command , $ criteria -> params ) ; return $ command ; }
|
Creates a SELECT command for a single table .
|
6,061
|
public function createDeleteCommand ( $ table , $ criteria ) { $ this -> ensureTable ( $ table ) ; $ sql = "DELETE FROM {$table->rawName}" ; $ sql = $ this -> applyJoin ( $ sql , $ criteria -> join ) ; $ sql = $ this -> applyCondition ( $ sql , $ criteria -> condition ) ; $ sql = $ this -> applyGroup ( $ sql , $ criteria -> group ) ; $ sql = $ this -> applyHaving ( $ sql , $ criteria -> having ) ; $ sql = $ this -> applyOrder ( $ sql , $ criteria -> order ) ; $ sql = $ this -> applyLimit ( $ sql , $ criteria -> limit , $ criteria -> offset ) ; $ command = $ this -> _connection -> createCommand ( $ sql ) ; $ this -> bindValues ( $ command , $ criteria -> params ) ; return $ command ; }
|
Creates a DELETE command .
|
6,062
|
public function createSqlCommand ( $ sql , $ params = array ( ) ) { $ command = $ this -> _connection -> createCommand ( $ sql ) ; $ this -> bindValues ( $ command , $ params ) ; return $ command ; }
|
Creates a command based on a given SQL statement .
|
6,063
|
public function bindValues ( $ command , $ values ) { if ( ( $ n = count ( $ values ) ) === 0 ) return ; if ( isset ( $ values [ 0 ] ) ) { for ( $ i = 0 ; $ i < $ n ; ++ $ i ) $ command -> bindValue ( $ i + 1 , $ values [ $ i ] ) ; } else { foreach ( $ values as $ name => $ value ) { if ( $ name [ 0 ] !== ':' ) $ name = ':' . $ name ; $ command -> bindValue ( $ name , $ value ) ; } } }
|
Binds parameter values for an SQL command .
|
6,064
|
public function createCriteria ( $ condition = '' , $ params = array ( ) ) { if ( is_array ( $ condition ) ) $ criteria = new CDbCriteria ( $ condition ) ; elseif ( $ condition instanceof CDbCriteria ) $ criteria = clone $ condition ; else { $ criteria = new CDbCriteria ; $ criteria -> condition = $ condition ; $ criteria -> params = $ params ; } return $ criteria ; }
|
Creates a query criteria .
|
6,065
|
public function createPkCriteria ( $ table , $ pk , $ condition = '' , $ params = array ( ) , $ prefix = null ) { $ this -> ensureTable ( $ table ) ; $ criteria = $ this -> createCriteria ( $ condition , $ params ) ; if ( $ criteria -> alias != '' ) $ prefix = $ this -> _schema -> quoteTableName ( $ criteria -> alias ) . '.' ; if ( ! is_array ( $ pk ) ) $ pk = array ( $ pk ) ; if ( is_array ( $ table -> primaryKey ) && ! isset ( $ pk [ 0 ] ) && $ pk !== array ( ) ) $ pk = array ( $ pk ) ; $ condition = $ this -> createInCondition ( $ table , $ table -> primaryKey , $ pk , $ prefix ) ; if ( $ criteria -> condition != '' ) $ criteria -> condition = $ condition . ' AND (' . $ criteria -> condition . ')' ; else $ criteria -> condition = $ condition ; return $ criteria ; }
|
Creates a query criteria with the specified primary key .
|
6,066
|
public function createColumnCriteria ( $ table , $ columns , $ condition = '' , $ params = array ( ) , $ prefix = null ) { $ this -> ensureTable ( $ table ) ; $ criteria = $ this -> createCriteria ( $ condition , $ params ) ; if ( $ criteria -> alias != '' ) $ prefix = $ this -> _schema -> quoteTableName ( $ criteria -> alias ) . '.' ; $ bindByPosition = isset ( $ criteria -> params [ 0 ] ) ; $ conditions = array ( ) ; $ values = array ( ) ; $ i = 0 ; if ( $ prefix === null ) $ prefix = $ table -> rawName . '.' ; foreach ( $ columns as $ name => $ value ) { if ( ( $ column = $ table -> getColumn ( $ name ) ) !== null ) { if ( is_array ( $ value ) ) $ conditions [ ] = $ this -> createInCondition ( $ table , $ name , $ value , $ prefix ) ; elseif ( $ value !== null ) { if ( $ bindByPosition ) { $ conditions [ ] = $ prefix . $ column -> rawName . '=?' ; $ values [ ] = $ value ; } else { $ conditions [ ] = $ prefix . $ column -> rawName . '=' . self :: PARAM_PREFIX . $ i ; $ values [ self :: PARAM_PREFIX . $ i ] = $ value ; $ i ++ ; } } else $ conditions [ ] = $ prefix . $ column -> rawName . ' IS NULL' ; } else throw new CDbException ( Yii :: t ( 'yii' , 'Table "{table}" does not have a column named "{column}".' , array ( '{table}' => $ table -> name , '{column}' => $ name ) ) ) ; } $ criteria -> params = array_merge ( $ values , $ criteria -> params ) ; if ( isset ( $ conditions [ 0 ] ) ) { if ( $ criteria -> condition != '' ) $ criteria -> condition = implode ( ' AND ' , $ conditions ) . ' AND (' . $ criteria -> condition . ')' ; else $ criteria -> condition = implode ( ' AND ' , $ conditions ) ; } return $ criteria ; }
|
Creates a query criteria with the specified column values .
|
6,067
|
public function createSearchCondition ( $ table , $ columns , $ keywords , $ prefix = null , $ caseSensitive = true ) { $ this -> ensureTable ( $ table ) ; if ( ! is_array ( $ keywords ) ) $ keywords = preg_split ( '/\s+/u' , $ keywords , - 1 , PREG_SPLIT_NO_EMPTY ) ; if ( empty ( $ keywords ) ) return '' ; if ( $ prefix === null ) $ prefix = $ table -> rawName . '.' ; $ conditions = array ( ) ; foreach ( $ columns as $ name ) { if ( ( $ column = $ table -> getColumn ( $ name ) ) === null ) throw new CDbException ( Yii :: t ( 'yii' , 'Table "{table}" does not have a column named "{column}".' , array ( '{table}' => $ table -> name , '{column}' => $ name ) ) ) ; $ condition = array ( ) ; foreach ( $ keywords as $ keyword ) { $ keyword = '%' . strtr ( $ keyword , array ( '%' => '\%' , '_' => '\_' , '\\' => '\\\\' ) ) . '%' ; if ( $ caseSensitive ) $ condition [ ] = $ prefix . $ column -> rawName . ' LIKE ' . $ this -> _connection -> quoteValue ( $ keyword ) ; else $ condition [ ] = 'LOWER(' . $ prefix . $ column -> rawName . ') LIKE LOWER(' . $ this -> _connection -> quoteValue ( $ keyword ) . ')' ; } $ conditions [ ] = implode ( ' AND ' , $ condition ) ; } return '(' . implode ( ' OR ' , $ conditions ) . ')' ; }
|
Generates the expression for searching the specified keywords within a list of columns . The search expression is generated using the LIKE SQL syntax . Every word in the keywords must be present and appear in at least one of the columns .
|
6,068
|
protected function ensureTable ( & $ table ) { if ( is_string ( $ table ) && ( $ table = $ this -> _schema -> getTable ( $ tableName = $ table ) ) === null ) throw new CDbException ( Yii :: t ( 'yii' , 'Table "{table}" does not exist.' , array ( '{table}' => $ tableName ) ) ) ; }
|
Checks if the parameter is a valid table schema . If it is a string the corresponding table schema will be retrieved .
|
6,069
|
public function save ( $ state ) { $ command = $ this -> db -> createCommand ( ) ; if ( false === $ this -> exists ( ) ) return $ command -> insert ( $ this -> stateTableName , array ( $ this -> keyField => Yii :: app ( ) -> name , $ this -> valueField => serialize ( $ state ) ) ) ; else return $ command -> update ( $ this -> stateTableName , array ( $ this -> valueField => serialize ( $ state ) ) , $ this -> db -> quoteColumnName ( $ this -> keyField ) . '=:key' , array ( ':key' => Yii :: app ( ) -> name ) ) ; }
|
Saves application state in persistent storage .
|
6,070
|
protected function createTable ( ) { try { $ command = $ this -> db -> createCommand ( ) ; $ command -> createTable ( $ this -> stateTableName , array ( $ this -> keyField => 'string NOT NULL' , $ this -> valueField => 'text NOT NULL' , 'PRIMARY KEY (' . $ this -> db -> quoteColumnName ( $ this -> keyField ) . ')' ) ) ; } catch ( CDbException $ e ) { throw new CException ( Yii :: t ( 'yii' , 'Can\'t create state persister table. Check CREATE privilege for \'{db}\' connection user or create table manually with SQL: {sql}.' , array ( '{db}' => $ this -> dbComponent , '{sql}' => $ command -> text ) ) ) ; } }
|
Creates state persister table
|
6,071
|
public function format ( $ pattern , $ time ) { if ( $ time === null ) return null ; if ( is_string ( $ time ) ) { if ( ctype_digit ( $ time ) || ( $ time { 0 } == '-' && ctype_digit ( substr ( $ time , 1 ) ) ) ) $ time = ( int ) $ time ; else $ time = strtotime ( $ time ) ; } $ date = CTimestamp :: getDate ( $ time , false , false ) ; $ tokens = $ this -> parseFormat ( $ pattern ) ; foreach ( $ tokens as & $ token ) { if ( is_array ( $ token ) ) $ token = $ this -> { $ token [ 0 ] } ( $ token [ 1 ] , $ date ) ; } return implode ( '' , $ tokens ) ; }
|
Formats a date according to a customized pattern .
|
6,072
|
public function formatDateTime ( $ timestamp , $ dateWidth = 'medium' , $ timeWidth = 'medium' ) { if ( ! empty ( $ dateWidth ) ) $ date = $ this -> format ( $ this -> _locale -> getDateFormat ( $ dateWidth ) , $ timestamp ) ; if ( ! empty ( $ timeWidth ) ) $ time = $ this -> format ( $ this -> _locale -> getTimeFormat ( $ timeWidth ) , $ timestamp ) ; if ( isset ( $ date ) && isset ( $ time ) ) { $ dateTimePattern = $ this -> _locale -> getDateTimeFormat ( ) ; return strtr ( $ dateTimePattern , array ( '{0}' => $ time , '{1}' => $ date ) ) ; } elseif ( isset ( $ date ) ) return $ date ; elseif ( isset ( $ time ) ) return $ time ; }
|
Formats a date according to a predefined pattern . The predefined pattern is determined based on the date pattern width and time pattern width .
|
6,073
|
protected function parseFormat ( $ pattern ) { static $ formats = array ( ) ; if ( isset ( $ formats [ $ pattern ] ) ) return $ formats [ $ pattern ] ; $ tokens = array ( ) ; $ n = strlen ( $ pattern ) ; $ isLiteral = false ; $ literal = '' ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { $ c = $ pattern [ $ i ] ; if ( $ c === "'" ) { if ( $ i < $ n - 1 && $ pattern [ $ i + 1 ] === "'" ) { $ tokens [ ] = "'" ; $ i ++ ; } elseif ( $ isLiteral ) { $ tokens [ ] = $ literal ; $ literal = '' ; $ isLiteral = false ; } else { $ isLiteral = true ; $ literal = '' ; } } elseif ( $ isLiteral ) $ literal .= $ c ; else { for ( $ j = $ i + 1 ; $ j < $ n ; ++ $ j ) { if ( $ pattern [ $ j ] !== $ c ) break ; } $ p = str_repeat ( $ c , $ j - $ i ) ; if ( isset ( self :: $ _formatters [ $ c ] ) ) $ tokens [ ] = array ( self :: $ _formatters [ $ c ] , $ p ) ; else $ tokens [ ] = $ p ; $ i = $ j - 1 ; } } if ( $ literal !== '' ) $ tokens [ ] = $ literal ; return $ formats [ $ pattern ] = $ tokens ; }
|
Parses the datetime format pattern .
|
6,074
|
protected function formatMinutes ( $ pattern , $ date ) { $ minutes = $ date [ 'minutes' ] ; if ( $ pattern === 'm' ) return $ minutes ; elseif ( $ pattern === 'mm' ) return str_pad ( $ minutes , 2 , '0' , STR_PAD_LEFT ) ; else throw new CException ( Yii :: t ( 'yii' , 'The pattern for minutes must be "m" or "mm".' ) ) ; }
|
Get the minutes . m for non - padding mm will always return 2 characters .
|
6,075
|
protected function formatSeconds ( $ pattern , $ date ) { $ seconds = $ date [ 'seconds' ] ; if ( $ pattern === 's' ) return $ seconds ; elseif ( $ pattern === 'ss' ) return str_pad ( $ seconds , 2 , '0' , STR_PAD_LEFT ) ; else throw new CException ( Yii :: t ( 'yii' , 'The pattern for seconds must be "s" or "ss".' ) ) ; }
|
Get the seconds . s for non - padding ss will always return 2 characters .
|
6,076
|
protected function formatWeekInYear ( $ pattern , $ date ) { if ( $ pattern === 'w' ) return @ date ( 'W' , @ mktime ( 0 , 0 , 0 , $ date [ 'mon' ] , $ date [ 'mday' ] , $ date [ 'year' ] ) ) ; else throw new CException ( Yii :: t ( 'yii' , 'The pattern for week in year must be "w".' ) ) ; }
|
Get the week in the year .
|
6,077
|
protected function formatWeekInMonth ( $ pattern , $ date ) { if ( $ pattern === 'W' ) { $ weekDay = date ( 'N' , mktime ( 0 , 0 , 0 , $ date [ 'mon' ] , 1 , $ date [ 'year' ] ) ) ; return floor ( ( $ weekDay + $ date [ 'mday' ] - 2 ) / 7 ) + 1 ; } else throw new CException ( Yii :: t ( 'yii' , 'The pattern for week in month must be "W".' ) ) ; }
|
Get week in the month .
|
6,078
|
protected function formatTimeZone ( $ pattern , $ date ) { if ( $ pattern [ 0 ] === 'z' || $ pattern [ 0 ] === 'v' ) return @ date ( 'T' , @ mktime ( $ date [ 'hours' ] , $ date [ 'minutes' ] , $ date [ 'seconds' ] , $ date [ 'mon' ] , $ date [ 'mday' ] , $ date [ 'year' ] ) ) ; elseif ( $ pattern [ 0 ] === 'Z' ) return @ date ( 'P' , @ mktime ( $ date [ 'hours' ] , $ date [ 'minutes' ] , $ date [ 'seconds' ] , $ date [ 'mon' ] , $ date [ 'mday' ] , $ date [ 'year' ] ) ) ; else throw new CException ( Yii :: t ( 'yii' , 'The pattern for time zone must be "z" or "v".' ) ) ; }
|
Get the timezone of the server machine .
|
6,079
|
protected function formatEra ( $ pattern , $ date ) { $ era = $ date [ 'year' ] > 0 ? 1 : 0 ; switch ( $ pattern ) { case 'G' : case 'GG' : case 'GGG' : return $ this -> _locale -> getEraName ( $ era , 'abbreviated' ) ; case 'GGGG' : return $ this -> _locale -> getEraName ( $ era , 'wide' ) ; case 'GGGGG' : return $ this -> _locale -> getEraName ( $ era , 'narrow' ) ; default : throw new CException ( Yii :: t ( 'yii' , 'The pattern for era must be "G", "GG", "GGG", "GGGG" or "GGGGG".' ) ) ; } }
|
Get the era . i . e . in gregorian year > 0 is AD else BC .
|
6,080
|
protected function processLogs ( $ logs ) { $ text = '' ; foreach ( $ logs as $ log ) $ text .= $ this -> formatLogMessage ( $ log [ 0 ] , $ log [ 1 ] , $ log [ 2 ] , $ log [ 3 ] ) ; $ logFile = $ this -> getLogPath ( ) . DIRECTORY_SEPARATOR . $ this -> getLogFile ( ) ; $ fp = @ fopen ( $ logFile , 'a' ) ; @ flock ( $ fp , LOCK_EX ) ; if ( @ filesize ( $ logFile ) > $ this -> getMaxFileSize ( ) * 1024 ) { $ this -> rotateFiles ( ) ; @ flock ( $ fp , LOCK_UN ) ; @ fclose ( $ fp ) ; @ file_put_contents ( $ logFile , $ text , FILE_APPEND | LOCK_EX ) ; } else { @ fwrite ( $ fp , $ text ) ; @ flock ( $ fp , LOCK_UN ) ; @ fclose ( $ fp ) ; } }
|
Saves log messages in files .
|
6,081
|
public static function init ( $ apiKey = null ) { if ( $ apiKey === null ) return CHtml :: scriptFile ( self :: $ bootstrapUrl ) ; else return CHtml :: scriptFile ( self :: $ bootstrapUrl . '?key=' . $ apiKey ) ; }
|
Renders the jsapi script file .
|
6,082
|
public function findTagWeights ( $ limit = 20 ) { $ models = $ this -> findAll ( array ( 'order' => 'frequency DESC' , 'limit' => $ limit , ) ) ; $ total = 0 ; foreach ( $ models as $ model ) $ total += $ model -> frequency ; $ tags = array ( ) ; if ( $ total > 0 ) { foreach ( $ models as $ model ) $ tags [ $ model -> name ] = 8 + ( int ) ( 16 * $ model -> frequency / ( $ total + 10 ) ) ; ksort ( $ tags ) ; } return $ tags ; }
|
Returns tag names and their corresponding weights . Only the tags with the top weights will be returned .
|
6,083
|
public function setBasePath ( $ value ) { if ( ( $ basePath = realpath ( $ value ) ) !== false && is_dir ( $ basePath ) && is_writable ( $ basePath ) ) $ this -> _basePath = $ basePath ; else throw new CException ( Yii :: t ( 'yii' , 'CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.' , array ( '{path}' => $ value ) ) ) ; }
|
Sets the root directory storing published asset files .
|
6,084
|
public function getPublishedUrl ( $ path , $ hashByName = false ) { if ( isset ( $ this -> _published [ $ path ] ) ) return $ this -> _published [ $ path ] ; if ( is_string ( $ path ) && ( $ path = realpath ( $ path ) ) !== false ) { $ base = $ this -> getBaseUrl ( ) . '/' . $ this -> generatePath ( $ path , $ hashByName ) ; return is_file ( $ path ) ? $ base . '/' . basename ( $ path ) : $ base ; } else return false ; }
|
Returns the URL of a published file path . This method does not perform any publishing . It merely tells you if the file path is published what the URL will be to access it .
|
6,085
|
protected function generatePath ( $ file , $ hashByName = false ) { if ( is_file ( $ file ) ) $ pathForHashing = $ hashByName ? dirname ( $ file ) : dirname ( $ file ) . filemtime ( $ file ) ; else $ pathForHashing = $ hashByName ? $ file : $ file . filemtime ( $ file ) ; return $ this -> hash ( $ pathForHashing ) ; }
|
Generates path segments relative to basePath .
|
6,086
|
public function sticky ( $ attribute , $ params ) { if ( ! $ this -> hasErrors ( ) ) $ this -> _stickyAttributes [ $ attribute ] = $ this -> $ attribute ; }
|
The sticky validator . This validator does not really validate the attributes . It actually saves the attribute value in a file to make it sticky .
|
6,087
|
public function loadStickyAttributes ( ) { $ this -> _stickyAttributes = array ( ) ; $ path = $ this -> getStickyFile ( ) ; if ( is_file ( $ path ) ) { $ result = @ include ( $ path ) ; if ( is_array ( $ result ) ) { $ this -> _stickyAttributes = $ result ; foreach ( $ this -> _stickyAttributes as $ name => $ value ) { if ( property_exists ( $ this , $ name ) || $ this -> canSetProperty ( $ name ) ) $ this -> $ name = $ value ; } } } }
|
Loads sticky attributes from a file and populates them into the model .
|
6,088
|
public function saveStickyAttributes ( ) { $ path = $ this -> getStickyFile ( ) ; @ mkdir ( dirname ( $ path ) , 0755 , true ) ; file_put_contents ( $ path , "<?php\nreturn " . var_export ( $ this -> _stickyAttributes , true ) . ";\n" ) ; }
|
Saves sticky attributes into a file .
|
6,089
|
public function class2name ( $ name , $ ucwords = true ) { $ result = trim ( strtolower ( str_replace ( '_' , ' ' , preg_replace ( '/(?<![A-Z])[A-Z]/' , ' \0' , $ name ) ) ) ) ; return $ ucwords ? ucwords ( $ result ) : $ result ; }
|
Converts a class name into space - separated words . For example PostTag will be converted as Post Tag .
|
6,090
|
public function validateReservedWord ( $ attribute , $ params ) { $ value = $ this -> $ attribute ; if ( in_array ( strtolower ( $ value ) , self :: $ keywords ) ) $ this -> addError ( $ attribute , $ this -> getAttributeLabel ( $ attribute ) . ' cannot take a reserved PHP keyword.' ) ; }
|
Validates an attribute to make sure it is not taking a PHP reserved keyword .
|
6,091
|
public static function validate ( $ models , $ attributes = null , $ loadInput = true ) { $ result = array ( ) ; if ( ! is_array ( $ models ) ) $ models = array ( $ models ) ; foreach ( $ models as $ model ) { $ modelName = CHtml :: modelName ( $ model ) ; if ( $ loadInput && isset ( $ _POST [ $ modelName ] ) ) $ model -> attributes = $ _POST [ $ modelName ] ; $ model -> validate ( $ attributes ) ; foreach ( $ model -> getErrors ( ) as $ attribute => $ errors ) $ result [ CHtml :: activeId ( $ model , $ attribute ) ] = $ errors ; } return function_exists ( 'json_encode' ) ? json_encode ( $ result ) : CJSON :: encode ( $ result ) ; }
|
Validates one or several models and returns the results in JSON format . This is a helper method that simplifies the way of writing AJAX validation code .
|
6,092
|
public function registerClientScript ( ) { $ cs = Yii :: app ( ) -> clientScript ; $ id = $ this -> imageOptions [ 'id' ] ; $ url = $ this -> getController ( ) -> createUrl ( $ this -> captchaAction , array ( CCaptchaAction :: REFRESH_GET_VAR => true ) ) ; $ js = "" ; if ( $ this -> showRefreshButton ) { $ cs -> registerScript ( 'Yii.CCaptcha#' . $ id , '// dummy' ) ; $ label = $ this -> buttonLabel === null ? Yii :: t ( 'yii' , 'Get a new code' ) : $ this -> buttonLabel ; $ options = $ this -> buttonOptions ; if ( isset ( $ options [ 'id' ] ) ) $ buttonID = $ options [ 'id' ] ; else $ buttonID = $ options [ 'id' ] = $ id . '_button' ; if ( $ this -> buttonType === 'button' ) $ html = CHtml :: button ( $ label , $ options ) ; else $ html = CHtml :: link ( $ label , $ url , $ options ) ; $ js = "jQuery('#$id').after(" . CJSON :: encode ( $ html ) . ");" ; $ selector = "#$buttonID" ; } if ( $ this -> clickableImage ) $ selector = isset ( $ selector ) ? "$selector, #$id" : "#$id" ; if ( ! isset ( $ selector ) ) return ; $ js .= "jQuery(document).on('click', '$selector', function(){ jQuery.ajax({ url: " . CJSON :: encode ( $ url ) . ", dataType: 'json', cache: false, success: function(data) { jQuery('#$id').attr('src', data['url']); jQuery('body').data('{$this->captchaAction}.hash', [data['hash1'], data['hash2']]); } }); return false;});" ; $ cs -> registerScript ( 'Yii.CCaptcha#' . $ id , $ js ) ; }
|
Registers the needed client scripts .
|
6,093
|
public static function checkRequirements ( $ extension = null ) { if ( extension_loaded ( 'imagick' ) ) { $ imagick = new Imagick ( ) ; $ imagickFormats = $ imagick -> queryFormats ( 'PNG' ) ; } if ( extension_loaded ( 'gd' ) ) { $ gdInfo = gd_info ( ) ; } if ( $ extension === null ) { if ( isset ( $ imagickFormats ) && in_array ( 'PNG' , $ imagickFormats ) ) return true ; if ( isset ( $ gdInfo ) && $ gdInfo [ 'FreeType Support' ] ) return true ; } elseif ( $ extension == 'imagick' && isset ( $ imagickFormats ) && in_array ( 'PNG' , $ imagickFormats ) ) return true ; elseif ( $ extension == 'gd' && isset ( $ gdInfo ) && $ gdInfo [ 'FreeType Support' ] ) return true ; return false ; }
|
Checks if specified graphic extension support is loaded .
|
6,094
|
public function jsonSerialize ( ) { return array_filter ( [ 'enable' => $ this -> getEnable ( ) , 'threshold' => $ this -> getThreshold ( ) , 'post_to_url' => $ this -> getPostToUrl ( ) ] , function ( $ value ) { return $ value !== null ; } ) ? : null ; }
|
Return an array representing a SpamCheck object for the Twilio SendGrid API
|
6,095
|
public function setGanalytics ( $ enable , $ utm_source = null , $ utm_medium = null , $ utm_term = null , $ utm_content = null , $ utm_campaign = null ) { if ( $ enable instanceof Ganalytics ) { $ ganalytics = $ enable ; $ this -> ganalytics = $ ganalytics ; return ; } $ this -> ganalytics = new Ganalytics ( $ enable , $ utm_source , $ utm_medium , $ utm_term , $ utm_content , $ utm_campaign ) ; }
|
Set the Google analytics settings on a TrackingSettings object
|
6,096
|
public function jsonSerialize ( ) { return array_filter ( [ 'click_tracking' => $ this -> getClickTracking ( ) , 'open_tracking' => $ this -> getOpenTracking ( ) , 'subscription_tracking' => $ this -> getSubscriptionTracking ( ) , 'ganalytics' => $ this -> getGanalytics ( ) ] , function ( $ value ) { return $ value !== null ; } ) ? : null ; }
|
Return an array representing a TrackingSettings object for the Twilio SendGrid API
|
6,097
|
public function jsonSerialize ( ) { return array_filter ( [ 'enable' => $ this -> getEnable ( ) , 'enable_text' => $ this -> getEnableText ( ) ] , function ( $ value ) { return $ value !== null ; } ) ? : null ; }
|
Return an array representing a ClickTracking object for the Twilio SendGrid API
|
6,098
|
public function jsonSerialize ( ) { return array_filter ( [ 'enable' => $ this -> getEnable ( ) , 'text' => $ this -> getText ( ) , 'html' => $ this -> getHtml ( ) ] , function ( $ value ) { return $ value !== null ; } ) ? : null ; }
|
Return an array representing a Footer object for the Twilio SendGrid API
|
6,099
|
public function jsonSerialize ( ) { return array_filter ( [ 'key' => $ this -> getKey ( ) , 'value' => $ this -> getValue ( ) ] , function ( $ value ) { return $ value !== null ; } ) ? : null ; }
|
Return an array representing a Header object for the Twilio SendGrid API
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.