repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.alterColumn
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"; }
php
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"; }
[ "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. @param string $table the table whose column is to be changed. The table name will be properly quoted by the method. @param string $column the name of the column to be changed. The name will be properly quoted by the method. @param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
[ "Builds", "and", "executes", "a", "SQL", "statement", "for", "changing", "the", "definition", "of", "a", "column", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L342-L348
train
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.addForeignKey
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"; }
php
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"; }
[ "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. @param string $name the name of the foreign key constraint. @param string $table the table that the foreign key constraint will be added to. @param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or pass as an array of column names. @param string $refTable the table that the foreign key references to. @param string|array $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or pass as an array of column names. @param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL @param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
[ "Builds", "a", "SQL", "statement", "for", "adding", "a", "foreign", "key", "constraint", "to", "an", "existing", "table", ".", "The", "method", "will", "properly", "quote", "the", "table", "and", "column", "names", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L361-L368
train
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.dropForeignKey
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"; }
php
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"; }
[ "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. @param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method. @param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
[ "Builds", "a", "SQL", "statement", "for", "dropping", "a", "foreign", "key", "constraint", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L375-L381
train
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.createIndex
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"; }
php
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"; }
[ "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. @param string $name the name of the index. The name will be properly quoted by the method. @param string $table the table that the new index will be created for. The table name will be properly quoted by the method. @param string|array $columns the column(s) that should be included in the index. If there are multiple columns, please separate them by commas or pass as an array of column names. Each column name will be properly quoted by the method, unless a parenthesis is found in the name. @param boolean $unique whether to add UNIQUE constraint on the created index.
[ "Builds", "and", "executes", "a", "SQL", "statement", "for", "creating", "a", "new", "index", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L391-L397
train
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.refreshTableSchema
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"; }
php
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"; }
[ "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 @param string $table name of the table to refresh @since 1.1.9
[ "Refreshed", "schema", "cache", "for", "a", "table" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L417-L423
train
yiisoft/yii
framework/db/CDbMigration.php
CDbMigration.addPrimaryKey
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"; }
php
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"; }
[ "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. @param string $name name of the primary key constraint to add @param string $table name of the table to add primary key to @param string|array $columns comma separated string or array of columns that the primary key will consist of. Array value can be passed since 1.1.14. @since 1.1.13
[ "Builds", "and", "executes", "a", "SQL", "statement", "for", "creating", "a", "primary", "key", "supports", "composite", "primary", "keys", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/CDbMigration.php#L433-L439
train
yiisoft/yii
framework/yiilite.php
CWidgetFactory.init
public function init() { parent::init(); if($this->enableSkin && $this->skinPath===null) $this->skinPath=Yii::app()->getViewPath().DIRECTORY_SEPARATOR.'skins'; }
php
public function init() { parent::init(); if($this->enableSkin && $this->skinPath===null) $this->skinPath=Yii::app()->getViewPath().DIRECTORY_SEPARATOR.'skins'; }
[ "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
[ "class", "name", "skin", "name", "property", "name", "=", ">", "value" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/yiilite.php#L6194-L6199
train
yiisoft/yii
framework/zii/widgets/grid/CButtonColumn.php
CButtonColumn.getDataCellContent
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); }
php
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); }
[ "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. @param integer $row the row number (zero-based) @return string the data cell content. @since 1.1.16
[ "Returns", "the", "data", "cell", "content", ".", "This", "method", "renders", "the", "view", "update", "and", "delete", "buttons", "in", "the", "data", "cell", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CButtonColumn.php#L314-L327
train
yiisoft/yii
demos/blog/protected/models/Post.php
Post.addComment
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(); }
php
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(); }
[ "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. @param Comment the comment to be added @return boolean whether the comment is saved successfully
[ "Adds", "a", "new", "comment", "to", "this", "post", ".", "This", "method", "will", "set", "status", "and", "post_id", "of", "the", "comment", "accordingly", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/models/Post.php#L123-L131
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.actionList
public function actionList() { $pages=new CPagination(Post::model()->count()); $postList=Post::model()->findAll($this->getListCriteria($pages)); $this->render('list',array( 'postList'=>$postList, 'pages'=>$pages)); }
php
public function actionList() { $pages=new CPagination(Post::model()->count()); $postList=Post::model()->findAll($this->getListCriteria($pages)); $this->render('list',array( 'postList'=>$postList, 'pages'=>$pages)); }
[ "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.
[ "Lists", "all", "posts", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L41-L49
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.actionCreate
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)); }
php
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)); }
[ "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.
[ "Creates", "a", "new", "post", ".", "If", "creation", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "show", "page", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L63-L74
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.actionUpdate
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)); }
php
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)); }
[ "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.
[ "Updates", "a", "particular", "post", ".", "If", "update", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "show", "page", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L80-L91
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.actionDelete
public function actionDelete() { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $this->loadPost()->delete(); $this->redirect(array('list')); } else throw new CHttpException(500,'Invalid request. Please do not repeat this request again.'); }
php
public function actionDelete() { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $this->loadPost()->delete(); $this->redirect(array('list')); } else throw new CHttpException(500,'Invalid request. Please do not repeat this request again.'); }
[ "public", "function", "actionDelete", "(", ")", "{", "if", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "isPostRequest", ")", "{", "// we only allow deletion via POST request", "$", "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.
[ "Deletes", "a", "particular", "post", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "list", "page", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L97-L107
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.loadPost
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.'); }
php
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.'); }
[ "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.
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L113-L121
train
yiisoft/yii
build/commands/lite/protected/controllers/PostController.php
PostController.generateColumnHeader
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); }
php
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); }
[ "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. @param string the column name @return string the generated header cell content
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/PostController.php#L150-L167
train
yiisoft/yii
framework/web/widgets/CStarRating.php
CStarRating.registerClientScript
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); }
php
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); }
[ "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. @param string $id the ID of the container
[ "Registers", "the", "necessary", "javascript", "and", "css", "scripts", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CStarRating.php#L122-L133
train
yiisoft/yii
framework/web/widgets/CStarRating.php
CStarRating.renderStars
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"; } }
php
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"; } }
[ "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. @param string $id the ID of the container @param string $name the name of the input
[ "Renders", "the", "stars", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CStarRating.php#L152-L175
train
yiisoft/yii
framework/web/widgets/pagers/CListPager.php
CListPager.generatePageText
protected function generatePageText($page) { if($this->pageTextFormat!==null) return sprintf($this->pageTextFormat,$page+1); else return $page+1; }
php
protected function generatePageText($page) { if($this->pageTextFormat!==null) return sprintf($this->pageTextFormat,$page+1); else return $page+1; }
[ "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. @param integer $page zero-based page number @return string the list option for the page number
[ "Generates", "the", "list", "option", "for", "the", "specified", "page", "number", ".", "You", "may", "override", "this", "method", "to", "customize", "the", "option", "display", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/pagers/CListPager.php#L81-L87
train
yiisoft/yii
framework/web/form/CFormElementCollection.php
CFormElementCollection.remove
public function remove($key) { if(($item=parent::remove($key))!==null) $this->_form->removedElement($key,$item,$this->_forButtons); }
php
public function remove($key) { if(($item=parent::remove($key))!==null) $this->_form->removedElement($key,$item,$this->_forButtons); }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "if", "(", "(", "$", "item", "=", "parent", "::", "remove", "(", "$", "key", ")", ")", "!==", "null", ")", "$", "this", "->", "_form", "->", "removedElement", "(", "$", "key", ",", "$", "item", ",", "$", "this", "->", "_forButtons", ")", ";", "}" ]
Removes the specified element by key. @param string $key the name of the element to be removed from the collection @throws CException
[ "Removes", "the", "specified", "element", "by", "key", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CFormElementCollection.php#L107-L111
train
yiisoft/yii
framework/zii/widgets/grid/CGridView.php
CGridView.renderFilter
public function renderFilter() { if($this->filter!==null) { echo "<tr class=\"{$this->filterCssClass}\">\n"; foreach($this->columns as $column) $column->renderFilterCell(); echo "</tr>\n"; } }
php
public function renderFilter() { if($this->filter!==null) { echo "<tr class=\"{$this->filterCssClass}\">\n"; foreach($this->columns as $column) $column->renderFilterCell(); echo "</tr>\n"; } }
[ "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. @since 1.1.1
[ "Renders", "the", "filter", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CGridView.php#L533-L542
train
yiisoft/yii
demos/hangman/protected/controllers/GameController.php
GameController.actionPlay
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 a difficulty level is correctly chosen 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); // show the guess page $this->render('guess'); } else { $params=array( 'levels'=>$levels, // if this is a POST request, it means the level is not chosen 'error'=>Yii::app()->request->isPostRequest, ); // show the difficulty level page $this->render('play',$params); } }
php
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 a difficulty level is correctly chosen 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); // show the guess page $this->render('guess'); } else { $params=array( 'levels'=>$levels, // if this is a POST request, it means the level is not chosen 'error'=>Yii::app()->request->isPostRequest, ); // show the difficulty level page $this->render('play',$params); } }
[ "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 a difficulty level is correctly chosen", "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", ")", ";", "// show the guess page", "$", "this", "->", "render", "(", "'guess'", ")", ";", "}", "else", "{", "$", "params", "=", "array", "(", "'levels'", "=>", "$", "levels", ",", "// if this is a POST request, it means the level is not chosen", "'error'", "=>", "Yii", "::", "app", "(", ")", "->", "request", "->", "isPostRequest", ",", ")", ";", "// show the difficulty level page", "$", "this", "->", "render", "(", "'play'", ",", "$", "params", ")", ";", "}", "}" ]
The 'play' action. In this action, users are asked to choose a difficulty level of the game.
[ "The", "play", "action", ".", "In", "this", "action", "users", "are", "asked", "to", "choose", "a", "difficulty", "level", "of", "the", "game", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/hangman/protected/controllers/GameController.php#L32-L61
train
yiisoft/yii
demos/hangman/protected/controllers/GameController.php
GameController.actionGuess
public function actionGuess() { // check to see if the letter is guessed correctly if(isset($_GET['g'][0]) && ($result=$this->guess($_GET['g'][0]))!==null) $this->render($result ? 'win' : 'lose'); else // the letter is guessed correctly, but not win yet { $guessed=$this->getPageState('guessed',array()); $guessed[$_GET['g'][0]]=true; $this->setPageState('guessed',$guessed,array()); $this->render('guess'); } }
php
public function actionGuess() { // check to see if the letter is guessed correctly if(isset($_GET['g'][0]) && ($result=$this->guess($_GET['g'][0]))!==null) $this->render($result ? 'win' : 'lose'); else // the letter is guessed correctly, but not win yet { $guessed=$this->getPageState('guessed',array()); $guessed[$_GET['g'][0]]=true; $this->setPageState('guessed',$guessed,array()); $this->render('guess'); } }
[ "public", "function", "actionGuess", "(", ")", "{", "// check to see if the letter is guessed correctly", "if", "(", "isset", "(", "$", "_GET", "[", "'g'", "]", "[", "0", "]", ")", "&&", "(", "$", "result", "=", "$", "this", "->", "guess", "(", "$", "_GET", "[", "'g'", "]", "[", "0", "]", ")", ")", "!==", "null", ")", "$", "this", "->", "render", "(", "$", "result", "?", "'win'", ":", "'lose'", ")", ";", "else", "// the letter is guessed correctly, but not win yet", "{", "$", "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.
[ "The", "guess", "action", ".", "This", "action", "is", "invoked", "each", "time", "when", "the", "user", "makes", "a", "guess", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/hangman/protected/controllers/GameController.php#L67-L79
train
yiisoft/yii
demos/hangman/protected/controllers/GameController.php
GameController.generateWord
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); }
php
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); }
[ "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. @return string the word to be guessed
[ "Generates", "a", "word", "to", "be", "guessed", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/hangman/protected/controllers/GameController.php#L105-L115
train
yiisoft/yii
demos/hangman/protected/controllers/GameController.php
GameController.guess
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; } }
php
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; } }
[ "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. @param string the letter @return mixed true if the word is guessed correctly, false if the user has used up all guesses and the word is guessed incorrectly, and null if the letter is guessed correctly but the whole word is guessed correctly yet.
[ "Checks", "to", "see", "if", "a", "letter", "is", "guessed", "correctly", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/hangman/protected/controllers/GameController.php#L125-L149
train
yiisoft/yii
framework/collections/CConfiguration.php
CConfiguration.loadFromFile
public function loadFromFile($configFile) { $data=require($configFile); if($this->getCount()>0) $this->mergeWith($data); else $this->copyFrom($data); }
php
public function loadFromFile($configFile) { $data=require($configFile); if($this->getCount()>0) $this->mergeWith($data); else $this->copyFrom($data); }
[ "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. A config file must be a PHP script returning a configuration array (like the following) <pre> return array ( 'name'=>'My Application', 'defaultController'=>'index', ); </pre> @param string $configFile configuration file path (if using relative path, be aware of what is the current path) @see mergeWith
[ "Loads", "configuration", "data", "from", "a", "file", "and", "merges", "it", "with", "the", "existing", "configuration", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/collections/CConfiguration.php#L70-L77
train
yiisoft/yii
framework/web/helpers/CJavaScript.php
CJavaScript.quote
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); }
php
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); }
[ "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. @param string $js string to be quoted @param boolean $forUrl whether this string is used as a URL @return string the quoted string
[ "Quotes", "a", "javascript", "string", ".", "After", "processing", "the", "string", "can", "be", "safely", "enclosed", "within", "a", "pair", "of", "quotation", "marks", "and", "serve", "as", "a", "javascript", "string", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/helpers/CJavaScript.php#L28-L38
train
yiisoft/yii
framework/web/helpers/CJavaScript.php
CJavaScript.encode
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); // locale-independent representation } 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 ''; }
php
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); // locale-independent representation } 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 ''; }
[ "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", ")", ";", "// locale-independent representation", "}", "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. Example: <pre> $options=array('key1'=>true,'key2'=>123,'key3'=>'value'); echo CJavaScript::encode($options); // The following javascript code would be generated: // {'key1':true,'key2':123,'key3':'value'} </pre> For highly complex data structures use {@link jsonEncode} and {@link jsonDecode} to serialize and unserialize. If you are encoding user input, make sure $safe is set to true. @param mixed $value PHP variable to be encoded @param boolean $safe If true, 'js:' will not be allowed. In case of wrapping code with {@link CJavaScriptExpression} JavaScript expression will stay as is no matter what value this parameter is set to. Default is false. This parameter is available since 1.1.11. @return string the encoded string
[ "Encodes", "a", "PHP", "variable", "into", "javascript", "representation", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/helpers/CJavaScript.php#L63-L109
train
yiisoft/yii
framework/logging/CLogRouter.php
CLogRouter.init
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')); }
php
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')); }
[ "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.
[ "Initializes", "this", "application", "component", ".", "This", "method", "is", "required", "by", "the", "IApplicationComponent", "interface", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/logging/CLogRouter.php#L60-L71
train
yiisoft/yii
build/tasks/YiiPearTask.php
YiiPearTask.main
function main() { $pkg = new PEAR_PackageFileManager2(); $e = $pkg->setOptions(array ( 'baseinstalldir' => 'yii', 'packagedirectory' => $this->pkgdir, 'filelistgenerator' => 'file', 'simpleoutput' => true, 'ignore' => array(), 'roles' => array('*' => 'php'), ) ); // PEAR error checking 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(); }
php
function main() { $pkg = new PEAR_PackageFileManager2(); $e = $pkg->setOptions(array ( 'baseinstalldir' => 'yii', 'packagedirectory' => $this->pkgdir, 'filelistgenerator' => 'file', 'simpleoutput' => true, 'ignore' => array(), 'roles' => array('*' => 'php'), ) ); // PEAR error checking 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(); }
[ "function", "main", "(", ")", "{", "$", "pkg", "=", "new", "PEAR_PackageFileManager2", "(", ")", ";", "$", "e", "=", "$", "pkg", "->", "setOptions", "(", "array", "(", "'baseinstalldir'", "=>", "'yii'", ",", "'packagedirectory'", "=>", "$", "this", "->", "pkgdir", ",", "'filelistgenerator'", "=>", "'file'", ",", "'simpleoutput'", "=>", "true", ",", "'ignore'", "=>", "array", "(", ")", ",", "'roles'", "=>", "array", "(", "'*'", "=>", "'php'", ")", ",", ")", ")", ";", "// PEAR error checking", "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
[ "Main", "entrypoint", "of", "the", "task" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/tasks/YiiPearTask.php#L87-L130
train
yiisoft/yii
framework/utils/CLocalizedFormatter.php
CLocalizedFormatter.setLocale
public function setLocale($locale) { if(is_string($locale)) $locale=CLocale::getInstance($locale); $this->sizeFormat['decimalSeparator']=$locale->getNumberSymbol('decimal'); $this->_locale=$locale; }
php
public function setLocale($locale) { if(is_string($locale)) $locale=CLocale::getInstance($locale); $this->sizeFormat['decimalSeparator']=$locale->getNumberSymbol('decimal'); $this->_locale=$locale; }
[ "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. @param CLocale|string $locale an instance of CLocale or a locale ID
[ "Set", "the", "locale", "to", "use", "for", "formatting", "values", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CLocalizedFormatter.php#L54-L60
train
yiisoft/yii
framework/caching/CCache.php
CCache.init
public function init() { parent::init(); if($this->keyPrefix===null) $this->keyPrefix=Yii::app()->getId(); }
php
public function init() { parent::init(); if($this->keyPrefix===null) $this->keyPrefix=Yii::app()->getId(); }
[ "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.
[ "Initializes", "the", "application", "component", ".", "This", "method", "overrides", "the", "parent", "implementation", "by", "setting", "default", "cache", "key", "prefix", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/CCache.php#L81-L86
train
yiisoft/yii
framework/caching/CCache.php
CCache.get
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; }
php
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; }
[ "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. @param string $id a key identifying the cached value @return mixed the value stored in cache, false if the value is not in the cache, expired or the dependency has changed.
[ "Retrieves", "a", "value", "from", "cache", "with", "a", "specified", "key", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/CCache.php#L102-L118
train
yiisoft/yii
framework/caching/CCache.php
CCache.set
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); }
php
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); }
[ "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. @param string $id the key identifying the value to be cached @param mixed $value the value to be cached @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire. @param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid. @return boolean true if the value is successfully stored into cache, false otherwise
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/CCache.php#L173-L186
train
yiisoft/yii
framework/caching/CCache.php
CCache.delete
public function delete($id) { Yii::trace('Deleting "'.$id.'" from cache','system.caching.'.get_class($this)); return $this->deleteValue($this->generateUniqueKey($id)); }
php
public function delete($id) { Yii::trace('Deleting "'.$id.'" from cache','system.caching.'.get_class($this)); return $this->deleteValue($this->generateUniqueKey($id)); }
[ "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 @param string $id the key of the value to be deleted @return boolean if no error happens during deletion
[ "Deletes", "a", "value", "with", "the", "specified", "key", "from", "cache" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/CCache.php#L217-L221
train
yiisoft/yii
framework/zii/widgets/jui/CJuiWidget.php
CJuiWidget.resolvePackagePath
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'; } }
php
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'; } }
[ "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.
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/jui/CJuiWidget.php#L92-L102
train
yiisoft/yii
framework/zii/widgets/jui/CJuiWidget.php
CJuiWidget.registerCoreScripts
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); } }
php
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); } }
[ "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.
[ "Registers", "the", "core", "script", "files", ".", "This", "method", "registers", "jquery", "and", "JUI", "JavaScript", "files", "and", "the", "theme", "CSS", "file", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/jui/CJuiWidget.php#L108-L127
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser._doCodeBlocks_callback
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); }
php
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); }
[ "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. @param array $matches matches @return string the highlighted code block
[ "Callback", "function", "when", "a", "code", "block", "is", "matched", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L97-L104
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser.highlightCodeBlock
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>"; }
php
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>"; }
[ "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. @param string $codeblock the code block @return string the highlighted code block. Null if the code block does not need to highlighted
[ "Highlights", "the", "code", "block", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L121-L133
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser.getHighlightTag
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; }
php
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; }
[ "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. @param string $codeblock code block with highlighting options. @return string the user-entered highlighting options. Null if no option is entered.
[ "Returns", "the", "user", "-", "entered", "highlighting", "options", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L140-L145
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser.createHighLighter
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; }
php
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; }
[ "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. @param string $options the user-entered options @return Text_Highlighter the highlighter instance
[ "Creates", "a", "highlighter", "instance", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L152-L164
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser.getHighlightConfig
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; }
php
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; }
[ "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. @param string $options user-entered options @return array the highlighter config
[ "Generates", "the", "config", "for", "the", "highlighter", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L171-L178
train
yiisoft/yii
framework/utils/CMarkdownParser.php
CMarkdownParser.getInlineOption
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; }
php
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; }
[ "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. @param string $name the configuration name @param string $str the user-entered options @param mixed $defaultValue default value if the configuration is not present @return mixed the configuration value
[ "Retrieves", "the", "specified", "configuration", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CMarkdownParser.php#L201-L207
train
yiisoft/yii
framework/utils/CFileHelper.php
CFileHelper.copyDirectory
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); }
php
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); }
[ "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. @param string $src the source directory @param string $dst the destination directory @param array $options options for directory copy. Valid options are: <ul> <li>fileTypes: array, list of file name suffix (without dot). Only files with these suffixes will be copied.</li> <li>exclude: array, list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant. </li> <li>level: integer, recursion depth, default=-1. Level -1 means copying all directories and files under the directory; Level 0 means copying only the files DIRECTLY under the directory; level N means copying those directories that are within N levels. </li> <li>newDirMode - the permission to be set for newly copied directories (defaults to 0777);</li> <li>newFileMode - the permission to be set for newly copied files (defaults to the current environment setting).</li> </ul>
[ "Copies", "a", "directory", "recursively", "as", "another", ".", "If", "the", "destination", "directory", "does", "not", "exist", "it", "will", "be", "created", "recursively", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFileHelper.php#L54-L64
train
yiisoft/yii
framework/utils/CFileHelper.php
CFileHelper.findFiles
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; }
php
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; }
[ "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. @param string $dir the directory under which the files will be looked for @param array $options options for file searching. Valid options are: <ul> <li>fileTypes: array, list of file name suffix (without dot). Only files with these suffixes will be returned.</li> <li>exclude: array, list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, it will not be copied. For example, an exclusion of '.svn' will exclude all files and directories whose name is '.svn'. And an exclusion of '/a/b' will exclude file or directory '$src/a/b'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant. </li> <li>level: integer, recursion depth, default=-1. Level -1 means searching for all directories and files under the directory; Level 0 means searching for only the files DIRECTLY under the directory; level N means searching for those directories that are within N levels. </li> <li>absolutePaths: boolean, whether to return absolute paths or relative ones, defaults to true.</li> </ul> @return array files found under the directory. The file list is sorted.
[ "Returns", "the", "files", "found", "under", "the", "specified", "directory", "and", "subdirectories", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFileHelper.php#L126-L136
train
yiisoft/yii
framework/utils/CFileHelper.php
CFileHelper.validatePath
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; }
php
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; }
[ "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. @param string $base the path relative to the original source directory @param string $file the file or directory name @param boolean $isFile whether this is a file @param array $fileTypes list of valid file name suffixes (without dot). @param array $exclude list of directory and file exclusions. Each exclusion can be either a name or a path. If a file or directory name or path matches the exclusion, false will be returned. For example, an exclusion of '.svn' will return false for all files and directories whose name is '.svn'. And an exclusion of '/a/b' will return false for file or directory '$src/a/b'. Note, that '/' should be used as separator regardless of the value of the DIRECTORY_SEPARATOR constant. @return boolean whether the file or directory is valid
[ "Validates", "a", "file", "or", "directory", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFileHelper.php#L242-L255
train
yiisoft/yii
framework/utils/CFileHelper.php
CFileHelper.getMimeTypeByExtension
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; }
php
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; }
[ "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. @param string $file the file name. @param string $magicFile the path of the file that contains all available MIME type information. If this is not set, the default 'system.utils.mimeTypes' file will be used. This parameter has been available since version 1.1.3. @return string the MIME type. Null is returned if the MIME type cannot be determined.
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFileHelper.php#L301-L317
train
yiisoft/yii
framework/utils/CFileHelper.php
CFileHelper.getExtensionByMimeType
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; }
php
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; }
[ "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. @param string $file the file name. @param string $magicFile the path of the file that contains all available extension information. If this is not set, the default 'system.utils.fileExtensions' file will be used. This parameter has been available since version 1.1.16. @return string extension name. Null is returned if the extension cannot be determined.
[ "Determines", "the", "file", "extension", "name", "based", "on", "its", "MIME", "type", ".", "This", "method", "will", "use", "a", "local", "map", "between", "MIME", "type", "and", "extension", "name", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFileHelper.php#L328-L344
train
yiisoft/yii
framework/web/widgets/COutputProcessor.php
COutputProcessor.processOutput
public function processOutput($output) { if($this->hasEventHandler('onProcessOutput')) { $event=new COutputEvent($this,$output); $this->onProcessOutput($event); if(!$event->handled) echo $output; } else echo $output; }
php
public function processOutput($output) { if($this->hasEventHandler('onProcessOutput')) { $event=new COutputEvent($this,$output); $this->onProcessOutput($event); if(!$event->handled) echo $output; } else echo $output; }
[ "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. The default implementation raises an {@link onProcessOutput} event. If the event is not handled by any event handler, the output will be echoed. @param string $output the captured output to be processed
[ "Processes", "the", "captured", "output", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/COutputProcessor.php#L55-L66
train
yiisoft/yii
framework/web/CSort.php
CSort.link
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); }
php
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); }
[ "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. @param string $attribute the attribute name. This must be the actual attribute name, not alias. If it is an attribute of a related AR object, the name should be prefixed with the relation name (e.g. 'author.name', where 'author' is the relation name). @param string $label the link label. If null, the label will be determined according to the attribute (see {@link resolveLabel}). @param array $htmlOptions additional HTML attributes for the hyperlink tag @return string the generated hyperlink
[ "Generates", "a", "hyperlink", "that", "can", "be", "clicked", "to", "cause", "sorting", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L279-L309
train
yiisoft/yii
framework/web/CSort.php
CSort.getDirections
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; }
php
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; }
[ "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. @return array sort directions indexed by attribute names. Sort direction can be either CSort::SORT_ASC for ascending order or CSort::SORT_DESC for descending order.
[ "Returns", "the", "currently", "requested", "sort", "information", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L341-L372
train
yiisoft/yii
framework/web/CSort.php
CSort.getDirection
public function getDirection($attribute) { $this->getDirections(); return isset($this->_directions[$attribute]) ? $this->_directions[$attribute] : null; }
php
public function getDirection($attribute) { $this->getDirections(); return isset($this->_directions[$attribute]) ? $this->_directions[$attribute] : null; }
[ "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. @param string $attribute the attribute name @return mixed Sort direction of the attribute. Can be either CSort::SORT_ASC for ascending order or CSort::SORT_DESC for descending order. Value is null if the attribute doesn't need to be sorted.
[ "Returns", "the", "sort", "direction", "of", "the", "specified", "attribute", "in", "the", "current", "request", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L381-L385
train
yiisoft/yii
framework/web/CSort.php
CSort.createUrl
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); }
php
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); }
[ "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. @param CController $controller the controller that will be used to create the URL. @param array $directions the sort directions indexed by attribute names. The sort direction can be either CSort::SORT_ASC for ascending order or CSort::SORT_DESC for descending order. @return string the URL for sorting
[ "Creates", "a", "URL", "that", "can", "lead", "to", "generating", "sorted", "data", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L395-L403
train
yiisoft/yii
framework/web/CSort.php
CSort.resolveAttribute
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; }
php
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; }
[ "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. The resolution is based on {@link attributes} and {@link CActiveRecord::attributeNames}. <ul> <li>When {@link attributes} is an empty array, if the name refers to an attribute of {@link modelClass}, then the name is returned back.</li> <li>When {@link attributes} is not empty, if the name refers to an attribute declared in {@link attributes}, then the corresponding virtual attribute definition is returned. Starting from version 1.1.3, if {@link attributes} contains a star ('*') element, the name will also be used to match against all model attributes.</li> <li>In all other cases, false is returned, meaning the name does not refer to a valid attribute.</li> </ul> @param string $attribute the attribute name that the user requests to sort on @return mixed the attribute name or the virtual attribute definition. False if the attribute cannot be sorted.
[ "Returns", "the", "real", "definition", "of", "an", "attribute", "given", "its", "name", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L420-L444
train
yiisoft/yii
framework/web/CSort.php
CSort.createLink
protected function createLink($attribute,$label,$url,$htmlOptions) { return CHtml::link($label,$url,$htmlOptions); }
php
protected function createLink($attribute,$label,$url,$htmlOptions) { return CHtml::link($label,$url,$htmlOptions); }
[ "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. @param string $attribute the name of the attribute that this link is for @param string $label the label of the hyperlink @param string $url the URL @param array $htmlOptions additional HTML options @return string the generated hyperlink
[ "Creates", "a", "hyperlink", "based", "on", "the", "given", "label", "and", "URL", ".", "You", "may", "override", "this", "method", "to", "customize", "the", "link", "generation", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CSort.php#L468-L471
train
yiisoft/yii
framework/zii/widgets/grid/CCheckBoxColumn.php
CCheckBoxColumn.init
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) { //.. read only $cbcode="return false;"; } elseif($this->selectableRows==1) { //.. only one can be checked, uncheck all other $cbcode="jQuery(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);"; } elseif(strpos($this->headerTemplate,'{item}')!==false) { //.. process check/uncheck all $cball=<<<CBALL jQuery(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.=<<<EOD jQuery(document).on('click', "input[name='$name']", function() { $cbcode }); EOD; Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id,$js); } }
php
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) { //.. read only $cbcode="return false;"; } elseif($this->selectableRows==1) { //.. only one can be checked, uncheck all other $cbcode="jQuery(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);"; } elseif(strpos($this->headerTemplate,'{item}')!==false) { //.. process check/uncheck all $cball=<<<CBALL jQuery(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.=<<<EOD jQuery(document).on('click', "input[name='$name']", function() { $cbcode }); EOD; Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id,$js); } }
[ "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", ")", "{", "//.. read only", "$", "cbcode", "=", "\"return false;\"", ";", "}", "elseif", "(", "$", "this", "->", "selectableRows", "==", "1", ")", "{", "//.. only one can be checked, uncheck all other", "$", "cbcode", "=", "\"jQuery(\\\"input:not(#\\\"+this.id+\\\")[name='$name']\\\").prop('checked',false);\"", ";", "}", "elseif", "(", "strpos", "(", "$", "this", "->", "headerTemplate", ",", "'{item}'", ")", "!==", "false", ")", "{", "//.. process check/uncheck all", "$", "cball", "=", "<<<CBALL\njQuery(document).on('click','#{$this->id}_all',function() {\n\tvar checked=this.checked;\n\tjQuery(\"input[name='$name']:enabled\").each(function() {this.checked=checked;});\n});\n\nCBALL", ";", "$", "cbcode", "=", "\"jQuery('#{$this->id}_all').prop('checked', jQuery(\\\"input[name='$name']\\\").length==jQuery(\\\"input[name='$name']:checked\\\").length);\"", ";", "}", "if", "(", "$", "cbcode", "!==", "''", ")", "{", "$", "js", "=", "$", "cball", ";", "$", "js", ".=", "<<<EOD\njQuery(document).on('click', \"input[name='$name']\", function() {\n\t$cbcode\n});\nEOD", ";", "Yii", "::", "app", "(", ")", "->", "getClientScript", "(", ")", "->", "registerScript", "(", "__CLASS__", ".", "'#'", ".", "$", "this", "->", "id", ",", "$", "js", ")", ";", "}", "}" ]
Initializes the column. This method registers necessary client script for the checkbox column.
[ "Initializes", "the", "column", ".", "This", "method", "registers", "necessary", "client", "script", "for", "the", "checkbox", "column", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CCheckBoxColumn.php#L131-L187
train
yiisoft/yii
framework/zii/widgets/grid/CCheckBoxColumn.php
CCheckBoxColumn.getDataCellContent
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); }
php
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); }
[ "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. @param integer $row the row number (zero-based) @return string the data cell content. @since 1.1.16
[ "Returns", "the", "data", "cell", "content", ".", "This", "method", "renders", "a", "checkbox", "in", "the", "data", "cell", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CCheckBoxColumn.php#L220-L243
train
yiisoft/yii
demos/blog/protected/controllers/CommentController.php
CommentController.actionDelete
public function actionDelete() { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $this->loadModel()->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_POST['ajax'])) $this->redirect(array('index')); } else throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); }
php
public function actionDelete() { if(Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $this->loadModel()->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if(!isset($_POST['ajax'])) $this->redirect(array('index')); } else throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); }
[ "public", "function", "actionDelete", "(", ")", "{", "if", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "isPostRequest", ")", "{", "// we only allow deletion via POST request", "$", "this", "->", "loadModel", "(", ")", "->", "delete", "(", ")", ";", "// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser", "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.
[ "Deletes", "a", "particular", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/controllers/CommentController.php#L67-L80
train
yiisoft/yii
demos/blog/protected/controllers/CommentController.php
CommentController.actionApprove
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.'); }
php
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.'); }
[ "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.
[ "Approves", "a", "particular", "comment", ".", "If", "approval", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "comment", "index", "page", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/controllers/CommentController.php#L103-L113
train
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
CBaseUserIdentity.getState
public function getState($name,$defaultValue=null) { return isset($this->_state[$name])?$this->_state[$name]:$defaultValue; }
php
public function getState($name,$defaultValue=null) { return isset($this->_state[$name])?$this->_state[$name]:$defaultValue; }
[ "public", "function", "getState", "(", "$", "name", ",", "$", "defaultValue", "=", "null", ")", "{", "return", "isset", "(", "$", "this", "->", "_state", "[", "$", "name", "]", ")", "?", "$", "this", "->", "_state", "[", "$", "name", "]", ":", "$", "defaultValue", ";", "}" ]
Gets the persisted state by the specified name. @param string $name the name of the state @param mixed $defaultValue the default value to be returned if the named state does not exist @return mixed the value of the named state
[ "Gets", "the", "persisted", "state", "by", "the", "specified", "name", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CBaseUserIdentity.php#L108-L111
train
yiisoft/yii
framework/web/CPagination.php
CPagination.applyLimit
public function applyLimit($criteria) { $criteria->limit=$this->getLimit(); $criteria->offset=$this->getOffset(); }
php
public function applyLimit($criteria) { $criteria->limit=$this->getLimit(); $criteria->offset=$this->getOffset(); }
[ "public", "function", "applyLimit", "(", "$", "criteria", ")", "{", "$", "criteria", "->", "limit", "=", "$", "this", "->", "getLimit", "(", ")", ";", "$", "criteria", "->", "offset", "=", "$", "this", "->", "getOffset", "(", ")", ";", "}" ]
Applies LIMIT and OFFSET to the specified query criteria. @param CDbCriteria $criteria the query criteria that should be applied with the limit
[ "Applies", "LIMIT", "and", "OFFSET", "to", "the", "specified", "query", "criteria", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CPagination.php#L214-L218
train
yiisoft/yii
framework/i18n/CGettextMessageSource.php
CGettextMessageSource.init
public function init() { parent::init(); if($this->basePath===null) $this->basePath=Yii::getPathOfAlias('application.messages'); }
php
public function init() { parent::init(); if($this->basePath===null) $this->basePath=Yii::getPathOfAlias('application.messages'); }
[ "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.
[ "Initializes", "the", "application", "component", ".", "This", "method", "overrides", "the", "parent", "implementation", "by", "preprocessing", "the", "user", "request", "data", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CGettextMessageSource.php#L71-L76
train
yiisoft/yii
framework/validators/CCaptchaValidator.php
CCaptchaValidator.getCaptchaAction
protected function getCaptchaAction() { if(($captcha=Yii::app()->getController()->createAction($this->captchaAction))===null) { if(strpos($this->captchaAction,'/')!==false) // contains controller or module { 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; }
php
protected function getCaptchaAction() { if(($captcha=Yii::app()->getController()->createAction($this->captchaAction))===null) { if(strpos($this->captchaAction,'/')!==false) // contains controller or module { 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; }
[ "protected", "function", "getCaptchaAction", "(", ")", "{", "if", "(", "(", "$", "captcha", "=", "Yii", "::", "app", "(", ")", "->", "getController", "(", ")", "->", "createAction", "(", "$", "this", "->", "captchaAction", ")", ")", "===", "null", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "captchaAction", ",", "'/'", ")", "!==", "false", ")", "// contains controller or module", "{", "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. @throws CException if {@link action} is invalid @return CCaptchaAction the action object @since 1.1.7
[ "Returns", "the", "CAPTCHA", "action", "object", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CCaptchaValidator.php#L64-L81
train
yiisoft/yii
framework/utils/CFormatter.php
CFormatter.format
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))); }
php
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))); }
[ "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. @param mixed $value the value to be formatted @param string $type the data type. This must correspond to a format method available in CFormatter. For example, we can use 'text' here because there is method named {@link formatText}. @throws CException if given type is unknown @return string the formatted data
[ "Formats", "a", "value", "based", "on", "the", "given", "type", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFormatter.php#L124-L131
train
yiisoft/yii
framework/utils/CFormatter.php
CFormatter.normalizeDateValue
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; }
php
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; }
[ "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. @param mixed $time the time expression to be normalized @return int the normalized result as a UNIX timestamp
[ "Normalizes", "an", "expression", "as", "a", "timestamp", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFormatter.php#L228-L241
train
yiisoft/yii
framework/utils/CFormatter.php
CFormatter.formatUrl
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); }
php
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); }
[ "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. @param mixed $value the value to be formatted @return string the formatted result
[ "Formats", "the", "value", "as", "a", "hyperlink", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFormatter.php#L279-L285
train
yiisoft/yii
framework/utils/CFormatter.php
CFormatter.formatSize
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); } }
php
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); } }
[ "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. @param integer $value value in bytes to be formatted @param boolean $verbose if full names should be used (e.g. bytes, kilobytes, ...). Defaults to false meaning that short names will be used (e.g. B, KB, ...). @return string the formatted result @see sizeFormat @since 1.1.11
[ "Formats", "the", "value", "in", "bytes", "as", "a", "size", "in", "human", "readable", "form", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/utils/CFormatter.php#L318-L341
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.run
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(); // named and unnamed options 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]); } // try global options 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; }
php
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(); // named and unnamed options 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]); } // try global options 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; }
[ "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", "(", ")", ";", "// named and unnamed options", "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", "]", ")", ";", "}", "// try global options", "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 @param array $args command line parameters for this command. @return integer application exit code, which is returned by the invoked action. 0 if the action did not return anything. (return value is available since version 1.1.11)
[ "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" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L117-L176
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.beforeAction
protected function beforeAction($action,$params) { if($this->hasEventHandler('onBeforeAction')) { $event = new CConsoleCommandEvent($this,$params,$action); $this->onBeforeAction($event); return !$event->stopCommand; } else { return true; } }
php
protected function beforeAction($action,$params) { if($this->hasEventHandler('onBeforeAction')) { $event = new CConsoleCommandEvent($this,$params,$action); $this->onBeforeAction($event); return !$event->stopCommand; } else { return true; } }
[ "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. @param string $action the action name @param array $params the parameters to be passed to the action method. @return boolean whether the action should be executed.
[ "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", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L185-L197
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.afterAction
protected function afterAction($action,$params,$exitCode=0) { $event=new CConsoleCommandEvent($this,$params,$action,$exitCode); if($this->hasEventHandler('onAfterAction')) $this->onAfterAction($event); return $event->exitCode; }
php
protected function afterAction($action,$params,$exitCode=0) { $event=new CConsoleCommandEvent($this,$params,$action,$exitCode); if($this->hasEventHandler('onAfterAction')) $this->onAfterAction($event); return $event->exitCode; }
[ "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. @param string $action the action name @param array $params the parameters to be passed to the action method. @param integer $exitCode the application exit code returned by the action method. @return integer application exit code (return value is available since version 1.1.11)
[ "This", "method", "is", "invoked", "right", "after", "an", "action", "finishes", "execution", ".", "You", "may", "override", "this", "method", "to", "do", "some", "postprocessing", "for", "the", "action", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L207-L213
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.resolveRequest
protected function resolveRequest($args) { $options=array(); // named parameters $params=array(); // unnamed parameters foreach($args as $arg) { if(preg_match('/^--(\w+)(=(.*))?$/',$arg,$matches)) // an option { $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); }
php
protected function resolveRequest($args) { $options=array(); // named parameters $params=array(); // unnamed parameters foreach($args as $arg) { if(preg_match('/^--(\w+)(=(.*))?$/',$arg,$matches)) // an option { $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); }
[ "protected", "function", "resolveRequest", "(", "$", "args", ")", "{", "$", "options", "=", "array", "(", ")", ";", "// named parameters", "$", "params", "=", "array", "(", ")", ";", "// unnamed parameters", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "if", "(", "preg_match", "(", "'/^--(\\w+)(=(.*))?$/'", ",", "$", "arg", ",", "$", "matches", ")", ")", "// an option", "{", "$", "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. @param array $args command line arguments @return array the action name, named options (name=>value), and unnamed options @since 1.1.5
[ "Parses", "the", "command", "line", "arguments", "and", "determines", "which", "action", "to", "perform", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L221-L249
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.getHelp
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; }
php
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; }
[ "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. @return string the command description. Defaults to 'Usage: php entry-script.php command-name'.
[ "Provides", "the", "command", "description", ".", "This", "method", "may", "be", "overridden", "to", "return", "the", "actual", "command", "description", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L272-L284
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.getOptionHelp
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; }
php
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; }
[ "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. @return array the command option help information. Each array element describes the help information for a single action. @since 1.1.5
[ "Provides", "the", "command", "option", "help", "information", ".", "The", "default", "implementation", "will", "return", "all", "available", "actions", "together", "with", "their", "corresponding", "option", "information", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L294-L328
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.copyFiles
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); } }
php
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); } }
[ "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. @param array $fileList the list of files to be copied (name=>spec). The array keys are names displayed during the copy process, and array values are specifications for files to be copied. Each array value must be an array of the following structure: <ul> <li>source: required, the full path of the file/directory to be copied from</li> <li>target: required, the full path of the file/directory to be copied to</li> <li>callback: optional, the callback to be invoked when copying a file. The callback function should be declared as follows: <pre> function foo($source,$params) </pre> where $source parameter is the source file path, and the content returned by the function will be saved into the target file.</li> <li>params: optional, the parameters to be passed to the callback</li> </ul> @param boolean $overwriteAll whether to overwrite all files. @see buildFileList
[ "Copies", "a", "list", "of", "files", "from", "one", "place", "to", "another", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L361-L417
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.ensureDirectory
public function ensureDirectory($directory) { if(!is_dir($directory)) { $this->ensureDirectory(dirname($directory)); echo " mkdir ".strtr($directory,'\\','/')."\n"; mkdir($directory); } }
php
public function ensureDirectory($directory) { if(!is_dir($directory)) { $this->ensureDirectory(dirname($directory)); echo " mkdir ".strtr($directory,'\\','/')."\n"; mkdir($directory); } }
[ "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. @param string $directory the directory to be checked
[ "Creates", "all", "parent", "directories", "if", "they", "do", "not", "exist", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L457-L465
train
yiisoft/yii
framework/console/CConsoleCommand.php
CConsoleCommand.pluralize
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'; }
php
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'; }
[ "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. @param string $name the word to be pluralized @return string the pluralized word
[ "Converts", "a", "word", "to", "its", "plural", "form", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommand.php#L496-L524
train
yiisoft/yii
framework/db/schema/pgsql/CPgsqlSchema.php
CPgsqlSchema.findPrimaryKey
protected function findPrimaryKey($table,$indices) { $indices=implode(', ',preg_split('/\s+/',$indices)); $sql=<<<EOD SELECT 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; } } }
php
protected function findPrimaryKey($table,$indices) { $indices=implode(', ',preg_split('/\s+/',$indices)); $sql=<<<EOD SELECT 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; } } }
[ "protected", "function", "findPrimaryKey", "(", "$", "table", ",", "$", "indices", ")", "{", "$", "indices", "=", "implode", "(", "', '", ",", "preg_split", "(", "'/\\s+/'", ",", "$", "indices", ")", ")", ";", "$", "sql", "=", "<<<EOD\nSELECT attnum, attname FROM pg_catalog.pg_attribute WHERE\n\tattrelid=(\n\t\tSELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=(\n\t\t\tSELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema\n\t\t)\n\t)\n\tAND attnum IN ({$indices})\nEOD", ";", "$", "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. @param CPgsqlTableSchema $table the table metadata @param string $indices pgsql primary key index list
[ "Collects", "primary", "key", "information", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/pgsql/CPgsqlSchema.php#L286-L315
train
yiisoft/yii
framework/db/schema/pgsql/CPgsqlSchema.php
CPgsqlSchema.findForeignKey
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; } } }
php
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; } } }
[ "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. @param CPgsqlTableSchema $table the table metadata @param string $src pgsql foreign key definition
[ "Collects", "foreign", "key", "information", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/pgsql/CPgsqlSchema.php#L322-L339
train
yiisoft/yii
framework/db/schema/mssql/CMssqlCommandBuilder.php
CMssqlCommandBuilder.createFindCommand
public function createFindCommand($table,$criteria,$alias='t') { $criteria=$this->checkCriteria($table,$criteria); return parent::createFindCommand($table,$criteria,$alias); }
php
public function createFindCommand($table,$criteria,$alias='t') { $criteria=$this->checkCriteria($table,$criteria); return parent::createFindCommand($table,$criteria,$alias); }
[ "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 @param CDbTableSchema $table the table metadata @param CDbCriteria $criteria the query criteria @param string $alias the alias name of the primary table. Defaults to 't'. @return CDbCommand query command.
[ "Creates", "a", "SELECT", "command", "for", "a", "single", "table", ".", "Override", "parent", "implementation", "to", "check", "if", "an", "orderby", "clause", "if", "specified", "when", "querying", "with", "an", "offset" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mssql/CMssqlCommandBuilder.php#L45-L50
train
yiisoft/yii
framework/db/schema/mssql/CMssqlCommandBuilder.php
CMssqlCommandBuilder.createUpdateCommand
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; }
php
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; }
[ "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 @param CDbTableSchema $table the table metadata @param array $data list of columns to be updated (name=>value) @param CDbCriteria $criteria the query criteria @throws CDbException if no columns are being updated @return CDbCommand update command.
[ "Creates", "an", "UPDATE", "command", ".", "Override", "parent", "implementation", "because", "mssql", "don", "t", "want", "to", "update", "an", "identity", "column" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mssql/CMssqlCommandBuilder.php#L61-L106
train
yiisoft/yii
framework/db/schema/mssql/CMssqlCommandBuilder.php
CMssqlCommandBuilder.createDeleteCommand
public function createDeleteCommand($table,$criteria) { $criteria=$this->checkCriteria($table, $criteria); return parent::createDeleteCommand($table, $criteria); }
php
public function createDeleteCommand($table,$criteria) { $criteria=$this->checkCriteria($table, $criteria); return parent::createDeleteCommand($table, $criteria); }
[ "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 @param CDbTableSchema $table the table metadata @param CDbCriteria $criteria the query criteria @return CDbCommand delete command.
[ "Creates", "a", "DELETE", "command", ".", "Override", "parent", "implementation", "to", "check", "if", "an", "orderby", "clause", "if", "specified", "when", "querying", "with", "an", "offset" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mssql/CMssqlCommandBuilder.php#L115-L119
train
yiisoft/yii
framework/db/schema/mssql/CMssqlCommandBuilder.php
CMssqlCommandBuilder.applyJoin
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); }
php
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); }
[ "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. @param string $sql the SQL statement to be altered @param string $join the JOIN clause (starting with join type, such as INNER JOIN) @return string the altered SQL statement
[ "Alters", "the", "SQL", "to", "apply", "JOIN", "clause", ".", "Overrides", "parent", "implementation", "to", "comply", "with", "the", "DELETE", "command", "syntax", "required", "when", "multiple", "tables", "are", "referenced", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mssql/CMssqlCommandBuilder.php#L143-L148
train
yiisoft/yii
framework/db/schema/mssql/CMssqlCommandBuilder.php
CMssqlCommandBuilder.applyLimit
public function applyLimit($sql, $limit, $offset) { $limit = $limit!==null ? (int)$limit : -1; $offset = $offset!==null ? (int)$offset : -1; if ($limit > 0 && $offset <= 0) //just limit $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; }
php
public function applyLimit($sql, $limit, $offset) { $limit = $limit!==null ? (int)$limit : -1; $offset = $offset!==null ? (int)$offset : -1; if ($limit > 0 && $offset <= 0) //just limit $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; }
[ "public", "function", "applyLimit", "(", "$", "sql", ",", "$", "limit", ",", "$", "offset", ")", "{", "$", "limit", "=", "$", "limit", "!==", "null", "?", "(", "int", ")", "$", "limit", ":", "-", "1", ";", "$", "offset", "=", "$", "offset", "!==", "null", "?", "(", "int", ")", "$", "offset", ":", "-", "1", ";", "if", "(", "$", "limit", ">", "0", "&&", "$", "offset", "<=", "0", ")", "//just limit", "$", "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. Overrides parent implementation. Alters the sql to apply $limit and $offset. The idea for limit with offset is done by modifying the sql on the fly with numerous assumptions on the structure of the sql string. The modification is done with reference to the notes from http://troels.arvin.dk/db/rdbms/#select-limit-offset <code> SELECT * FROM ( SELECT TOP n * FROM ( SELECT TOP z columns -- (z=n+skip) FROM tablename ORDER BY key ASC ) AS FOO ORDER BY key DESC -- ('FOO' may be anything) ) AS BAR ORDER BY key ASC -- ('BAR' may be anything) </code> <b>Regular expressions are used to alter the SQL query. The resulting SQL query may be malformed for complex queries.</b> The following restrictions apply <ul> <li> In particular, <b>commas</b> should <b>NOT</b> be used as part of the ordering expression or identifier. Commas must only be used for separating the ordering clauses. </li> <li> In the ORDER BY clause, the column name should NOT be be qualified with a table name or view name. Alias the column names or use column index. </li> <li> No clauses should follow the ORDER BY clause, e.g. no COMPUTE or FOR clauses. </li> </ul> @param string $sql SQL query string. @param integer $limit maximum number of rows, -1 to ignore limit. @param integer $offset row offset, -1 to ignore offset. @return string SQL with limit and offset. @author Wei Zhuo <weizhuo[at]gmail[dot]com>
[ "This", "is", "a", "port", "from", "Prado", "Framework", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mssql/CMssqlCommandBuilder.php#L194-L203
train
yiisoft/yii
framework/logging/CSysLogRoute.php
CSysLogRoute.processLogs
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(); }
php
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(); }
[ "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. @param array $logs list of log messages.
[ "Sends", "log", "messages", "to", "syslog", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/logging/CSysLogRoute.php#L35-L49
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CActiveFinder.query
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; }
php
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; }
[ "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. @param CDbCriteria $criteria the DB criteria @param boolean $all whether to bring back all records @return mixed the query result
[ "Do", "not", "call", "this", "method", ".", "This", "method", "is", "used", "internally", "to", "perform", "the", "relational", "query", "based", "on", "the", "given", "DB", "criteria", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L58-L90
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.destroy
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); }
php
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); }
[ "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.
[ "Removes", "references", "to", "child", "elements", "and", "finder", "to", "avoid", "circular", "references", ".", "This", "is", "internally", "used", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L419-L427
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.find
public function find($criteria=null) { if($this->_parent===null) // root element { $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)) // not joined before { $query=new CJoinQuery($this->_parent); $this->_joined=true; $query->join($this); $this->buildQuery($query); $this->_parent->runQuery($query); } foreach($this->children as $child) // find recursively $child->find(); foreach($this->stats as $stat) $stat->query(); }
php
public function find($criteria=null) { if($this->_parent===null) // root element { $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)) // not joined before { $query=new CJoinQuery($this->_parent); $this->_joined=true; $query->join($this); $this->buildQuery($query); $this->_parent->runQuery($query); } foreach($this->children as $child) // find recursively $child->find(); foreach($this->stats as $stat) $stat->query(); }
[ "public", "function", "find", "(", "$", "criteria", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_parent", "===", "null", ")", "// root element", "{", "$", "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", ")", ")", "// not joined before", "{", "$", "query", "=", "new", "CJoinQuery", "(", "$", "this", "->", "_parent", ")", ";", "$", "this", "->", "_joined", "=", "true", ";", "$", "query", "->", "join", "(", "$", "this", ")", ";", "$", "this", "->", "buildQuery", "(", "$", "query", ")", ";", "$", "this", "->", "_parent", "->", "runQuery", "(", "$", "query", ")", ";", "}", "foreach", "(", "$", "this", "->", "children", "as", "$", "child", ")", "// find recursively", "$", "child", "->", "find", "(", ")", ";", "foreach", "(", "$", "this", "->", "stats", "as", "$", "stat", ")", "$", "stat", "->", "query", "(", ")", ";", "}" ]
Performs the recursive finding with the criteria. @param CDbCriteria $criteria the query criteria
[ "Performs", "the", "recursive", "finding", "with", "the", "criteria", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L433-L457
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.lazyFind
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 // has_many and many_many { 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); } } }
php
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 // has_many and many_many { 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); } } }
[ "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", "// has_many and many_many", "{", "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. @param CActiveRecord $baseRecord the active record whose related object is to be fetched.
[ "Performs", "lazy", "find", "with", "the", "specified", "base", "record", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L463-L529
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.findWithBase
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(); }
php
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(); }
[ "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. @param mixed $baseRecords the available base record(s).
[ "Performs", "the", "eager", "loading", "with", "the", "base", "records", "ready", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L693-L722
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.count
public function count($criteria=null) { $query=new CJoinQuery($this,$criteria); // ensure only one big join statement is used $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(); } }
php
public function count($criteria=null) { $query=new CJoinQuery($this,$criteria); // ensure only one big join statement is used $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(); } }
[ "public", "function", "count", "(", "$", "criteria", "=", "null", ")", "{", "$", "query", "=", "new", "CJoinQuery", "(", "$", "this", ",", "$", "criteria", ")", ";", "// ensure only one big join statement is used", "$", "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. @param CDbCriteria $criteria the query criteria @return string number of primary records. Note: type is string to keep max. precision.
[ "Count", "the", "number", "of", "primary", "records", "returned", "by", "the", "join", "statement", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L729-L768
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.buildQuery
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); } } }
php
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); } } }
[ "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. @param CJoinQuery $query the query being built up
[ "Builds", "the", "join", "query", "with", "all", "descendant", "HAS_ONE", "and", "BELONGS_TO", "nodes", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L787-L801
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.runQuery
public function runQuery($query) { $command=$query->createCommand($this->_builder); foreach($command->queryAll() as $row) $this->populateRecord($query,$row); }
php
public function runQuery($query) { $command=$query->createCommand($this->_builder); foreach($command->queryAll() as $row) $this->populateRecord($query,$row); }
[ "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. @param CJoinQuery $query the query to be executed.
[ "Executes", "the", "join", "query", "and", "populates", "the", "query", "results", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L807-L812
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.populateRecord
private function populateRecord($query,$row) { // determine the primary key value if(is_string($this->_pkAlias)) // single key { if(isset($row[$this->_pkAlias])) $pk=$row[$this->_pkAlias]; else // no matching related objects return null; } else // is_array, composite key { $pk=array(); foreach($this->_pkAlias as $name=>$alias) { if(isset($row[$alias])) $pk[$name]=$row[$alias]; else // no matching related objects return null; } $pk=serialize($pk); } // retrieve or populate the record according to the primary key value 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; } // populate child records recursively 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 // has_many and many_many { // need to double check to avoid adding duplicated related objects 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; }
php
private function populateRecord($query,$row) { // determine the primary key value if(is_string($this->_pkAlias)) // single key { if(isset($row[$this->_pkAlias])) $pk=$row[$this->_pkAlias]; else // no matching related objects return null; } else // is_array, composite key { $pk=array(); foreach($this->_pkAlias as $name=>$alias) { if(isset($row[$alias])) $pk[$name]=$row[$alias]; else // no matching related objects return null; } $pk=serialize($pk); } // retrieve or populate the record according to the primary key value 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; } // populate child records recursively 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 // has_many and many_many { // need to double check to avoid adding duplicated related objects 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; }
[ "private", "function", "populateRecord", "(", "$", "query", ",", "$", "row", ")", "{", "// determine the primary key value", "if", "(", "is_string", "(", "$", "this", "->", "_pkAlias", ")", ")", "// single key", "{", "if", "(", "isset", "(", "$", "row", "[", "$", "this", "->", "_pkAlias", "]", ")", ")", "$", "pk", "=", "$", "row", "[", "$", "this", "->", "_pkAlias", "]", ";", "else", "// no matching related objects", "return", "null", ";", "}", "else", "// is_array, composite key", "{", "$", "pk", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_pkAlias", "as", "$", "name", "=>", "$", "alias", ")", "{", "if", "(", "isset", "(", "$", "row", "[", "$", "alias", "]", ")", ")", "$", "pk", "[", "$", "name", "]", "=", "$", "row", "[", "$", "alias", "]", ";", "else", "// no matching related objects", "return", "null", ";", "}", "$", "pk", "=", "serialize", "(", "$", "pk", ")", ";", "}", "// retrieve or populate the record according to the primary key value", "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", ";", "}", "// populate child records recursively", "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", "// has_many and many_many", "{", "// need to double check to avoid adding duplicated related objects", "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. @param CJoinQuery $query the query executed @param array $row a row of data @return CActiveRecord the populated record
[ "Populates", "the", "active", "records", "with", "the", "query", "data", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L820-L892
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinElement.joinOneMany
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 // FK constraints undefined { if(is_array($pke->_table->primaryKey)) // composite PK $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).')'; }
php
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 // FK constraints undefined { if(is_array($pke->_table->primaryKey)) // composite PK $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).')'; }
[ "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", "// FK constraints undefined", "{", "if", "(", "is_array", "(", "$", "pke", "->", "_table", "->", "primaryKey", ")", ")", "// composite PK", "$", "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. @param CJoinElement $fke the join element containing foreign keys @param array $fks the foreign keys @param CJoinElement $pke the join element contains primary keys @param CJoinElement $parent the parent join element @return string the join statement @throws CDbException if a foreign key is invalid
[ "Generates", "the", "join", "statement", "for", "one", "-", "many", "relationship", ".", "This", "works", "for", "HAS_ONE", "HAS_MANY", "and", "BELONGS_TO", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L1088-L1129
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinQuery.join
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; }
php
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; }
[ "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 @param CJoinElement $element the element to be joined
[ "Joins", "with", "another", "join", "element" ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L1312-L1333
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CJoinQuery.createCommand
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; }
php
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; }
[ "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. @param CDbCommandBuilder $builder the command builder @return CDbCommand DB command instance representing the SQL statement
[ "Creates", "the", "SQL", "statement", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L1340-L1377
train
yiisoft/yii
framework/db/ar/CActiveFinder.php
CStatElement.query
public function query() { if(preg_match('/^\s*(.*?)\((.*)\)\s*$/',$this->relation->foreignKey,$matches)) $this->queryManyMany($matches[1],$matches[2]); else $this->queryOneMany(); }
php
public function query() { if(preg_match('/^\s*(.*?)\((.*)\)\s*$/',$this->relation->foreignKey,$matches)) $this->queryManyMany($matches[1],$matches[2]); else $this->queryOneMany(); }
[ "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.
[ "Performs", "the", "STAT", "query", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/ar/CActiveFinder.php#L1414-L1420
train
yiisoft/yii
framework/web/widgets/CTabView.php
CTabView.renderHeader
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"; }
php
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"; }
[ "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.
[ "Renders", "the", "header", "part", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CTabView.php#L182-L193
train
yiisoft/yii
framework/web/widgets/CTabView.php
CTabView.renderBody
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} -->\n"; } }
php
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} -->\n"; } }
[ "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} -->\\n\"", ";", "}", "}" ]
Renders the body part.
[ "Renders", "the", "body", "part", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CTabView.php#L198-L221
train
yiisoft/yii
framework/web/widgets/CTreeView.php
CTreeView.init
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); }
php
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); }
[ "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.
[ "Initializes", "the", "widget", ".", "This", "method", "registers", "all", "needed", "client", "scripts", "and", "renders", "the", "tree", "view", "content", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CTreeView.php#L134-L154
train
yiisoft/yii
framework/web/widgets/CTreeView.php
CTreeView.saveDataAsHtml
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; }
php
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; }
[ "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. @param array $data the data for the tree view (see {@link data} for possible data structure). @return string the generated HTML for the tree view
[ "Generates", "tree", "view", "nodes", "in", "HTML", "from", "the", "data", "array", "." ]
af3cbce71db83c4476c8a4289517b2984c740f31
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CTreeView.php#L183-L228
train