idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
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 ) - ...
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 ( ',' ...
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 ( ) -> createComma...
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 ( $ nam...
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 ( ) ; ...
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...
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 ( 'u...
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' ] ...
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'...
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 -> mode...
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 ...
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 -> setPage...
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 (...
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 = $ guess...
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 ...
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 ( ...
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 ) ...
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...
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 ) $ valu...
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 = $ c...
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 ) $ c...
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 ) ; ...
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' ) . '...
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 ...
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 $ li...
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 )...
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 ( ...
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 (...
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 ( $ direc...
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 $...
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 ...
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 => $ definit...
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 ( '[' => ...
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 , $ t...
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 ( $ con...
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 ) ret...
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 [ 'decimalSepar...
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 Reflectio...
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 ] ) ) { ...
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 .= " <...
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 = sub...
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 = isse...
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|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_...
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 ...
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 ->...
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 ) ; else...
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_...
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 ) ;...
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 -> runQu...
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 -> re...
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 ...
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 -...
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 -> togeth...
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...
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 =...
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 ; $ ...
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 !== ...
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}" ;...
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 ...
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 ( ) ; $ c...
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' ] ...
Generates tree view nodes in HTML from the data array .