_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 33
8k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q263400
|
Collection.get_model
|
test
|
public function get_model( $pk ) {
$i = $this->get_model_index( $pk
|
php
|
{
"resource": ""
}
|
q263401
|
Collection.remove_model
|
test
|
public function remove_model( $pk ) {
$i = $this->get_model_index( $pk
|
php
|
{
"resource": ""
}
|
q263402
|
Collection.get_model_index
|
test
|
protected function get_model_index( $pk ) {
if ( isset( $this->pk_map[ $pk ] ) ) {
return $this->pk_map[ $pk ];
}
foreach ( $this->elements as $i => $element ) {
if (
|
php
|
{
"resource": ""
}
|
q263403
|
Collection.save
|
test
|
public function save( array $options = array() ) {
foreach ( $this->elements as $element ) {
|
php
|
{
"resource": ""
}
|
q263404
|
InternalQueryHelper.prefixWhereWithTable
|
test
|
public function prefixWhereWithTable($data, $tableName)
{
if (count($data) == 0) {
return $data;
}
foreach ($data as $key => $v) {
$newKey = $tableName . '.' . trim($key,
|
php
|
{
"resource": ""
}
|
q263405
|
InternalQueryHelper.prefixOrderWithTable
|
test
|
public function prefixOrderWithTable($data, $tableName)
{
if (count($data) == 0) {
return $data;
}
foreach ($data as $key => $v) {
// if $v is empty, we have a custom order like RAND() and do not have to prefix
if (!empty($v)) {
|
php
|
{
"resource": ""
}
|
q263406
|
BaseColumn.get_definition_without_column_name
|
test
|
protected function get_definition_without_column_name( array $exclude_options = array() ) {
$definition = $this->get_mysql_type();
if ( $this->type_options ) {
$definition .= '(' . implode( ',', $this->type_options ) . ')';
}
if ( $this->options ) {
|
php
|
{
"resource": ""
}
|
q263407
|
Manager.register
|
test
|
public static function register( Table $table, $complex_query_class = '', $model_class = '' ) {
if ( $complex_query_class && ! is_subclass_of( $complex_query_class, 'IronBound\DB\Query\Complex_Query' ) ) {
throw new \InvalidArgumentException( '$complex_query_class must subclass Complex_Query' );
}
if ( $model_class && ! is_subclass_of( $model_class, 'IronBound\DB\Model' ) ) {
throw new \InvalidArgumentException( '$model_class must subclass Model.' );
}
static::$tables[ $table->get_slug() ] = array(
'table' => $table,
'query'
|
php
|
{
"resource": ""
}
|
q263408
|
Manager.make_simple_query_object
|
test
|
public static function make_simple_query_object( $slug, \wpdb $wpdb = null ) {
$table = static::get( $slug );
$wpdb = $wpdb ?: $GLOBALS['wpdb'];
if ( $table ) {
|
php
|
{
"resource": ""
}
|
q263409
|
Manager.make_complex_query_object
|
test
|
public static function make_complex_query_object( $slug, array $args = array() ) {
$table = static::get( $slug );
if ( empty( $table ) || empty( static::$tables[ $slug ]['query'] ) ) {
return null;
|
php
|
{
"resource": ""
}
|
q263410
|
Manager.get_model
|
test
|
public static function get_model( $slug ) {
$slug = $slug instanceof Table ? $slug->get_slug() :
|
php
|
{
"resource": ""
}
|
q263411
|
Manager.maybe_install_table
|
test
|
public static function maybe_install_table( Table $table, \wpdb $wpdb = null ) {
$wpdb = $wpdb ?: $GLOBALS['wpdb'];
$installed = (int) get_option( $table->get_table_name( $wpdb ) . '_version', 0 );
if ( $installed >= $table->get_version() ) {
return false;
}
if ( $installed === 0 ) {
if ( ! static::is_table_installed( $table, $wpdb ) ) {
$prev = $wpdb->show_errors( false );
$wpdb->query( $table->get_creation_sql( $wpdb ) );
$wpdb->show_errors( $prev );
if ( $wpdb->last_error ) {
throw new Exception( $wpdb->last_error );
}
static::fire_plugin_event( $table, 'installed' );
}
} else {
$update = $installed + 1;
while ( $update <= $table->get_version() ) {
if ( method_exists(
|
php
|
{
"resource": ""
}
|
q263412
|
Manager.maybe_uninstall_table
|
test
|
public static function maybe_uninstall_table( Table $table, \wpdb $wpdb = null ) {
$wpdb = $wpdb ?: $GLOBALS['wpdb'];
if ( static::is_table_installed( $table, $wpdb ) ) {
$tn = $table->get_table_name( $wpdb );
$wpdb->query(
|
php
|
{
"resource": ""
}
|
q263413
|
Manager.is_table_installed
|
test
|
public static function is_table_installed( Table $table, \wpdb $wpdb = null ) {
$wpdb = $wpdb ?: $GLOBALS['wpdb'];
$name = $table->get_table_name( $wpdb );
|
php
|
{
"resource": ""
}
|
q263414
|
Manager.fire_plugin_event
|
test
|
protected static function fire_plugin_event( Table $table, $event, $args = array() ) {
foreach ( static::$plugins as $plugin ) {
if ( $plugin->accepts( $table ) ) {
if ( method_exists( $plugin, $event )
|
php
|
{
"resource": ""
}
|
q263415
|
PostSaver.do_save
|
test
|
protected function do_save( \WP_Post $post ) {
if ( ! $post->ID ) {
$id = wp_insert_post( wp_slash( $post->to_array() ), true );
} else {
$id = wp_update_post( $post, true );
}
if ( is_wp_error( $id
|
php
|
{
"resource": ""
}
|
q263416
|
SimpleForeign.get_column
|
test
|
protected function get_column() {
$column = $this->foreign_column ?: $this->foreign_table->get_primary_key();
$columns =
|
php
|
{
"resource": ""
}
|
q263417
|
InMemoryTable.parse_defaults
|
test
|
protected function parse_defaults( array $columns ) {
foreach ( $columns as $column_name => $column ) {
if ( array_key_exists( $column_name, $this->defaults ) ) {
continue;
}
switch ( $column->get_mysql_type() ) {
case 'TINYINT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'INT':
case 'BIGINT':
$this->defaults[ $column_name ] = 0;
break;
|
php
|
{
"resource": ""
}
|
q263418
|
FluentQuery.from_model
|
test
|
public static function from_model( $model ) {
$query = new static( $model::table(), $GLOBALS['wpdb']
|
php
|
{
"resource": ""
}
|
q263419
|
FluentQuery.select
|
test
|
public function select( $columns ) {
if ( $columns === Select::ALL ) {
$this->select->all( $this->alias );
return $this;
}
if ( ! is_array( $columns ) ) {
$columns = func_get_args();
}
foreach ( $columns as $column ) {
|
php
|
{
"resource": ""
}
|
q263420
|
FluentQuery.select_single
|
test
|
public function select_single( $column ) {
$this->select->also( $this->prepare_column( $column ) );
|
php
|
{
"resource": ""
}
|
q263421
|
FluentQuery.select_all
|
test
|
public function select_all( $local_only = true ) {
$this->select->all( $local_only ?
|
php
|
{
"resource": ""
}
|
q263422
|
FluentQuery.expression
|
test
|
public function expression( $function, $column, $as ) {
$this->select->expression( $function, $this->prepare_column( $column ),
|
php
|
{
"resource": ""
}
|
q263423
|
FluentQuery.where
|
test
|
public function where( $column, $equality = '', $value = '', Closure $callback = null, $boolean = null ) {
if ( $equality ) {
$this->assert_comparator( $equality );
}
if ( is_array( $column ) ) {
$where = Where::for_clause();
foreach ( $column as $col => $val ) {
$where->qAnd( $this->generate_where_tag( $col, true, $val )
|
php
|
{
"resource": ""
}
|
q263424
|
FluentQuery.generate_where_tag
|
test
|
protected function generate_where_tag( $column, $equality = '', $value = '' ) {
if ( $column instanceof Where ) {
return $column;
}
if ( is_array( $value ) ) {
if ( count( $value ) === 0 ) {
throw new \InvalidArgumentException( 'Must provide at least one value for IN query.' );
}
$self = $this;
$value = array_map( function ( $value ) use ( $column, $self )
|
php
|
{
"resource": ""
}
|
q263425
|
FluentQuery.add_nested_where
|
test
|
public function add_nested_where( Closure $callback, $boolean = 'and' ) {
$_where = $this->where;
$this->where = Where::for_clause();
$callback( $this );
|
php
|
{
"resource": ""
}
|
q263426
|
FluentQuery.where_joined
|
test
|
public function where_joined( Table $table, Closure $callback, $boolean = 'and' ) {
$found = false;
foreach ( $this->joined_tables as $alias => $maybe_table ) {
if ( $maybe_table->get_slug() === $table->get_slug() ) {
$found = $alias;
break;
}
}
if ( ! $found ) {
throw new \InvalidArgumentException( "Table {$table->get_slug()} has not already been joined to this table." );
}
$other_query = new FluentQuery(
|
php
|
{
"resource": ""
}
|
q263427
|
FluentQuery.or_where
|
test
|
public function or_where( $column, $equality = '', $value = '', Closure $callback = null ) {
return $this->where(
|
php
|
{
"resource": ""
}
|
q263428
|
FluentQuery.where_date
|
test
|
public function where_date( $query, $column, Closure $callback = null, $boolean = 'and' ) {
$query = new \WP_Date_Query( $query, $this->prepare_column( $column ) );
|
php
|
{
"resource": ""
}
|
q263429
|
FluentQuery.where_meta
|
test
|
public function where_meta( $query, MetaTable $table = null, $meta_type = '' ) {
if ( ! $table && $this->model && method_exists( $this->model, 'get_meta_table' ) ) {
$table = call_user_func( array( $this->model, 'get_meta_table' ) );
}
if ( ! $meta_type && $this->model && method_exists( $this->model, 'get_meta_type' ) ) {
$meta_type = call_user_func( array( $this->model, 'get_meta_type' ) );
}
if ( ! $table ) {
throw new \InvalidArgumentException( "MetaTable can't be determined from the given arguments." );
}
if ( ! $meta_type ) {
throw new \InvalidArgumentException( "\$meta_type can't be determined from the given arguments." );
}
if ( ! $query instanceof \WP_Meta_Query ) {
$query = new \WP_Meta_Query( $query );
}
$fn = function ( $key, $original ) use ( $table, $meta_type ) {
if ( $original === $meta_type . '_id' ) {
|
php
|
{
"resource": ""
}
|
q263430
|
FluentQuery.order_by
|
test
|
public function order_by( $column, $direction = null ) {
$column = $this->prepare_column( $column );
if (
|
php
|
{
"resource": ""
}
|
q263431
|
FluentQuery.order_by_expression
|
test
|
public function order_by_expression( $expression_alias, $direction = null ) {
if ( ! in_array( $expression_alias, $this->expressions, true ) ) {
throw new InvalidColumnException( 'Cannot order by expression alias because the alias has not been used.' );
}
|
php
|
{
"resource": ""
}
|
q263432
|
FluentQuery.group_by
|
test
|
public function group_by( $column ) {
$column = $this->prepare_column( $column );
if ( is_null( $this->group ) ) {
$this->group
|
php
|
{
"resource": ""
}
|
q263433
|
FluentQuery.group_by_expression
|
test
|
public function group_by_expression( $function, $column ) {
$column = $this->prepare_column( $column );
$group =
|
php
|
{
"resource": ""
}
|
q263434
|
FluentQuery.join
|
test
|
public function join( Table $table, $this_column, $other_column, $comparator = '=', $callback = null, $type = 'INNER' ) {
$this->assert_comparator( $comparator );
$other_alias = 't' . ( ++ $this->alias_count );
$other_query = new FluentQuery( $table, $this->wpdb );
$other_query->alias = $other_alias;
$other_query->alias_count = $this->alias_count + 1;
$other_query->joined_tables = $this->joined_tables;
$other_query->joined_tables[ $this->alias ] = $this->table;
$from = new From( $table->get_table_name( $this->wpdb ), $other_alias
|
php
|
{
"resource": ""
}
|
q263435
|
FluentQuery.join_correlated_subquery
|
test
|
public function join_correlated_subquery( Table $table, $this_column, $comparator, $other_column, Closure $callback, $type = 'INNER' ) {
$this->assert_comparator( $comparator );
$other_alias = 't' . ( ++ $this->alias_count );
$other_query = new FluentQuery( $table, $this->wpdb );
$other_query->from = new From( $table->get_table_name( $this->wpdb ), $other_alias );
$other_query->alias = $other_alias;
$other_query->alias_count = $this->alias_count + 1;
$other_query->joined_tables = $this->joined_tables;
$other_query->joined_tables[ $this->alias ] = $this->table;
|
php
|
{
"resource": ""
}
|
q263436
|
FluentQuery.paginate
|
test
|
public function paginate( $page, $per_page ) {
$this->count = $per_page;
$this->offset = $per_page * ( $page -
|
php
|
{
"resource": ""
}
|
q263437
|
FluentQuery.each
|
test
|
public function each( $number, $callback ) {
$this->offset = 0;
$this->count = $number;
$query = clone $this;
do {
$_query = clone $query;
$results = $query->results();
foreach ( $results as $result ) {
if ( $callback( $result ) === false ) {
return false;
}
|
php
|
{
"resource": ""
}
|
q263438
|
FluentQuery.with
|
test
|
public function with( $relations, $callback = null ) {
$default = null;
if ( is_string( $relations ) ) {
$relations = func_get_args();
if ( func_num_args() === 2 && $relations[1] instanceof Closure ) {
$relations = array(
$relations[0] => $relations[1],
|
php
|
{
"resource": ""
}
|
q263439
|
FluentQuery.parse_nested_with
|
test
|
protected function parse_nested_with( $name, $results ) {
$parts = explode( '.', $name );
|
php
|
{
"resource": ""
}
|
q263440
|
FluentQuery.assign_array_by_path
|
test
|
protected function assign_array_by_path( &$arr, $path, $value ) {
$keys = explode( '.', $path );
foreach
|
php
|
{
"resource": ""
}
|
q263441
|
FluentQuery.make_limit_tag
|
test
|
protected function make_limit_tag() {
if ( ! $this->count ) {
return $this;
}
|
php
|
{
"resource": ""
}
|
q263442
|
FluentQuery.build_sql
|
test
|
protected function build_sql() {
$this->make_limit_tag();
$builder = new Builder();
if ( ! $this->select->is_all() && ! $this->select->get_columns() ) {
$this->select->all( $this->alias );
}
$this->select->calc_found_rows( $this->calc_found_rows );
$builder->append( $this->select );
$builder->append( $this->from );
foreach ( $this->joins as $join
|
php
|
{
"resource": ""
}
|
q263443
|
FluentQuery.update_meta_cache
|
test
|
protected function update_meta_cache() {
$ids = $this->results->getKeys();
$table = $this->meta_table ?: call_user_func( array( $this->model, 'get_meta_table' ) );
$meta_type = $this->meta_type ?: call_user_func( array( $this->model, 'get_meta_type' ) );
$fn = function ( $key, $original ) use ( $table, $meta_type ) {
if ( $original === $meta_type . '_id' ) {
|
php
|
{
"resource": ""
}
|
q263444
|
FluentQuery.find
|
test
|
public function find( $primary_key ) {
if ( is_array( $primary_key ) ) {
return $this->find_many( $primary_key );
}
|
php
|
{
"resource": ""
}
|
q263445
|
FluentQuery.find_many
|
test
|
public function find_many( array $primary_keys ) {
return
|
php
|
{
"resource": ""
}
|
q263446
|
FluentQuery.find_or_fail
|
test
|
public function find_or_fail( $primary_key ) {
$result = $this->find( $primary_key );
if ( is_array( $primary_key ) ) {
if ( count( $result ) == count( array_unique( $primary_key ) ) ) {
return $result;
|
php
|
{
"resource": ""
}
|
q263447
|
FluentQuery.find_or_new
|
test
|
public function find_or_new( $primary_key ) {
$model = $this->find( $primary_key
|
php
|
{
"resource": ""
}
|
q263448
|
FluentQuery.first_or_new
|
test
|
public function first_or_new( array $attributes ) {
$model = $this->where( $attributes )->first();
if ( $model ) {
|
php
|
{
"resource": ""
}
|
q263449
|
FluentQuery.first_or_create
|
test
|
public function first_or_create( array $attributes ) {
$model = $this->where( $attributes )->first();
if ( $model ) {
return $model;
}
|
php
|
{
"resource": ""
}
|
q263450
|
FluentQuery.update_or_create
|
test
|
public function update_or_create( array $attributes, array $values ) {
$model = $this->first_or_new( $attributes );
|
php
|
{
"resource": ""
}
|
q263451
|
FluentQuery.handle_eager_loading
|
test
|
protected function handle_eager_loading( $models ) {
/** @var Model $model */
$model = new $this->model;
foreach ( $this->relations as $relation => $customize_callback ) {
if ( is_array( $customize_callback ) ) {
$loaded = $model->get_relation( $relation )->eager_load( $models );
|
php
|
{
"resource": ""
}
|
q263452
|
FluentQuery.do_nested_eager_load
|
test
|
protected function do_nested_eager_load( Collection $loaded, $relation, $nested ) {
$model = $loaded->first();
foreach ( $nested as $value => $ignore ) {
if ( is_string( $value ) ) {
if ( $model instanceof Model ) {
$model->get_relation( $value )->eager_load( $loaded->toArray() );
}
return;
} else {
if (
|
php
|
{
"resource": ""
}
|
q263453
|
FluentQuery.assert_comparator
|
test
|
protected function assert_comparator( $operator ) {
if ( is_bool( $operator ) ) {
return;
}
if ( in_array( $operator, array(
'=',
'!=',
'>',
'<',
'>=',
'<=',
'<=>',
'<>',
'LIKE',
'BETWEEN',
'COALESCE',
'GREATEST',
'IN',
'INTERVAL',
'IS',
'IS NOT',
'IS NOT NULL',
|
php
|
{
"resource": ""
}
|
q263454
|
FluentQuery.prepare_column
|
test
|
public function prepare_column( $column ) {
$columns = $this->table->get_columns();
if ( ! isset( $columns[ $column ] ) ) {
|
php
|
{
"resource": ""
}
|
q263455
|
FluentQuery.escape_value
|
test
|
public function escape_value( $column, $value ) {
$columns = $this->table->get_columns();
if ( ! isset( $columns[ $column ] ) ) {
throw new InvalidColumnException( "Invalid database column '$column'." );
}
if ( is_null( $value ) ) {
|
php
|
{
"resource": ""
}
|
q263456
|
PicORM.configure
|
test
|
final public static function configure(array $configuration)
{
// override with default configuration if not present
$configuration += static::$_defaultConfiguration;
// test if datasource is a PDO instance
if ($configuration['datasource'] === null || !$configuration['datasource'] instanceof \PDO) {
throw new Exception("PDO Datasource is required!");
}
|
php
|
{
"resource": ""
}
|
q263457
|
Builder.get_col_value
|
test
|
protected final function get_col_value( $col ) {
if ( ! isset( $this->data[ $col ] ) ) {
throw new
|
php
|
{
"resource": ""
}
|
q263458
|
Builder.create
|
test
|
protected function create() {
foreach ( $this->data as $col => $val ) {
if ( method_exists( $this, "validate_$col" ) ) {
$this->data[ $col ] = $this->{"validate_$col"}( $val );
}
}
|
php
|
{
"resource": ""
}
|
q263459
|
Order.then
|
test
|
public function then( $col, $direction = null ) {
if ( $this->is_rand ) {
throw new
|
php
|
{
"resource": ""
}
|
q263460
|
Order.add_order
|
test
|
protected function add_order( $col, $direction ) {
if ( $direction !== null && ! in_array( $direction, array( self::ASC, self::DESC ) ) ) {
|
php
|
{
"resource": ""
}
|
q263461
|
Select.all
|
test
|
public function all( $as = null ) {
$this->all_columns = true;
if ( $as )
|
php
|
{
"resource": ""
}
|
q263462
|
HasOneOrMany.build_eager_load_map
|
test
|
protected function build_eager_load_map( $models ) {
$map = array();
$foreign = $this->foreign_key;
foreach ( $models as $model ) {
$pk = $model->get_raw_attribute( $foreign );
if ( $pk
|
php
|
{
"resource": ""
}
|
q263463
|
CommentSaver.do_save
|
test
|
protected function do_save( $comment ) {
if ( ! $comment->comment_ID ) {
$id = wp_insert_comment( wp_slash( $comment->to_array() ) );
} else {
if ( wp_update_comment( wp_slash( $comment->to_array()
|
php
|
{
"resource": ""
}
|
q263464
|
Complex_Query.get_default_arg
|
test
|
protected function get_default_arg( $arg ) {
$args = $this->get_default_args();
if ( isset( $args[ $arg ] ) ) {
return $args[ $arg
|
php
|
{
"resource": ""
}
|
q263465
|
Complex_Query.query
|
test
|
protected function query() {
$results = $this->wpdb->get_results( $this->sql );
// we query for found rows first to prevent instantiation of record objects from interfering with the count
if ( $this->args['sql_calc_found_rows'] ) {
$count_results = $this->wpdb->get_results( "SELECT FOUND_ROWS() AS COUNT" );
if ( empty( $count_results ) || empty( $count_results[0] ) ) {
$this->total_items = 0;
} else {
$this->total_items
|
php
|
{
"resource": ""
}
|
q263466
|
Complex_Query.parse_results
|
test
|
protected function parse_results( $results ) {
if ( is_array( $this->args['return_value'] ) ) {
return $results;
} elseif ( $this->args['return_value'] == 'count' ) {
if ( empty( $results ) || empty( $results[0] ) ) {
return 0;
}
return $results[0]->COUNT;
} elseif ( $this->args['return_value'] != 'object' ) {
$values = array();
$field = $this->args['return_value'];
foreach ( $results as $result ) {
$values[] = $result->$field;
|
php
|
{
"resource": ""
}
|
q263467
|
Complex_Query.parse_select
|
test
|
protected function parse_select( $alias = 'q' ) {
if ( is_array( $this->args['return_value'] ) ) {
$select = new Select( null );
foreach ( $this->args['return_value'] as $column ) {
$select->also( "$alias.$column" );
}
} elseif ( $this->args['return_value'] == 'count' ) {
$select = new Select( 'COUNT(1)', 'COUNT' );
} elseif ( $this->args['return_value'] != 'object' ) {
$select = new Select( "$alias." . $this->args['return_value'] );
|
php
|
{
"resource": ""
}
|
q263468
|
Complex_Query.parse_order
|
test
|
protected function parse_order( $alias = 'q' ) {
if ( ! is_array( $this->args['order'] ) && $this->args['order'] === 'rand' ) {
return new Order( Order::RAND );
} elseif ( ! is_array( $this->args['order'] ) ) {
throw new \InvalidArgumentException( "Order must either be 'rand' or an array of columns to directions." );
}
$white_list = $this->table->get_columns();
foreach ( $this->args['order'] as $column => $direction ) {
$direction = strtoupper( $direction );
|
php
|
{
"resource": ""
}
|
q263469
|
Complex_Query.parse_pagination
|
test
|
protected function parse_pagination() {
if ( $this->args['items_per_page'] == - 1 ) {
return null;
}
if ( $this->args['page'] < 1 ) {
throw new \InvalidArgumentException( "page parameter must be at least 1." );
}
$per_page = absint( $this->args['items_per_page']
|
php
|
{
"resource": ""
}
|
q263470
|
Saver.numerically_equivalent
|
test
|
protected function numerically_equivalent( $a, $b ) {
return
|
php
|
{
"resource": ""
}
|
q263471
|
Saver.has_changes
|
test
|
protected function has_changes( $old, $new ) {
foreach ( $new as $key => $value ) {
if ( $value !== $old[ $key ] && ! $this->numerically_equivalent(
|
php
|
{
"resource": ""
}
|
q263472
|
Collection.fetch
|
test
|
public function fetch()
{
$modelName = $this->_className;
// execute fetch query
$query = $this->_dataSource->prepare($this->_queryHelper->buildQuery());
$query->execute($this->_queryHelper->getWhereParamsValues());
// check for mysql error
$errorcode = $query->errorInfo();
if ($errorcode[0] != "00000") {
throw new Exception($errorcode[2]);
}
// fetch query and hydrate models
$fetch = $query->fetchAll(\PDO::FETCH_ASSOC);
foreach ($fetch as &$unRes) {
/** @var $object \PicORM\Model */
|
php
|
{
"resource": ""
}
|
q263473
|
Collection.delete
|
test
|
public function delete()
{
$modelClass = $this->_className;
// cloning fetch query to get where,order by and limit values
$deleteQuery = clone($this->_queryHelper);
// transform query to delete
$deleteQuery->cleanQueryBeforeSwitching()
->delete($modelClass::formatTableNameMySQL());
// execute query
|
php
|
{
"resource": ""
}
|
q263474
|
Collection.update
|
test
|
public function update(array $setValues)
{
$modelClass = $this->_className;
// cloning fetch query to get where,order by and limit values
$updateQuery = clone($this->_queryHelper);
// transform query to update
$updateQuery->cleanQueryBeforeSwitching()
->update($modelClass::formatTableNameMySQL());
// build set values
$params = array();
foreach ($setValues as $fieldName => $value) {
$updateQuery->set($fieldName, '?');
$params[] = $value;
}
// merge set values with where values
|
php
|
{
"resource": ""
}
|
q263475
|
Collection.getTotalPages
|
test
|
public function getTotalPages()
{
if ($this->_usePagination === false) {
return 0;
}
if (!$this->isFetched) {
$this->fetch();
}
|
php
|
{
"resource": ""
}
|
q263476
|
Collection.paginate
|
test
|
public function paginate($neededNumPage)
{
if ($this->_usePagination === false) {
return $this;
}
// build the limit start
$limitStart = max(0, $neededNumPage - 1) * $this->_paginationNbModelByPage;
|
php
|
{
"resource": ""
}
|
q263477
|
Collection.queryFoundModels
|
test
|
protected function queryFoundModels()
{
$countQueryHelper = clone($this->_queryHelper);
$countQueryHelper->resetSelect("count(*)");
$countQueryHelper->resetOrderBy();
$countQueryHelper->resetLimit();
$query
|
php
|
{
"resource": ""
}
|
q263478
|
Collection.countModelsWithoutLimit
|
test
|
public function countModelsWithoutLimit()
{
if (!$this->isFetched) {
$this->fetch();
}
// no pagination, we have
|
php
|
{
"resource": ""
}
|
q263479
|
Collection.offsetExists
|
test
|
public function offsetExists($offset)
{
if (!$this->isFetched) {
$this->fetch();
|
php
|
{
"resource": ""
}
|
q263480
|
Collection.offsetSet
|
test
|
public function offsetSet($offset, $value)
{
if (!$this->isFetched) {
$this->fetch();
|
php
|
{
"resource": ""
}
|
q263481
|
Collection.offsetGet
|
test
|
public function offsetGet($offset)
{
if (!$this->isFetched) {
$this->fetch();
}
|
php
|
{
"resource": ""
}
|
q263482
|
Builder.build
|
test
|
public function build() {
if ( empty( $this->parts ) ) {
return '';
}
$query = '';
foreach ( $this->parts as $part) {
if ($part instanceof Builder) {
$query .=
|
php
|
{
"resource": ""
}
|
q263483
|
Model.boot_if_not_booted
|
test
|
protected static function boot_if_not_booted() {
if ( isset( static::$_booted[ get_called_class() ] ) ) {
return;
}
|
php
|
{
"resource": ""
}
|
q263484
|
Model.boot_traits
|
test
|
protected static function boot_traits() {
$class = get_called_class();
// this method will return an empty array on PHP < 5.4
$uses = class_uses_recursive( get_called_class() );
foreach ( $uses as $trait ) {
if ( method_exists(
|
php
|
{
"resource": ""
}
|
q263485
|
Model.fill
|
test
|
public function fill( array $data = array() ) {
foreach ( $data as $column => $value )
|
php
|
{
"resource": ""
}
|
q263486
|
Model.with_guarded
|
test
|
public function with_guarded( $attribute, $callback ) {
if ( is_array( $attribute ) ) {
$attributes = $attribute;
} else {
$attributes = func_get_args();
$callback = array_pop( $attributes );
}
$unguarded = static::$_unguarded;
if ( $unguarded ) {
static::$_unguarded = false;
}
$_fillable = $this->_fillable;
$_guarded = $this->_guarded;
if ( $this->_fillable ) {
$this->_fillable = array_diff( $this->_fillable, $attributes );
// If the diff removes all fillable attributes we
|
php
|
{
"resource": ""
}
|
q263487
|
Model.with_unguarded
|
test
|
public function with_unguarded( $attribute, $callback ) {
if ( static::$_unguarded ) {
$callback( $this );
return;
}
if ( is_array( $attribute ) ) {
$attributes = $attribute;
} else {
$attributes = func_get_args();
$callback = array_pop( $attributes );
}
$_fillable = $this->_fillable;
$_guarded = $this->_guarded;
if ( $this->_fillable ) {
$this->_fillable = array_merge( $this->_fillable,
|
php
|
{
"resource": ""
}
|
q263488
|
Model.is_fillable
|
test
|
protected function is_fillable( $column ) {
if ( static::$_unguarded ) {
return true;
}
if ( empty( $this->_fillable ) ) {
|
php
|
{
"resource": ""
}
|
q263489
|
Model.set_attribute
|
test
|
public function set_attribute( $attribute, $value ) {
if ( $this->has_relation( $attribute ) ) {
if ( is_object( $value ) ) {
$this->set_relation_value( $attribute, $value );
return $this;
}
unset( $this->_relations[ $attribute ] );
} elseif ( ! array_key_exists( $attribute, static::table()->get_columns() ) ) {
throw new \OutOfBoundsException(
sprintf( "Requested attribute '%s' does not exist for '%s'.", $attribute, get_class( $this ) )
);
} elseif ( method_exists( $this, $this->get_mutator_method_for_attribute( $attribute ) )
|
php
|
{
"resource": ""
}
|
q263490
|
Model.set_raw_attribute
|
test
|
public function set_raw_attribute( $attribute, $value ) {
$attributes = $this->get_raw_attributes();
$attributes[ $attribute ] = $value;
|
php
|
{
"resource": ""
}
|
q263491
|
Model.get_attribute
|
test
|
public function get_attribute( $attribute ) {
if ( $this->has_relation( $attribute ) ) {
return $this->get_relation_value( $attribute );
}
if ( array_key_exists( $attribute, static::table()->get_columns() ) ) {
return $this->get_attribute_value( $attribute );
}
|
php
|
{
"resource": ""
}
|
q263492
|
Model.get_raw_attribute
|
test
|
public function get_raw_attribute( $attribute ) {
$attributes = $this->get_raw_attributes();
return
|
php
|
{
"resource": ""
}
|
q263493
|
Model.get_attribute_value
|
test
|
protected function get_attribute_value( $attribute ) {
$value = $this->get_attribute_from_array( $attribute );
if ( method_exists( $this, $this->get_accessor_method_for_attribute( $attribute ) ) ) {
|
php
|
{
"resource": ""
}
|
q263494
|
Model.get_attribute_from_array
|
test
|
protected function get_attribute_from_array( $attribute ) {
$raw = $this->get_raw_attribute( $attribute );
|
php
|
{
"resource": ""
}
|
q263495
|
Model.get_all_relations
|
test
|
public function get_all_relations() {
if ( isset( static::$_relation_attribute_cache[ get_class( $this ) ] ) ) {
return static::$_relation_attribute_cache[ get_class( $this ) ];
}
$relations = array();
$methods = get_class_methods( $this );
foreach ( $methods as $method ) {
preg_match( '/^_(\S+)_relation$/', $method, $matches );
if ( empty( $matches[1] ) ) {
|
php
|
{
"resource": ""
}
|
q263496
|
Model.get_relation
|
test
|
public function get_relation( $attribute ) {
if ( ! $this->has_relation( $attribute ) ) {
throw new \OutOfBoundsException(
sprintf( "Requested relation '%s' does not exist for '%s'.", $attribute, get_class( $this
|
php
|
{
"resource": ""
}
|
q263497
|
Model.set_relation_value
|
test
|
public function set_relation_value( $attribute, $value ) {
if ( ! $this->has_relation( $attribute ) ) {
throw new \OutOfBoundsException(
sprintf( "Requested relation '%s' does
|
php
|
{
"resource": ""
}
|
q263498
|
Model.get_relation_value
|
test
|
protected function get_relation_value( $attribute ) {
if ( array_key_exists( $attribute, $this->_relations ) ) {
return $this->_relations[ $attribute
|
php
|
{
"resource": ""
}
|
q263499
|
Model.refresh
|
test
|
public function refresh( $destroy_changes = false ) {
if ( ! $this->exists() ) {
return;
}
$data = (array) static::get_data_from_pk( $this->get_pk() );
$this->_original
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.