idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
5,800
public function alterColumn ( $ table , $ column , $ type ) { echo " > alter column $column in table $table to $type ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> alterColumn ( $ table , $ column , $ type ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds and executes a SQL statement for changing the definition of a column .
5,801
public function addForeignKey ( $ name , $ table , $ columns , $ refTable , $ refColumns , $ delete = null , $ update = null ) { echo " > add foreign key $name: $table (" . ( is_array ( $ columns ) ? implode ( ',' , $ columns ) : $ columns ) . ") references $refTable (" . ( is_array ( $ refColumns ) ? implode ( ',' , $ refColumns ) : $ refColumns ) . ") ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> addForeignKey ( $ name , $ table , $ columns , $ refTable , $ refColumns , $ delete , $ update ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds a SQL statement for adding a foreign key constraint to an existing table . The method will properly quote the table and column names .
5,802
public function dropForeignKey ( $ name , $ table ) { echo " > drop foreign key $name from table $table ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> dropForeignKey ( $ name , $ table ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds a SQL statement for dropping a foreign key constraint .
5,803
public function createIndex ( $ name , $ table , $ columns , $ unique = false ) { echo " > create" . ( $ unique ? ' unique' : '' ) . " index $name on $table (" . ( is_array ( $ columns ) ? implode ( ',' , $ columns ) : $ columns ) . ") ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> createIndex ( $ name , $ table , $ columns , $ unique ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds and executes a SQL statement for creating a new index .
5,804
public function refreshTableSchema ( $ table ) { echo " > refresh table $table schema cache ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> getSchema ( ) -> getTable ( $ table , true ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Refreshed schema cache for a table
5,805
public function addPrimaryKey ( $ name , $ table , $ columns ) { echo " > alter table $table add constraint $name primary key (" . ( is_array ( $ columns ) ? implode ( ',' , $ columns ) : $ columns ) . ") ..." ; $ time = microtime ( true ) ; $ this -> getDbConnection ( ) -> createCommand ( ) -> addPrimaryKey ( $ name , $ table , $ columns ) ; echo " done (time: " . sprintf ( '%.3f' , microtime ( true ) - $ time ) . "s)\n" ; }
Builds and executes a SQL statement for creating a primary key supports composite primary keys .
5,806
public function init ( ) { parent :: init ( ) ; if ( $ this -> enableSkin && $ this -> skinPath === null ) $ this -> skinPath = Yii :: app ( ) -> getViewPath ( ) . DIRECTORY_SEPARATOR . 'skins' ; }
class name skin name property name = > value
5,807
public function getDataCellContent ( $ row ) { $ data = $ this -> grid -> dataProvider -> data [ $ row ] ; $ tr = array ( ) ; ob_start ( ) ; foreach ( $ this -> buttons as $ id => $ button ) { $ this -> renderButton ( $ id , $ button , $ row , $ data ) ; $ tr [ '{' . $ id . '}' ] = ob_get_contents ( ) ; ob_clean ( ) ; } ob_end_clean ( ) ; return strtr ( $ this -> template , $ tr ) ; }
Returns the data cell content . This method renders the view update and delete buttons in the data cell .
5,808
public function addComment ( $ comment ) { if ( Yii :: app ( ) -> params [ 'commentNeedApproval' ] ) $ comment -> status = Comment :: STATUS_PENDING ; else $ comment -> status = Comment :: STATUS_APPROVED ; $ comment -> post_id = $ this -> id ; return $ comment -> save ( ) ; }
Adds a new comment to this post . This method will set status and post_id of the comment accordingly .
5,809
public function actionList ( ) { $ pages = new CPagination ( Post :: model ( ) -> count ( ) ) ; $ postList = Post :: model ( ) -> findAll ( $ this -> getListCriteria ( $ pages ) ) ; $ this -> render ( 'list' , array ( 'postList' => $ postList , 'pages' => $ pages ) ) ; }
Lists all posts .
5,810
public function actionCreate ( ) { $ post = new Post ; if ( Yii :: app ( ) -> request -> isPostRequest ) { if ( isset ( $ _POST [ 'Post' ] ) ) $ post -> setAttributes ( $ _POST [ 'Post' ] ) ; if ( $ post -> save ( ) ) $ this -> redirect ( array ( 'show' , 'id' => $ post -> id ) ) ; } $ this -> render ( 'create' , array ( 'post' => $ post ) ) ; }
Creates a new post . If creation is successful the browser will be redirected to the show page .
5,811
public function actionUpdate ( ) { $ post = $ this -> loadPost ( ) ; if ( Yii :: app ( ) -> request -> isPostRequest ) { if ( isset ( $ _POST [ 'Post' ] ) ) $ post -> setAttributes ( $ _POST [ 'Post' ] ) ; if ( $ post -> save ( ) ) $ this -> redirect ( array ( 'show' , 'id' => $ post -> id ) ) ; } $ this -> render ( 'update' , array ( 'post' => $ post ) ) ; }
Updates a particular post . If update is successful the browser will be redirected to the show page .
5,812
public function actionDelete ( ) { if ( Yii :: app ( ) -> request -> isPostRequest ) { $ this -> loadPost ( ) -> delete ( ) ; $ this -> redirect ( array ( 'list' ) ) ; } else throw new CHttpException ( 500 , 'Invalid request. Please do not repeat this request again.' ) ; }
Deletes a particular post . If deletion is successful the browser will be redirected to the list page .
5,813
protected function loadPost ( ) { if ( isset ( $ _GET [ 'id' ] ) ) $ post = Post :: model ( ) -> findbyPk ( $ _GET [ 'id' ] ) ; if ( isset ( $ post ) ) return $ post ; else throw new CHttpException ( 500 , 'The requested post does not exist.' ) ; }
Loads the data model based on the primary key given in the GET variable . If the data model is not found an HTTP exception will be raised .
5,814
protected function generateColumnHeader ( $ column ) { $ params = $ _GET ; if ( isset ( $ params [ 'sort' ] ) && $ params [ 'sort' ] === $ column ) { if ( isset ( $ params [ 'desc' ] ) ) unset ( $ params [ 'desc' ] ) ; else $ params [ 'desc' ] = 1 ; } else { $ params [ 'sort' ] = $ column ; unset ( $ params [ 'desc' ] ) ; } $ url = $ this -> createUrl ( 'list' , $ params ) ; return CHtml :: link ( Post :: model ( ) -> getAttributeLabel ( $ column ) , $ url ) ; }
Generates the header cell for the specified column . This method will generate a hyperlink for the column . Clicking on the link will cause the data to be sorted according to the column .
5,815
public function registerClientScript ( $ id ) { $ jsOptions = $ this -> getClientOptions ( ) ; $ jsOptions = empty ( $ jsOptions ) ? '' : CJavaScript :: encode ( $ jsOptions ) ; $ js = "jQuery('#{$id} > input').rating({$jsOptions});" ; $ cs = Yii :: app ( ) -> getClientScript ( ) ; $ cs -> registerCoreScript ( 'rating' ) ; $ cs -> registerScript ( 'Yii.CStarRating#' . $ id , $ js ) ; if ( $ this -> cssFile !== false ) self :: registerCssFile ( $ this -> cssFile ) ; }
Registers the necessary javascript and css scripts .
5,816
protected function renderStars ( $ id , $ name ) { $ inputCount = ( int ) ( ( $ this -> maxRating - $ this -> minRating ) / $ this -> ratingStepSize + 1 ) ; $ starSplit = ( int ) ( $ inputCount / $ this -> starCount ) ; if ( $ this -> hasModel ( ) ) { $ attr = $ this -> attribute ; CHtml :: resolveName ( $ this -> model , $ attr ) ; $ selection = $ this -> model -> $ attr ; } else $ selection = $ this -> value ; $ options = $ starSplit > 1 ? array ( 'class' => "{split:{$starSplit}}" ) : array ( ) ; for ( $ value = $ this -> minRating , $ i = 0 ; $ i < $ inputCount ; ++ $ i , $ value += $ this -> ratingStepSize ) { $ options [ 'id' ] = $ id . '_' . $ i ; $ options [ 'value' ] = $ value ; if ( isset ( $ this -> titles [ $ value ] ) ) $ options [ 'title' ] = $ this -> titles [ $ value ] ; else unset ( $ options [ 'title' ] ) ; echo CHtml :: radioButton ( $ name , ! strcmp ( $ value , $ selection ) , $ options ) . "\n" ; } }
Renders the stars .
5,817
protected function generatePageText ( $ page ) { if ( $ this -> pageTextFormat !== null ) return sprintf ( $ this -> pageTextFormat , $ page + 1 ) ; else return $ page + 1 ; }
Generates the list option for the specified page number . You may override this method to customize the option display .
5,818
public function remove ( $ key ) { if ( ( $ item = parent :: remove ( $ key ) ) !== null ) $ this -> _form -> removedElement ( $ key , $ item , $ this -> _forButtons ) ; }
Removes the specified element by key .
5,819
public function renderFilter ( ) { if ( $ this -> filter !== null ) { echo "<tr class=\"{$this->filterCssClass}\">\n" ; foreach ( $ this -> columns as $ column ) $ column -> renderFilterCell ( ) ; echo "</tr>\n" ; } }
Renders the filter .
5,820
public function actionPlay ( ) { static $ levels = array ( '10' => 'Easy game; you are allowed 10 misses.' , '5' => 'Medium game; you are allowed 5 misses.' , '3' => 'Hard game; you are allowed 3 misses.' , ) ; if ( isset ( $ _POST [ 'level' ] ) && isset ( $ levels [ $ _POST [ 'level' ] ] ) ) { $ this -> word = $ this -> generateWord ( ) ; $ this -> guessWord = str_repeat ( '_' , strlen ( $ this -> word ) ) ; $ this -> level = $ _POST [ 'level' ] ; $ this -> misses = 0 ; $ this -> setPageState ( 'guessed' , null ) ; $ this -> render ( 'guess' ) ; } else { $ params = array ( 'levels' => $ levels , 'error' => Yii :: app ( ) -> request -> isPostRequest , ) ; $ this -> render ( 'play' , $ params ) ; } }
The play action . In this action users are asked to choose a difficulty level of the game .
5,821
public function actionGuess ( ) { if ( isset ( $ _GET [ 'g' ] [ 0 ] ) && ( $ result = $ this -> guess ( $ _GET [ 'g' ] [ 0 ] ) ) !== null ) $ this -> render ( $ result ? 'win' : 'lose' ) ; else { $ guessed = $ this -> getPageState ( 'guessed' , array ( ) ) ; $ guessed [ $ _GET [ 'g' ] [ 0 ] ] = true ; $ this -> setPageState ( 'guessed' , $ guessed , array ( ) ) ; $ this -> render ( 'guess' ) ; } }
The guess action . This action is invoked each time when the user makes a guess .
5,822
protected function generateWord ( ) { $ wordFile = dirname ( __FILE__ ) . '/words.txt' ; $ words = preg_split ( "/[\s,]+/" , file_get_contents ( $ wordFile ) ) ; do { $ i = rand ( 0 , count ( $ words ) - 1 ) ; $ word = $ words [ $ i ] ; } while ( strlen ( $ word ) < 5 || ! ctype_alpha ( $ word ) ) ; return strtoupper ( $ word ) ; }
Generates a word to be guessed .
5,823
protected function guess ( $ letter ) { $ word = $ this -> word ; $ guessWord = $ this -> guessWord ; $ pos = 0 ; $ success = false ; while ( ( $ pos = strpos ( $ word , $ letter , $ pos ) ) !== false ) { $ guessWord [ $ pos ] = $ letter ; $ success = true ; $ pos ++ ; } if ( $ success ) { $ this -> guessWord = $ guessWord ; if ( $ guessWord === $ word ) return true ; } else { $ this -> misses ++ ; if ( $ this -> misses >= $ this -> level ) return false ; } }
Checks to see if a letter is guessed correctly .
5,824
public function loadFromFile ( $ configFile ) { $ data = require ( $ configFile ) ; if ( $ this -> getCount ( ) > 0 ) $ this -> mergeWith ( $ data ) ; else $ this -> copyFrom ( $ data ) ; }
Loads configuration data from a file and merges it with the existing configuration .
5,825
public static function quote ( $ js , $ forUrl = false ) { $ js = ( string ) $ js ; Yii :: import ( 'system.vendors.zend-escaper.Escaper' ) ; $ escaper = new Escaper ( Yii :: app ( ) -> charset ) ; if ( $ forUrl ) return $ escaper -> escapeUrl ( $ js ) ; else return $ escaper -> escapeJs ( $ js ) ; }
Quotes a javascript string . After processing the string can be safely enclosed within a pair of quotation marks and serve as a javascript string .
5,826
public static function encode ( $ value , $ safe = false ) { if ( is_string ( $ value ) ) { if ( strpos ( $ value , 'js:' ) === 0 && $ safe === false ) return substr ( $ value , 3 ) ; else return "'" . self :: quote ( $ value ) . "'" ; } elseif ( $ value === null ) return 'null' ; elseif ( is_bool ( $ value ) ) return $ value ? 'true' : 'false' ; elseif ( is_integer ( $ value ) ) return "$value" ; elseif ( is_float ( $ value ) ) { if ( $ value === - INF ) return 'Number.NEGATIVE_INFINITY' ; elseif ( $ value === INF ) return 'Number.POSITIVE_INFINITY' ; else return str_replace ( ',' , '.' , ( float ) $ value ) ; } elseif ( $ value instanceof CJavaScriptExpression ) return $ value -> __toString ( ) ; elseif ( is_object ( $ value ) ) return self :: encode ( get_object_vars ( $ value ) , $ safe ) ; elseif ( is_array ( $ value ) ) { $ es = array ( ) ; if ( ( $ n = count ( $ value ) ) > 0 && array_keys ( $ value ) !== range ( 0 , $ n - 1 ) ) { foreach ( $ value as $ k => $ v ) $ es [ ] = "'" . self :: quote ( $ k ) . "':" . self :: encode ( $ v , $ safe ) ; return '{' . implode ( ',' , $ es ) . '}' ; } else { foreach ( $ value as $ v ) $ es [ ] = self :: encode ( $ v , $ safe ) ; return '[' . implode ( ',' , $ es ) . ']' ; } } else return '' ; }
Encodes a PHP variable into javascript representation .
5,827
public function init ( ) { parent :: init ( ) ; foreach ( $ this -> _routes as $ name => $ route ) { $ route = Yii :: createComponent ( $ route ) ; $ route -> init ( ) ; $ this -> _routes [ $ name ] = $ route ; } Yii :: getLogger ( ) -> attachEventHandler ( 'onFlush' , array ( $ this , 'collectLogs' ) ) ; Yii :: app ( ) -> attachEventHandler ( 'onEndRequest' , array ( $ this , 'processLogs' ) ) ; }
Initializes this application component . This method is required by the IApplicationComponent interface .
5,828
function main ( ) { $ pkg = new PEAR_PackageFileManager2 ( ) ; $ e = $ pkg -> setOptions ( array ( 'baseinstalldir' => 'yii' , 'packagedirectory' => $ this -> pkgdir , 'filelistgenerator' => 'file' , 'simpleoutput' => true , 'ignore' => array ( ) , 'roles' => array ( '*' => 'php' ) , ) ) ; if ( PEAR :: isError ( $ e ) ) die ( $ e -> getMessage ( ) ) ; $ pkg -> setPackage ( $ this -> package ) ; $ pkg -> setSummary ( $ this -> summary ) ; $ pkg -> setDescription ( $ this -> pkgdescription ) ; $ pkg -> setChannel ( $ this -> channel ) ; $ pkg -> setReleaseStability ( $ this -> state ) ; $ pkg -> setAPIStability ( $ this -> state ) ; $ pkg -> setReleaseVersion ( $ this -> version ) ; $ pkg -> setAPIVersion ( $ this -> version ) ; $ pkg -> setLicense ( $ this -> license ) ; $ pkg -> setNotes ( $ this -> notes ) ; $ pkg -> setPackageType ( 'php' ) ; $ pkg -> setPhpDep ( '5.1.0' ) ; $ pkg -> setPearinstallerDep ( '1.4.2' ) ; $ pkg -> addRelease ( ) ; $ pkg -> addMaintainer ( 'lead' , 'qxue' , 'Qiang Xue' , 'qiang.xue@gmail.com' ) ; $ test = $ pkg -> generateContents ( ) ; $ e = $ pkg -> writePackageFile ( ) ; if ( PEAR :: isError ( $ e ) ) echo $ e -> getMessage ( ) ; }
Main entrypoint of the task
5,829
public function setLocale ( $ locale ) { if ( is_string ( $ locale ) ) $ locale = CLocale :: getInstance ( $ locale ) ; $ this -> sizeFormat [ 'decimalSeparator' ] = $ locale -> getNumberSymbol ( 'decimal' ) ; $ this -> _locale = $ locale ; }
Set the locale to use for formatting values .
5,830
public function init ( ) { parent :: init ( ) ; if ( $ this -> keyPrefix === null ) $ this -> keyPrefix = Yii :: app ( ) -> getId ( ) ; }
Initializes the application component . This method overrides the parent implementation by setting default cache key prefix .
5,831
public function get ( $ id ) { $ value = $ this -> getValue ( $ this -> generateUniqueKey ( $ id ) ) ; if ( $ value === false || $ this -> serializer === false ) return $ value ; if ( $ this -> serializer === null ) $ value = unserialize ( $ value ) ; else $ value = call_user_func ( $ this -> serializer [ 1 ] , $ value ) ; if ( is_array ( $ value ) && ( ! $ value [ 1 ] instanceof ICacheDependency || ! $ value [ 1 ] -> getHasChanged ( ) ) ) { Yii :: trace ( 'Serving "' . $ id . '" from cache' , 'system.caching.' . get_class ( $ this ) ) ; return $ value [ 0 ] ; } else return false ; }
Retrieves a value from cache with a specified key .
5,832
public function set ( $ id , $ value , $ expire = 0 , $ dependency = null ) { Yii :: trace ( 'Saving "' . $ id . '" to cache' , 'system.caching.' . get_class ( $ this ) ) ; if ( $ dependency !== null && $ this -> serializer !== false ) $ dependency -> evaluateDependency ( ) ; if ( $ this -> serializer === null ) $ value = serialize ( array ( $ value , $ dependency ) ) ; elseif ( $ this -> serializer !== false ) $ value = call_user_func ( $ this -> serializer [ 0 ] , array ( $ value , $ dependency ) ) ; return $ this -> setValue ( $ this -> generateUniqueKey ( $ id ) , $ value , $ expire ) ; }
Stores a value identified by a key into cache . If the cache already contains such a key the existing value and expiration time will be replaced with the new ones .
5,833
public function delete ( $ id ) { Yii :: trace ( 'Deleting "' . $ id . '" from cache' , 'system.caching.' . get_class ( $ this ) ) ; return $ this -> deleteValue ( $ this -> generateUniqueKey ( $ id ) ) ; }
Deletes a value with the specified key from cache
5,834
protected function resolvePackagePath ( ) { if ( $ this -> scriptUrl === null || $ this -> themeUrl === null ) { $ cs = Yii :: app ( ) -> getClientScript ( ) ; if ( $ this -> scriptUrl === null ) $ this -> scriptUrl = $ cs -> getCoreScriptUrl ( ) . '/jui/js' ; if ( $ this -> themeUrl === null ) $ this -> themeUrl = $ cs -> getCoreScriptUrl ( ) . '/jui/css' ; } }
Determine the JUI package installation path . This method will identify the JavaScript root URL and theme root URL . If they are not explicitly specified it will publish the included JUI package and use that to resolve the needed paths .
5,835
protected function registerCoreScripts ( ) { $ cs = Yii :: app ( ) -> getClientScript ( ) ; if ( is_string ( $ this -> cssFile ) ) $ cs -> registerCssFile ( $ this -> themeUrl . '/' . $ this -> theme . '/' . $ this -> cssFile ) ; elseif ( is_array ( $ this -> cssFile ) ) { foreach ( $ this -> cssFile as $ cssFile ) $ cs -> registerCssFile ( $ this -> themeUrl . '/' . $ this -> theme . '/' . $ cssFile ) ; } $ cs -> registerCoreScript ( 'jquery' ) ; if ( is_string ( $ this -> scriptFile ) ) $ this -> registerScriptFile ( $ this -> scriptFile ) ; elseif ( is_array ( $ this -> scriptFile ) ) { foreach ( $ this -> scriptFile as $ scriptFile ) $ this -> registerScriptFile ( $ scriptFile ) ; } }
Registers the core script files . This method registers jquery and JUI JavaScript files and the theme CSS file .
5,836
public function _doCodeBlocks_callback ( $ matches ) { $ codeblock = $ this -> outdent ( $ matches [ 1 ] ) ; if ( ( $ codeblock = $ this -> highlightCodeBlock ( $ codeblock ) ) !== null ) return "\n\n" . $ this -> hashBlock ( $ codeblock ) . "\n\n" ; else return parent :: _doCodeBlocks_callback ( $ matches ) ; }
Callback function when a code block is matched .
5,837
protected function highlightCodeBlock ( $ codeblock ) { if ( ( $ tag = $ this -> getHighlightTag ( $ codeblock ) ) !== null && ( $ highlighter = $ this -> createHighLighter ( $ tag ) ) ) { $ codeblock = preg_replace ( '/\A\n+|\n+\z/' , '' , $ codeblock ) ; $ tagLen = strpos ( $ codeblock , $ tag ) + strlen ( $ tag ) ; $ codeblock = ltrim ( substr ( $ codeblock , $ tagLen ) ) ; $ output = preg_replace ( '/<span\s+[^>]*>(\s*)<\/span>/' , '\1' , $ highlighter -> highlight ( $ codeblock ) ) ; return "<div class=\"{$this->highlightCssClass}\">" . $ output . "</div>" ; } else return "<pre>" . CHtml :: encode ( $ codeblock ) . "</pre>" ; }
Highlights the code block .
5,838
protected function getHighlightTag ( $ codeblock ) { $ str = trim ( current ( preg_split ( "/\r|\n/" , $ codeblock , 2 ) ) ) ; if ( strlen ( $ str ) > 2 && $ str [ 0 ] === '[' && $ str [ strlen ( $ str ) - 1 ] === ']' ) return $ str ; }
Returns the user - entered highlighting options .
5,839
protected function createHighLighter ( $ options ) { if ( ! class_exists ( 'Text_Highlighter' , false ) ) { require_once ( Yii :: getPathOfAlias ( 'system.vendors.TextHighlighter.Text.Highlighter' ) . '.php' ) ; require_once ( Yii :: getPathOfAlias ( 'system.vendors.TextHighlighter.Text.Highlighter.Renderer.Html' ) . '.php' ) ; } $ lang = current ( preg_split ( '/\s+/' , substr ( substr ( $ options , 1 ) , 0 , - 1 ) , 2 ) ) ; $ highlighter = Text_Highlighter :: factory ( $ lang ) ; if ( $ highlighter ) $ highlighter -> setRenderer ( new Text_Highlighter_Renderer_Html ( $ this -> getHighlightConfig ( $ options ) ) ) ; return $ highlighter ; }
Creates a highlighter instance .
5,840
public function getHighlightConfig ( $ options ) { $ config = array ( 'use_language' => true ) ; if ( $ this -> getInlineOption ( 'showLineNumbers' , $ options , false ) ) $ config [ 'numbers' ] = HL_NUMBERS_LI ; $ config [ 'tabsize' ] = $ this -> getInlineOption ( 'tabSize' , $ options , 4 ) ; return $ config ; }
Generates the config for the highlighter .
5,841
protected function getInlineOption ( $ name , $ str , $ defaultValue ) { if ( preg_match ( '/' . $ name . '(\s*=\s*(\d+))?/i' , $ str , $ v ) && count ( $ v ) > 2 ) return $ v [ 2 ] ; else return $ defaultValue ; }
Retrieves the specified configuration .
5,842
public static function copyDirectory ( $ src , $ dst , $ options = array ( ) ) { $ fileTypes = array ( ) ; $ exclude = array ( ) ; $ level = - 1 ; extract ( $ options ) ; if ( ! is_dir ( $ dst ) ) self :: createDirectory ( $ dst , isset ( $ options [ 'newDirMode' ] ) ? $ options [ 'newDirMode' ] : null , true ) ; self :: copyDirectoryRecursive ( $ src , $ dst , '' , $ fileTypes , $ exclude , $ level , $ options ) ; }
Copies a directory recursively as another . If the destination directory does not exist it will be created recursively .
5,843
public static function findFiles ( $ dir , $ options = array ( ) ) { $ fileTypes = array ( ) ; $ exclude = array ( ) ; $ level = - 1 ; $ absolutePaths = true ; extract ( $ options ) ; $ list = self :: findFilesRecursive ( $ dir , '' , $ fileTypes , $ exclude , $ level , $ absolutePaths ) ; sort ( $ list ) ; return $ list ; }
Returns the files found under the specified directory and subdirectories .
5,844
protected static function validatePath ( $ base , $ file , $ isFile , $ fileTypes , $ exclude ) { foreach ( $ exclude as $ e ) { if ( $ file === $ e || strpos ( $ base . '/' . $ file , $ e ) === 0 ) return false ; } if ( ! $ isFile || empty ( $ fileTypes ) ) return true ; if ( ( $ type = self :: getExtension ( $ file ) ) !== '' ) return in_array ( $ type , $ fileTypes ) ; else return false ; }
Validates a file or directory .
5,845
public static function getMimeTypeByExtension ( $ file , $ magicFile = null ) { static $ extensions , $ customExtensions = array ( ) ; if ( $ magicFile === null && $ extensions === null ) $ extensions = require ( Yii :: getPathOfAlias ( 'system.utils.mimeTypes' ) . '.php' ) ; elseif ( $ magicFile !== null && ! isset ( $ customExtensions [ $ magicFile ] ) ) $ customExtensions [ $ magicFile ] = require ( $ magicFile ) ; if ( ( $ ext = self :: getExtension ( $ file ) ) !== '' ) { $ ext = strtolower ( $ ext ) ; if ( $ magicFile === null && isset ( $ extensions [ $ ext ] ) ) return $ extensions [ $ ext ] ; elseif ( $ magicFile !== null && isset ( $ customExtensions [ $ magicFile ] [ $ ext ] ) ) return $ customExtensions [ $ magicFile ] [ $ ext ] ; } return null ; }
Determines the MIME type based on the extension name of the specified file . This method will use a local map between extension name and MIME type .
5,846
public static function getExtensionByMimeType ( $ file , $ magicFile = null ) { static $ mimeTypes , $ customMimeTypes = array ( ) ; if ( $ magicFile === null && $ mimeTypes === null ) $ mimeTypes = require ( Yii :: getPathOfAlias ( 'system.utils.fileExtensions' ) . '.php' ) ; elseif ( $ magicFile !== null && ! isset ( $ customMimeTypes [ $ magicFile ] ) ) $ customMimeTypes [ $ magicFile ] = require ( $ magicFile ) ; if ( ( $ mime = self :: getMimeType ( $ file ) ) !== null ) { $ mime = strtolower ( $ mime ) ; if ( $ magicFile === null && isset ( $ mimeTypes [ $ mime ] ) ) return $ mimeTypes [ $ mime ] ; elseif ( $ magicFile !== null && isset ( $ customMimeTypes [ $ magicFile ] [ $ mime ] ) ) return $ customMimeTypes [ $ magicFile ] [ $ mime ] ; } return null ; }
Determines the file extension name based on its MIME type . This method will use a local map between MIME type and extension name .
5,847
public function processOutput ( $ output ) { if ( $ this -> hasEventHandler ( 'onProcessOutput' ) ) { $ event = new COutputEvent ( $ this , $ output ) ; $ this -> onProcessOutput ( $ event ) ; if ( ! $ event -> handled ) echo $ output ; } else echo $ output ; }
Processes the captured output .
5,848
public function link ( $ attribute , $ label = null , $ htmlOptions = array ( ) ) { if ( $ label === null ) $ label = $ this -> resolveLabel ( $ attribute ) ; if ( ( $ definition = $ this -> resolveAttribute ( $ attribute ) ) === false ) return $ label ; $ directions = $ this -> getDirections ( ) ; if ( isset ( $ directions [ $ attribute ] ) ) { $ class = $ directions [ $ attribute ] ? 'desc' : 'asc' ; if ( isset ( $ htmlOptions [ 'class' ] ) ) $ htmlOptions [ 'class' ] .= ' ' . $ class ; else $ htmlOptions [ 'class' ] = $ class ; $ descending = ! $ directions [ $ attribute ] ; unset ( $ directions [ $ attribute ] ) ; } elseif ( is_array ( $ definition ) && isset ( $ definition [ 'default' ] ) ) $ descending = $ definition [ 'default' ] === 'desc' ; else $ descending = false ; if ( $ this -> multiSort ) $ directions = array_merge ( array ( $ attribute => $ descending ) , $ directions ) ; else $ directions = array ( $ attribute => $ descending ) ; $ url = $ this -> createUrl ( Yii :: app ( ) -> getController ( ) , $ directions ) ; return $ this -> createLink ( $ attribute , $ label , $ url , $ htmlOptions ) ; }
Generates a hyperlink that can be clicked to cause sorting .
5,849
public function getDirections ( ) { if ( $ this -> _directions === null ) { $ this -> _directions = array ( ) ; if ( isset ( $ _GET [ $ this -> sortVar ] ) && is_string ( $ _GET [ $ this -> sortVar ] ) ) { $ attributes = explode ( $ this -> separators [ 0 ] , $ _GET [ $ this -> sortVar ] ) ; foreach ( $ attributes as $ attribute ) { if ( ( $ pos = strrpos ( $ attribute , $ this -> separators [ 1 ] ) ) !== false ) { $ descending = substr ( $ attribute , $ pos + 1 ) === $ this -> descTag ; if ( $ descending ) $ attribute = substr ( $ attribute , 0 , $ pos ) ; } else $ descending = false ; if ( ( $ this -> resolveAttribute ( $ attribute ) ) !== false ) { $ this -> _directions [ $ attribute ] = $ descending ; if ( ! $ this -> multiSort ) return $ this -> _directions ; } } } if ( $ this -> _directions === array ( ) && is_array ( $ this -> defaultOrder ) ) $ this -> _directions = $ this -> defaultOrder ; } return $ this -> _directions ; }
Returns the currently requested sort information .
5,850
public function getDirection ( $ attribute ) { $ this -> getDirections ( ) ; return isset ( $ this -> _directions [ $ attribute ] ) ? $ this -> _directions [ $ attribute ] : null ; }
Returns the sort direction of the specified attribute in the current request .
5,851
public function createUrl ( $ controller , $ directions ) { $ sorts = array ( ) ; foreach ( $ directions as $ attribute => $ descending ) $ sorts [ ] = $ descending ? $ attribute . $ this -> separators [ 1 ] . $ this -> descTag : $ attribute ; $ params = $ this -> params === null ? $ _GET : $ this -> params ; $ params [ $ this -> sortVar ] = implode ( $ this -> separators [ 0 ] , $ sorts ) ; return $ controller -> createUrl ( $ this -> route , $ params ) ; }
Creates a URL that can lead to generating sorted data .
5,852
public function resolveAttribute ( $ attribute ) { if ( $ this -> attributes !== array ( ) ) $ attributes = $ this -> attributes ; elseif ( $ this -> modelClass !== null ) $ attributes = $ this -> getModel ( $ this -> modelClass ) -> attributeNames ( ) ; else return false ; foreach ( $ attributes as $ name => $ definition ) { if ( is_string ( $ name ) ) { if ( $ name === $ attribute ) return $ definition ; } elseif ( $ definition === '*' ) { if ( $ this -> modelClass !== null && $ this -> getModel ( $ this -> modelClass ) -> hasAttribute ( $ attribute ) ) return $ attribute ; } elseif ( $ definition === $ attribute ) return $ attribute ; } return false ; }
Returns the real definition of an attribute given its name .
5,853
protected function createLink ( $ attribute , $ label , $ url , $ htmlOptions ) { return CHtml :: link ( $ label , $ url , $ htmlOptions ) ; }
Creates a hyperlink based on the given label and URL . You may override this method to customize the link generation .
5,854
public function init ( ) { if ( isset ( $ this -> checkBoxHtmlOptions [ 'name' ] ) ) $ name = $ this -> checkBoxHtmlOptions [ 'name' ] ; else { $ name = $ this -> id ; if ( substr ( $ name , - 2 ) !== '[]' ) $ name .= '[]' ; $ this -> checkBoxHtmlOptions [ 'name' ] = $ name ; } $ name = strtr ( $ name , array ( '[' => "\\[" , ']' => "\\]" ) ) ; if ( $ this -> selectableRows === null ) { if ( isset ( $ this -> checkBoxHtmlOptions [ 'class' ] ) ) $ this -> checkBoxHtmlOptions [ 'class' ] .= ' select-on-check' ; else $ this -> checkBoxHtmlOptions [ 'class' ] = 'select-on-check' ; return ; } $ cball = $ cbcode = '' ; if ( $ this -> selectableRows == 0 ) { $ cbcode = "return false;" ; } elseif ( $ this -> selectableRows == 1 ) { $ cbcode = "jQuery(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);" ; } elseif ( strpos ( $ this -> headerTemplate , '{item}' ) !== false ) { $ cball = <<<CBALLjQuery(document).on('click','#{$this->id}_all',function() { var checked=this.checked; jQuery("input[name='$name']:enabled").each(function() {this.checked=checked;});});CBALL ; $ cbcode = "jQuery('#{$this->id}_all').prop('checked', jQuery(\"input[name='$name']\").length==jQuery(\"input[name='$name']:checked\").length);" ; } if ( $ cbcode !== '' ) { $ js = $ cball ; $ js .= <<<EODjQuery(document).on('click', "input[name='$name']", function() { $cbcode});EOD ; Yii :: app ( ) -> getClientScript ( ) -> registerScript ( __CLASS__ . '#' . $ this -> id , $ js ) ; } }
Initializes the column . This method registers necessary client script for the checkbox column .
5,855
public function getDataCellContent ( $ row ) { $ data = $ this -> grid -> dataProvider -> data [ $ row ] ; if ( $ this -> value !== null ) $ value = $ this -> evaluateExpression ( $ this -> value , array ( 'data' => $ data , 'row' => $ row ) ) ; elseif ( $ this -> name !== null ) $ value = CHtml :: value ( $ data , $ this -> name ) ; else $ value = $ this -> grid -> dataProvider -> keys [ $ row ] ; $ checked = false ; if ( $ this -> checked !== null ) $ checked = $ this -> evaluateExpression ( $ this -> checked , array ( 'data' => $ data , 'row' => $ row ) ) ; $ options = $ this -> checkBoxHtmlOptions ; if ( $ this -> disabled !== null ) $ options [ 'disabled' ] = $ this -> evaluateExpression ( $ this -> disabled , array ( 'data' => $ data , 'row' => $ row ) ) ; $ name = $ options [ 'name' ] ; unset ( $ options [ 'name' ] ) ; $ options [ 'value' ] = $ value ; $ options [ 'id' ] = $ this -> id . '_' . $ row ; return CHtml :: checkBox ( $ name , $ checked , $ options ) ; }
Returns the data cell content . This method renders a checkbox in the data cell .
5,856
public function actionDelete ( ) { if ( Yii :: app ( ) -> request -> isPostRequest ) { $ this -> loadModel ( ) -> delete ( ) ; if ( ! isset ( $ _POST [ 'ajax' ] ) ) $ this -> redirect ( array ( 'index' ) ) ; } else throw new CHttpException ( 400 , 'Invalid request. Please do not repeat this request again.' ) ; }
Deletes a particular model . If deletion is successful the browser will be redirected to the index page .
5,857
public function actionApprove ( ) { if ( Yii :: app ( ) -> request -> isPostRequest ) { $ comment = $ this -> loadModel ( ) ; $ comment -> approve ( ) ; $ this -> redirect ( array ( 'index' ) ) ; } else throw new CHttpException ( 400 , 'Invalid request. Please do not repeat this request again.' ) ; }
Approves a particular comment . If approval is successful the browser will be redirected to the comment index page .
5,858
public function getState ( $ name , $ defaultValue = null ) { return isset ( $ this -> _state [ $ name ] ) ? $ this -> _state [ $ name ] : $ defaultValue ; }
Gets the persisted state by the specified name .
5,859
public function applyLimit ( $ criteria ) { $ criteria -> limit = $ this -> getLimit ( ) ; $ criteria -> offset = $ this -> getOffset ( ) ; }
Applies LIMIT and OFFSET to the specified query criteria .
5,860
public function init ( ) { parent :: init ( ) ; if ( $ this -> basePath === null ) $ this -> basePath = Yii :: getPathOfAlias ( 'application.messages' ) ; }
Initializes the application component . This method overrides the parent implementation by preprocessing the user request data .
5,861
protected function getCaptchaAction ( ) { if ( ( $ captcha = Yii :: app ( ) -> getController ( ) -> createAction ( $ this -> captchaAction ) ) === null ) { if ( strpos ( $ this -> captchaAction , '/' ) !== false ) { if ( ( $ ca = Yii :: app ( ) -> createController ( $ this -> captchaAction ) ) !== null ) { list ( $ controller , $ actionID ) = $ ca ; $ captcha = $ controller -> createAction ( $ actionID ) ; } } if ( $ captcha === null ) throw new CException ( Yii :: t ( 'yii' , 'CCaptchaValidator.action "{id}" is invalid. Unable to find such an action in the current controller.' , array ( '{id}' => $ this -> captchaAction ) ) ) ; } return $ captcha ; }
Returns the CAPTCHA action object .
5,862
public function format ( $ value , $ type ) { $ method = 'format' . $ type ; if ( method_exists ( $ this , $ method ) ) return $ this -> $ method ( $ value ) ; else throw new CException ( Yii :: t ( 'yii' , 'Unknown type "{type}".' , array ( '{type}' => $ type ) ) ) ; }
Formats a value based on the given type .
5,863
protected function normalizeDateValue ( $ time ) { if ( is_string ( $ time ) ) { if ( ctype_digit ( $ time ) || ( $ time { 0 } == '-' && ctype_digit ( substr ( $ time , 1 ) ) ) ) return ( int ) $ time ; else return strtotime ( $ time ) ; } elseif ( class_exists ( 'DateTime' , false ) && $ time instanceof DateTime ) return $ time -> getTimestamp ( ) ; else return ( int ) $ time ; }
Normalizes an expression as a timestamp .
5,864
public function formatUrl ( $ value ) { $ url = $ value ; if ( strpos ( $ url , 'http://' ) !== 0 && strpos ( $ url , 'https://' ) !== 0 ) $ url = 'http://' . $ url ; return CHtml :: link ( CHtml :: encode ( $ value ) , $ url ) ; }
Formats the value as a hyperlink .
5,865
public function formatSize ( $ value , $ verbose = false ) { $ base = $ this -> sizeFormat [ 'base' ] ; for ( $ i = 0 ; $ base <= $ value && $ i < 5 ; $ i ++ ) $ value = $ value / $ base ; $ value = round ( $ value , $ this -> sizeFormat [ 'decimals' ] ) ; $ formattedValue = isset ( $ this -> sizeFormat [ 'decimalSeparator' ] ) ? str_replace ( '.' , $ this -> sizeFormat [ 'decimalSeparator' ] , $ value ) : $ value ; $ params = array ( $ value , '{n}' => $ formattedValue ) ; switch ( $ i ) { case 0 : return $ verbose ? Yii :: t ( 'yii' , '{n} byte|{n} bytes' , $ params ) : Yii :: t ( 'yii' , '{n} B' , $ params ) ; case 1 : return $ verbose ? Yii :: t ( 'yii' , '{n} kilobyte|{n} kilobytes' , $ params ) : Yii :: t ( 'yii' , '{n} KB' , $ params ) ; case 2 : return $ verbose ? Yii :: t ( 'yii' , '{n} megabyte|{n} megabytes' , $ params ) : Yii :: t ( 'yii' , '{n} MB' , $ params ) ; case 3 : return $ verbose ? Yii :: t ( 'yii' , '{n} gigabyte|{n} gigabytes' , $ params ) : Yii :: t ( 'yii' , '{n} GB' , $ params ) ; default : return $ verbose ? Yii :: t ( 'yii' , '{n} terabyte|{n} terabytes' , $ params ) : Yii :: t ( 'yii' , '{n} TB' , $ params ) ; } }
Formats the value in bytes as a size in human readable form .
5,866
public function run ( $ args ) { list ( $ action , $ options , $ args ) = $ this -> resolveRequest ( $ args ) ; $ methodName = 'action' . $ action ; if ( ! preg_match ( '/^\w+$/' , $ action ) || ! method_exists ( $ this , $ methodName ) ) $ this -> usageError ( "Unknown action: " . $ action ) ; $ method = new ReflectionMethod ( $ this , $ methodName ) ; $ params = array ( ) ; foreach ( $ method -> getParameters ( ) as $ i => $ param ) { $ name = $ param -> getName ( ) ; if ( isset ( $ options [ $ name ] ) ) { if ( $ param -> isArray ( ) ) $ params [ ] = is_array ( $ options [ $ name ] ) ? $ options [ $ name ] : array ( $ options [ $ name ] ) ; elseif ( ! is_array ( $ options [ $ name ] ) ) $ params [ ] = $ options [ $ name ] ; else $ this -> usageError ( "Option --$name requires a scalar. Array is given." ) ; } elseif ( $ name === 'args' ) $ params [ ] = $ args ; elseif ( $ param -> isDefaultValueAvailable ( ) ) $ params [ ] = $ param -> getDefaultValue ( ) ; else $ this -> usageError ( "Missing required option --$name." ) ; unset ( $ options [ $ name ] ) ; } if ( ! empty ( $ options ) ) { $ class = new ReflectionClass ( get_class ( $ this ) ) ; foreach ( $ options as $ name => $ value ) { if ( $ class -> hasProperty ( $ name ) ) { $ property = $ class -> getProperty ( $ name ) ; if ( $ property -> isPublic ( ) && ! $ property -> isStatic ( ) ) { $ this -> $ name = $ value ; unset ( $ options [ $ name ] ) ; } } } } if ( ! empty ( $ options ) ) $ this -> usageError ( "Unknown options: " . implode ( ', ' , array_keys ( $ options ) ) ) ; $ exitCode = 0 ; if ( $ this -> beforeAction ( $ action , $ params ) ) { $ exitCode = $ method -> invokeArgs ( $ this , $ params ) ; $ exitCode = $ this -> afterAction ( $ action , $ params , is_int ( $ exitCode ) ? $ exitCode : 0 ) ; } return $ exitCode ; }
Executes the command . The default implementation will parse the input parameters and dispatch the command request to an appropriate action with the corresponding option values
5,867
protected function beforeAction ( $ action , $ params ) { if ( $ this -> hasEventHandler ( 'onBeforeAction' ) ) { $ event = new CConsoleCommandEvent ( $ this , $ params , $ action ) ; $ this -> onBeforeAction ( $ event ) ; return ! $ event -> stopCommand ; } else { return true ; } }
This method is invoked right before an action is to be executed . You may override this method to do last - minute preparation for the action .
5,868
protected function afterAction ( $ action , $ params , $ exitCode = 0 ) { $ event = new CConsoleCommandEvent ( $ this , $ params , $ action , $ exitCode ) ; if ( $ this -> hasEventHandler ( 'onAfterAction' ) ) $ this -> onAfterAction ( $ event ) ; return $ event -> exitCode ; }
This method is invoked right after an action finishes execution . You may override this method to do some postprocessing for the action .
5,869
protected function resolveRequest ( $ args ) { $ options = array ( ) ; $ params = array ( ) ; foreach ( $ args as $ arg ) { if ( preg_match ( '/^--(\w+)(=(.*))?$/' , $ arg , $ matches ) ) { $ name = $ matches [ 1 ] ; $ value = isset ( $ matches [ 3 ] ) ? $ matches [ 3 ] : true ; if ( isset ( $ options [ $ name ] ) ) { if ( ! is_array ( $ options [ $ name ] ) ) $ options [ $ name ] = array ( $ options [ $ name ] ) ; $ options [ $ name ] [ ] = $ value ; } else $ options [ $ name ] = $ value ; } elseif ( isset ( $ action ) ) $ params [ ] = $ arg ; else $ action = $ arg ; } if ( ! isset ( $ action ) ) $ action = $ this -> defaultAction ; return array ( $ action , $ options , $ params ) ; }
Parses the command line arguments and determines which action to perform .
5,870
public function getHelp ( ) { $ help = 'Usage: ' . $ this -> getCommandRunner ( ) -> getScriptName ( ) . ' ' . $ this -> getName ( ) ; $ options = $ this -> getOptionHelp ( ) ; if ( empty ( $ options ) ) return $ help . "\n" ; if ( count ( $ options ) === 1 ) return $ help . ' ' . $ options [ 0 ] . "\n" ; $ help .= " <action>\nActions:\n" ; foreach ( $ options as $ option ) $ help .= ' ' . $ option . "\n" ; return $ help ; }
Provides the command description . This method may be overridden to return the actual command description .
5,871
public function getOptionHelp ( ) { $ options = array ( ) ; $ class = new ReflectionClass ( get_class ( $ this ) ) ; foreach ( $ class -> getMethods ( ReflectionMethod :: IS_PUBLIC ) as $ method ) { $ name = $ method -> getName ( ) ; if ( ! strncasecmp ( $ name , 'action' , 6 ) && strlen ( $ name ) > 6 ) { $ name = substr ( $ name , 6 ) ; $ name [ 0 ] = strtolower ( $ name [ 0 ] ) ; $ help = $ name ; foreach ( $ method -> getParameters ( ) as $ param ) { $ optional = $ param -> isDefaultValueAvailable ( ) ; $ defaultValue = $ optional ? $ param -> getDefaultValue ( ) : null ; if ( is_array ( $ defaultValue ) ) { $ defaultValue = str_replace ( array ( "\r\n" , "\n" , "\r" ) , "" , print_r ( $ defaultValue , true ) ) ; } $ name = $ param -> getName ( ) ; if ( $ name === 'args' ) continue ; if ( $ optional ) $ help .= " [--$name=$defaultValue]" ; else $ help .= " --$name=value" ; } $ options [ ] = $ help ; } } return $ options ; }
Provides the command option help information . The default implementation will return all available actions together with their corresponding option information .
5,872
public function copyFiles ( $ fileList , $ overwriteAll = false ) { foreach ( $ fileList as $ name => $ file ) { $ source = strtr ( $ file [ 'source' ] , '/\\' , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) ; $ target = strtr ( $ file [ 'target' ] , '/\\' , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) ; $ callback = isset ( $ file [ 'callback' ] ) ? $ file [ 'callback' ] : null ; $ params = isset ( $ file [ 'params' ] ) ? $ file [ 'params' ] : null ; if ( is_dir ( $ source ) ) { $ this -> ensureDirectory ( $ target ) ; continue ; } if ( $ callback !== null ) $ content = call_user_func ( $ callback , $ source , $ params ) ; else $ content = file_get_contents ( $ source ) ; if ( is_file ( $ target ) ) { if ( $ content === file_get_contents ( $ target ) ) { echo " unchanged $name\n" ; continue ; } if ( $ overwriteAll ) echo " overwrite $name\n" ; else { echo " exist $name\n" ; echo " ...overwrite? [Yes|No|All|Quit] " ; $ answer = trim ( fgets ( STDIN ) ) ; if ( ! strncasecmp ( $ answer , 'q' , 1 ) ) return ; elseif ( ! strncasecmp ( $ answer , 'y' , 1 ) ) echo " overwrite $name\n" ; elseif ( ! strncasecmp ( $ answer , 'a' , 1 ) ) { echo " overwrite $name\n" ; $ overwriteAll = true ; } else { echo " skip $name\n" ; continue ; } } } else { $ this -> ensureDirectory ( dirname ( $ target ) ) ; echo " generate $name\n" ; } file_put_contents ( $ target , $ content ) ; } }
Copies a list of files from one place to another .
5,873
public function ensureDirectory ( $ directory ) { if ( ! is_dir ( $ directory ) ) { $ this -> ensureDirectory ( dirname ( $ directory ) ) ; echo " mkdir " . strtr ( $ directory , '\\' , '/' ) . "\n" ; mkdir ( $ directory ) ; } }
Creates all parent directories if they do not exist .
5,874
public function pluralize ( $ name ) { $ rules = array ( '/(m)ove$/i' => '\1oves' , '/(f)oot$/i' => '\1eet' , '/(c)hild$/i' => '\1hildren' , '/(h)uman$/i' => '\1umans' , '/(m)an$/i' => '\1en' , '/(s)taff$/i' => '\1taff' , '/(t)ooth$/i' => '\1eeth' , '/(p)erson$/i' => '\1eople' , '/([m|l])ouse$/i' => '\1ice' , '/(x|ch|ss|sh|us|as|is|os)$/i' => '\1es' , '/([^aeiouy]|qu)y$/i' => '\1ies' , '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves' , '/(shea|lea|loa|thie)f$/i' => '\1ves' , '/([ti])um$/i' => '\1a' , '/(tomat|potat|ech|her|vet)o$/i' => '\1oes' , '/(bu)s$/i' => '\1ses' , '/(ax|test)is$/i' => '\1es' , '/s$/' => 's' , ) ; foreach ( $ rules as $ rule => $ replacement ) { if ( preg_match ( $ rule , $ name ) ) return preg_replace ( $ rule , $ replacement , $ name ) ; } return $ name . 's' ; }
Converts a word to its plural form .
5,875
protected function findPrimaryKey ( $ table , $ indices ) { $ indices = implode ( ', ' , preg_split ( '/\s+/' , $ indices ) ) ; $ sql = <<<EODSELECT attnum, attname FROM pg_catalog.pg_attribute WHERE attrelid=( SELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=( SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema ) ) AND attnum IN ({$indices})EOD ; $ command = $ this -> getDbConnection ( ) -> createCommand ( $ sql ) ; $ command -> bindValue ( ':table' , $ table -> name ) ; $ command -> bindValue ( ':schema' , $ table -> schemaName ) ; foreach ( $ command -> queryAll ( ) as $ row ) { $ name = $ row [ 'attname' ] ; if ( isset ( $ table -> columns [ $ name ] ) ) { $ table -> columns [ $ name ] -> isPrimaryKey = true ; if ( $ table -> primaryKey === null ) $ table -> primaryKey = $ name ; elseif ( is_string ( $ table -> primaryKey ) ) $ table -> primaryKey = array ( $ table -> primaryKey , $ name ) ; else $ table -> primaryKey [ ] = $ name ; } } }
Collects primary key information .
5,876
protected function findForeignKey ( $ table , $ src ) { $ matches = array ( ) ; $ brackets = '\(([^\)]+)\)' ; $ pattern = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i" ; if ( preg_match ( $ pattern , str_replace ( '"' , '' , $ src ) , $ matches ) ) { $ keys = preg_split ( '/,\s+/' , $ matches [ 1 ] ) ; $ tableName = $ matches [ 2 ] ; $ fkeys = preg_split ( '/,\s+/' , $ matches [ 3 ] ) ; foreach ( $ keys as $ i => $ key ) { $ table -> foreignKeys [ $ key ] = array ( $ tableName , $ fkeys [ $ i ] ) ; if ( isset ( $ table -> columns [ $ key ] ) ) $ table -> columns [ $ key ] -> isForeignKey = true ; } } }
Collects foreign key information .
5,877
public function createFindCommand ( $ table , $ criteria , $ alias = 't' ) { $ criteria = $ this -> checkCriteria ( $ table , $ criteria ) ; return parent :: createFindCommand ( $ table , $ criteria , $ alias ) ; }
Creates a SELECT command for a single table . Override parent implementation to check if an orderby clause if specified when querying with an offset
5,878
public function createUpdateCommand ( $ table , $ data , $ criteria ) { $ criteria = $ this -> checkCriteria ( $ table , $ criteria ) ; $ fields = array ( ) ; $ values = array ( ) ; $ bindByPosition = isset ( $ criteria -> params [ 0 ] ) ; $ i = 0 ; foreach ( $ data as $ name => $ value ) { if ( ( $ column = $ table -> getColumn ( $ name ) ) !== null ) { if ( $ table -> sequenceName !== null && $ column -> isPrimaryKey === true ) continue ; if ( $ column -> dbType === 'timestamp' ) continue ; if ( $ value instanceof CDbExpression ) { $ fields [ ] = $ column -> rawName . '=' . $ value -> expression ; foreach ( $ value -> params as $ n => $ v ) $ values [ $ n ] = $ v ; } elseif ( $ bindByPosition ) { $ fields [ ] = $ column -> rawName . '=?' ; $ values [ ] = $ column -> typecast ( $ value ) ; } else { $ fields [ ] = $ column -> rawName . '=' . self :: PARAM_PREFIX . $ i ; $ values [ self :: PARAM_PREFIX . $ i ] = $ column -> typecast ( $ value ) ; $ i ++ ; } } } if ( $ fields === array ( ) ) throw new CDbException ( Yii :: t ( 'yii' , 'No columns are being updated for table "{table}".' , array ( '{table}' => $ table -> name ) ) ) ; $ sql = "UPDATE {$table->rawName} SET " . implode ( ', ' , $ fields ) ; $ sql = $ this -> applyJoin ( $ sql , $ criteria -> join ) ; $ sql = $ this -> applyCondition ( $ sql , $ criteria -> condition ) ; $ sql = $ this -> applyOrder ( $ sql , $ criteria -> order ) ; $ sql = $ this -> applyLimit ( $ sql , $ criteria -> limit , $ criteria -> offset ) ; $ command = $ this -> getDbConnection ( ) -> createCommand ( $ sql ) ; $ this -> bindValues ( $ command , array_merge ( $ values , $ criteria -> params ) ) ; return $ command ; }
Creates an UPDATE command . Override parent implementation because mssql don t want to update an identity column
5,879
public function createDeleteCommand ( $ table , $ criteria ) { $ criteria = $ this -> checkCriteria ( $ table , $ criteria ) ; return parent :: createDeleteCommand ( $ table , $ criteria ) ; }
Creates a DELETE command . Override parent implementation to check if an orderby clause if specified when querying with an offset
5,880
public function applyJoin ( $ sql , $ join ) { if ( trim ( $ join ) !== '' ) $ sql = preg_replace ( '/^\s*DELETE\s+FROM\s+((\[.+\])|([^\s]+))\s*/i' , "DELETE \\1 FROM \\1" , $ sql ) ; return parent :: applyJoin ( $ sql , $ join ) ; }
Alters the SQL to apply JOIN clause . Overrides parent implementation to comply with the DELETE command syntax required when multiple tables are referenced .
5,881
public function applyLimit ( $ sql , $ limit , $ offset ) { $ limit = $ limit !== null ? ( int ) $ limit : - 1 ; $ offset = $ offset !== null ? ( int ) $ offset : - 1 ; if ( $ limit > 0 && $ offset <= 0 ) $ sql = preg_replace ( '/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i' , "\\1SELECT\\2 TOP $limit" , $ sql ) ; elseif ( $ limit > 0 && $ offset > 0 ) $ sql = $ this -> rewriteLimitOffsetSql ( $ sql , $ limit , $ offset ) ; return $ sql ; }
This is a port from Prado Framework .
5,882
protected function processLogs ( $ logs ) { static $ syslogLevels = array ( CLogger :: LEVEL_TRACE => LOG_DEBUG , CLogger :: LEVEL_WARNING => LOG_WARNING , CLogger :: LEVEL_ERROR => LOG_ERR , CLogger :: LEVEL_INFO => LOG_INFO , CLogger :: LEVEL_PROFILE => LOG_DEBUG , ) ; openlog ( $ this -> identity , LOG_ODELAY | LOG_PID , $ this -> facility ) ; foreach ( $ logs as $ log ) syslog ( $ syslogLevels [ $ log [ 1 ] ] , $ this -> formatLogMessage ( str_replace ( "\n" , ', ' , $ log [ 0 ] ) , $ log [ 1 ] , $ log [ 2 ] , $ log [ 3 ] ) ) ; closelog ( ) ; }
Sends log messages to syslog .
5,883
public function query ( $ criteria , $ all = false ) { $ this -> joinAll = $ criteria -> together === true ; if ( $ criteria -> alias != '' ) { $ this -> _joinTree -> tableAlias = $ criteria -> alias ; $ this -> _joinTree -> rawTableAlias = $ this -> _builder -> getSchema ( ) -> quoteTableName ( $ criteria -> alias ) ; } $ this -> _joinTree -> find ( $ criteria ) ; $ this -> _joinTree -> afterFind ( ) ; if ( $ all ) { $ result = array_values ( $ this -> _joinTree -> records ) ; if ( $ criteria -> index !== null ) { $ index = $ criteria -> index ; $ array = array ( ) ; foreach ( $ result as $ object ) $ array [ $ object -> $ index ] = $ object ; $ result = $ array ; } } elseif ( count ( $ this -> _joinTree -> records ) ) $ result = reset ( $ this -> _joinTree -> records ) ; else $ result = null ; $ this -> destroyJoinTree ( ) ; return $ result ; }
Do not call this method . This method is used internally to perform the relational query based on the given DB criteria .
5,884
public function destroy ( ) { if ( ! empty ( $ this -> children ) ) { foreach ( $ this -> children as $ child ) $ child -> destroy ( ) ; } unset ( $ this -> _finder , $ this -> _parent , $ this -> model , $ this -> relation , $ this -> master , $ this -> slave , $ this -> records , $ this -> children , $ this -> stats ) ; }
Removes references to child elements and finder to avoid circular references . This is internally used .
5,885
public function find ( $ criteria = null ) { if ( $ this -> _parent === null ) { $ query = new CJoinQuery ( $ this , $ criteria ) ; $ this -> _finder -> baseLimited = ( $ criteria -> offset >= 0 || $ criteria -> limit >= 0 ) ; $ this -> buildQuery ( $ query ) ; $ this -> _finder -> baseLimited = false ; $ this -> runQuery ( $ query ) ; } elseif ( ! $ this -> _joined && ! empty ( $ this -> _parent -> records ) ) { $ query = new CJoinQuery ( $ this -> _parent ) ; $ this -> _joined = true ; $ query -> join ( $ this ) ; $ this -> buildQuery ( $ query ) ; $ this -> _parent -> runQuery ( $ query ) ; } foreach ( $ this -> children as $ child ) $ child -> find ( ) ; foreach ( $ this -> stats as $ stat ) $ stat -> query ( ) ; }
Performs the recursive finding with the criteria .
5,886
public function lazyFind ( $ baseRecord ) { if ( is_string ( $ this -> _table -> primaryKey ) ) $ this -> records [ $ baseRecord -> { $ this -> _table -> primaryKey } ] = $ baseRecord ; else { $ pk = array ( ) ; foreach ( $ this -> _table -> primaryKey as $ name ) $ pk [ $ name ] = $ baseRecord -> $ name ; $ this -> records [ serialize ( $ pk ) ] = $ baseRecord ; } foreach ( $ this -> stats as $ stat ) $ stat -> query ( ) ; if ( ! $ this -> children ) return ; $ params = array ( ) ; foreach ( $ this -> children as $ child ) if ( is_array ( $ child -> relation -> params ) ) $ params = array_merge ( $ params , $ child -> relation -> params ) ; $ query = new CJoinQuery ( $ child ) ; $ query -> selects = array ( $ child -> getColumnSelect ( $ child -> relation -> select ) ) ; $ query -> conditions = array ( $ child -> relation -> on , ) ; $ query -> groups [ ] = $ child -> relation -> group ; $ query -> joins [ ] = $ child -> relation -> join ; $ query -> havings [ ] = $ child -> relation -> having ; $ query -> orders [ ] = $ child -> relation -> order ; $ query -> params = $ params ; $ query -> elements [ $ child -> id ] = true ; if ( $ child -> relation instanceof CHasManyRelation ) { $ query -> limit = $ child -> relation -> limit ; $ query -> offset = $ child -> relation -> offset ; } $ child -> applyLazyCondition ( $ query , $ baseRecord ) ; $ this -> _joined = true ; $ child -> _joined = true ; $ this -> _finder -> baseLimited = false ; $ child -> buildQuery ( $ query ) ; $ child -> runQuery ( $ query ) ; foreach ( $ child -> children as $ c ) $ c -> find ( ) ; if ( empty ( $ child -> records ) ) return ; if ( $ child -> relation instanceof CHasOneRelation || $ child -> relation instanceof CBelongsToRelation ) $ baseRecord -> addRelatedRecord ( $ child -> relation -> name , reset ( $ child -> records ) , false ) ; else { foreach ( $ child -> records as $ record ) { if ( $ child -> relation -> index !== null ) $ index = $ record -> { $ child -> relation -> index } ; else $ index = true ; $ baseRecord -> addRelatedRecord ( $ child -> relation -> name , $ record , $ index ) ; } } }
Performs lazy find with the specified base record .
5,887
public function findWithBase ( $ baseRecords ) { if ( ! is_array ( $ baseRecords ) ) $ baseRecords = array ( $ baseRecords ) ; if ( is_string ( $ this -> _table -> primaryKey ) ) { foreach ( $ baseRecords as $ baseRecord ) $ this -> records [ $ baseRecord -> { $ this -> _table -> primaryKey } ] = $ baseRecord ; } else { foreach ( $ baseRecords as $ baseRecord ) { $ pk = array ( ) ; foreach ( $ this -> _table -> primaryKey as $ name ) $ pk [ $ name ] = $ baseRecord -> $ name ; $ this -> records [ serialize ( $ pk ) ] = $ baseRecord ; } } $ query = new CJoinQuery ( $ this ) ; $ this -> buildQuery ( $ query ) ; if ( count ( $ query -> joins ) > 1 ) $ this -> runQuery ( $ query ) ; foreach ( $ this -> children as $ child ) $ child -> find ( ) ; foreach ( $ this -> stats as $ stat ) $ stat -> query ( ) ; }
Performs the eager loading with the base records ready .
5,888
public function count ( $ criteria = null ) { $ query = new CJoinQuery ( $ this , $ criteria ) ; $ this -> _finder -> baseLimited = false ; $ this -> _finder -> joinAll = true ; $ this -> buildQuery ( $ query ) ; $ query -> limit = $ query -> offset = - 1 ; if ( ! empty ( $ criteria -> group ) || ! empty ( $ criteria -> having ) ) { $ query -> orders = array ( ) ; $ command = $ query -> createCommand ( $ this -> _builder ) ; $ sql = $ command -> getText ( ) ; $ sql = "SELECT COUNT(*) FROM ({$sql}) sq" ; $ command -> setText ( $ sql ) ; $ command -> params = $ query -> params ; return $ command -> queryScalar ( ) ; } else { $ select = is_array ( $ criteria -> select ) ? implode ( ',' , $ criteria -> select ) : $ criteria -> select ; if ( $ select !== '*' && preg_match ( '/^count\s*\(/i' , trim ( $ select ) ) ) $ query -> selects = array ( $ select ) ; elseif ( is_string ( $ this -> _table -> primaryKey ) ) { $ prefix = $ this -> getColumnPrefix ( ) ; $ schema = $ this -> _builder -> getSchema ( ) ; $ column = $ prefix . $ schema -> quoteColumnName ( $ this -> _table -> primaryKey ) ; $ query -> selects = array ( "COUNT(DISTINCT $column)" ) ; } else $ query -> selects = array ( "COUNT(*)" ) ; $ query -> orders = $ query -> groups = $ query -> havings = array ( ) ; $ command = $ query -> createCommand ( $ this -> _builder ) ; return $ command -> queryScalar ( ) ; } }
Count the number of primary records returned by the join statement .
5,889
public function buildQuery ( $ query ) { foreach ( $ this -> children as $ child ) { if ( $ child -> master !== null ) $ child -> _joined = true ; elseif ( $ child -> relation instanceof CHasOneRelation || $ child -> relation instanceof CBelongsToRelation || $ this -> _finder -> joinAll || $ child -> relation -> together || ( ! $ this -> _finder -> baseLimited && $ child -> relation -> together === null ) ) { $ child -> _joined = true ; $ query -> join ( $ child ) ; $ child -> buildQuery ( $ query ) ; } } }
Builds the join query with all descendant HAS_ONE and BELONGS_TO nodes .
5,890
public function runQuery ( $ query ) { $ command = $ query -> createCommand ( $ this -> _builder ) ; foreach ( $ command -> queryAll ( ) as $ row ) $ this -> populateRecord ( $ query , $ row ) ; }
Executes the join query and populates the query results .
5,891
private function populateRecord ( $ query , $ row ) { if ( is_string ( $ this -> _pkAlias ) ) { if ( isset ( $ row [ $ this -> _pkAlias ] ) ) $ pk = $ row [ $ this -> _pkAlias ] ; else return null ; } else { $ pk = array ( ) ; foreach ( $ this -> _pkAlias as $ name => $ alias ) { if ( isset ( $ row [ $ alias ] ) ) $ pk [ $ name ] = $ row [ $ alias ] ; else return null ; } $ pk = serialize ( $ pk ) ; } if ( isset ( $ this -> records [ $ pk ] ) ) $ record = $ this -> records [ $ pk ] ; else { $ attributes = array ( ) ; $ aliases = array_flip ( $ this -> _columnAliases ) ; foreach ( $ row as $ alias => $ value ) { if ( isset ( $ aliases [ $ alias ] ) ) $ attributes [ $ aliases [ $ alias ] ] = $ value ; } $ record = $ this -> model -> populateRecord ( $ attributes , false ) ; foreach ( $ this -> children as $ child ) { if ( ! empty ( $ child -> relation -> select ) ) $ record -> addRelatedRecord ( $ child -> relation -> name , null , $ child -> relation instanceof CHasManyRelation ) ; } $ this -> records [ $ pk ] = $ record ; } foreach ( $ this -> children as $ child ) { if ( ! isset ( $ query -> elements [ $ child -> id ] ) || empty ( $ child -> relation -> select ) ) continue ; $ childRecord = $ child -> populateRecord ( $ query , $ row ) ; if ( $ child -> relation instanceof CHasOneRelation || $ child -> relation instanceof CBelongsToRelation ) $ record -> addRelatedRecord ( $ child -> relation -> name , $ childRecord , false ) ; else { if ( $ childRecord instanceof CActiveRecord ) $ fpk = serialize ( $ childRecord -> getPrimaryKey ( ) ) ; else $ fpk = 0 ; if ( ! isset ( $ this -> _related [ $ pk ] [ $ child -> relation -> name ] [ $ fpk ] ) ) { if ( $ childRecord instanceof CActiveRecord && $ child -> relation -> index !== null ) $ index = $ childRecord -> { $ child -> relation -> index } ; else $ index = true ; $ record -> addRelatedRecord ( $ child -> relation -> name , $ childRecord , $ index ) ; $ this -> _related [ $ pk ] [ $ child -> relation -> name ] [ $ fpk ] = true ; } } } return $ record ; }
Populates the active records with the query data .
5,892
private function joinOneMany ( $ fke , $ fks , $ pke , $ parent ) { $ schema = $ this -> _builder -> getSchema ( ) ; $ joins = array ( ) ; if ( is_string ( $ fks ) ) $ fks = preg_split ( '/\s*,\s*/' , $ fks , - 1 , PREG_SPLIT_NO_EMPTY ) ; foreach ( $ fks as $ i => $ fk ) { if ( ! is_int ( $ i ) ) { $ pk = $ fk ; $ fk = $ i ; } if ( ! isset ( $ fke -> _table -> columns [ $ fk ] ) ) throw new CDbException ( Yii :: t ( 'yii' , 'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".' , array ( '{class}' => get_class ( $ parent -> model ) , '{relation}' => $ this -> relation -> name , '{key}' => $ fk , '{table}' => $ fke -> _table -> name ) ) ) ; if ( is_int ( $ i ) ) { if ( isset ( $ fke -> _table -> foreignKeys [ $ fk ] ) && $ schema -> compareTableNames ( $ pke -> _table -> rawName , $ fke -> _table -> foreignKeys [ $ fk ] [ 0 ] ) ) $ pk = $ fke -> _table -> foreignKeys [ $ fk ] [ 1 ] ; else { if ( is_array ( $ pke -> _table -> primaryKey ) ) $ pk = $ pke -> _table -> primaryKey [ $ i ] ; else $ pk = $ pke -> _table -> primaryKey ; } } $ joins [ ] = $ fke -> getColumnPrefix ( ) . $ schema -> quoteColumnName ( $ fk ) . '=' . $ pke -> getColumnPrefix ( ) . $ schema -> quoteColumnName ( $ pk ) ; } if ( ! empty ( $ this -> relation -> on ) ) $ joins [ ] = $ this -> relation -> on ; if ( ! empty ( $ this -> relation -> joinOptions ) && is_string ( $ this -> relation -> joinOptions ) ) return $ this -> relation -> joinType . ' ' . $ this -> getTableNameWithAlias ( ) . ' ' . $ this -> relation -> joinOptions . ' ON (' . implode ( ') AND (' , $ joins ) . ')' ; else return $ this -> relation -> joinType . ' ' . $ this -> getTableNameWithAlias ( ) . ' ON (' . implode ( ') AND (' , $ joins ) . ')' ; }
Generates the join statement for one - many relationship . This works for HAS_ONE HAS_MANY and BELONGS_TO .
5,893
public function join ( $ element ) { if ( $ element -> slave !== null ) $ this -> join ( $ element -> slave ) ; if ( ! empty ( $ element -> relation -> select ) ) $ this -> selects [ ] = $ element -> getColumnSelect ( $ element -> relation -> select ) ; $ this -> conditions [ ] = $ element -> relation -> condition ; $ this -> orders [ ] = $ element -> relation -> order ; $ this -> joins [ ] = $ element -> getJoinCondition ( ) ; $ this -> joins [ ] = $ element -> relation -> join ; $ this -> groups [ ] = $ element -> relation -> group ; $ this -> havings [ ] = $ element -> relation -> having ; if ( is_array ( $ element -> relation -> params ) ) { if ( is_array ( $ this -> params ) ) $ this -> params = array_merge ( $ this -> params , $ element -> relation -> params ) ; else $ this -> params = $ element -> relation -> params ; } $ this -> elements [ $ element -> id ] = true ; }
Joins with another join element
5,894
public function createCommand ( $ builder ) { $ sql = ( $ this -> distinct ? 'SELECT DISTINCT ' : 'SELECT ' ) . implode ( ', ' , $ this -> selects ) ; $ sql .= ' FROM ' . implode ( ' ' , array_unique ( $ this -> joins ) ) ; $ conditions = array ( ) ; foreach ( $ this -> conditions as $ condition ) if ( $ condition !== '' ) $ conditions [ ] = $ condition ; if ( $ conditions !== array ( ) ) $ sql .= ' WHERE (' . implode ( ') AND (' , $ conditions ) . ')' ; $ groups = array ( ) ; foreach ( $ this -> groups as $ group ) if ( $ group !== '' ) $ groups [ ] = $ group ; if ( $ groups !== array ( ) ) $ sql .= ' GROUP BY ' . implode ( ', ' , $ groups ) ; $ havings = array ( ) ; foreach ( $ this -> havings as $ having ) if ( $ having !== '' ) $ havings [ ] = $ having ; if ( $ havings !== array ( ) ) $ sql .= ' HAVING (' . implode ( ') AND (' , $ havings ) . ')' ; $ orders = array ( ) ; foreach ( $ this -> orders as $ order ) if ( $ order !== '' ) $ orders [ ] = $ order ; if ( $ orders !== array ( ) ) $ sql .= ' ORDER BY ' . implode ( ', ' , $ orders ) ; $ sql = $ builder -> applyLimit ( $ sql , $ this -> limit , $ this -> offset ) ; $ command = $ builder -> getDbConnection ( ) -> createCommand ( $ sql ) ; $ builder -> bindValues ( $ command , $ this -> params ) ; return $ command ; }
Creates the SQL statement .
5,895
public function query ( ) { if ( preg_match ( '/^\s*(.*?)\((.*)\)\s*$/' , $ this -> relation -> foreignKey , $ matches ) ) $ this -> queryManyMany ( $ matches [ 1 ] , $ matches [ 2 ] ) ; else $ this -> queryOneMany ( ) ; }
Performs the STAT query .
5,896
protected function renderHeader ( ) { echo "<ul class=\"tabs\">\n" ; foreach ( $ this -> tabs as $ id => $ tab ) { $ title = isset ( $ tab [ 'title' ] ) ? $ tab [ 'title' ] : 'undefined' ; $ active = $ id === $ this -> activeTab ? ' class="active"' : '' ; $ url = isset ( $ tab [ 'url' ] ) ? $ tab [ 'url' ] : "#{$id}" ; echo "<li><a href=\"{$url}\"{$active}>{$title}</a></li>\n" ; } echo "</ul>\n" ; }
Renders the header part .
5,897
protected function renderBody ( ) { foreach ( $ this -> tabs as $ id => $ tab ) { $ inactive = $ id !== $ this -> activeTab ? ' style="display:none"' : '' ; echo "<div class=\"view\" id=\"{$id}\"{$inactive}>\n" ; if ( isset ( $ tab [ 'content' ] ) ) echo $ tab [ 'content' ] ; elseif ( isset ( $ tab [ 'view' ] ) ) { if ( isset ( $ tab [ 'data' ] ) ) { if ( is_array ( $ this -> viewData ) ) $ data = array_merge ( $ this -> viewData , $ tab [ 'data' ] ) ; else $ data = $ tab [ 'data' ] ; } else $ data = $ this -> viewData ; $ this -> getController ( ) -> renderPartial ( $ tab [ 'view' ] , $ data ) ; } echo "</div><!-- {$id} ; } }
Renders the body part .
5,898
public function init ( ) { if ( isset ( $ this -> htmlOptions [ 'id' ] ) ) $ id = $ this -> htmlOptions [ 'id' ] ; else $ id = $ this -> htmlOptions [ 'id' ] = $ this -> getId ( ) ; if ( $ this -> url !== null ) $ this -> url = CHtml :: normalizeUrl ( $ this -> url ) ; $ cs = Yii :: app ( ) -> getClientScript ( ) ; $ cs -> registerCoreScript ( 'treeview' ) ; $ options = $ this -> getClientOptions ( ) ; $ options = $ options === array ( ) ? '{}' : CJavaScript :: encode ( $ options ) ; $ cs -> registerScript ( 'Yii.CTreeView#' . $ id , "jQuery(\"#{$id}\").treeview($options);" ) ; if ( $ this -> cssFile === null ) $ cs -> registerCssFile ( $ cs -> getCoreScriptUrl ( ) . '/treeview/jquery.treeview.css' ) ; elseif ( $ this -> cssFile !== false ) $ cs -> registerCssFile ( $ this -> cssFile ) ; echo CHtml :: tag ( 'ul' , $ this -> htmlOptions , false , false ) . "\n" ; echo self :: saveDataAsHtml ( $ this -> data ) ; }
Initializes the widget . This method registers all needed client scripts and renders the tree view content .
5,899
public static function saveDataAsHtml ( $ data ) { $ html = '' ; if ( is_array ( $ data ) ) { foreach ( $ data as $ node ) { if ( ! isset ( $ node [ 'text' ] ) ) continue ; if ( isset ( $ node [ 'expanded' ] ) ) $ css = $ node [ 'expanded' ] ? 'open' : 'closed' ; else $ css = '' ; if ( isset ( $ node [ 'hasChildren' ] ) && $ node [ 'hasChildren' ] ) { if ( $ css !== '' ) $ css .= ' ' ; $ css .= 'hasChildren' ; } $ options = isset ( $ node [ 'htmlOptions' ] ) ? $ node [ 'htmlOptions' ] : array ( ) ; if ( $ css !== '' ) { if ( isset ( $ options [ 'class' ] ) ) $ options [ 'class' ] .= ' ' . $ css ; else $ options [ 'class' ] = $ css ; } if ( isset ( $ node [ 'id' ] ) ) $ options [ 'id' ] = $ node [ 'id' ] ; $ html .= CHtml :: tag ( 'li' , $ options , $ node [ 'text' ] , false ) ; if ( ! empty ( $ node [ 'children' ] ) ) { $ html .= "\n<ul>\n" ; $ html .= self :: saveDataAsHtml ( $ node [ 'children' ] ) ; $ html .= "</ul>\n" ; } $ html .= CHtml :: closeTag ( 'li' ) . "\n" ; } } return $ html ; }
Generates tree view nodes in HTML from the data array .