_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q263400 | Collection.get_model | test | public function get_model( $pk ) {
$i = $this->get_model_index( $pk );
if ( $i === - 1 ) {
return null;
}
return $this->elements[ $i ];
} | php | {
"resource": ""
} |
q263401 | Collection.remove_model | test | public function remove_model( $pk ) {
$i = $this->get_model_index( $pk );
if ( $i === - 1 ) {
return false;
}
$this->remove( $i );
return true;
} | 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 ( $this->saver->get_pk( $element ) === $pk ) {
$this->pk_map[ $pk ] = $i;
return $i;
}
}
return - 1;
} | php | {
"resource": ""
} |
q263403 | Collection.save | test | public function save( array $options = array() ) {
foreach ( $this->elements as $element ) {
$this->saver->save( $element, $options );
}
} | 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, '`');
$data[$newKey] = $v;
unset($data[$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)) {
$newKey ... | 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 ) {
$options = array_udiff( $this->options, $exclude_opt... | 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 ( $mode... | 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 ) {
return new Simple_Query( $wpdb, $table );
} else {
return null;
}
} | 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;
}
$class = static::$tables[ $slug ]['query'];
$query = new $class( $args );
return $query;
} | php | {
"resource": ""
} |
q263410 | Manager.get_model | test | public static function get_model( $slug ) {
$slug = $slug instanceof Table ? $slug->get_slug() : $slug;
if ( isset( static::$tables[ $slug ] ) ) {
return static::$tables[ $slug ]['model'];
} else {
return null;
}
} | 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::... | 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( "DROP TABLE IF EXISTS `{$tn}`" );
static::fire_plugin_event( $table, 'deleted' ... | 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 );
$results = $wpdb->get_results( "SHOW TABLES LIKE '$name'" );
return is_array( $results ) && count( $results ) > 0;
} | 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 ) ) {
$args = array( $table ) + $args;
call_user_func_array( array( $plugin, $event ), $args );
... | 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 ) ) {
throw new \InvalidArgumentException( 'Error encountered while saving WP_Post: ' . $id->get_error... | php | {
"resource": ""
} |
q263416 | SimpleForeign.get_column | test | protected function get_column() {
$column = $this->foreign_column ?: $this->foreign_table->get_primary_key();
$columns = $this->foreign_table->get_columns();
return $columns[ $column ];
} | 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 'B... | php | {
"resource": ""
} |
q263418 | FluentQuery.from_model | test | public static function from_model( $model ) {
$query = new static( $model::table(), $GLOBALS['wpdb'] );
$query->model = $model;
return $query;
} | 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 ) {
$this->select->also( $this->prepare_column( $column ) );
}
$this->sel... | php | {
"resource": ""
} |
q263420 | FluentQuery.select_single | test | public function select_single( $column ) {
$this->select->also( $this->prepare_column( $column ) );
$this->select->also( $this->prepare_column( $this->table->get_primary_key() ) );
$this->select_single = true;
return $this;
} | php | {
"resource": ""
} |
q263421 | FluentQuery.select_all | test | public function select_all( $local_only = true ) {
$this->select->all( $local_only ? $this->alias : null );
return $this;
} | php | {
"resource": ""
} |
q263422 | FluentQuery.expression | test | public function expression( $function, $column, $as ) {
$this->select->expression( $function, $this->prepare_column( $column ), $as );
$this->expressions[] = $as;
return $this;
} | 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_whe... | 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 = $thi... | 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 );
$clause = $this->where;
$this->where = $_where;
if ( $clause->is_empty() ) {
return;
}
$boolean = $boolean ?: 'and';
$boolean = 'q... | 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 \InvalidArgumentEx... | php | {
"resource": ""
} |
q263427 | FluentQuery.or_where | test | public function or_where( $column, $equality = '', $value = '', Closure $callback = null ) {
return $this->where( $column, $equality, $value, $callback, 'or' );
} | 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 ) );
return $this->where( new Where_Date( $query ), '', '', $callback, $boolean );
} | 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_me... | php | {
"resource": ""
} |
q263430 | FluentQuery.order_by | test | public function order_by( $column, $direction = null ) {
$column = $this->prepare_column( $column );
if ( is_null( $this->order ) ) {
$this->order = new Order( $column, $direction );
} else {
$this->order->then( $column, $direction );
}
return $this;
} | 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.' );
}
if ( is_null( $this->order ) ) {
$this->order = new... | php | {
"resource": ""
} |
q263432 | FluentQuery.group_by | test | public function group_by( $column ) {
$column = $this->prepare_column( $column );
if ( is_null( $this->group ) ) {
$this->group = new Group( $column );
} else {
$this->group->then( $column );
}
return $this;
} | php | {
"resource": ""
} |
q263433 | FluentQuery.group_by_expression | test | public function group_by_expression( $function, $column ) {
$column = $this->prepare_column( $column );
$group = "{$function}($column)";
if ( is_null( $this->group ) ) {
$this->group = new Group( $group );
} else {
$this->group->then( $group );
}
return $this;
} | 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 = $o... | 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->f... | php | {
"resource": ""
} |
q263436 | FluentQuery.paginate | test | public function paginate( $page, $per_page ) {
$this->count = $per_page;
$this->offset = $per_page * ( $page - 1 );
$this->calc_found_rows = true;
return $this;
} | 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;
}
}
$_query->offset... | 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],
);
}
}
$parsed = array();
for... | php | {
"resource": ""
} |
q263439 | FluentQuery.parse_nested_with | test | protected function parse_nested_with( $name, $results ) {
$parts = explode( '.', $name );
$first = $parts[0];
$results[ $first ] = false;
$this->assign_array_by_path( $results, $name, true );
return $results;
} | php | {
"resource": ""
} |
q263440 | FluentQuery.assign_array_by_path | test | protected function assign_array_by_path( &$arr, $path, $value ) {
$keys = explode( '.', $path );
foreach ( $keys as $key ) {
$arr = &$arr[ $key ];
}
$arr = $value;
} | php | {
"resource": ""
} |
q263441 | FluentQuery.make_limit_tag | test | protected function make_limit_tag() {
if ( ! $this->count ) {
return $this;
}
$this->limit = new Limit( $this->count, $this->offset );
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->appe... | 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 ( $tab... | php | {
"resource": ""
} |
q263444 | FluentQuery.find | test | public function find( $primary_key ) {
if ( is_array( $primary_key ) ) {
return $this->find_many( $primary_key );
}
return $this->where( $this->table->get_primary_key(), true, $primary_key )->first();
} | php | {
"resource": ""
} |
q263445 | FluentQuery.find_many | test | public function find_many( array $primary_keys ) {
return $this->where( $this->table->get_primary_key(), true, $primary_keys )->results();
} | 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;
}
} elseif ( $result ) {
return $result;
}
throw new ModelNotFoundException( "No model foun... | php | {
"resource": ""
} |
q263447 | FluentQuery.find_or_new | test | public function find_or_new( $primary_key ) {
$model = $this->find( $primary_key );
if ( is_null( $model ) ) {
$model = new $this->model;
}
return $model;
} | php | {
"resource": ""
} |
q263448 | FluentQuery.first_or_new | test | public function first_or_new( array $attributes ) {
$model = $this->where( $attributes )->first();
if ( $model ) {
return $model;
}
return new $this->model( (object) $attributes );
} | php | {
"resource": ""
} |
q263449 | FluentQuery.first_or_create | test | public function first_or_create( array $attributes ) {
$model = $this->where( $attributes )->first();
if ( $model ) {
return $model;
}
$model = new $this->model( (object) $attributes );
$model->save();
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 );
$model->fill( $values )->save();
return $model;
} | 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 );
$this->do_nested_eag... | 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;
... | 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 NUL... | php | {
"resource": ""
} |
q263454 | FluentQuery.prepare_column | test | public function prepare_column( $column ) {
$columns = $this->table->get_columns();
if ( ! isset( $columns[ $column ] ) ) {
throw new InvalidColumnException( "Invalid database column '$column'." );
}
return "{$this->alias}.`{$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 ) ) {
return null;
}
if ( empty( $value ) ) {
return '';
}
retu... | 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'] i... | php | {
"resource": ""
} |
q263457 | Builder.get_col_value | test | protected final function get_col_value( $col ) {
if ( ! isset( $this->data[ $col ] ) ) {
throw new \InvalidArgumentException( "Column does not exist." );
}
return $this->data[ $col ];
} | 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 );
}
}
return Manager::make_simple_query_object( $this->get_table()->get_slug() )
->insert( $this->data );
} | php | {
"resource": ""
} |
q263459 | Order.then | test | public function then( $col, $direction = null ) {
if ( $this->is_rand ) {
throw new \LogicException( "This ORDER BY statement is already RAND()." );
}
$this->orders[ $col ] = $direction;
return $this;
} | php | {
"resource": ""
} |
q263460 | Order.add_order | test | protected function add_order( $col, $direction ) {
if ( $direction !== null && ! in_array( $direction, array( self::ASC, self::DESC ) ) ) {
throw new \InvalidArgumentException( "Invalid ORDER BY direction." );
}
$this->orders[ $col ] = $direction;
} | php | {
"resource": ""
} |
q263461 | Select.all | test | public function all( $as = null ) {
$this->all_columns = true;
if ( $as ) {
$this->all_as = $as;
}
return $this;
} | 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 instanceof Model ) {
$pk = $pk->get_pk();
}
$map[ $pk ][ $model->get_pk() ] = $model;
}
return $map;
... | 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() ) ) ) {
$id = $comment->comment_ID;
}
}
if ( empty( $id ) ) {
throw new \InvalidArgumentExceptio... | 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 ];
} else {
throw new \InvalidArgumentException();
}
} | 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"... | 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']... | 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( 'CO... | 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 direct... | 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'] );
$page = absint( $this->args['... | php | {
"resource": ""
} |
q263470 | Saver.numerically_equivalent | test | protected function numerically_equivalent( $a, $b ) {
return is_numeric( $a ) && is_numeric( $b ) && strcmp( (string) $a, (string) $b ) === 0;
} | 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( $value, $old[ $key ] ) ) {
return true;
}
}
return false;
} | 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->erro... | 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($modelCla... | 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()
->... | php | {
"resource": ""
} |
q263475 | Collection.getTotalPages | test | public function getTotalPages()
{
if ($this->_usePagination === false) {
return 0;
}
if (!$this->isFetched) {
$this->fetch();
}
return (int)ceil($this->_paginationFoundModels / $this->_paginationNbModelByPage);
} | 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;
// limit fetch query for page $neededNumPage
$this->_qu... | php | {
"resource": ""
} |
q263477 | Collection.queryFoundModels | test | protected function queryFoundModels()
{
$countQueryHelper = clone($this->_queryHelper);
$countQueryHelper->resetSelect("count(*)");
$countQueryHelper->resetOrderBy();
$countQueryHelper->resetLimit();
$query = $this->_dataSource->prepare($countQueryHelper->buildQuery());
... | php | {
"resource": ""
} |
q263478 | Collection.countModelsWithoutLimit | test | public function countModelsWithoutLimit()
{
if (!$this->isFetched) {
$this->fetch();
}
// no pagination, we have to manually count number of model
if (!$this->_usePagination) {
$this->_paginationFoundModels = $this->queryFoundModels();
}
retu... | php | {
"resource": ""
} |
q263479 | Collection.offsetExists | test | public function offsetExists($offset)
{
if (!$this->isFetched) {
$this->fetch();
}
return isset($this->models[$offset]);
} | php | {
"resource": ""
} |
q263480 | Collection.offsetSet | test | public function offsetSet($offset, $value)
{
if (!$this->isFetched) {
$this->fetch();
}
if (is_null($offset)) {
$this->models[] = $value;
} else {
$this->models[$offset] = $value;
}
} | php | {
"resource": ""
} |
q263481 | Collection.offsetGet | test | public function offsetGet($offset)
{
if (!$this->isFetched) {
$this->fetch();
}
return isset($this->models[$offset]) ? $this->models[$offset] : null;
} | 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 .= "($part)";
} elseif ( $sql = (string) $part ) {
$query .= "$part ";
}
}
return $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;
}
static::$_booted[ get_called_class() ] = true;
$instance = new static();
$instance->fire_model_event( 'booting' );
static::boot();
$instance->fire_model_event( 'booted' );
} | 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( $class, $method = 'boot_' . class_basename( $trait ) ) ) {
forward_static_... | php | {
"resource": ""
} |
q263485 | Model.fill | test | public function fill( array $data = array() ) {
foreach ( $data as $column => $value ) {
if ( $this->is_fillable( $column ) ) {
$this->set_attribute( $column, $value );
}
}
return $this;
} | 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;
}
$_fillabl... | 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;
... | php | {
"resource": ""
} |
q263488 | Model.is_fillable | test | protected function is_fillable( $column ) {
if ( static::$_unguarded ) {
return true;
}
if ( empty( $this->_fillable ) ) {
return ! in_array( $column, $this->_guarded );
} else {
return in_array( $column, $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... | php | {
"resource": ""
} |
q263490 | Model.set_raw_attribute | test | public function set_raw_attribute( $attribute, $value ) {
$attributes = $this->get_raw_attributes();
$attributes[ $attribute ] = $value;
$this->set_raw_attributes( $attributes );
return $this;
} | 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 );
}
throw new \OutOfBoundsException(
spr... | php | {
"resource": ""
} |
q263492 | Model.get_raw_attribute | test | public function get_raw_attribute( $attribute ) {
$attributes = $this->get_raw_attributes();
return isset( $attributes[ $attribute ] ) ? $attributes[ $attribute ] : null;
} | 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 ) ) ) {
$value = call_user_func( array( $this, $this->get_accessor_method_for_attribute( $attribute ) ), $value );
}
... | php | {
"resource": ""
} |
q263494 | Model.get_attribute_from_array | test | protected function get_attribute_from_array( $attribute ) {
$raw = $this->get_raw_attribute( $attribute );
$columns = static::table()->get_columns();
return $columns[ $attribute ]->convert_raw_to_value( $raw );
} | 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+)_re... | 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 ) )
);
}
$method = "_{$attribute}_relation";
$relation = $this->{$method}();
if ( ... | 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 not exist for '%s'.", $attribute, get_class( $this ) )
);
}
$this->_relations[ $attribute ] = $value;
return $this;
} | 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 ];
}
$relation = $this->get_relation( $attribute );
$this->set_relation_value( $attribute, $relation->get_results() );
return $this->get_relation_value( $... | 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 = $data;
if ( $destroy_changes ) {
$this->set_raw_attributes( $data );
}
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.