idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
35,500
protected function to ( ) { if ( static :: $ to === 1 ) { $ method = 'renderAsArray' ; } elseif ( static :: $ to === 2 ) { $ method = 'renderAsJson' ; } elseif ( static :: $ to === 3 ) { $ method = 'renderAsHtml' ; } elseif ( static :: $ to === 4 ) { $ method = 'renderAsDropdown' ; } else { return $ this -> source ; } ...
Pass data to nest methods .
35,501
protected function saveParameter ( $ method , $ value ) { if ( ! isset ( static :: $ parameters [ $ method ] ) ) { static :: $ parameters [ $ method ] = [ ] ; } if ( $ value instanceof Closure ) { static :: $ parameters [ $ method ] [ 'callback' ] = $ value ; } elseif ( is_array ( $ value ) ) { foreach ( $ value as $ k...
Save the service parameters .
35,502
public static function where ( $ column , $ operator = null , $ value = null , $ boolean = 'and' ) { return parent :: query ( ) -> where ( $ column , $ operator , $ value , $ boolean ) ; }
Call the parent where method
35,503
public function runMacro ( $ name , $ args ) { if ( isset ( $ this -> macros [ $ name ] ) ) { if ( is_callable ( $ this -> macros [ $ name ] ) ) { return call_user_func_array ( $ this -> macros [ $ name ] , array_merge ( [ $ this ] , $ args ) ) ; } } }
Run the macros .
35,504
public function make ( $ data ) { if ( $ data instanceof Collection ) { $ this -> data = collect ( $ data -> toArray ( ) ) ; } elseif ( is_array ( $ data ) ) { $ this -> data = collect ( $ data ) ; } else { throw new InvalidArgumentException ( 'Invalid data type.' ) ; } $ this -> config = Config :: get ( 'nestable' ) ;...
Set the data to wrap class .
35,505
public function renderAsArray ( $ data = false , $ parent = 0 ) { $ args = $ this -> setParameters ( func_get_args ( ) ) ; $ tree = collect ( [ ] ) ; $ args [ 'data' ] -> each ( function ( $ item ) use ( & $ tree , $ args ) { $ currentData = collect ( [ ] ) ; if ( intval ( $ item [ $ this -> parent ] ) == intval ( $ ar...
Pass to array of all data as nesting .
35,506
public function renderAsJson ( $ data = false , $ parent = 0 ) { $ args = func_get_args ( ) ; if ( count ( $ args ) < 1 ) { $ data = $ this -> renderAsArray ( ) ; } else { $ data = $ this -> renderAsArray ( $ data ) ; } return json_encode ( $ data ) ; }
Pass to json string of all data as nesting .
35,507
public function renderAsDropdown ( $ data = false , $ parent = 0 , $ first = true , $ level = 0 ) { $ args = $ this -> setParameters ( func_get_args ( ) ) ; $ tree = '' ; if ( $ first ) { $ tree = $ first ? '<select ' . $ this -> addAttributes ( ) . ' ' : '' ; } if ( $ first && $ this -> multiple == true ) { $ tree .= ...
Convert to dropdown .
35,508
protected function addAttributes ( ) { $ attrs = '' ; foreach ( $ this -> dropdownAttr as $ attr => $ value ) { $ attrs .= $ attr . '=' . '"' . $ value . '" ' ; } return $ attrs ; }
Contact th attributes to dropdown .
35,509
public function hasChild ( $ key = null , $ value = null , Collect $ data = null ) { if ( func_num_args ( ) < 3 ) { $ data = $ this -> data ; $ key = $ this -> parent ; $ value = current ( func_get_args ( ) ) ; } $ child = false ; $ data -> each ( function ( $ item ) use ( & $ child , $ key , $ value ) { if ( intval ( ...
Child menu checker .
35,510
public function selected ( $ values ) { if ( is_array ( $ values ) || $ values instanceof Closure ) { $ this -> selected = $ values ; } else if ( func_num_args ( ) > 1 ) { $ this -> selected = func_get_args ( ) ; } else { $ this -> selected = [ $ values ] ; } return $ this ; }
Save the will select values .
35,511
public function active ( ) { $ args = func_get_args ( ) ; $ this -> active = current ( $ args ) ; if ( func_num_args ( ) > 1 ) { $ this -> active = $ args ; } return $ this ; }
Attribute insert helper for html render .
35,512
public function parent ( $ parent = false ) { if ( $ parent ) { $ this -> parents = ! is_array ( $ parent ) ? [ $ parent ] : $ parent ; if ( func_num_args ( ) > 1 ) { $ this -> parents = func_get_args ( ) ; } } return $ this ; }
Set the parent id for child elements .
35,513
protected function doSelect ( $ value , $ label ) { if ( $ this -> selected ) { if ( is_array ( $ this -> selected ) && count ( $ this -> selected ) > 0 ) { $ result = array_search ( $ value , $ this -> selected ) ; if ( $ result !== false ) { unset ( $ this -> selected [ $ result ] ) ; return 'selected="selected"' ; }...
Set the as selected of items .
35,514
protected function renderAttr ( $ attributes = false , $ params = false ) { $ attrStr = '' ; if ( isset ( $ attributes [ 'callback' ] ) ) { $ callbackParams = [ $ this ] ; if ( $ params !== false ) { array_push ( $ callbackParams , $ params ) ; } call_user_func_array ( $ attributes [ 'callback' ] , $ callbackParams ) ;...
Render the attritues of html elements .
35,515
public function save ( array $ params ) { foreach ( $ params as $ method => $ param ) { if ( is_array ( $ param ) && isset ( $ param [ 0 ] ) ) { call_user_func_array ( [ $ this , $ method ] , $ param ) ; } else { $ this -> { $ method } ( $ param ) ; } } }
Save the parameters .
35,516
protected function url ( $ path , $ label , $ parent = null ) { if ( $ this -> config [ 'generate_url' ] ) { if ( $ this -> route ) { if ( array_has ( $ this -> route , 'callback' ) ) { if ( is_array ( $ parent ) ) $ parent = ( object ) $ parent ; return call_user_func_array ( $ this -> route [ 'callback' ] , [ $ path ...
URL Generator .
35,517
protected function makeUrl ( $ path ) { return URL :: to ( str_replace ( '{' . $ this -> config [ 'html' ] [ 'href' ] . '}' , $ path , $ this -> customUrl ) ) ; }
Generate custom url
35,518
public function ul ( $ items = false , $ parent_id = 0 , $ first = false ) { $ attrs = '' ; if ( ! $ first && is_array ( $ this -> optionUlAttr ) && count ( $ this -> optionUlAttr ) > 0 ) { $ attrs = $ this -> renderAttr ( $ this -> optionUlAttr , $ parent_id ) ; } else if ( $ first && count ( $ this -> firstUlAttrs ) ...
Generate open ul tag .
35,519
public function isValid ( $ type , $ render = false ) { $ original = $ type ; if ( in_array ( $ type , [ 'json' , 'array' ] ) ) { $ type = 'body' ; } $ type = $ type == 'multiple' ? 'dropdown' : $ type ; $ fields = $ this -> config [ $ type ] ; $ valid = true ; $ this -> data -> map ( function ( $ item ) use ( $ fields...
Array validator .
35,520
public function write ( $ data , array $ options = [ ] ) { if ( ! $ this -> has_real_call ) { $ this -> createRealCall ( $ data ) ; $ this -> has_real_call = true ; } $ this -> real_call -> write ( $ data , $ options ) ; }
Write a single message to the server . This cannot be called after writesDone is called .
35,521
public function writesDone ( ) { if ( ! $ this -> has_real_call ) { $ this -> createRealCall ( ) ; $ this -> has_real_call = true ; } $ this -> real_call -> writesDone ( ) ; }
Indicate that no more writes will be sent .
35,522
public function setMethod ( $ var ) { $ arr = GPBUtil :: checkRepeatedField ( $ var , \ Google \ Protobuf \ Internal \ GPBType :: MESSAGE , \ Grpc \ Gcp \ MethodConfig :: class ) ; $ this -> method = $ arr ; return $ this ; }
The method configurations .
35,523
public function bind ( $ channel_ref , $ affinity_key ) { if ( ! array_key_exists ( $ affinity_key , $ this -> affinity_key_to_channel_ref ) ) { $ this -> affinity_key_to_channel_ref [ $ affinity_key ] = $ channel_ref ; } $ channel_ref -> affinityRefIncr ( ) ; return $ channel_ref ; }
Bind the ChannelRef with the affinity key . This is a private method .
35,524
public function unbind ( $ affinity_key ) { $ channel_ref = null ; if ( array_key_exists ( $ affinity_key , $ this -> affinity_key_to_channel_ref ) ) { $ channel_ref = $ this -> affinity_key_to_channel_ref [ $ affinity_key ] ; $ channel_ref -> affinityRefDecr ( ) ; } unset ( $ this -> affinity_key_to_channel_ref [ $ af...
Unbind the affinity key . This is a private method .
35,525
public function getChannelRef ( $ affinity_key = null ) { if ( $ affinity_key ) { if ( array_key_exists ( $ affinity_key , $ this -> affinity_key_to_channel_ref ) ) { return $ this -> affinity_key_to_channel_ref [ $ affinity_key ] ; } return $ this -> getChannelRef ( ) ; } usort ( $ this -> channel_refs , array ( $ thi...
Pick or create a ChannelRef from the pool by affinity key .
35,526
public function getConnectivityState ( $ try_to_connect = false ) { if ( $ this -> is_closed ) { throw new \ RuntimeException ( "Channel has already been closed" ) ; } $ ready = 0 ; $ idle = 0 ; $ connecting = 0 ; $ transient_failure = 0 ; $ shutdown = 0 ; foreach ( $ this -> channel_refs as $ channel_ref ) { $ state =...
Get the connectivity state of the channel
35,527
public function watchConnectivityState ( $ last_state , $ deadline_obj = null ) { if ( $ deadline_obj == null || ! is_a ( $ deadline_obj , '\Grpc\Timeval' ) ) { throw new \ InvalidArgumentException ( "" ) ; } if ( $ this -> is_closed ) { throw new \ RuntimeException ( "Channel has already been closed" ) ; } $ state = 0...
Watch the connectivity state of the channel until it changed
35,528
public function close ( ) { foreach ( $ this -> channel_refs as $ channel_ref ) { $ channel_ref -> getRealChannel ( $ this -> credentials ) -> close ( ) ; } $ this -> is_closed = true ; }
Close the channel
35,529
protected function _rpcPreProcess ( $ argument ) { $ this -> affinity_key = null ; if ( $ this -> _affinity ) { $ command = $ this -> _affinity [ 'command' ] ; if ( $ command == self :: BOUND || $ command == self :: UNBIND ) { $ this -> affinity_key = $ this -> getAffinityKeyFromProto ( $ argument ) ; } } $ this -> cha...
Pick a ChannelRef from the channel pool based on the request and the affinity config .
35,530
protected function _rpcPostProcess ( $ status , $ response ) { if ( $ this -> _affinity ) { $ command = $ this -> _affinity [ 'command' ] ; if ( $ command == self :: BIND ) { if ( $ status -> code != \ Grpc \ STATUS_OK ) { return ; } $ affinity_key = $ this -> getAffinityKeyFromProto ( $ response ) ; $ this -> gcp_chan...
Update ChannelRef when RPC finishes .
35,531
protected function getAffinityKeyFromProto ( $ proto ) { if ( $ this -> _affinity ) { $ names = $ this -> _affinity [ 'affinityKey' ] ; $ names_arr = explode ( "." , $ names ) ; foreach ( $ names_arr as $ name ) { $ getAttrMethod = 'get' . ucfirst ( $ name ) ; $ proto = call_user_func_array ( array ( $ proto , $ getAtt...
Get the affinity key based on the affinity config .
35,532
public function cancel ( ) { if ( ! $ this -> has_real_call ) { $ this -> has_real_call = true ; $ this -> createRealCall ( ) ; } $ this -> real_call -> cancel ( ) ; }
Cancels the call .
35,533
public function start ( $ argument , $ metadata , $ options ) { $ channel_ref = $ this -> _rpcPreProcess ( $ argument ) ; $ real_channel = $ channel_ref -> getRealChannel ( $ this -> gcp_channel -> credentials ) ; $ this -> createRealCall ( $ real_channel ) ; $ this -> real_call -> start ( $ argument , $ metadata , $ o...
Pick a channel and start the call .
35,534
public function load ( $ file ) { $ handle = strcasecmp ( substr ( $ file , - 3 ) , '.gz' ) ? fopen ( $ file , 'rb' ) : gzopen ( $ file , 'rb' ) ; if ( ! $ handle ) { throw new Exception ( "ERROR: Cannot open file '$file'." ) ; } return $ this -> read ( $ handle ) ; }
Loads dump from the file .
35,535
public function read ( $ handle ) { if ( ! is_resource ( $ handle ) || get_resource_type ( $ handle ) !== 'stream' ) { throw new Exception ( 'Argument must be stream resource.' ) ; } $ stat = fstat ( $ handle ) ; $ sql = '' ; $ delimiter = ';' ; $ count = $ size = 0 ; while ( ! feof ( $ handle ) ) { $ s = fgets ( $ han...
Reads dump from logical file .
35,536
public function save ( $ file ) { $ handle = strcasecmp ( substr ( $ file , - 3 ) , '.gz' ) ? fopen ( $ file , 'wb' ) : gzopen ( $ file , 'wb' ) ; if ( ! $ handle ) { throw new Exception ( "ERROR: Cannot write file '$file'." ) ; } $ this -> write ( $ handle ) ; }
Saves dump to the file .
35,537
public function write ( $ handle = null ) { if ( $ handle === null ) { $ handle = fopen ( 'php://output' , 'wb' ) ; } elseif ( ! is_resource ( $ handle ) || get_resource_type ( $ handle ) !== 'stream' ) { throw new Exception ( 'Argument must be stream resource.' ) ; } $ tables = $ views = [ ] ; $ res = $ this -> connec...
Writes dump to logical file .
35,538
public function buildWherePosition ( $ column , array $ values ) { if ( count ( $ values ) == 1 || is_null ( $ values [ 1 ] ) ) { $ this -> where ( $ column , '>=' , $ values [ 0 ] ) ; } else { $ this -> whereIn ( $ column , range ( $ values [ 0 ] , $ values [ 1 ] ) ) ; } return $ this ; }
Builds where position query part based on given values .
35,539
public function insertNode ( $ ancestorId , $ descendantId ) { $ table = $ this -> getPrefixedTable ( ) ; $ ancestor = $ this -> getAncestorColumn ( ) ; $ descendant = $ this -> getDescendantColumn ( ) ; $ depth = $ this -> getDepthColumn ( ) ; $ query = " INSERT INTO {$table} ({$ancestor}, {$descendant}, {$...
Inserts new node into closure table .
35,540
public function moveNodeTo ( $ ancestorId = null ) { $ table = $ this -> getPrefixedTable ( ) ; $ ancestor = $ this -> getAncestorColumn ( ) ; $ descendant = $ this -> getDescendantColumn ( ) ; $ depth = $ this -> getDepthColumn ( ) ; $ thisAncestorId = $ this -> ancestor ; $ thisDescendantId = $ this -> descendant ; i...
Make a node a descendant of another ancestor or makes it a root node .
35,541
protected function unbindRelationships ( ) { $ table = $ this -> getPrefixedTable ( ) ; $ ancestorColumn = $ this -> getAncestorColumn ( ) ; $ descendantColumn = $ this -> getDescendantColumn ( ) ; $ descendant = $ this -> descendant ; $ query = " DELETE FROM {$table} WHERE {$descendantColumn} IN ...
Unbinds current relationships .
35,542
protected function getStub ( $ name , $ type ) { if ( stripos ( $ name , '.php' ) === false ) { $ name = $ name . '.php' ; } return $ this -> filesystem -> get ( $ this -> getStubsPath ( $ type ) . '/' . $ name ) ; }
Get a stub file by name .
35,543
protected function parseStub ( $ stub , array $ replacements = [ ] ) { foreach ( $ replacements as $ key => $ replacement ) { $ stub = str_replace ( '{{' . $ key . '}}' , $ replacement , $ stub ) ; } return $ stub ; }
Parses a stub file replacing tags with provided values .
35,544
public function getChildrenOf ( $ position ) { if ( ! $ this -> hasChildren ( $ position ) ) { return null ; } $ item = $ this -> get ( $ position ) ; $ relation = $ item -> getChildrenRelationIndex ( ) ; return $ item -> getRelation ( $ relation ) ; }
Retrieves children relation .
35,545
public function hasChildren ( $ position ) { $ item = $ this -> get ( $ position ) ; $ relation = $ item -> getChildrenRelationIndex ( ) ; return array_key_exists ( $ relation , $ item -> getRelations ( ) ) ; }
Indicates whether an item has children .
35,546
protected function makeTree ( array & $ items ) { $ result = [ ] ; $ tops = [ ] ; foreach ( $ items as $ item ) { $ result [ $ item -> getKey ( ) ] = $ item ; } foreach ( $ items as $ item ) { $ parentId = $ item -> { $ item -> getParentIdColumn ( ) } ; if ( array_key_exists ( $ parentId , $ result ) ) { $ result [ $ p...
Performs actual tree building .
35,547
public static function tableize ( $ name ) { $ name = str_replace ( '\\' , '' , $ name ) ; return ( ends_with ( $ name , 'Closure' ) ? snake_case ( $ name ) : snake_case ( str_plural ( $ name ) ) ) ; }
Makes database table name from given class name .
35,548
public function create ( array $ options ) { $ paths = [ ] ; $ nsplaceholder = ( ! empty ( $ options [ 'namespace' ] ) ? "namespace " . $ options [ 'namespace' ] . ";" : '' ) ; $ closureInterface = $ options [ 'closure' ] . 'Interface' ; $ qualifiedEntityName = $ options [ 'entity' ] ; $ qualifiedEntityInterfaceName = ...
Creates models and interfaces files .
35,549
public function setParentIdAttribute ( $ value ) { if ( $ this -> parent_id === $ value ) { return ; } $ this -> old_parent_id = $ this -> parent_id ; $ this -> attributes [ $ this -> getParentIdColumn ( ) ] = $ value ; }
Sets new parent id and caches the old one .
35,550
public function setPositionAttribute ( $ value ) { if ( $ this -> position === $ value ) { return ; } $ this -> old_position = $ this -> position ; $ this -> attributes [ $ this -> getPositionColumn ( ) ] = intval ( $ value ) ; }
Sets new position and caches the old one .
35,551
protected function setRealDepthAttribute ( $ value ) { if ( $ this -> real_depth === $ value ) { return ; } $ this -> old_real_depth = $ this -> real_depth ; $ this -> attributes [ $ this -> getRealDepthColumn ( ) ] = intval ( $ value ) ; }
Sets value of the real depth attribute .
35,552
protected function joinClosureBy ( $ column , $ withSelf = false ) { $ primary = $ this -> getQualifiedKeyName ( ) ; $ closure = $ this -> closure -> getTable ( ) ; $ ancestor = $ this -> closure -> getQualifiedAncestorColumn ( ) ; $ descendant = $ this -> closure -> getQualifiedDescendantColumn ( ) ; switch ( $ column...
Builds closure table join based on the given column .
35,553
protected function subqueryClosureBy ( $ column , $ withSelf = false ) { $ self = $ this ; return $ this -> whereIn ( $ this -> getQualifiedKeyName ( ) , function ( $ qb ) use ( $ self , $ column , $ withSelf ) { switch ( $ column ) { case 'ancestor' : $ selectedColumn = $ self -> closure -> getAncestorColumn ( ) ; $ w...
Builds closure table where in query on the given column .
35,554
public function getAncestorsWhere ( $ column , $ operator = null , $ value = null , array $ columns = [ '*' ] ) { return $ this -> joinClosureBy ( 'ancestor' ) -> where ( $ column , $ operator , $ value ) -> get ( $ columns ) ; }
Retrieves ancestors applying given conditions .
35,555
protected function children ( $ position = null , $ order = 'asc' ) { $ query = $ this -> queryByParentId ( ) ; if ( ! is_null ( $ position ) ) { if ( is_array ( $ position ) ) { $ query -> buildWherePosition ( $ this -> getPositionColumn ( ) , $ position ) ; } else { if ( $ position === static :: QUERY_LAST ) { $ quer...
Shorthand of the children query part .
35,556
protected function queryByParentId ( $ id = null ) { $ id = ( $ id ? : $ this -> getKey ( ) ) ; return $ this -> where ( $ this -> getParentIdColumn ( ) , '=' , $ id ) ; }
Starts a query by parent identifier .
35,557
public function getChildren ( array $ columns = [ '*' ] ) { if ( $ this -> hasChildrenRelation ( ) ) { $ result = $ this -> getRelation ( $ this -> getChildrenRelationIndex ( ) ) ; } else { $ result = $ this -> children ( ) -> get ( $ columns ) ; } return $ result ; }
Retrieves all children of a model .
35,558
public function countChildren ( ) { if ( $ this -> hasChildrenRelation ( ) ) { $ result = $ this -> getRelation ( $ this -> getChildrenRelationIndex ( ) ) -> count ( ) ; } else { $ result = $ this -> queryByParentId ( ) -> count ( ) ; } return $ result ; }
Returns a number of model s children .
35,559
public function appendRelation ( $ relation , $ value ) { if ( ! array_key_exists ( $ relation , $ this -> getRelations ( ) ) ) { $ this -> setRelation ( $ relation , new Collection ( [ $ value ] ) ) ; } else { $ this -> getRelation ( $ relation ) -> add ( $ value ) ; } return $ this ; }
Pushes a new item to a relation .
35,560
public function getChildAt ( $ position , array $ columns = [ '*' ] ) { if ( $ this -> hasChildrenRelation ( ) ) { $ result = $ this -> getRelation ( $ this -> getChildrenRelationIndex ( ) ) -> get ( $ position ) ; } else { $ result = $ this -> children ( $ position ) -> first ( $ columns ) ; } return $ result ; }
Retrieves a child with given position .
35,561
public function getLastChild ( array $ columns = [ '*' ] ) { if ( $ this -> hasChildrenRelation ( ) ) { $ result = $ this -> getRelation ( $ this -> getChildrenRelationIndex ( ) ) -> last ( ) ; } else { $ result = $ this -> children ( static :: QUERY_LAST ) -> first ( $ columns ) ; } return $ result ; }
Retrieves the last child .
35,562
public function getChildrenRange ( $ from , $ to = null , array $ columns = [ '*' ] ) { return $ this -> children ( [ $ from , $ to ] ) -> get ( $ columns ) ; }
Retrieves children within given positions range .
35,563
protected function getLastChildPosition ( ) { $ lastChild = $ this -> getLastChild ( [ $ this -> getPositionColumn ( ) ] ) ; return ( is_null ( $ lastChild ) ? 0 : $ lastChild -> position ) ; }
Gets last child position .
35,564
public function addChild ( EntityInterface $ child , $ position = null , $ returnChild = false ) { if ( $ this -> exists ) { if ( is_null ( $ position ) ) { $ position = $ this -> getNextAfterLastPosition ( $ this -> getKey ( ) ) ; } $ child -> moveTo ( $ position , $ this ) ; } return ( $ returnChild === true ? $ chil...
Appends a child to the model .
35,565
public function addChildren ( array $ children ) { if ( $ this -> exists ) { \ DB :: connection ( $ this -> connection ) -> transaction ( function ( ) use ( $ children ) { $ lastChildPosition = $ this -> getLastChildPosition ( ) ; foreach ( $ children as $ child ) { if ( ! $ child instanceof EntityInterface ) { if ( is...
Appends a collection of children to the model .
35,566
public function removeChild ( $ position = null , $ forceDelete = false ) { if ( $ this -> exists ) { $ action = ( $ forceDelete === true ? 'forceDelete' : 'delete' ) ; $ this -> children ( $ position ) -> $ action ( ) ; } return $ this ; }
Removes a model s child with given position .
35,567
public function removeChildren ( $ from , $ to = null , $ forceDelete = false ) { if ( ! is_numeric ( $ from ) || ( ! is_null ( $ to ) && ! is_numeric ( $ to ) ) ) { throw new \ InvalidArgumentException ( '`from` and `to` are the position boundaries. They must be of type int.' ) ; } if ( $ this -> exists ) { $ action =...
Removes model s children within a range of positions .
35,568
protected function siblings ( $ direction = '' , $ parentId = false , $ order = 'asc' ) { $ parentId = ( $ parentId === false ? $ this -> parent_id : $ parentId ) ; $ query = $ this -> where ( $ this -> getParentIdColumn ( ) , '=' , $ parentId ) ; $ column = $ this -> getPositionColumn ( ) ; switch ( $ direction ) { ca...
Builds a part of the siblings query .
35,569
public function getSiblingsRange ( $ from , $ to = null , array $ columns = [ '*' ] ) { return $ this -> siblings ( [ $ from , $ to ] ) -> get ( $ columns ) ; }
Retrieves siblings within given positions range .
35,570
public function addSibling ( EntityInterface $ sibling , $ position = null , $ returnSibling = false ) { if ( $ this -> exists ) { if ( is_null ( $ position ) ) { $ position = $ this -> getNextAfterLastPosition ( ) ; } $ sibling -> moveTo ( $ position , $ this -> parent_id ) ; } return ( $ returnSibling === true ? $ si...
Appends a sibling within the current depth .
35,571
public function addSiblings ( array $ siblings , $ from = null ) { if ( $ this -> exists ) { if ( is_null ( $ from ) ) { $ from = $ this -> getNextAfterLastPosition ( ) ; } $ parent = $ this -> getParent ( ) ; foreach ( $ siblings as $ sibling ) { $ sibling -> moveTo ( $ from , $ parent ) ; $ from ++ ; } } return $ thi...
Appends multiple siblings within the current depth .
35,572
public static function getTree ( array $ columns = [ '*' ] ) { $ instance = new static ; return $ instance -> orderBy ( $ instance -> getParentIdColumn ( ) ) -> orderBy ( $ instance -> getPositionColumn ( ) ) -> get ( $ instance -> prepareTreeQueryColumns ( $ columns ) ) -> toTree ( ) ; }
Retrieves entire tree .
35,573
public static function getTreeWhere ( $ column , $ operator = null , $ value = null , array $ columns = [ '*' ] ) { $ instance = new static ; $ columns = $ instance -> prepareTreeQueryColumns ( $ columns ) ; return $ instance -> where ( $ column , $ operator , $ value ) -> get ( $ columns ) -> toTree ( ) ; }
Retrieves tree by condition .
35,574
public static function getTreeByQuery ( EloquentBuilder $ query , array $ columns = [ '*' ] ) { $ instance = new static ; $ columns = $ instance -> prepareTreeQueryColumns ( $ columns ) ; return $ query -> get ( $ columns ) -> toTree ( ) ; }
Retrieves tree with any conditions using QueryBuilder
35,575
public static function createFromArray ( array $ tree , EntityInterface $ parent = null ) { $ childrenRelationIndex = with ( new static ) -> getChildrenRelationIndex ( ) ; $ entities = [ ] ; foreach ( $ tree as $ item ) { $ children = array_pull ( $ item , $ childrenRelationIndex ) ; $ entity = new static ( $ item ) ; ...
Saves models from the given attributes array .
35,576
protected function getNewRealDepth ( $ ancestor ) { if ( ! $ ancestor instanceof EntityInterface ) { if ( is_null ( $ ancestor ) ) { return 0 ; } else { return static :: find ( $ ancestor ) -> real_depth + 1 ; } } else { return $ ancestor -> real_depth + 1 ; } }
Gets real depth of the new ancestor of the model .
35,577
public function getNextAfterLastPosition ( $ parentId = false ) { $ position = $ this -> getLastPosition ( $ parentId ) ; return $ position === null ? 0 : $ position + 1 ; }
Gets the next sibling position after the last one at the given ancestor .
35,578
protected function reorderSiblings ( $ parentIdChanged = false ) { list ( $ range , $ action ) = $ this -> setupReordering ( $ parentIdChanged ) ; $ positionColumn = $ this -> getPositionColumn ( ) ; if ( $ parentIdChanged === true ) { $ query = $ this -> siblings ( false , $ this -> old_parent_id ) ; } else { $ query ...
Reorders model s siblings when one is moved to another position or ancestor .
35,579
protected function setupReordering ( $ parentIdChanged ) { $ range = $ action = null ; if ( $ parentIdChanged === true ) { $ range = $ this -> old_position ; $ action = 'decrement' ; } else { if ( $ this -> old_parent_id !== false && $ this -> old_parent_id == $ this -> parent_id ) { if ( $ this -> position > $ this ->...
Setups model s siblings reordering .
35,580
protected function insertNode ( ) { $ descendant = $ this -> getKey ( ) ; $ ancestor = ( isset ( $ this -> parent_id ) ? $ this -> parent_id : $ descendant ) ; $ this -> closure -> insertNode ( $ ancestor , $ descendant ) ; }
Inserts new node to closure table .
35,581
protected function moveNode ( ) { if ( $ this -> exists ) { if ( is_null ( $ this -> closure -> ancestor ) ) { $ primaryKey = $ this -> getKey ( ) ; $ this -> closure -> ancestor = $ primaryKey ; $ this -> closure -> descendant = $ primaryKey ; $ this -> closure -> depth = 0 ; } if ( $ this -> isDirty ( $ this -> getPa...
Moves node to another ancestor .
35,582
protected function clampPosition ( ) { if ( ! $ this -> isDirty ( $ this -> getPositionColumn ( ) ) ) { return ; } $ newPosition = max ( 0 , min ( $ this -> position , $ this -> getNextAfterLastPosition ( ) ) ) ; $ this -> attributes [ $ this -> getPositionColumn ( ) ] = $ newPosition ; }
Clamp the position between 0 and the last position of the current parent .
35,583
protected function writeMigrations ( ) { $ files = $ this -> migrator -> create ( $ this -> options ) ; foreach ( $ files as $ file ) { $ path = pathinfo ( $ file , PATHINFO_FILENAME ) ; $ this -> line ( " <fg=green;options=bold>create</fg=green;options=bold> $path" ) ; } $ this -> composer -> dumpAutoloads ( ) ;...
Writes migration files to disk .
35,584
protected function writeModels ( ) { $ files = $ this -> modeler -> create ( $ this -> options ) ; foreach ( $ files as $ file ) { $ path = pathinfo ( $ file , PATHINFO_FILENAME ) ; $ this -> line ( " <fg=green;options=bold>create</fg=green;options=bold> $path" ) ; } }
Writes model files to disk .
35,585
protected function getOptions ( ) { return [ [ 'namespace' , 'ns' , InputOption :: VALUE_OPTIONAL , 'Namespace for entity and its closure.' ] , [ 'entity' , 'e' , InputOption :: VALUE_REQUIRED , 'Entity class name.' ] , [ 'entity-table' , 'et' , InputOption :: VALUE_OPTIONAL , 'Entity table name.' ] , [ 'closure' , 'c'...
Gets the console command options .
35,586
protected function prepareOptions ( ) { $ options = $ this -> getOptions ( ) ; $ input = [ ] ; foreach ( $ options as $ option ) { $ input [ ] = $ this -> option ( $ option [ 0 ] ) ; } $ lastnsdelim = strrpos ( $ input [ 1 ] , '\\' ) ; $ this -> options [ $ options [ 0 ] [ 0 ] ] = $ input [ 0 ] ? : rtrim ( $ this -> ge...
Prepares user input options to be passed to migrator and modeler instances .
35,587
public function register ( ) { $ this -> commands ( [ Commands \ HelperMakeCommand :: class , ] ) ; foreach ( config ( 'helpers.package_helpers' , [ ] ) as $ activeHelper ) { $ file = __DIR__ . '/Helpers/' . $ activeHelper . '.php' ; if ( file_exists ( $ file ) ) { require_once ( $ file ) ; } } if ( count ( config ( 'h...
register the service provider
35,588
public function redirectConfig ( $ name = null , $ config = null ) { if ( $ name === null && $ config === null ) { return $ this -> getConfig ( 'redirect' ) ; } $ path = sprintf ( 'redirect.%s' , $ name ) ; if ( $ config === null ) { return $ this -> getConfig ( $ path ) ; } return $ this -> setConfig ( $ path , $ conf...
Change redirect configuration
35,589
protected function _refererRedirectUrl ( $ default = null ) { $ controller = $ this -> _controller ( ) ; return $ this -> _redirectUrl ( $ controller -> referer ( $ default , true ) ) ; }
Returns the redirect_url for this request with a fallback to the referring page
35,590
protected function _redirectUrl ( $ default = null ) { $ request = $ this -> _request ( ) ; if ( ! empty ( $ request -> getData ( '_redirect_url' ) ) ) { return $ request -> getData ( '_redirect_url' ) ; } if ( ! empty ( $ request -> getQuery ( '_redirect_url' ) ) ) { return $ request -> getQuery ( '_redirect_url' ) ; ...
Returns the _redirect_url for this request .
35,591
protected function _redirect ( Subject $ subject , $ url = null , $ status = null ) { $ url = $ this -> _redirectUrl ( $ url ) ; $ subject -> url = $ url ; $ subject -> status = $ status ; $ event = $ this -> _trigger ( 'beforeRedirect' , $ subject ) ; if ( $ event -> isStopped ( ) ) { return $ this -> _controller ( ) ...
Called for all redirects inside CRUD
35,592
public function shouldProcess ( $ mode , $ actions = [ ] ) { if ( is_string ( $ actions ) ) { $ actions = [ $ actions ] ; } switch ( $ mode ) { case 'only' : return in_array ( $ this -> action , $ actions ) ; case 'not' : return ! in_array ( $ this -> action , $ actions ) ; default : throw new \ Exception ( 'Invalid mo...
Check if the called action is white listed or blacklisted depending on the mode
35,593
public function serialize ( $ keys = null ) { if ( $ keys === null ) { return ( array ) $ this -> getConfig ( 'serialize' ) ; } return $ this -> setConfig ( 'serialize' , ( array ) $ keys ) ; }
Change the serialize keys
35,594
public function saveOptions ( $ config = null ) { if ( $ config === null ) { return $ this -> getConfig ( 'saveOptions' ) ; } return $ this -> setConfig ( 'saveOptions' , $ config ) ; }
Change the saveOptions configuration
35,595
public function validation ( $ error ) { $ url = $ this -> controller -> request -> getRequestTarget ( ) ; $ status = $ code = $ error -> getCode ( ) ; try { $ this -> controller -> response = $ this -> controller -> response -> withStatus ( $ status ) ; } catch ( Exception $ e ) { $ status = 422 ; $ this -> controller...
Renders validation errors and sends a 422 error code
35,596
protected function _getErrorData ( ) { $ data = [ ] ; $ viewVars = $ this -> controller -> viewVars ; if ( ! empty ( $ viewVars [ '_serialize' ] ) ) { foreach ( $ viewVars [ '_serialize' ] as $ v ) { $ data [ $ v ] = $ viewVars [ $ v ] ; } } if ( ! empty ( $ viewVars [ 'error' ] ) && Configure :: read ( 'debug' ) ) { $...
Helper method used to generate extra debugging data into the error template
35,597
protected function _getQueryLog ( ) { $ queryLog = [ ] ; $ sources = ConnectionManager :: configured ( ) ; foreach ( $ sources as $ source ) { $ logger = ConnectionManager :: get ( $ source ) -> getLogger ( ) ; if ( method_exists ( $ logger , 'getLogs' ) ) { $ queryLog [ $ source ] = $ logger -> getLogs ( ) ; } } retur...
Helper method to get query log .
35,598
public function message ( $ type , array $ replacements = [ ] ) { if ( empty ( $ type ) ) { throw new \ Exception ( 'Missing message type' ) ; } $ crud = $ this -> _crud ( ) ; $ config = $ this -> getConfig ( 'messages.' . $ type ) ; if ( empty ( $ config ) ) { $ config = $ crud -> getConfig ( 'messages.' . $ type ) ; ...
return the config for a given message type
35,599
public function publishSuccess ( Event $ event ) { if ( ! isset ( $ event -> getSubject ( ) -> success ) ) { return false ; } $ this -> _controller ( ) -> set ( 'success' , $ event -> getSubject ( ) -> success ) ; }
Set success variable for view .