idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
52,100
protected function enrichReferenceData ( ModelMetaReferenceInterface $ data ) { if ( null === $ data -> source ( ) || null === $ data -> strategy ( ) ) { if ( $ info = $ this -> getModelInformation ( $ data -> model ( ) ) ) { if ( null === $ data -> source ( ) ) { $ data -> source = $ info -> reference -> source ; } if ( null === $ data -> strategy ( ) ) { $ data -> strategy = $ info -> reference -> strategy ; } } } return $ data ; }
Enriches refernce data object as required .
52,101
public function registerCommands ( ) { $ this -> app [ 'foruminstallcommand' ] = $ this -> app -> share ( function ( $ app ) { return new InstallCommand ; } ) ; $ this -> commands ( 'foruminstallcommand' ) ; }
Register package artisan commands .
52,102
protected function getListColumnStrategyInstances ( ) { $ instances = [ ] ; $ info = $ this -> getModelInformation ( ) ; foreach ( $ info -> list -> columns as $ key => $ data ) { $ instance = $ this -> getListDisplayFactory ( ) -> make ( $ data -> strategy ) ; $ instance -> setListInformation ( $ data ) -> setOptions ( $ data -> options ( ) ) ; if ( $ data -> source ) { if ( isset ( $ info -> attributes [ $ data -> source ] ) ) { $ instance -> setAttributeInformation ( $ info -> attributes [ $ data -> source ] ) ; } } $ instance -> initialize ( $ info -> modelClass ( ) ) ; $ instances [ $ key ] = $ instance ; } return $ instances ; }
Collects and returns strategy instances for list columns .
52,103
public function collect ( ) { $ this -> information = new Collection ; $ this -> cmsModelFiles = $ this -> getCmsModelFiles ( ) ; $ this -> modelClasses = $ this -> getModelsToCollect ( ) ; $ this -> collectRawModels ( ) -> collectCmsModels ( ) -> enrichModelInformation ( ) ; return $ this -> information ; }
Collects and returns information about models .
52,104
protected function collectRawModels ( ) { foreach ( $ this -> modelClasses as $ class ) { $ key = $ this -> moduleHelper -> modelInformationKeyForModel ( $ class ) ; try { $ this -> information -> put ( $ key , $ this -> modelAnalyzer -> analyze ( $ class ) ) ; } catch ( \ Exception $ e ) { throw ( new ModelInformationCollectionException ( "Issue analyzing model {$class}: \n{$e->getMessage()}" , ( int ) $ e -> getCode ( ) , $ e ) ) -> setModelClass ( $ class ) ; } } return $ this ; }
Collects information about config - defined app model classes .
52,105
protected function collectCmsModels ( ) { foreach ( $ this -> cmsModelFiles as $ file ) { try { $ this -> collectSingleCmsModelFromFile ( $ file ) ; } catch ( \ Exception $ e ) { $ message = $ e -> getMessage ( ) ; if ( $ e instanceof ModelConfigurationDataException ) { $ message = "{$e->getMessage()} ({$e->getDotKey()})" ; } throw ( new ModelInformationCollectionException ( "Issue reading/interpreting model configuration file {$file->getRealPath()}: \n{$message}" , ( int ) $ e -> getCode ( ) , $ e ) ) -> setConfigurationFile ( $ file -> getRealPath ( ) ) ; } } return $ this ; }
Collects information from dedicated CMS model information classes .
52,106
protected function collectSingleCmsModelFromFile ( SplFileInfo $ file ) { $ info = $ this -> informationReader -> read ( $ file -> getRealPath ( ) ) ; if ( ! is_array ( $ info ) ) { $ path = basename ( $ file -> getRelativePath ( ) ? : $ file -> getRealPath ( ) ) ; throw new UnexpectedValueException ( "Incorrect data from CMS model information file: '{$path}'" ) ; } $ info = $ this -> informationInterpreter -> interpret ( $ info ) ; $ modelClass = $ this -> makeModelFqnFromCmsModelPath ( $ file -> getRelativePathname ( ) ) ; $ key = $ this -> moduleHelper -> modelInformationKeyForModel ( $ modelClass ) ; if ( ! $ this -> information -> has ( $ key ) ) { $ this -> getCore ( ) -> log ( 'debug' , "CMS model data for unset model information key '{$key}'" ) ; return ; } $ originalInfo = $ this -> information -> get ( $ key ) ; $ originalInfo -> merge ( $ info ) ; $ this -> information -> put ( $ key , $ originalInfo ) ; }
Collects CMS configuration information from a given Spl file .
52,107
protected function makeModelFqnFromCmsModelPath ( $ path ) { $ extension = pathinfo ( $ path , PATHINFO_EXTENSION ) ; if ( $ extension ) { $ path = substr ( $ path , 0 , - 1 * strlen ( $ extension ) - 1 ) ; } return rtrim ( config ( 'cms-models.collector.source.models-namespace' ) , '\\' ) . '\\' . str_replace ( '/' , '\\' , $ path ) ; }
Returns the FQN for the model that is related to a given cms model information file path .
52,108
protected function getMorphableModelsForFieldData ( ModelFormFieldDataInterface $ data ) { $ modelsOption = array_get ( $ data -> options ( ) , 'models' , [ ] ) ; $ modelClasses = array_map ( function ( $ key , $ value ) { if ( is_string ( $ value ) ) { return $ value ; } return $ key ; } , array_keys ( $ modelsOption ) , array_values ( $ modelsOption ) ) ; return array_unique ( $ modelClasses ) ; }
Returns the model class names that the model may be related to .
52,109
protected function isPotentialRelationMethod ( ReflectionMethod $ method ) { if ( ! $ method -> isPublic ( ) || in_array ( $ method -> name , $ this -> getIgnoredRelationNames ( ) ) || $ method -> getNumberOfRequiredParameters ( ) ) { return false ; } foreach ( $ this -> mustNotMatchClass as $ regEx ) { if ( preg_match ( $ regEx , $ method -> class ) ) { return false ; } } $ file = $ method -> getFileName ( ) ; foreach ( $ this -> mustNotMatchFile as $ regEx ) { if ( preg_match ( $ regEx , $ file ) ) { return false ; } } return true ; }
Returns whether a reflected method may be an Eloquent relation .
52,110
protected function isNullableKey ( $ key ) { if ( ! array_key_exists ( $ key , $ this -> info -> attributes ) ) { throw new RuntimeException ( "Foreign key '{$key}' defined for relation does not exist on model " . get_class ( $ this -> model ( ) ) ) ; } return ( bool ) $ this -> info -> attributes [ $ key ] -> nullable ; }
Returns whether attribute with key is known to be nullable .
52,111
protected function isReflectionMethodEloquentRelation ( ReflectionMethod $ method ) { $ cmsTags = $ this -> getCmsDocBlockTags ( $ method ) ; if ( array_get ( $ cmsTags , 'relation' ) ) { return true ; } if ( array_get ( $ cmsTags , 'ignore' ) ) { return false ; } $ body = $ this -> getMethodBody ( $ method ) ; return ( bool ) $ this -> findRelationMethodCall ( $ body ) ; }
Determines whether a given method is a typical relation method
52,112
protected function findRelationMethodCall ( $ methodBody ) { $ methodBody = trim ( preg_replace ( '#\\n\\s*#' , '' , $ methodBody ) ) ; $ foundOpener = null ; $ lastPosition = - 1 ; foreach ( $ this -> relationMethodCallOpeners ( ) as $ opener ) { if ( false === ( $ pos = strrpos ( $ methodBody , $ opener ) ) || $ pos <= $ lastPosition ) { continue ; } $ foundOpener = $ opener ; $ lastPosition = $ pos ; } if ( ! $ foundOpener || $ lastPosition < 0 ) { return false ; } return $ foundOpener ; }
Attempts to find the relation method call in a string method body .
52,113
public function render ( Model $ model , $ source ) { $ source = $ this -> resolveModelSource ( $ model , $ source ) ; return '#' . $ model -> getKey ( ) . ': ' . $ source ; }
Returns model reference string
52,114
public function analyze ( Model $ model , $ strategy = 'translatable' ) { $ this -> model = $ model ; $ this -> info = new ModelInformation ( [ ] ) ; switch ( $ strategy ) { case 'translatable' : $ this -> analyzeForTranslatable ( ) ; break ; default : throw new \ UnexpectedValueException ( "Cannot handle translation strategy '{$strategy}" ) ; } return $ this -> info ; }
Analyzes a model for its translations and returns relevant information .
52,115
protected function analyzeForTranslatable ( ) { $ model = $ this -> model ; $ translationModel = $ model -> getTranslationModelName ( ) ; $ this -> info = $ this -> analyzer -> analyze ( $ translationModel ) ; $ attributes = $ this -> info [ 'attributes' ] ; foreach ( $ attributes as $ key => $ attribute ) { if ( ! $ model -> isTranslationAttribute ( $ key ) ) continue ; $ attributes [ $ key ] [ 'translated' ] = true ; } $ this -> info [ 'attributes' ] = $ attributes ; }
Analyzes a model using the translatable trait strategy .
52,116
public function errors ( ) { $ errors = parent :: errors ( ) ; if ( ! empty ( $ errors ) ) { $ errors [ $ this -> generalErrorsKey ( ) ] = $ this -> collectGeneralErrors ( $ errors ) ; } return $ errors ; }
Get all of the validation error messages .
52,117
public function header ( ) { if ( $ this -> header_translated ) { return cms_trans ( $ this -> header_translated ) ; } if ( $ this -> header ) { return $ this -> header ; } return ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ this -> source ) ) ) ; }
Returns display header label for the column .
52,118
public function setMaxFileSize ( int $ value ) { $ this -> maxFileSize = $ value ; $ this -> addValidationRule ( 'max:' . $ this -> maxFileSize ) ; return $ this ; }
The maximum size allowed for an uploaded file in kilobytes
52,119
public function setFileExtensions ( string $ value ) { $ this -> fileExtensions = $ value ; $ this -> addValidationRule ( 'mimes:' . $ value ) ; return $ this ; }
A list of allowable extensions that can be uploaded .
52,120
public function saveFile ( UploadedFile $ file ) { Validator :: validate ( [ $ this -> getName ( ) => $ file ] , $ this -> getUploadValidationRules ( ) , $ this -> getUploadValidationMessages ( ) , $ this -> getUploadValidationTitles ( ) ) ; $ path = $ file -> storeAs ( $ this -> getUploadPath ( $ file ) , $ this -> getUploadFileName ( $ file ) , $ this -> getDisk ( ) ) ; return $ this -> getFileInfo ( $ path ) ; }
Save file to storage
52,121
protected function incrementKey ( $ initial = 1 ) { $ result = $ this -> database -> openBucket ( $ this -> table ) -> counter ( $ this -> identifier ( ) , $ initial , [ 'initial' => abs ( $ initial ) ] ) ; return $ result -> value ; }
generate increment key
52,122
public function upsert ( array $ values ) { if ( empty ( $ values ) ) { return true ; } $ values = $ this -> detectValues ( $ values ) ; $ bindings = [ ] ; foreach ( $ values as $ record ) { foreach ( $ record as $ key => $ value ) { $ bindings [ $ key ] = $ value ; } } $ sql = $ this -> grammar -> compileUpsert ( $ this , $ values ) ; return $ this -> connection -> upsert ( $ sql , $ bindings ) ; }
supported N1QL upsert query .
52,123
protected function getAttributeFrom ( ) { $ attribute = array_get ( $ this -> formFieldData -> options ( ) , 'from' , $ this -> formFieldData -> source ( ) ) ; if ( ! $ attribute ) { throw new UnexpectedValueException ( "DateRangeStrategy must have 'date_from' option set" ) ; } return $ attribute ; }
Returns attribute name for the from date .
52,124
protected function registerCouchbaseBucketCacheDriver ( ) : void { $ this -> app [ 'cache' ] -> extend ( 'couchbase' , function ( $ app , $ config ) { $ cluster = $ app [ 'db' ] -> connection ( $ config [ 'driver' ] ) -> getCouchbase ( ) ; $ password = ( isset ( $ config [ 'bucket_password' ] ) ) ? $ config [ 'bucket_password' ] : '' ; return new Repository ( new CouchbaseStore ( $ cluster , $ config [ 'bucket' ] , $ password , $ app [ 'config' ] -> get ( 'cache.prefix' ) ) ) ; } ) ; }
register couchbase cache driver . for bucket type couchbase .
52,125
protected function registerMemcachedBucketCacheDriver ( ) : void { $ this -> app [ 'cache' ] -> extend ( 'couchbase-memcached' , function ( $ app , $ config ) { $ prefix = $ app [ 'config' ] [ 'cache.prefix' ] ; $ credential = $ config [ 'sasl' ] ?? [ ] ; $ memcachedBucket = $ this -> app [ 'couchbase.memcached.connector' ] -> connect ( $ config [ 'servers' ] ) ; return new Repository ( new MemcachedBucketStore ( $ memcachedBucket , strval ( $ prefix ) , $ config [ 'servers' ] , $ credential ) ) ; } ) ; }
register couchbase cache driver . for bucket type memcached .
52,126
protected function registerCouchbaseQueueDriver ( ) : void { $ queueManager = $ this -> app [ 'queue' ] ; $ queueManager -> addConnector ( 'couchbase' , function ( ) { $ databaseManager = $ this -> app [ 'db' ] ; return new QueueConnector ( $ databaseManager ) ; } ) ; }
register custom queue couchbase driver
52,127
protected function getEnumValuesFromType ( $ type ) { if ( ! preg_match ( '#^enum\((?<values>.*)\)$#i' , $ type , $ matches ) ) { return false ; } $ enum = [ ] ; foreach ( explode ( ',' , $ matches [ 'values' ] ) as $ value ) { $ v = trim ( $ value , "'" ) ; $ enum [ ] = $ v ; } return $ enum ; }
Returns enum values for column type string .
52,128
public function setPage ( $ page ) { if ( empty ( $ page ) ) { return $ this -> clearPage ( ) ; } session ( ) -> put ( $ this -> getSessionKey ( static :: TYPE_PAGE ) , $ page ) ; return $ this ; }
Sets active page for the current context .
52,129
public function setPageSize ( $ size ) { if ( ! $ size ) { return $ this -> clearPageSize ( ) ; } session ( ) -> put ( $ this -> getSessionKey ( static :: TYPE_PAGESIZE ) , $ size ) ; return $ this ; }
Sets active page size for the current context .
52,130
public function setScope ( $ scope ) { if ( empty ( $ scope ) ) { return $ this -> clearScope ( ) ; } session ( ) -> put ( $ this -> getSessionKey ( static :: TYPE_SCOPE ) , $ scope ) ; return $ this ; }
Sets active scope for the current context .
52,131
public function getListParent ( ) { $ parent = session ( ) -> get ( $ this -> getSessionKey ( static :: TYPE_PARENT ) ) ; if ( null === $ parent ) { return null ; } if ( static :: PARENT_DISABLE === $ parent ) { return false ; } list ( $ relation , $ key ) = explode ( ':' , $ parent , 2 ) ; return compact ( 'relation' , 'key' ) ; }
Returns active parent for current context .
52,132
public function setListParent ( $ relation , $ recordKey = null ) { if ( false !== $ relation && empty ( $ relation ) ) { return $ this -> clearListParent ( ) ; } if ( false === $ relation ) { session ( ) -> put ( $ this -> getSessionKey ( static :: TYPE_PARENT ) , static :: PARENT_DISABLE ) ; } else { session ( ) -> put ( $ this -> getSessionKey ( static :: TYPE_PARENT ) , $ relation . ':' . $ recordKey ) ; } return $ this ; }
Sets active parent for the current context .
52,133
protected function getSessionKey ( $ type = null ) { return $ this -> context . ( $ this -> contextSub ? '[' . $ this -> contextSub . ']' : null ) . ( $ type ? ':' . $ type : null ) ; }
Returns session key optionally for a given type of data .
52,134
protected function isUploadModuleAvailable ( ) { if ( $ this -> isUploadModuleAvailable === null ) { $ this -> isUploadModuleAvailable = false !== $ this -> getUploadModule ( ) && app ( ) -> bound ( FileRepositoryInterface :: class ) ; } return $ this -> isUploadModuleAvailable ; }
Returns whether the upload module is loaded .
52,135
protected function checkFileUploadWithSessionGuard ( $ id ) { $ guard = $ this -> getFileUploadSesssionGuard ( ) ; return ! $ guard -> enabled ( ) || $ guard -> check ( $ id ) ; }
Returns whether file upload is allowed to be used within this session .
52,136
protected function checkAttributeAssignable ( $ attribute ) : void { if ( ! $ this -> exceptionOnUnknown || empty ( $ this -> known ) ) { return ; } if ( is_array ( $ attribute ) ) { foreach ( $ attribute as $ singleAttribute ) { $ this -> checkAttributeAssignable ( $ singleAttribute ) ; } return ; } if ( ! in_array ( $ attribute , $ this -> known , true ) ) { throw ( new ModelConfigurationDataException ( "Unknown model configuration data key: '{$attribute}' in " . get_class ( $ this ) ) ) -> setDotKey ( $ attribute ) ; } }
Overridden to use for known nested attribute checks
52,137
public function modelSlug ( $ model ) { if ( is_object ( $ model ) ) { $ model = get_class ( $ model ) ; } return str_replace ( '\\' , '-' , strtolower ( $ model ) ) ; }
Returns the model slug for a model or model FQN .
52,138
public function dropPrimary ( $ index = null , $ ignoreIfNotExist = false ) { $ this -> connection -> openBucket ( $ this -> getTable ( ) ) -> manager ( ) -> dropN1qlPrimaryIndex ( $ this -> detectIndexName ( $ index ) , $ ignoreIfNotExist ) ; }
drop for N1QL primary index
52,139
public function dropIndex ( $ index , $ ignoreIfNotExist = false ) { $ this -> connection -> openBucket ( $ this -> getTable ( ) ) -> manager ( ) -> dropN1qlIndex ( $ index , $ ignoreIfNotExist ) ; }
drop for N1QL secondary index
52,140
public function primaryIndex ( $ name = null , $ ignoreIfExist = false , $ defer = false ) { $ this -> connection -> openBucket ( $ this -> getTable ( ) ) -> manager ( ) -> createN1qlPrimaryIndex ( $ this -> detectIndexName ( $ name ) , $ ignoreIfExist , $ defer ) ; }
Specify the primary index for the current bucket .
52,141
public function index ( $ columns , $ name = null , $ whereClause = '' , $ ignoreIfExist = false , $ defer = false ) { $ name = ( is_null ( $ name ) ) ? $ this -> getTable ( ) . "_secondary_index" : $ name ; return $ this -> connection -> openBucket ( $ this -> getTable ( ) ) -> manager ( ) -> createN1qlIndex ( $ name , $ columns , $ whereClause , $ ignoreIfExist , $ defer ) ; }
Specify a secondary index for the current bucket .
52,142
protected function resolveModelSource ( Model $ model , $ source ) { if ( $ method = $ this -> parseAsModelMethodStrategyString ( $ source , $ model ) ) { return $ model -> { $ method } ( ) ; } if ( $ data = $ this -> parseAsInstantiableClassMethodStrategyString ( $ source ) ) { $ method = $ data [ 'method' ] ; $ instance = $ data [ 'instance' ] ; return $ instance -> { $ method } ( $ model ) ; } if ( method_exists ( $ model , $ source ) ) { return $ model -> { $ source } ( ) ; } return $ model -> { $ source } ; }
Resolves and returns source content for a list strategy .
52,143
public function getRouteNameForModelInformation ( ModelInformationInterface $ information , $ prefix = false ) { if ( ! $ information -> modelClass ( ) ) { throw new \ UnexpectedValueException ( "No model class in information, cannot make route name" ) ; } return $ this -> getRouteNameForModelClass ( $ information -> modelClass ( ) , $ prefix ) ; }
Returns the route name for a given set of model information .
52,144
public function getRouteNameForModelClass ( $ modelClass , $ prefix = false ) { $ modelSlug = static :: MODEL_ROUTE_NAME_PREFIX . $ this -> getRouteSlugForModelClass ( $ modelClass ) ; if ( ! $ prefix ) { return $ modelSlug ; } return config ( 'cms-core.route.name-prefix' ) . config ( 'cms-models.route.name-prefix' ) . $ modelSlug ; }
Returns the route name for a given model FQN .
52,145
public function getRoutePathForModelInformation ( ModelInformationInterface $ information , $ prefix = false ) { if ( ! $ information -> modelClass ( ) ) { throw new \ UnexpectedValueException ( "No model class in information, cannot make route path" ) ; } return $ this -> getRoutePathForModelClass ( $ information -> modelClass ( ) , $ prefix ) ; }
Returns the route path for a given set of model information .
52,146
public function getRoutePathForModelClass ( $ modelClass , $ prefix = false ) { $ modelSlug = $ this -> getRouteSlugForModelClass ( $ modelClass ) ; if ( ! $ prefix ) { return $ modelSlug ; } return config ( 'cms-core.route.prefix' ) . config ( 'cms-models.route.prefix' ) . '/' . $ modelSlug ; }
Returns the route path for a given model FQN .
52,147
public function getPermissionPrefixForModuleKey ( $ key ) { if ( starts_with ( $ key , ModuleHelper :: MODULE_PREFIX ) ) { $ key = substr ( $ key , strlen ( ModuleHelper :: MODULE_PREFIX ) ) ; } return $ this -> getPermissionPrefixForModelSlug ( $ key ) ; }
Returns the full permission prefix for a model module s key .
52,148
protected function getModelModuleKeyForRouteNameSegment ( $ nameSegment ) { if ( false === $ nameSegment ) { return false ; } return ModuleHelper :: MODULE_PREFIX . $ this -> getModelSlugForRouteNameSegment ( $ nameSegment ) ; }
Returns the model module key for a model route name segment .
52,149
protected function getModelSlugForRouteNameSegment ( $ nameSegment ) { $ dotPosition = strpos ( $ nameSegment , '.' ) ; if ( false === $ dotPosition ) { return $ nameSegment ; } return substr ( $ nameSegment , 0 , $ dotPosition ) ; }
Returns the model slug for a model route name segment .
52,150
protected function getModelRouteNameSegment ( $ routeName = null ) { $ routeName = $ routeName ? : $ this -> getRouteName ( ) ; $ combinedPrefix = config ( 'cms-core.route.name-prefix' ) . config ( 'cms-models.route.name-prefix' ) . static :: MODEL_ROUTE_NAME_PREFIX ; if ( ! starts_with ( $ routeName , $ combinedPrefix ) ) { return false ; } return substr ( $ routeName , strlen ( $ combinedPrefix ) ) ; }
Returns the route name part that represents the model .
52,151
protected function resolveStrategyClass ( $ strategy ) { if ( empty ( $ strategy ) ) { return false ; } if ( ! str_contains ( $ strategy , '.' ) ) { $ strategy = config ( $ this -> getAliasesBaseConfigKey ( ) . $ strategy , $ strategy ) ; } if ( class_exists ( $ strategy ) && is_a ( $ strategy , $ this -> getStrategyInterfaceClass ( ) , true ) ) { return $ strategy ; } $ strategy = $ this -> prefixStrategyNamespace ( $ strategy ) ; if ( class_exists ( $ strategy ) && is_a ( $ strategy , $ this -> getStrategyInterfaceClass ( ) , true ) ) { return $ strategy ; } return false ; }
Resolves strategy assuming it is the class name or FQN of an action strategy interface implementation or an alias for one .
52,152
protected function getNestedRelation ( Model $ model , $ source , $ actual = false ) { if ( $ source instanceof Relation ) { return $ source ; } $ relationNames = explode ( '.' , $ source ) ; $ relationName = array_shift ( $ relationNames ) ; if ( ! method_exists ( $ model , $ relationName ) ) { throw new UnexpectedValueException ( 'Model ' . get_class ( $ model ) . " does not have relation method {$relationName}" ) ; } $ relation = $ model -> { $ relationName } ( ) ; if ( ! ( $ relation instanceof Relation ) ) { throw new UnexpectedValueException ( 'Model ' . get_class ( $ model ) . ".{$relationName} is not an Eloquent relation" ) ; } if ( ! count ( $ relationNames ) ) { return $ relation ; } if ( $ actual && ! $ this -> isRelationSingle ( $ relation ) ) { throw new UnexpectedValueException ( 'Model ' . get_class ( $ model ) . ".{$relationName} does not allow deeper nesting (not to-one)" ) ; } if ( $ actual ) { $ model = $ relation -> first ( ) ; } else { $ model = $ relation -> getRelated ( ) ; } if ( ! $ model ) return null ; return $ this -> getNestedRelation ( $ model , implode ( '.' , $ relationNames ) ) ; }
Returns relation nested to any level for a dot notation source .
52,153
public function apply ( $ query , $ target , $ value , $ parameters = [ ] ) { $ this -> model = $ query -> getModel ( ) ; $ this -> parameters = $ parameters ; $ targets = $ this -> parseTargets ( $ target ) ; if ( count ( $ targets ) == 1 ) { $ this -> applyForSingleTarget ( $ query , head ( $ targets ) , $ value , true ) ; return ; } $ query -> where ( function ( $ query ) use ( $ targets , $ value ) { $ this -> combineOr = true ; foreach ( $ targets as $ index => $ singleTarget ) { $ this -> applyForSingleTarget ( $ query , $ singleTarget , $ value , $ index < 1 ) ; } } ) ; }
Applies the filter value to the query .
52,154
protected function applyForSingleTarget ( $ query , array $ targetParts , $ value , $ isFirst = false ) { $ this -> translated = $ this -> isTranslatedTargetAttribute ( $ targetParts , $ query -> getModel ( ) ) ; $ this -> applyRecursive ( $ query , $ targetParts , $ value , $ isFirst ) ; }
Applies the filter for a single part of multiple targets
52,155
protected function applyRecursive ( $ query , array $ targetParts , $ value , $ isFirst = false ) { if ( count ( $ targetParts ) < 2 ) { if ( $ this -> translated ) { return $ this -> applyTranslatedValue ( $ query , head ( $ targetParts ) , $ value , $ isFirst ) ; } return $ this -> applyValue ( $ query , head ( $ targetParts ) , $ value , null , $ isFirst ) ; } $ relation = array_shift ( $ targetParts ) ; $ whereHasMethod = ! $ isFirst && $ this -> combineOr ? 'orWhereHas' : 'whereHas' ; return $ query -> { $ whereHasMethod } ( $ relation , function ( $ query ) use ( $ targetParts , $ value ) { return $ this -> applyRecursive ( $ query , $ targetParts , $ value , true ) ; } ) ; }
Applies a the filter value recursively for normalized target segments .
52,156
protected function interpretSpecialTargets ( array $ targets ) { $ normalized = [ ] ; foreach ( $ targets as $ targetParts ) { if ( count ( $ targetParts ) == 1 && trim ( head ( $ targetParts ) ) == '*' ) { $ normalized += $ this -> makeTargetsForAllAttributes ( ) ; continue ; } $ normalized [ ] = $ targetParts ; } return $ normalized ; }
Interprets and translates special targets into separate target arrays .
52,157
protected function makeTargetsForAllAttributes ( ) { $ modelInfo = $ this -> getModelInformation ( ) ; if ( ! $ modelInfo ) { return [ ] ; } $ targets = [ ] ; foreach ( $ modelInfo -> attributes as $ key => $ attribute ) { if ( ! $ this -> isAttributeRelevant ( $ attribute ) ) continue ; $ targets [ ] = $ this -> parseTarget ( $ key ) ; } return $ targets ; }
Returns a targets array with normalized target parts for all relevant attributes of the main query model .
52,158
protected function getModelInformation ( ) { if ( null === $ this -> model ) { return false ; } return $ this -> getModelInformationRepository ( ) -> getByModel ( $ this -> model ) ; }
Returns model information instance for query if possible .
52,159
protected function registerCommands ( ) : void { $ this -> app -> singleton ( 'command.couchbase.indexes' , function ( $ app ) { return new IndexFinderCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.primary.index.create' , function ( $ app ) { return new PrimaryIndexCreatorCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.primary.index.drop' , function ( $ app ) { return new PrimaryIndexRemoverCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.index.create' , function ( $ app ) { return new IndexCreatorCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.index.drop' , function ( $ app ) { return new IndexRemoverCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.queue.index.create' , function ( $ app ) { return new QueueCreatorCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] ) ; } ) ; $ this -> app -> singleton ( 'command.couchbase.design.document.create' , function ( $ app ) { return new DesignCreatorCommand ( $ app [ 'Illuminate\Database\DatabaseManager' ] , $ app [ 'config' ] -> get ( 'couchbase.design' ) ) ; } ) ; $ this -> commands ( [ 'command.couchbase.indexes' , 'command.couchbase.primary.index.create' , 'command.couchbase.primary.index.drop' , 'command.couchbase.index.create' , 'command.couchbase.index.drop' , 'command.couchbase.queue.index.create' , 'command.couchbase.design.document.create' , ] ) ; }
register laravel - couchbase commands
52,160
protected function fillDataForEmpty ( ) { $ fields = [ ] ; foreach ( $ this -> info -> attributes as $ attribute ) { if ( $ attribute -> hidden || ! $ this -> shouldAttributeBeDisplayedByDefault ( $ attribute , $ this -> info ) ) { continue ; } $ fields [ $ attribute -> name ] = $ this -> makeModelShowFieldDataForAttributeData ( $ attribute , $ this -> info ) ; } $ this -> info -> show -> fields = $ fields ; }
Fills field data if no custom data is set .
52,161
protected function enrichField ( $ key , ModelShowFieldDataInterface $ field , array & $ fields ) { $ normalizedRelationName = $ this -> normalizeRelationName ( $ key ) ; if ( ! isset ( $ this -> info -> attributes [ $ key ] ) && ! isset ( $ this -> info -> relations [ $ normalizedRelationName ] ) ) { if ( $ this -> isShowFieldDataComplete ( $ field ) ) { $ fields [ $ key ] = $ field ; return ; } throw new UnexpectedValueException ( "Incomplete data for for show field key that does not match known model attribute or relation method. " . "Requires at least 'source' and 'strategy' values." ) ; } if ( isset ( $ this -> info -> attributes [ $ key ] ) ) { $ attributeFieldInfo = $ this -> makeModelShowFieldDataForAttributeData ( $ this -> info -> attributes [ $ key ] , $ this -> info ) ; } else { $ attributeFieldInfo = $ this -> makeModelShowFieldDataForRelationData ( $ this -> info -> relations [ $ normalizedRelationName ] , $ this -> info ) ; } $ attributeFieldInfo -> merge ( $ field ) ; $ fields [ $ key ] = $ attributeFieldInfo ; }
Enriches a single show field and saves the data .
52,162
protected function makeModelShowFieldDataForAttributeData ( ModelAttributeData $ attribute , ModelInformationInterface $ info ) { $ primaryIncrementing = $ attribute -> name === $ this -> model -> getKeyName ( ) && $ info -> incrementing ; return new ModelShowFieldData ( [ 'source' => $ attribute -> name , 'strategy' => $ this -> determineListDisplayStrategyForAttribute ( $ attribute ) , 'style' => $ primaryIncrementing ? 'primary-id' : null , 'label' => ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ attribute -> name ) ) ) , ] ) ; }
Makes data set for show field given attribute data .
52,163
protected function makeModelShowFieldDataForRelationData ( ModelRelationData $ relation , ModelInformationInterface $ info ) { return new ModelShowFieldData ( [ 'source' => $ relation -> method , 'strategy' => $ this -> determineListDisplayStrategyForRelation ( $ relation ) , 'label' => ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ relation -> method ) ) ) , ] ) ; }
Makes data set for list field given relation data .
52,164
protected function fillDataForEmpty ( ) { if ( config ( 'cms-models.analyzer.filters.single-any-string' ) ) { $ filters = $ this -> makeCombinedFiltersWithAnyStringFilter ( ) ; } else { $ filters = $ this -> makeFiltersForAllAttributes ( ) ; } $ this -> info -> list -> filters = $ filters ; }
Fills filter data if no custom data is set .
52,165
protected function makeFiltersForAllAttributes ( ) { $ filters = [ ] ; foreach ( $ this -> info -> attributes as $ attribute ) { if ( $ attribute -> hidden || ! $ this -> shouldAttributeBeFilterable ( $ attribute ) ) { continue ; } $ filterData = $ this -> makeModelListFilterDataForAttributeData ( $ attribute , $ this -> info ) ; if ( ! $ filterData ) continue ; $ filters [ $ attribute -> name ] = $ filterData ; } return $ filters ; }
Makes separate filter data sets for all attributes .
52,166
protected function shouldAttributeBeFilterable ( ModelAttributeDataInterface $ attribute ) { foreach ( $ this -> info -> relations as $ key => $ relation ) { switch ( $ relation -> type ) { case RelationType :: MORPH_TO : case RelationType :: BELONGS_TO : case RelationType :: BELONGS_TO_THROUGH : $ keys = $ relation -> foreign_keys ? : [ ] ; if ( in_array ( $ attribute -> name , $ keys ) ) { return false ; } break ; } } return true ; }
Returns whether a given attribute should be filterable by default .
52,167
protected function makeModelListFilterDataForAttributeData ( ModelAttributeData $ attribute , ModelInformationInterface $ info ) { $ strategy = false ; $ options = [ ] ; if ( $ attribute -> cast === AttributeCast :: BOOLEAN ) { $ strategy = FilterStrategy :: BOOLEAN ; } elseif ( $ attribute -> type === 'enum' ) { $ strategy = FilterStrategy :: DROPDOWN ; $ options [ 'values' ] = $ attribute -> values ; } elseif ( $ attribute -> cast === AttributeCast :: STRING ) { $ strategy = FilterStrategy :: STRING ; } elseif ( $ attribute -> cast === AttributeCast :: DATE ) { $ strategy = FilterStrategy :: DATE ; } if ( ! $ strategy ) { return false ; } return new ModelListFilterData ( [ 'source' => $ attribute -> name , 'label' => str_replace ( '_' , ' ' , snake_case ( $ attribute -> name ) ) , 'target' => $ attribute -> name , 'strategy' => $ strategy , 'options' => $ options , ] ) ; }
Makes list filter data given attribute data .
52,168
public function labelPlural ( $ translated = true ) { if ( $ translated && $ key = $ this -> getAttribute ( 'translated_name_plural' ) ) { if ( ( $ label = cms_trans ( $ key ) ) !== $ key ) { return $ label ; } } return $ this -> getAttribute ( 'verbose_name_plural' ) ; }
Returns label for multiple items .
52,169
public function deleteCondition ( ) { if ( null === $ this -> delete_condition || false === $ this -> delete_condition ) { return false ; } return $ this -> delete_condition ; }
Returns delete condition if set or false if not .
52,170
public function deleteStrategy ( ) { if ( null === $ this -> delete_strategy || false === $ this -> delete_strategy ) { return false ; } return $ this -> delete_strategy ; }
Returns delete strategy if set or false if not .
52,171
public function confirmDelete ( ) { if ( null === $ this -> confirm_delete ) { return ( bool ) config ( 'cms-models.defaults.confirm_delete' , false ) ; } return ( bool ) $ this -> confirm_delete ; }
Returns whether deletions should be confirmed by the user .
52,172
public function merge ( ModelInformationInterface $ with ) { if ( ! empty ( $ with -> model ) ) { $ this -> model = $ with -> model ; } if ( ! empty ( $ with -> original_model ) ) { $ this -> original_model = $ with -> original_model ; } $ mergeAttributes = [ 'single' , 'meta' , 'verbose_name' , 'translated_name' , 'verbose_name_plural' , 'translated_name_plural' , 'allow_delete' , 'delete_condition' , 'delete_strategy' , 'confirm_delete' , 'list' , 'form' , 'show' , 'export' , 'reference' , 'includes' , ] ; foreach ( $ mergeAttributes as $ attribute ) { $ this -> mergeAttribute ( $ attribute , $ with -> { $ attribute } ) ; } }
Merges information into this information set with the new information being leading .
52,173
public function determineValidationRules ( ModelRelationData $ relation , ModelFormFieldData $ field ) { $ rules = [ ] ; if ( $ field -> required ( ) && ! $ field -> translated ( ) ) { $ rules [ ] = 'required' ; } else { $ rules [ ] = 'nullable' ; } return $ rules ; }
Determines validation rules for given relation data .
52,174
public function shouldDisplay ( ) : bool { if ( $ this -> before || $ this -> after ) { return true ; } return ( bool ) count ( $ this -> children ) ; }
Returns whether the tab - pane should be displayed
52,175
protected function interpretDateIndicator ( $ indicator ) { if ( ! is_string ( $ indicator ) ) { throw new \ UnexpectedValueException ( 'Unexpected date indicator value: ' . print_r ( $ indicator , true ) ) ; } if ( 'now' === strtolower ( $ indicator ) ) { return Carbon :: now ( ) -> format ( 'Y-m-d H:i:s' ) ; } if ( starts_with ( $ indicator , '-' ) ) { return Carbon :: now ( ) -> sub ( new \ DateInterval ( substr ( $ indicator , 1 ) ) ) -> format ( 'Y-m-d H:i:s' ) ; } if ( starts_with ( $ indicator , '+' ) ) { return Carbon :: now ( ) -> add ( new \ DateInterval ( substr ( $ indicator , 1 ) ) ) -> format ( 'Y-m-d H:i:s' ) ; } return ( new Carbon ( $ indicator ) ) -> format ( 'Y-m-d H:i:s' ) ; }
Interprets a date indicator string value as a date time string relative to the current date .
52,176
protected function convertDateFormatToMoment ( $ format ) { $ replacements = [ 'd' => 'DD' , 'D' => 'ddd' , 'j' => 'D' , 'l' => 'dddd' , 'N' => 'E' , 'S' => 'o' , 'w' => 'e' , 'z' => 'DDD' , 'W' => 'W' , 'F' => 'MMMM' , 'm' => 'MM' , 'M' => 'MMM' , 'n' => 'M' , 't' => '' , 'L' => '' , 'o' => 'YYYY' , 'Y' => 'YYYY' , 'y' => 'YY' , 'a' => 'a' , 'A' => 'A' , 'B' => '' , 'g' => 'h' , 'G' => 'H' , 'h' => 'hh' , 'H' => 'HH' , 'i' => 'mm' , 's' => 'ss' , 'u' => 'SSS' , 'e' => 'zz' , 'I' => '' , 'O' => '' , 'P' => '' , 'T' => '' , 'Z' => '' , 'c' => '' , 'r' => '' , 'U' => 'X' , ] ; foreach ( $ replacements as $ from => $ to ) { $ replacements [ '\\' . $ from ] = '[' . $ from . ']' ; } return strtr ( $ format , $ replacements ) ; }
Converts PHP date format to MommentJS date format .
52,177
protected function getCount ( Relation $ relation ) { if ( ! $ relation ) return 0 ; $ query = $ this -> modifyRelationQueryForContext ( $ relation -> getRelated ( ) , $ relation -> getQuery ( ) ) ; return $ query -> count ( ) ; }
Returns the count for a given relation .
52,178
protected function getOtherModelClass ( ) { $ this -> otherModelClass = array_get ( $ this -> actionData -> options ( ) , 'model' ) ; if ( ! $ this -> otherModelClass ) { throw new UnexpectedValueException ( "No target model class set in options" ) ; } if ( ! is_a ( $ this -> otherModelClass , Model :: class , true ) ) { throw new UnexpectedValueException ( "{$this->otherModelClass} is not a valid target model class" ) ; } $ infoRepository = app ( ModelInformationRepositoryInterface :: class ) ; $ info = $ infoRepository -> getByModelClass ( $ this -> otherModelClass ) ; if ( ! $ info ) { throw new UnexpectedValueException ( "{$this->otherModelClass} is not a CMS model" ) ; } return $ this -> otherModelClass ; }
Returns the model FQN for the target model for the link .
52,179
protected function getRelationName ( ) { $ relation = array_get ( $ this -> actionData -> options ( ) , 'relation' ) ; if ( $ relation ) { return $ relation ; } $ infoRepository = app ( ModelInformationRepositoryInterface :: class ) ; $ info = $ infoRepository -> getByModelClass ( $ this -> otherModelClass ) ; if ( ! $ info || empty ( $ info -> list -> parents ) || count ( $ info -> list -> parents ) !== 1 ) { return false ; } return head ( $ info -> list -> parents ) -> relation ; }
Returns configured relation name for children link .
52,180
public function index ( ) { if ( $ this -> luceneIndex -> count ( ) !== 0 ) { $ this -> luceneIndex = Lucene :: create ( $ this -> indexDirectory ) ; } foreach ( $ this -> models as $ modelName ) { $ model = new $ modelName ; if ( $ model -> hasMethod ( 'getSearchModels' ) ) { foreach ( $ model -> getSearchModels ( ) -> all ( ) as $ pageModel ) { $ this -> luceneIndex -> addDocument ( $ this -> createDocument ( call_user_func ( $ model -> searchFields , $ pageModel ) ) ) ; } } else { throw new InvalidConfigException ( "Not found right `SearchBehavior` behavior in `{$modelName}`." ) ; } } }
Indexing the contents of the specified models .
52,181
public function find ( $ term , $ fields = [ ] ) { Wildcard :: setMinPrefixLength ( $ this -> minPrefixLength ) ; Lucene :: setResultSetLimit ( $ this -> resultsLimit ) ; if ( empty ( $ fields ) ) { return [ 'results' => $ this -> luceneIndex -> find ( $ term ) , 'query' => $ term ] ; } $ fieldTerms [ ] = new IndexTerm ( $ term ) ; foreach ( $ fields as $ field => $ fieldText ) { $ fieldTerms [ ] = new IndexTerm ( $ fieldText , $ field ) ; } return [ 'results' => $ this -> luceneIndex -> find ( new MultiTerm ( $ fieldTerms ) ) , 'query' => $ term ] ; }
Search page for the term in the index .
52,182
public function delete ( $ text , $ field = null ) { $ query = new Term ( new IndexTerm ( $ text , $ field ) ) ; $ hits = $ this -> luceneIndex -> find ( $ query ) ; foreach ( $ hits as $ hit ) { $ this -> luceneIndex -> delete ( $ hit ) ; } }
Delete document from the index .
52,183
protected function checkListParents ( $ update = true ) { if ( empty ( $ this -> getModelInformation ( ) -> list -> parents ) ) { return $ this ; } $ this -> retrieveActiveParentFromSession ( ) ; $ this -> collectListParentHierarchy ( ) ; if ( $ update ) { $ this -> updateActiveParent ( ) ; } $ this -> enrichListParents ( ) ; return $ this ; }
Checks and loads list parent from the session .
52,184
protected function showsTopParentsOnly ( ) { $ relation = $ this -> getModelInformation ( ) -> list -> default_top_relation ; return $ relation && false !== $ this -> listParentRelation ; }
Returns whether the index will only show the top level parents .
52,185
protected function applyListParentContext ( ) { $ parents = $ this -> getModelInformation ( ) -> list -> parents ; if ( empty ( $ parents ) ) { return $ this ; } if ( $ this -> listParentRelation ) { $ contextKey = $ this -> listParentRelation . $ this -> getListParentSeparator ( ) . $ this -> listParentRecordKey ; } else { $ contextKey = null ; } $ this -> getListMemory ( ) -> setSubContext ( $ contextKey ) ; return $ this ; }
Applies the context for the current list parent scope .
52,186
protected function applyListParentToQuery ( $ query ) { if ( ! $ this -> listParentRelation ) { if ( $ this -> showsTopParentsOnly ( ) ) { $ query -> has ( $ this -> getModelInformation ( ) -> list -> default_top_relation , '<' , 1 ) ; } return $ this ; } $ parentInfo = array_last ( $ this -> listParents ) ; if ( ! $ parentInfo ) { return $ this ; } $ relationInstance = $ query -> getModel ( ) -> { $ this -> listParentRelation } ( ) ; if ( $ relationInstance instanceof MorphTo ) { $ separator = $ this -> getListParentMorphKeySeparator ( ) ; if ( false === strpos ( $ this -> listParentRecordKey , $ separator ) ) { return $ this ; } list ( $ parentType , $ parentKey ) = explode ( $ separator , $ this -> listParentRecordKey , 2 ) ; $ parentType = $ this -> getRelationMappedMorphType ( $ parentType ) ; $ query -> withoutGlobalScopes ( ) -> where ( $ query -> getModel ( ) -> getTable ( ) . '.' . $ relationInstance -> getMorphType ( ) , $ parentType ) -> where ( $ relationInstance -> getQualifiedForeignKey ( ) , $ parentKey ) ; return $ this ; } $ query -> whereHas ( $ this -> listParentRelation , function ( $ query ) use ( $ parentInfo ) { $ query -> withoutGlobalScopes ( ) -> where ( $ parentInfo -> model -> getKeyName ( ) , $ this -> listParentRecordKey ) ; } ) ; return $ this ; }
Applies the active list parent as a filter on a query builder .
52,187
protected function collectListParentHierarchy ( $ relation = null , $ key = null ) { $ this -> listParents = [ ] ; if ( null === $ relation ) { $ relation = $ this -> listParentRelation ; $ key = $ this -> listParentRecordKey ; } if ( ! $ relation || null === $ key ) { return ; } $ model = $ this -> getNewModelInstance ( ) ; $ info = $ this -> getModelInformationForModel ( $ model ) ; $ this -> listParents = $ this -> getListParentInformation ( $ model , $ this -> listParentRelation , $ this -> listParentRecordKey , $ info , true ) ; }
Looks up the current full list parent hierarchy chain to the top level .
52,188
protected function normalizeListParentParameter ( $ parent ) { $ separator = $ this -> getListParentSeparator ( ) ; if ( is_integer ( $ parent ) && $ parent < 0 || is_string ( $ parent ) && preg_match ( '#-\d+#' , $ parent ) ) { $ parent = ( int ) $ parent ; if ( $ parent < 0 ) { $ index = count ( $ this -> listParents ) + $ parent - 1 ; if ( $ index >= 0 && isset ( $ this -> listParents [ $ index ] ) ) { $ parent = $ this -> listParents [ $ index ] -> relation . $ separator . $ this -> listParents [ $ index ] -> key ; } else { $ parent = null ; } } else { $ parent = null ; } } if ( is_string ( $ parent ) && false === strpos ( $ parent , $ separator ) ) { $ parent = null ; } return $ parent ; }
Normalizes parent query parameter for list parent update .
52,189
protected function updateActiveParents ( array $ parents ) { $ modelInfo = $ this -> getModelInformation ( ) ; $ modelClass = $ modelInfo -> modelClass ( ) ; $ model = new $ modelClass ; $ previousContext = null ; $ previousParent = array_shift ( $ parents ) ; $ separator = $ this -> getListParentSeparator ( ) ; if ( ! $ previousParent || is_string ( $ previousParent ) && false === strpos ( $ previousParent , $ separator ) ) { $ this -> listParentRelation = $ previousParent === false ? false : null ; $ this -> listParentRecordKey = null ; } else { list ( $ this -> listParentRelation , $ this -> listParentRecordKey ) = explode ( $ separator , $ previousParent , 2 ) ; } $ count = 0 ; $ parents [ ] = null ; foreach ( $ parents as $ parent ) { $ count ++ ; if ( ! $ previousParent || is_string ( $ previousParent ) && false === strpos ( $ previousParent , $ separator ) ) { break ; } if ( ! $ parent || is_string ( $ parent ) && false === strpos ( $ parent , $ separator ) ) { $ this -> setListParentDataInMemory ( null , null , $ previousParent , $ previousContext ) ; break ; } list ( $ relation , $ key ) = explode ( $ separator , $ parent , 2 ) ; $ this -> setListParentDataInMemory ( $ relation , $ key , $ previousParent , $ previousContext ) ; if ( $ count == count ( $ parents ) ) { break ; } $ listParentInfo = $ this -> getListParentInformation ( $ model , $ relation , $ key , $ modelInfo ) ; if ( ! count ( $ listParentInfo ) ) { break ; } $ listParentInfo = head ( $ listParentInfo ) ; if ( $ modelClass !== get_class ( $ listParentInfo -> model ) ) { $ model = $ listParentInfo -> model ; $ modelClass = get_class ( $ model ) ; $ previousContext = $ this -> getModelSessionKey ( $ this -> getModuleHelper ( ) -> modelSlug ( $ model ) ) ; } $ previousParent = $ parent ; } }
Update a full list parent chain .
52,190
protected function enrichListParents ( ) { if ( empty ( $ this -> listParents ) ) { return ; } $ queries = [ ] ; $ previousModel = $ this -> getModelInformation ( ) -> modelClass ( ) ; $ reversed = array_reverse ( $ this -> listParents ) ; foreach ( $ reversed as $ index => $ parent ) { $ nextParent = isset ( $ reversed [ $ index + 1 ] ) ? $ reversed [ $ index + 1 ] : null ; if ( $ previousModel != get_class ( $ parent -> model ) ) { $ queries [ ] = null ; } else { if ( $ nextParent ) { $ queries [ ] = 'parent=' . $ nextParent -> relation . $ this -> getListParentSeparator ( ) . $ nextParent -> key ; } else { $ queries [ ] = 'parents=' ; } } $ previousModel = get_class ( $ parent -> model ) ; } $ queries = array_values ( array_reverse ( $ queries ) ) ; foreach ( $ queries as $ index => $ query ) { $ this -> listParents [ $ index ] -> query = $ query ; } }
Enriches list parent data for view .
52,191
protected function clearEntireListParentHierarchy ( ) { $ separator = $ this -> getListParentSeparator ( ) ; foreach ( $ this -> listParents as $ parent ) { if ( ! $ parent || is_string ( $ parent ) && false === strpos ( $ parent , $ separator ) ) { break ; } $ context = $ this -> getModelSessionKey ( $ this -> getModuleHelper ( ) -> modelSlug ( get_class ( $ parent -> model ) ) ) ; $ this -> setListParentDataInMemory ( null , null , $ parent -> relation . $ separator . $ parent -> key , $ context ) ; } $ this -> setListParentDataInMemory ( null , null , $ this -> globalSubContext ( ) ) ; $ this -> listParentRelation = null ; $ this -> listParentRecordKey = null ; $ this -> listParents = [ ] ; }
Clears list parent chain as currently memorized .
52,192
protected function retrieveActiveParentFromSession ( ) { $ parent = $ this -> getListParentDataFromMemory ( $ this -> globalSubContext ( ) ) ; if ( false === $ parent || null === $ parent ) { $ this -> listParentRelation = $ parent ; $ this -> listParentRecordKey = null ; return ; } $ this -> listParentRelation = array_get ( $ parent , 'relation' ) ; $ this -> listParentRecordKey = array_get ( $ parent , 'key' ) ; }
Retrieves the currently set global list parent from the session and stores it locally .
52,193
protected function getListParentInformation ( Model $ model , $ relation , $ key , ModelInformationInterface $ info , $ recurse = false ) { if ( empty ( $ info -> list -> parents ) || ! count ( array_filter ( $ info -> list -> parents , function ( $ parent ) use ( $ relation ) { return $ parent -> relation == $ relation ; } ) ) ) { return [ ] ; } $ relationInstance = $ model -> { $ relation } ( ) ; if ( $ relationInstance instanceof MorphTo ) { $ separator = $ this -> getListParentMorphKeySeparator ( ) ; if ( false === strpos ( $ key , $ separator ) ) { return [ ] ; } list ( $ parentType , $ parentKey ) = explode ( $ separator , $ key , 2 ) ; $ parentModelClass = $ this -> getRelationMappedMorphClass ( $ parentType ) ; if ( ! is_a ( $ parentModelClass , Model :: class , true ) ) { throw new UnexpectedValueException ( "Parent record indicator {$key} does not refer to usable Eloquent model parent." ) ; } $ parentModel = new $ parentModelClass ; $ key = $ parentKey ; } else { $ parentModel = $ relationInstance -> getRelated ( ) ; } $ parentModel = $ this -> getModelByKey ( $ parentModel , $ key ) ; if ( ! $ parentModel ) { return [ ] ; } $ parentInfo = $ this -> getModelInformationForModel ( $ parentModel ) ; $ list = [ ] ; if ( $ recurse && ! empty ( $ parentInfo -> list -> parents ) ) { $ parentListParent = $ this -> getListParentDataFromMemory ( get_class ( $ model ) != get_class ( $ parentModel ) ? $ this -> globalSubContext ( ) : $ relation . ':' . $ key , $ this -> getModelSessionKey ( $ this -> getModuleHelper ( ) -> modelSlug ( $ parentModel ) ) ) ; if ( is_array ( $ parentListParent ) ) { $ list = $ this -> getListParentInformation ( $ parentModel , array_get ( $ parentListParent , 'relation' ) , array_get ( $ parentListParent , 'key' ) , $ parentInfo , true ) ; } } $ module = $ this -> getModuleByModel ( $ parentModel ) ; if ( ! $ module ) { return [ ] ; } $ routeHelper = app ( RouteHelperInterface :: class ) ; $ list [ ] = new ListParentData ( [ 'relation' => $ relation , 'key' => $ key , 'model' => $ parentModel , 'information' => $ parentInfo , 'module_key' => $ module -> getKey ( ) , 'route_prefix' => $ routeHelper -> getRouteNameForModelClass ( get_class ( $ parentModel ) , true ) , 'permission_prefix' => $ routeHelper -> getPermissionPrefixForModelSlug ( $ this -> getModuleHelper ( ) -> modelInformationKeyForModel ( $ parentModel ) ) , ] ) ; return $ list ; }
Returns information about a list parent or all list parents in the chain .
52,194
protected function getModelByKey ( Model $ model , $ key ) { return $ model :: withoutGlobalScopes ( ) -> where ( $ model -> getKeyName ( ) , $ key ) -> first ( ) ; }
Returns model instance by key .
52,195
protected function getModuleByModel ( Model $ model ) { $ modules = app ( ModuleManagerInterface :: class ) ; return $ modules -> getByAssociatedClass ( get_class ( $ model ) ) ; }
Returns the module for a given model .
52,196
protected function isFieldValueBeDerivableFromListParent ( $ field ) { if ( ! $ this -> hasActiveListParent ( ) ) { return false ; } $ listParentData = $ this -> getListParentDataForRelation ( $ this -> listParentRelation ) ; if ( ! $ listParentData ) { return false ; } return $ field == $ listParentData -> field ( ) ; }
Returns whether the set list parent corresponds to a given field key .
52,197
protected function getListParentDataFromMemory ( $ subContext , $ context = null ) { $ memory = $ this -> getListMemory ( ) ; $ oldContext = $ memory -> getContext ( ) ; $ oldSubContext = $ memory -> getSubContext ( ) ; if ( null !== $ context ) { $ memory -> setContext ( $ context ) ; } $ memory -> setSubContext ( $ subContext ) ; $ listParent = $ memory -> getListParent ( ) ; if ( null !== $ context ) { $ memory -> setContext ( $ oldContext ) ; } $ memory -> setSubContext ( $ oldSubContext ) ; return $ listParent ; }
Retrieves list parent data from memory and resets memory context .
52,198
protected function setListParentDataInMemory ( $ relation , $ key , $ subContext , $ context = null ) { $ memory = $ this -> getListMemory ( ) ; $ oldContext = $ memory -> getContext ( ) ; $ oldSubContext = $ memory -> getSubContext ( ) ; if ( null !== $ context ) { $ memory -> setContext ( $ context ) ; } $ memory -> setSubContext ( $ subContext ) ; $ memory -> setListParent ( $ relation , $ key ) ; if ( null !== $ context ) { $ memory -> setContext ( $ oldContext ) ; } $ memory -> setSubContext ( $ oldSubContext ) ; }
Stores list parent data in memory and resets memory context .
52,199
protected function getRelationMappedMorphType ( $ class ) { $ map = Relation :: morphMap ( ) ; if ( empty ( $ map ) ) { return ltrim ( $ class , '\\' ) ; } if ( false !== ( $ type = array_search ( $ class , $ map ) ) || false !== ( $ type = array_search ( ltrim ( $ class , '\\' ) , $ map ) ) ) { return $ type ; } return trim ( $ class , '\\' ) ; }
Returns morph relation type string for a model class or returns class if not mapped .