idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
52,300
|
protected function normalizeTypeAndLength ( $ type ) { if ( empty ( $ type ) ) { return [ null , null ] ; } if ( preg_match ( '#^(?<type>.*)\((?<length>\d+)\)$#' , $ type , $ matches ) ) { return [ $ this -> normalizeType ( $ matches [ 'type' ] ) , ( int ) $ matches [ 'length' ] ] ; } return [ $ this -> normalizeType ( $ type ) , $ this -> getDefaultLengthForType ( $ type ) ] ; }
|
Returns clean type string and length value .
|
52,301
|
public function make ( $ strategy , $ key = null , ModelFilterDataInterface $ info = null ) { if ( ! ( $ strategyClass = $ this -> resolveStrategyClass ( $ strategy ) ) ) { throw new RuntimeException ( "Could not resolve filter strategy class for {$key}: '{$strategy}'" ) ; } $ instance = app ( $ strategyClass ) ; if ( null !== $ info ) { $ instance -> setFilterInformation ( $ info ) ; } return $ instance ; }
|
Makes a filter display instance .
|
52,302
|
protected function getDropdownValuesFromSource ( $ source ) { if ( is_a ( $ source , Enum :: class , true ) ) { return array_map ( function ( $ value ) { return ( string ) $ value ; } , $ source :: values ( ) ) ; } if ( is_a ( $ source , DropdownStrategyInterface :: class , true ) ) { $ source = app ( $ source ) ; return $ source -> values ( ) ; } return false ; }
|
Returns values from a source FQN if possible .
|
52,303
|
protected function getDropdownLabelsFromSource ( $ source ) { if ( is_a ( $ source , DropdownStrategyInterface :: class , true ) ) { $ source = app ( $ source ) ; return $ source -> labels ( ) ; } return false ; }
|
Returns display labels from a source FQN if possible .
|
52,304
|
public function label ( ) { if ( $ this -> label_translated ) { return cms_trans ( $ this -> label_translated ) ; } if ( $ this -> label ) { return $ this -> label ; } return ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ this -> key ) ) ) ; }
|
Returns display label for form field .
|
52,305
|
public function permissions ( ) { if ( is_array ( $ this -> permissions ) ) { return $ this -> permissions ; } if ( $ this -> permissions ) { return [ $ this -> permissions ] ; } return [ ] ; }
|
Returns permissions required to use the field .
|
52,306
|
protected function determineActiveColumn ( ) { $ info = $ this -> getModelInformation ( ) ; if ( $ info && $ info -> list -> activatable && $ info -> list -> active_column ) { return $ info -> list -> active_column ; } return 'active' ; }
|
Determines and returns name of active column .
|
52,307
|
protected function adjustValue ( $ value ) { if ( is_string ( $ value ) ) { $ value = explode ( ';' , $ value ) ; } if ( ! $ value ) { $ value = [ ] ; } return array_filter ( $ value ) ; }
|
Adjusts a value for compatibility with taggable methods .
|
52,308
|
protected function determineRelations ( ) { if ( count ( $ this -> parameters ) ) { return $ this -> parameters ; } if ( ! ( $ info = $ this -> getModelInformation ( ) ) ) { return [ ] ; } return array_pluck ( $ info -> relations , 'method' ) ; }
|
Determines and returns relation method names that should be checked .
|
52,309
|
protected function loadComponents ( $ paths ) { $ paths = array_unique ( is_array ( $ paths ) ? $ paths : ( array ) $ paths ) ; $ paths = array_filter ( $ paths , function ( $ path ) { return is_dir ( $ path ) ; } ) ; if ( empty ( $ paths ) ) { return ; } $ namespace = $ this -> app -> getNamespace ( ) ; foreach ( ( new Finder ( ) ) -> in ( $ paths ) -> exclude ( 'Observers' ) -> files ( ) as $ file ) { $ class = trim ( $ namespace , '\\' ) . '\\' . str_replace ( [ '/' , '.php' ] , [ '\\' , '' ] , Str :: after ( realpath ( $ file -> getPathname ( ) ) , app_path ( ) . DIRECTORY_SEPARATOR ) ) ; if ( is_subclass_of ( $ class , Component :: class ) && ! ( new \ ReflectionClass ( $ class ) ) -> isAbstract ( ) ) { $ this -> registerComponent ( $ class ) ; } } }
|
Load component class from the paths
|
52,310
|
protected function registerComponent ( $ class ) { $ component = $ this -> app -> make ( $ class ) ; if ( ! ( $ component instanceof ComponentInterface ) ) { throw new InvalidArgumentException ( sprintf ( 'Class "%s" must be instanced of "%s".' , $ component , ComponentInterface :: class ) ) ; } if ( $ component instanceof Initializable ) { $ component -> initialize ( ) ; } $ component -> addToNavigation ( ) ; $ this -> app [ 'admin.components' ] -> put ( $ component -> getName ( ) , $ component ) ; }
|
register the component class
|
52,311
|
protected function updateConnection ( $ connection ) { if ( $ this -> connection !== $ connection ) { $ this -> connection = $ connection ; $ this -> schemaSetUp = false ; } return $ this ; }
|
Updates the connection name to use .
|
52,312
|
protected function setUpDoctrineSchema ( ) { if ( $ this -> schemaSetUp ) { return ; } DB :: connection ( $ this -> connection ) -> getDoctrineSchemaManager ( ) -> getDatabasePlatform ( ) -> registerDoctrineTypeMapping ( 'enum' , 'string' ) ; $ this -> schemaSetUp = true ; }
|
Sets up the schema for the current connection .
|
52,313
|
public function getUploadPath ( UploadedFile $ file ) { if ( ( $ path = $ this -> uploadPath ) ) { if ( is_callable ( $ path ) ) { $ path = call_user_func ( $ path , $ file ) ; } return trim ( $ path , '/' ) ; } return $ this -> getDefaultUploadPath ( $ file ) ; }
|
Get relative path of the upload file .
|
52,314
|
public function getUploadFileName ( UploadedFile $ file ) { if ( is_callable ( $ this -> uploadFileNameRule ) ) { return call_user_func ( $ this -> uploadFileNameRule , $ file ) ; } return $ this -> getDefaultFileName ( $ file ) ; }
|
Get a file name of the upload file .
|
52,315
|
protected function checkScope ( $ update = true ) { $ request = request ( ) ; if ( $ update && $ request -> exists ( 'scope' ) ) { $ this -> activeScope = $ request -> get ( 'scope' ) ; $ this -> markResetActivePage ( ) ; $ this -> storeActiveScopeInSession ( ) ; } else { $ this -> retrieveActiveScopeFromSession ( ) ; } if ( $ this -> activeScope && ! $ this -> isValidScopeKey ( $ this -> activeScope ) ) { $ this -> activeScope = null ; $ this -> storeActiveScopeInSession ( ) ; } return $ this ; }
|
Checks for the active scope .
|
52,316
|
protected function applyScope ( ExtendedRepositoryInterface $ repository , $ scope = null ) { $ scope = ( null === $ scope ) ? $ this -> activeScope : $ scope ; $ repository -> clearScopes ( ) ; if ( $ this -> hasActiveListParent ( ) ) { return $ this ; } if ( $ scope ) { $ info = $ this -> getModelInformation ( ) ; $ method = $ info -> list -> scopes [ $ scope ] -> method ? : $ scope ; $ repository -> addScope ( $ method ) ; } return $ this ; }
|
Applies the currently active scope to a repository .
|
52,317
|
protected function getScopeCounts ( ) { if ( ! $ this -> areScopesEnabled ( ) ) { return [ ] ; } $ info = $ this -> getModelInformation ( ) ; if ( ! $ info -> list -> scopes || ! count ( $ info -> list -> scopes ) ) { return [ ] ; } $ counts = [ ] ; $ repository = $ this -> getModelRepository ( ) ; foreach ( array_keys ( $ info -> list -> scopes ) as $ key ) { $ this -> applyScope ( $ repository , $ key ) ; $ query = $ this -> getModelRepository ( ) -> query ( ) ; $ this -> applyListParentToQuery ( $ query ) ; $ counts [ $ key ] = $ query -> count ( ) ; } return $ counts ; }
|
Returns total amount of matches for each available scope .
|
52,318
|
protected function determineStrategy ( Model $ model , $ column ) { if ( $ this -> isColumnTranslated ( $ model , $ column ) ) { return $ this -> getStrategyForTranslated ( ) ; } if ( $ this -> isColumnOnRelatedModel ( $ model , $ column ) ) { return $ this -> getStrategyForRelatedModelAttribute ( ) ; } if ( $ this -> isColumnOnModelTable ( $ model , $ column ) ) { return $ this -> getStrategyForDirectAttribute ( ) ; } return false ; }
|
Returns classname for the strategy to use or false if no strategy could be determined .
|
52,319
|
protected function isColumnTranslated ( Model $ model , $ column ) { $ info = $ this -> getModelInformation ( $ model ) ; if ( $ info ) { return ( $ info -> translated && array_key_exists ( $ column , $ info -> attributes ) && $ info -> attributes [ $ column ] -> translated ) ; } if ( ! $ this -> hasTranslatableTrait ( $ model ) ) return false ; return $ model -> isTranslationAttribute ( $ column ) ; }
|
Returns whether the column is a translated attribute of the model .
|
52,320
|
protected function isColumnOnModelTable ( Model $ model , $ column ) { $ info = $ this -> getModelInformation ( $ model ) ; if ( $ info ) { return ( array_key_exists ( $ column , $ info -> attributes ) && ! $ info -> attributes [ $ column ] -> translated ) ; } return ( $ model -> getKeyName ( ) == $ column || $ model -> isFillable ( $ column ) || $ model -> isGuarded ( $ column ) ) ; }
|
Returns whether the column is a direct attribute of model .
|
52,321
|
protected function hasTranslatableTrait ( $ class ) { $ translatable = config ( 'cms-models.analyzer.traits.translatable' , [ ] ) ; if ( ! count ( $ translatable ) ) { return false ; } return ( bool ) count ( array_intersect ( $ this -> classUsesDeep ( $ class ) , $ translatable ) ) ; }
|
Returns whether a class has the translatable trait .
|
52,322
|
protected function registerCommands ( ) { $ this -> app -> singleton ( 'cms.commands.models.cache-information' , Commands \ CacheModelInformation :: class ) ; $ this -> app -> singleton ( 'cms.commands.models.clear-information-cache' , Commands \ ClearModelInformationCache :: class ) ; $ this -> app -> singleton ( 'cms.commands.models.show-information' , Commands \ ShowModelInformation :: class ) ; $ this -> app -> singleton ( 'cms.commands.models.write-information' , Commands \ WriteModelInformation :: class ) ; $ this -> commands ( [ 'cms.commands.models.cache-information' , 'cms.commands.models.clear-information-cache' , 'cms.commands.models.show-information' , 'cms.commands.models.write-information' , ] ) ; return $ this ; }
|
Register Model related CMS commands
|
52,323
|
protected function registerInterfaceBindings ( ) { $ this -> app -> bind ( RepositoriesContracts \ ModelRepositoryInterface :: class , Repositories \ ModelRepository :: class ) ; $ this -> app -> bind ( FactoriesContracts \ ModelRepositoryFactoryInterface :: class , Factories \ ModelRepositoryFactory :: class ) ; $ this -> app -> singleton ( RepositoriesContracts \ ModelReferenceRepositoryInterface :: class , Repositories \ ModelReferenceRepository :: class ) ; $ this -> app -> bind ( FormDataStorerInterface :: class , FormDataStorer :: class ) ; $ this -> registerHelperInterfaceBindings ( ) -> registerModelInformationInterfaceBindings ( ) -> registerStrategyInterfaceBindings ( ) -> registerFacadeBindings ( ) ; return $ this ; }
|
Registers interface bindings for various components .
|
52,324
|
protected function registerHelperInterfaceBindings ( ) { $ this -> app -> singleton ( RouteHelperInterface :: class , RouteHelper :: class ) ; $ this -> app -> singleton ( ModuleHelperInterface :: class , ModuleHelper :: class ) ; $ this -> app -> singleton ( MetaReferenceDataProviderInterface :: class , MetaReferenceDataProvider :: class ) ; $ this -> app -> singleton ( TranslationLocaleHelperInterface :: class , TranslationLocaleHelper :: class ) ; $ this -> app -> singleton ( ModelListMemoryInterface :: class , ModelListMemory :: class ) ; $ this -> app -> singleton ( ValidationRuleDecoratorInterface :: class , ValidationRuleDecorator :: class ) ; $ this -> app -> bind ( ValidationRuleMergerInterface :: class , ValidationRuleMerger :: class ) ; return $ this ; }
|
Registers interface bindings for helpers classes .
|
52,325
|
protected function registerModelInformationInterfaceBindings ( ) { $ this -> app -> singleton ( RepositoriesContracts \ ModelInformationRepositoryInterface :: class , Repositories \ ModelInformationRepository :: class ) ; $ this -> app -> singleton ( ModelInfoContracts \ Collector \ ModelInformationFileReaderInterface :: class , ModelInformation \ Collector \ ModelInformationFileReader :: class ) ; $ this -> app -> singleton ( ModelInfoContracts \ ModelInformationEnricherInterface :: class , ModelInformation \ Enricher \ ModelInformationEnricher :: class ) ; $ this -> app -> singleton ( ModelInfoContracts \ ModelInformationInterpreterInterface :: class , ModelInformation \ Interpreter \ CmsModelInformationInterpreter :: class ) ; $ this -> app -> singleton ( ModelAnalyzerInterface :: class , ModelAnalyzer :: class ) ; $ this -> app -> singleton ( DatabaseAnalyzerInterface :: class , SimpleDatabaseAnalyzer :: class ) ; $ this -> app -> singleton ( ModelInfoContracts \ Writer \ ModelInformationWriterInterface :: class , ModelInformation \ Writer \ CmsModelWriter :: class ) ; $ this -> app -> singleton ( RepositoriesContracts \ CurrentModelInformationInterface :: class , Repositories \ CurrentModelInformation :: class ) ; return $ this ; }
|
Registers interface bindings for model information handling .
|
52,326
|
protected function registerStrategyInterfaceBindings ( ) { $ this -> app -> singleton ( RepositoriesContracts \ ActivateStrategyResolverInterface :: class , Repositories \ ActivateStrategies \ ActivateStrategyResolver :: class ) ; $ this -> app -> singleton ( RepositoriesContracts \ OrderableStrategyResolverInterface :: class , Repositories \ OrderableStrategies \ OrderableStrategyResolver :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ FilterStrategyFactoryInterface :: class , Factories \ FilterStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ ListDisplayStrategyFactoryInterface :: class , Factories \ ListDisplayStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ ShowFieldStrategyFactoryInterface :: class , Factories \ ShowFieldStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ FormFieldStrategyFactoryInterface :: class , Factories \ FormFieldStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ FormStoreStrategyFactoryInterface :: class , Factories \ FormStoreStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ ActionStrategyFactoryInterface :: class , Factories \ ActionStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ DeleteStrategyFactoryInterface :: class , Factories \ DeleteStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ DeleteConditionStrategyFactoryInterface :: class , Factories \ DeleteConditionStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ ExportColumnStrategyFactoryInterface :: class , Factories \ ExportColumnStrategyFactory :: class ) ; $ this -> app -> singleton ( FactoriesContracts \ ExportStrategyFactoryInterface :: class , Factories \ ExportStrategyFactory :: class ) ; return $ this ; }
|
Registers interface bindings for various strategies .
|
52,327
|
protected function registerFacadeBindings ( ) { $ this -> app -> bind ( 'cms-models-modelinfo' , RepositoriesContracts \ CurrentModelInformationInterface :: class ) ; $ this -> app -> bind ( 'cms-translation-locale-helper' , TranslationLocaleHelperInterface :: class ) ; return $ this ; }
|
Registers bindings for facade service names .
|
52,328
|
protected function registerEventListeners ( ) { foreach ( $ this -> events as $ event => $ listener ) { Event :: listen ( $ event , $ listener ) ; } return $ this ; }
|
Registers listeners for events .
|
52,329
|
public function label ( ) { if ( $ this -> label_translated ) { return cms_trans ( $ this -> label_translated ) ; } if ( $ this -> label ) { return $ this -> label ; } return ucfirst ( str_replace ( '_' , ' ' , snake_case ( $ this -> source ) ) ) ; }
|
Returns display label for show field .
|
52,330
|
public function get ( $ id ) { foreach ( $ this -> instructions as $ instruction ) { if ( ! $ instruction instanceof Node && ! $ instruction instanceof Subgraph ) { continue ; } if ( $ instruction -> getId ( ) == $ id ) { return $ instruction ; } } throw new \ InvalidArgumentException ( sprintf ( 'Found no node or graph with id "%s" in "%s".' , $ id , $ this -> id ) ) ; }
|
Returns a node or a subgraph given his id .
|
52,331
|
public function getEdge ( array $ edge ) { foreach ( $ this -> instructions as $ instruction ) { if ( ! $ instruction instanceof Edge ) { continue ; } if ( $ instruction -> getList ( ) == $ edge ) { return $ instruction ; } } $ label = implode ( ' -> ' , array_map ( function ( $ edge ) { if ( is_string ( $ edge ) ) { return $ edge ; } return implode ( ':' , $ edge ) ; } , $ edge ) ) ; throw new \ InvalidArgumentException ( sprintf ( 'Found no edge "%s".' , $ label ) ) ; }
|
Returns an edge by its path .
|
52,332
|
public function set ( $ name , $ value ) { if ( in_array ( $ name , array ( 'graph' , 'node' , 'edge' ) ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Use method attr for setting %s' , $ name ) ) ; } $ this -> instructions [ ] = new Assign ( $ name , $ value ) ; return $ this ; }
|
Adds an assignment instruction .
|
52,333
|
public function node ( $ id , array $ attributes = array ( ) ) { $ this -> instructions [ ] = new Node ( $ id , $ attributes , $ this ) ; return $ this ; }
|
Created a new node on graph .
|
52,334
|
public function style ( Model $ model , $ source ) { if ( ! $ this -> attributeData ) { return null ; } switch ( $ this -> attributeData -> cast ) { case AttributeCast :: INTEGER : case AttributeCast :: FLOAT : return 'column-right' ; case AttributeCast :: DATE : return 'column-date' ; } return null ; }
|
Returns an optional style string for the list display value container .
|
52,335
|
protected function getDropdownOptions ( ) { $ values = $ this -> getDropdownValues ( ) ; $ labels = $ this -> getDropdownLabels ( ) ; foreach ( $ values as $ value ) { if ( isset ( $ labels [ $ value ] ) ) continue ; $ labels [ $ value ] = $ value ; } return array_intersect_key ( $ labels , array_flip ( $ values ) ) ; }
|
Returns dropdown options as an associative array with display labels for values .
|
52,336
|
protected function getDropdownValues ( ) { if ( $ source = array_get ( $ this -> field -> options ( ) , 'value_source' ) ) { $ values = $ this -> getDropdownValuesFromSource ( $ source ) ; if ( false !== $ values ) { return $ values ; } } return array_get ( $ this -> field -> options ( ) , 'values' , [ ] ) ; }
|
Returns values to include in the dropdown .
|
52,337
|
protected function getDropdownLabels ( ) { if ( $ source = array_get ( $ this -> field -> options ( ) , 'label_source' ) ) { $ labels = $ this -> getDropdownLabelsFromSource ( $ source ) ; if ( false !== $ labels ) { return $ labels ; } } $ labels = array_get ( $ this -> field -> options ( ) , 'labels_translated' , [ ] ) ; if ( count ( $ labels ) ) { return array_map ( 'cms_trans' , $ labels ) ; } return array_get ( $ this -> field -> options ( ) , 'labels' , [ ] ) ; }
|
Returns display labels to show in the dropdown keyed by value .
|
52,338
|
protected function getReferenceValue ( Model $ model , $ strategy = null , $ source = null ) { $ strategy = $ this -> determineModelReferenceStrategy ( $ model , $ strategy ) ; if ( ! $ strategy ) { return $ this -> getReferenceFallback ( $ model ) ; } if ( ! $ source ) { $ source = $ this -> determineModelReferenceSource ( $ model ) ; } return $ strategy -> render ( $ model , $ source ) ; }
|
Returns the model reference as a string .
|
52,339
|
protected function determineModelReferenceStrategy ( Model $ model , $ strategy = null ) { if ( null !== $ strategy ) { $ strategy = $ this -> makeReferenceStrategyInstance ( $ strategy ) ; } if ( ! $ strategy ) { $ strategy = $ this -> makeReferenceStrategy ( $ model ) ; } if ( ! $ strategy ) { $ strategy = $ this -> getDefaultReferenceStrategyInstance ( ) ; } return $ strategy ; }
|
Returns the strategy reference instance for a model .
|
52,340
|
protected function determineModelReferenceSource ( Model $ model ) { $ source = $ this -> getReferenceSource ( $ model ) ; if ( ! $ source ) { $ source = $ model -> getKeyName ( ) ; } return $ source ; }
|
Returns the reference source string .
|
52,341
|
protected function makeReferenceStrategy ( Model $ model ) { $ information = $ this -> getInformationRepository ( ) -> getByModel ( $ model ) ; if ( ! $ information ) return null ; $ strategy = $ information -> reference -> strategy ; if ( ! $ strategy ) { $ strategy = config ( 'cms-models.strategies.reference.default-strategy' ) ; } return $ this -> makeReferenceStrategyInstance ( $ strategy ) ; }
|
Returns strategy instance for getting reference string .
|
52,342
|
protected function getReferenceSource ( Model $ model , $ source = null ) { if ( null === $ source ) { $ information = $ this -> getInformationRepository ( ) -> getByModel ( $ model ) ; if ( $ information && $ information -> reference -> source ) { $ source = $ information -> reference -> source ; } } if ( ! $ source ) return null ; return $ source ; }
|
Returns the source to feed to the reference strategy .
|
52,343
|
protected function getAttributeLatitude ( ) { $ attribute = array_get ( $ this -> formFieldData -> options ( ) , 'latitude_name' , 'latitude' ) ; if ( ! $ attribute ) { $ attribute = false ; } return $ attribute ; }
|
Returns attribute name for the latitude attribute .
|
52,344
|
protected function getAttributeLongitude ( ) { $ attribute = array_get ( $ this -> formFieldData -> options ( ) , 'longitude_name' , 'longitude' ) ; if ( ! $ attribute ) { $ attribute = false ; } return $ attribute ; }
|
Returns attribute name for the longitude attribute .
|
52,345
|
protected function getAttributeText ( ) { $ attribute = array_get ( $ this -> formFieldData -> options ( ) , 'location_name' , 'location' ) ; if ( ! $ attribute ) { $ attribute = false ; } return $ attribute ; }
|
Returns attribute name for the location text attribute . This stores a textual representation of the location .
|
52,346
|
protected function renderedListFilterStrategies ( array $ values ) { if ( $ this -> getModelInformation ( ) -> list -> disable_filters ) { return [ ] ; } $ views = [ ] ; foreach ( $ this -> getModelInformation ( ) -> list -> filters as $ key => $ data ) { try { $ instance = $ this -> getFilterFactory ( ) -> make ( $ data -> strategy , $ key , $ data ) ; } catch ( \ Exception $ e ) { $ message = "Failed to make list filter strategy for '{$key}': \n{$e->getMessage()}" ; throw new StrategyRenderException ( $ message , $ e -> getCode ( ) , $ e ) ; } try { $ views [ $ key ] = $ instance -> render ( $ key , array_get ( $ values , $ key ) ) ; } catch ( \ Exception $ e ) { $ message = "Failed to render list filter '{$key}' for strategy " . get_class ( $ instance ) . ": \n{$e->getMessage()}" ; throw new StrategyRenderException ( $ message , $ e -> getCode ( ) , $ e ) ; } } return $ views ; }
|
Renders Vies or HTML for list filter strategies .
|
52,347
|
protected function changeModelOrderablePosition ( Model $ model , $ position ) { $ resolver = app ( OrderableStrategyResolverInterface :: class ) ; $ strategy = $ resolver -> resolve ( $ this -> getModelInformation ( ) ) ; return $ strategy -> setPosition ( $ model , $ position ) ; }
|
Changes the orderable position for a model .
|
52,348
|
public function index ( ) { if ( $ this -> modelInformation -> single ) { return $ this -> returnViewForSingleDisplay ( ) ; } $ this -> resetStateBeforeIndexAction ( ) -> checkListParents ( ) -> applyListParentContext ( ) -> checkActiveSort ( ) -> checkScope ( ) -> checkFilters ( ) -> checkActivePage ( ) ; $ totalCount = $ this -> getTotalCount ( ) ; $ scopeCounts = $ this -> getScopeCounts ( ) ; $ this -> applySort ( ) -> applyScope ( $ this -> modelRepository ) ; $ query = $ this -> getModelRepository ( ) -> query ( ) ; $ this -> applyFilter ( $ query ) -> applyListParentToQuery ( $ query ) ; $ records = $ query -> paginate ( $ this -> getActualPageSize ( ) , [ '*' ] , 'page' , $ this -> getActualPage ( ) ) ; if ( $ this -> getActualPage ( ) > $ records -> lastPage ( ) ) { $ records = $ query -> paginate ( $ this -> getActualPageSize ( ) , [ '*' ] , 'page' , $ records -> lastPage ( ) ) ; } $ currentCount = method_exists ( $ records , 'total' ) ? $ records -> total ( ) : 0 ; return view ( $ this -> getIndexView ( ) , [ 'moduleKey' => $ this -> moduleKey , 'routePrefix' => $ this -> routePrefix , 'permissionPrefix' => $ this -> permissionPrefix , 'model' => $ this -> modelInformation , 'records' => $ records , 'recordReferences' => $ this -> getReferenceRepository ( ) -> getReferencesForModels ( $ records -> items ( ) ) , 'totalCount' => $ totalCount , 'currentCount' => $ currentCount , 'listStrategies' => $ this -> getListColumnStrategyInstances ( ) , 'sortColumn' => $ this -> getActualSort ( ) , 'sortDirection' => $ this -> getActualSortDirection ( ) , 'pageSize' => $ this -> getActualPageSize ( ) , 'pageSizeOptions' => $ this -> getPageSizeOptions ( ) , 'filterStrategies' => $ this -> renderedListFilterStrategies ( $ this -> getActiveFilters ( ) ) , 'activeScope' => $ this -> getActiveScope ( ) , 'scopeCounts' => $ scopeCounts , 'unconditionalDelete' => $ this -> isUnconditionallyDeletable ( ) , 'defaultRowAction' => $ this -> getDefaultRowActionInstance ( ) , 'hasActiveListParent' => ( bool ) $ this -> listParentRelation , 'listParents' => $ this -> listParents , 'topListParentOnly' => $ this -> showsTopParentsOnly ( ) , 'draggableOrderable' => $ this -> isListOrderDraggable ( $ totalCount , $ currentCount ) , 'availableExportKeys' => $ this -> getAvailableExportStrategyKeys ( ) , ] ) ; }
|
Returns listing of filtered sorted records .
|
52,349
|
public function show ( $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; $ this -> checkListParents ( false ) ; return view ( $ this -> getShowView ( ) , [ 'moduleKey' => $ this -> moduleKey , 'routePrefix' => $ this -> routePrefix , 'permissionPrefix' => $ this -> permissionPrefix , 'model' => $ this -> modelInformation , 'record' => $ record , 'recordReference' => $ this -> getReferenceRepository ( ) -> getReferenceForModel ( $ record ) , 'fieldStrategies' => $ this -> renderedShowFieldStrategies ( $ record ) , 'hasActiveListParent' => ( bool ) $ this -> listParentRelation , 'topListParentOnly' => $ this -> showsTopParentsOnly ( ) , 'listParents' => $ this -> listParents , ] ) ; }
|
Displays a single record .
|
52,350
|
public function create ( ) { $ record = $ this -> getNewModelInstance ( ) ; $ fields = array_only ( $ this -> modelInformation -> form -> fields , $ this -> getRelevantFormFieldKeys ( true ) ) ; $ this -> checkListParents ( false ) ; $ values = $ this -> getFormFieldValuesFromModel ( $ record , array_keys ( $ fields ) ) ; $ errors = $ this -> getNormalizedFormFieldErrors ( ) ; $ renderedFields = $ this -> renderedFormFieldStrategies ( $ record , $ fields , $ values , $ errors ) ; return view ( $ this -> getCreateView ( ) , [ 'moduleKey' => $ this -> moduleKey , 'routePrefix' => $ this -> routePrefix , 'permissionPrefix' => $ this -> permissionPrefix , 'model' => $ this -> modelInformation , 'record' => $ record , 'recordReference' => null , 'creating' => true , 'fields' => $ fields , 'fieldStrategies' => $ renderedFields , 'values' => $ values , 'fieldErrors' => $ errors , 'activeTab' => $ this -> getActiveTab ( ) , 'errorsPerTab' => $ this -> getErrorCountsPerTabPane ( ) , 'hasActiveListParent' => ( bool ) $ this -> listParentRelation , 'topListParentOnly' => $ this -> showsTopParentsOnly ( ) , 'listParents' => $ this -> listParents , ] ) ; }
|
Displays form to create a new record .
|
52,351
|
public function store ( ) { $ request = app ( $ this -> getCreateRequestClass ( ) ) ; $ record = $ this -> getNewModelInstance ( ) ; $ data = $ request -> only ( $ this -> getRelevantFormFieldKeys ( true ) ) ; $ storer = app ( FormDataStorerInterface :: class ) ; $ storer -> setModelInformation ( $ this -> getModelInformation ( ) ) ; if ( ! $ storer -> store ( $ record , $ data ) ) { return redirect ( ) -> back ( ) -> withInput ( ) -> withErrors ( [ static :: GENERAL_ERRORS_KEY => [ $ this -> getGeneralStoreFailureError ( ) ] , ] ) ; } $ this -> storeActiveTab ( $ request -> input ( static :: ACTIVE_TAB_PANE_KEY ) ) ; cms_flash ( cms_trans ( 'models.store.success-message-create' , [ 'record' => $ this -> getSimpleRecordReference ( $ record -> getKey ( ) , $ record ) ] ) , FlashLevel :: SUCCESS ) ; event ( new Events \ ModelCreatedInCms ( $ record ) ) ; if ( $ request -> input ( static :: SAVE_AND_CLOSE_KEY ) ) { return redirect ( ) -> route ( "{$this->routePrefix}.index" ) ; } return redirect ( ) -> route ( "{$this->routePrefix}.edit" , [ $ record -> getKey ( ) ] ) ; }
|
Processes submitted form to create a new record .
|
52,352
|
public function edit ( $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; $ fields = array_only ( $ this -> modelInformation -> form -> fields , $ this -> getRelevantFormFieldKeys ( ) ) ; $ this -> checkListParents ( false ) ; $ values = $ this -> getFormFieldValuesFromModel ( $ record , array_keys ( $ fields ) ) ; $ errors = $ this -> getNormalizedFormFieldErrors ( ) ; $ renderedFields = $ this -> renderedFormFieldStrategies ( $ record , $ fields , $ values , $ errors ) ; return view ( $ this -> getEditView ( ) , [ 'moduleKey' => $ this -> moduleKey , 'routePrefix' => $ this -> routePrefix , 'permissionPrefix' => $ this -> permissionPrefix , 'model' => $ this -> modelInformation , 'record' => $ record , 'recordReference' => $ this -> getReferenceRepository ( ) -> getReferenceForModel ( $ record ) , 'creating' => false , 'fields' => $ fields , 'fieldStrategies' => $ renderedFields , 'values' => $ values , 'fieldErrors' => $ errors , 'activeTab' => $ this -> getActiveTab ( ) , 'errorsPerTab' => $ this -> getErrorCountsPerTabPane ( ) , 'hasActiveListParent' => ( bool ) $ this -> listParentRelation , 'topListParentOnly' => $ this -> showsTopParentsOnly ( ) , 'listParents' => $ this -> listParents , ] ) ; }
|
Displays form to edit an existing record .
|
52,353
|
public function update ( $ id ) { $ request = app ( $ this -> getUpdateRequestClass ( ) ) ; $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; $ data = $ request -> only ( $ this -> getRelevantFormFieldKeys ( ) ) ; $ storer = app ( FormDataStorerInterface :: class ) ; $ storer -> setModelInformation ( $ this -> getModelInformation ( ) ) ; if ( ! $ storer -> store ( $ record , $ data ) ) { return redirect ( ) -> back ( ) -> withInput ( ) -> withErrors ( [ static :: GENERAL_ERRORS_KEY => [ $ this -> getGeneralStoreFailureError ( ) ] , ] ) ; } $ this -> storeActiveTab ( $ request -> input ( static :: ACTIVE_TAB_PANE_KEY ) ) ; cms_flash ( cms_trans ( 'models.store.success-message-edit' , [ 'record' => $ this -> getSimpleRecordReference ( $ id , $ record ) ] ) , FlashLevel :: SUCCESS ) ; event ( new Events \ ModelUpdatedInCms ( $ record ) ) ; if ( $ request -> input ( static :: SAVE_AND_CLOSE_KEY ) ) { return redirect ( ) -> route ( "{$this->routePrefix}.index" ) ; } return redirect ( ) -> route ( "{$this->routePrefix}.edit" , [ $ record -> getKey ( ) ] ) ; }
|
Processes a submitted for to edit an existing record .
|
52,354
|
public function destroy ( $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; if ( ! $ this -> isModelDeletable ( $ record ) ) { return $ this -> failureResponse ( $ this -> getLastUnmetDeleteConditionMessage ( ) ) ; } event ( new Events \ DeletingModelInCms ( $ record ) ) ; if ( ! $ this -> deleteModel ( $ record ) ) { return $ this -> failureResponse ( cms_trans ( 'models.delete.failure.unknown' ) ) ; } event ( new Events \ ModelDeletedInCms ( $ this -> getModelInformation ( ) -> modelClass ( ) , $ id ) ) ; if ( request ( ) -> ajax ( ) ) { return response ( ) -> json ( [ 'success' => true , ] ) ; } cms_flash ( cms_trans ( 'models.delete.success-message' , [ 'record' => $ this -> getSimpleRecordReference ( $ id , $ record ) ] ) , FlashLevel :: SUCCESS ) ; return redirect ( ) -> back ( ) ; }
|
Deletes a record if allowed .
|
52,355
|
public function deletable ( $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; if ( ! $ this -> isModelDeletable ( $ record ) ) { return $ this -> failureResponse ( $ this -> getLastUnmetDeleteConditionMessage ( ) ) ; } return $ this -> successResponse ( ) ; }
|
Checks whether a model is deletable .
|
52,356
|
public function filter ( ) { $ this -> updateFilters ( ) -> checkActivePage ( ) ; $ previousUrl = app ( 'url' ) -> previous ( ) ; $ previousUrl = $ this -> removePageQueryFromUrl ( $ previousUrl ) ; return redirect ( ) -> to ( $ previousUrl ) ; }
|
Applies posted filters .
|
52,357
|
public function position ( OrderUpdateRequest $ request , $ id ) { $ record = $ this -> modelRepository -> findOrFail ( $ id ) ; $ success = false ; $ result = null ; if ( $ this -> getModelInformation ( ) -> list -> orderable ) { $ success = true ; $ result = $ this -> changeModelOrderablePosition ( $ record , $ request -> get ( 'position' ) ) ; } if ( $ success && config ( 'cms-models.notifications.flash.position' ) ) { cms_flash ( cms_trans ( 'models.store.success-message-position' , [ 'record' => $ this -> getSimpleRecordReference ( $ id , $ record ) ] ) , FlashLevel :: SUCCESS ) ; } event ( new Events \ ModelPositionUpdatedInCms ( $ record ) ) ; if ( request ( ) -> ajax ( ) ) { return response ( ) -> json ( [ 'success' => $ success , 'position' => $ result ] ) ; } return redirect ( ) -> back ( ) ; }
|
Changes orderable position for a record .
|
52,358
|
public function export ( $ strategy ) { if ( ! $ this -> isExportStrategyAvailable ( $ strategy ) ) { abort ( 403 , "Not possible or allowed to perform export '{$strategy}'" ) ; } $ exporter = $ this -> getExportStrategyInstance ( $ strategy ) ; $ filename = $ this -> getExportDownloadFilename ( $ strategy , $ exporter -> extension ( ) ) ; $ this -> checkListParents ( ) -> checkActiveSort ( false ) -> checkScope ( false ) -> checkFilters ( ) -> checkActivePage ( false ) -> applySort ( ) -> applyScope ( $ this -> modelRepository ) ; $ query = $ this -> getModelRepository ( ) -> query ( ) ; $ this -> applyFilter ( $ query ) -> applyListParentToQuery ( $ query ) ; $ download = $ exporter -> download ( $ query , $ filename ) ; if ( false === $ download ) { abort ( 500 , "Failed to export model listing for strategy '{$strategy}'" ) ; } event ( new Events \ ModelListExportedInCms ( $ this -> modelInformation -> modelClass ( ) , $ strategy ) ) ; return $ download ; }
|
Exports the current listing with a given strategy .
|
52,359
|
protected function resetStateBeforeIndexAction ( ) { $ this -> activeSort = null ; $ this -> activeSortDescending = null ; $ this -> activeScope = null ; $ this -> filters = [ ] ; $ this -> activePage = null ; $ this -> activePageSize = null ; $ this -> resetActivePage = false ; return $ this ; }
|
Resets the controller s state before handling the index action .
|
52,360
|
protected function removePageQueryFromUrl ( $ url ) { $ parts = parse_url ( $ url ) ; $ query = preg_replace ( '#page=\d+&?#i' , '' , array_get ( $ parts , 'query' , '' ) ) ; return array_get ( $ parts , 'path' ) . ( $ query ? '?' . $ query : null ) ; }
|
Removes the page query parameter from a full URL .
|
52,361
|
protected function getTotalCount ( ) { $ query = $ this -> modelRepository -> query ( ) ; $ this -> applyListParentToQuery ( $ query ) ; return $ query -> count ( ) ; }
|
Returns total count of all models .
|
52,362
|
protected function isListOrderDraggable ( $ totalCount , $ currentCount ) { $ info = $ this -> getModelInformation ( ) ; if ( ! $ info -> list -> orderable ) { return false ; } $ showTopParentsOnly = $ this -> showsTopParentsOnly ( ) ; $ scopedRelation = $ info -> list -> order_scope_relation ; if ( $ showTopParentsOnly || $ this -> hasActiveListParent ( ) ) { if ( ! $ scopedRelation ) { return false ; } if ( $ showTopParentsOnly ) { if ( $ scopedRelation != $ info -> list -> default_top_relation ) { return false ; } } else { $ parent = head ( $ this -> listParents ) ; if ( $ scopedRelation != $ parent -> relation ) { return false ; } } } elseif ( $ scopedRelation ) { return false ; } $ hasScope = ( bool ) $ this -> getActiveScope ( ) ; $ hasFilters = ! empty ( $ this -> getActiveFilters ( ) ) ; return $ info -> list -> getOrderableColumn ( ) === $ this -> getActualSort ( ) && ( $ totalCount == $ currentCount || ( ! $ hasScope && ! $ hasFilters ) ) ; }
|
Returns whether given the current circumstances the list may be ordered by dragging rows .
|
52,363
|
protected function failureResponse ( $ error = null ) { if ( request ( ) -> ajax ( ) ) { return response ( ) -> json ( [ 'success' => false , 'error' => $ error , ] ) ; } return redirect ( ) -> back ( ) -> withErrors ( [ 'general' => $ error , ] ) ; }
|
Returns standard failure response .
|
52,364
|
protected function getSimpleRecordReference ( $ key , Model $ record = null ) { return ucfirst ( $ this -> modelInformation -> label ( ) ) . ' #' . $ key ; }
|
Returns a simple reference .
|
52,365
|
protected function getActiveTab ( $ pull = true ) { $ key = $ this -> getModelSessionKey ( ) . ':' . static :: ACTIVE_TAB_SESSION_KEY ; if ( $ pull ) { return session ( ) -> pull ( $ key ) ; } return session ( ) -> get ( $ key ) ; }
|
Returns the active edit form tab pane key if it is set .
|
52,366
|
protected function storeActiveTab ( $ tab ) { $ key = $ this -> getModelSessionKey ( ) . ':' . static :: ACTIVE_TAB_SESSION_KEY ; if ( null === $ tab ) { session ( ) -> forget ( $ key ) ; } else { session ( ) -> put ( $ key , $ tab ) ; } return $ this ; }
|
Stores the currently active edit form tab pane key .
|
52,367
|
protected function deleteModel ( Model $ model ) { $ strategy = $ this -> getModelInformation ( ) -> deleteStrategy ( ) ; if ( ! $ strategy ) { return $ model -> delete ( ) ; } $ factory = app ( DeleteStrategyFactoryInterface :: class ) ; $ strategy = $ factory -> make ( $ strategy ) ; return $ strategy -> delete ( $ model ) ; }
|
Deletes model .
|
52,368
|
protected function getForeignKeyNamesForRelation ( Relation $ relation ) { if ( $ relation instanceof BelongsTo || $ relation instanceof HasOne || $ relation instanceof HasMany || is_a ( $ relation , '\\Znck\\Eloquent\\Relations\\BelongsToThrough' , true ) ) { return [ $ relation -> getForeignKey ( ) ] ; } if ( $ relation instanceof BelongsToMany ) { return [ $ relation -> getQualifiedForeignPivotKeyName ( ) , $ relation -> getQualifiedRelatedPivotKeyName ( ) ] ; } if ( $ relation instanceof MorphTo || $ relation instanceof MorphOne || $ relation instanceof MorphMany ) { return [ $ relation -> getForeignKey ( ) , $ relation -> getMorphType ( ) ] ; } if ( $ relation instanceof MorphToMany ) { return [ $ relation -> getQualifiedForeignPivotKeyName ( ) , $ relation -> getMorphType ( ) , $ relation -> getQualifiedRelatedPivotKeyName ( ) , ] ; } return [ ] ; }
|
Returns the foreign key names for a given relation class .
|
52,369
|
protected function hasNullableForeignKeys ( Relation $ relation , Model $ model = null , array $ keys = null ) { if ( null === $ keys ) { $ keys = $ this -> getForeignKeyNamesForRelation ( $ relation ) ; } if ( ! count ( $ keys ) ) return false ; if ( null === $ model ) { if ( $ relation instanceof BelongsTo || $ relation instanceof MorphTo || is_a ( $ relation , '\\Znck\\Eloquent\\Relations\\BelongsToThrough' , true ) ) { $ model = $ this -> model ; } elseif ( $ relation instanceof HasOne || $ relation instanceof HasMany || $ relation instanceof BelongsToMany ) { $ model = $ relation -> getRelated ( ) ; } } if ( ! $ model ) { throw new RuntimeException ( 'No model could be determined for nullable foreign key check' ) ; } $ info = $ this -> getModelInformation ( $ model ) ; if ( $ info ) { $ attribute = array_get ( $ info -> attributes , $ this -> normalizeForeignKey ( head ( $ keys ) ) ) ; $ nullable = $ attribute ? $ attribute -> nullable : false ; if ( $ nullable && count ( $ keys ) > 1 && ( $ relation instanceof MorphTo || $ relation instanceof MorphOne || $ relation instanceof MorphMany ) ) { $ attribute = array_get ( $ info -> attributes , $ this -> normalizeForeignKey ( array_values ( $ keys ) [ 1 ] ) ) ; $ nullable = $ attribute ? $ attribute -> nullable : false ; } return $ nullable ; } return false ; }
|
Returns whether a relation s related model has nullable foreign keys .
|
52,370
|
protected function setForeignKeysToNull ( Model $ model , Relation $ relation , array $ keys ) { if ( ! count ( $ keys ) ) return ; $ key = $ this -> normalizeForeignKey ( head ( $ keys ) ) ; $ model -> { $ key } = null ; if ( count ( $ keys ) > 1 && ( $ relation instanceof MorphTo || $ relation instanceof MorphOne || $ relation instanceof MorphMany ) ) { $ key = $ this -> normalizeForeignKey ( array_values ( $ keys ) [ 1 ] ) ; $ model -> { $ key } = null ; } $ model -> save ( ) ; }
|
Sets the foreign keys to null on a given model .
|
52,371
|
protected function explicitlyConfiguredForeignKeysNullable ( ) { $ nullable = array_get ( $ this -> formFieldData -> options ( ) , 'nullable_key' ) ; if ( null === $ nullable ) return null ; return ( bool ) $ nullable ; }
|
Returns whether the relation s foreign keys were configured nullable .
|
52,372
|
protected function getAttributeCastForColumnType ( $ type , $ length = null ) { switch ( $ type ) { case 'bool' : return AttributeCast :: BOOLEAN ; case 'tinyint' : if ( $ length === 1 ) { return AttributeCast :: BOOLEAN ; } return AttributeCast :: INTEGER ; case 'int' : case 'integer' : case 'mediumint' : case 'smallint' : case 'bigint' : return AttributeCast :: INTEGER ; case 'dec' : case 'decimal' : case 'double' : case 'float' : case 'real' : return AttributeCast :: FLOAT ; case 'varchar' : case 'char' : case 'enum' : case 'text' : case 'mediumtext' : case 'longtext' : case 'tinytext' : case 'year' : case 'blob' ; case 'mediumblob' ; case 'longblob' ; case 'binary' ; case 'varbinary' ; return AttributeCast :: STRING ; case 'date' : case 'datetime' : case 'time' : case 'timestamp' : return AttributeCast :: DATE ; default : return $ type ; } }
|
Returns cast enum value for database column type string and length .
|
52,373
|
protected function normalizeCastString ( $ cast ) { switch ( $ cast ) { case 'bool' : case 'boolean' : $ cast = AttributeCast :: BOOLEAN ; break ; case 'decimal' : case 'double' : case 'float' : case 'real' : $ cast = AttributeCast :: FLOAT ; break ; case 'int' : case 'integer' : $ cast = AttributeCast :: INTEGER ; break ; case 'date' : case 'datetime' : $ cast = AttributeCast :: DATE ; break ; } return $ cast ; }
|
Normalizes a cast string to enum value if possible .
|
52,374
|
public function enrich ( ModelInformationInterface $ info , $ allInformation = null ) { $ this -> info = $ info ; $ class = $ this -> info -> modelClass ( ) ; $ this -> model = new $ class ; $ this -> allInfo = $ allInformation ; $ this -> performEnrichment ( ) ; return $ this -> info ; }
|
Performs enrichment on model information .
|
52,375
|
protected function shouldAttributeBeDisplayedByDefault ( ModelAttributeData $ attribute , ModelInformationInterface $ info ) { if ( in_array ( $ attribute -> type , [ 'text' , 'longtext' , 'mediumtext' , 'blob' , 'longblob' , 'mediumblob' , ] ) ) { return false ; } if ( $ info -> list -> activatable && $ info -> list -> active_column == $ attribute -> name ) { return false ; } if ( $ info -> list -> orderable && $ info -> list -> order_column == $ attribute -> name ) { return false ; } if ( preg_match ( '#^(?<field>[^_]+)_(file_name|file_size|content_type|updated_at)$#' , $ attribute -> name , $ matches ) && array_has ( $ info -> attributes , $ matches [ 'field' ] ) ) { return $ info -> attributes [ $ matches [ 'field' ] ] -> cast !== AttributeCast :: PAPERCLIP_ATTACHMENT ; } return ! $ this -> isAttributeForeignKey ( $ attribute -> name , $ info ) ; }
|
Returns whether an attribute should be displayed if no user - defined list columns are configured .
|
52,376
|
public function mapWebRoutes ( Router $ router ) { $ router -> group ( [ 'prefix' => $ this -> getRoutePrefix ( ) , 'as' => $ this -> getRouteNamePrefix ( ) , ] , function ( Router $ router ) { $ controller = $ this -> getModelWebController ( ) ; $ router -> post ( 'references' , [ 'as' => 'references' , 'uses' => $ controller . '@references' , ] ) ; } ) ; }
|
Generates web routes for the module given a contextual router instance .
|
52,377
|
public function mapApiRoutes ( Router $ router ) { $ router -> group ( [ 'prefix' => $ this -> getRoutePrefix ( ) , 'as' => $ this -> getRouteNamePrefix ( ) , ] , function ( Router $ router ) { $ controller = $ this -> getModelApiController ( ) ; $ router -> post ( 'references' , [ 'as' => 'references' , 'uses' => $ controller . '@references' , ] ) ; } ) ; }
|
Generates API routes for the module given a contextual router instance .
|
52,378
|
public function store ( Model $ model , array $ data ) { if ( ! config ( 'cms-models.transactions' ) ) { return $ this -> storeFormFieldValuesForModel ( $ model , $ data ) ; } DB :: beginTransaction ( ) ; try { $ success = $ this -> storeFormFieldValuesForModel ( $ model , $ data ) ; if ( $ success ) { DB :: commit ( ) ; } else { DB :: rollBack ( ) ; } } catch ( Exception $ e ) { DB :: rollBack ( ) ; throw $ e ; } return $ success ; }
|
Stores submitted form field data on a model .
|
52,379
|
protected function storeFormFieldValuesForModel ( Model $ model , array $ values ) { $ fields = [ ] ; $ strategies = [ ] ; foreach ( array_keys ( $ values ) as $ key ) { $ field = $ this -> getModelFormFieldDataForKey ( $ key ) ; if ( ! $ this -> allowedToUseFormFieldData ( $ field ) ) continue ; $ fields [ $ key ] = $ field ; $ strategies [ $ key ] = $ this -> getFormFieldStoreStrategyInstanceForField ( $ fields [ $ key ] ) ; $ strategies [ $ key ] -> setFormFieldData ( $ fields [ $ key ] ) ; $ strategies [ $ key ] -> setParameters ( $ this -> getFormFieldStoreStrategyParametersForField ( $ fields [ $ key ] ) ) ; } foreach ( $ values as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ strategies ) ) continue ; try { $ strategies [ $ key ] -> store ( $ model , $ fields [ $ key ] -> source ( ) , $ value ) ; } catch ( Exception $ e ) { $ class = get_class ( $ strategies [ $ key ] ) ; $ message = "Failed storing value for form field '{$key}' (using $class): \n{$e->getMessage()}" ; throw new StrategyApplicationException ( $ message , $ e -> getCode ( ) , $ e ) ; } } $ success = $ model -> save ( ) ; if ( ! $ success ) { return false ; } foreach ( $ values as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ strategies ) ) continue ; try { $ strategies [ $ key ] -> storeAfter ( $ model , $ fields [ $ key ] -> source ( ) , $ value ) ; } catch ( Exception $ e ) { $ class = get_class ( $ strategies [ $ key ] ) ; $ message = "Failed storing value for form field '{$key}' (using $class (after)): \n{$e->getMessage()}" ; throw new StrategyApplicationException ( $ message , $ e -> getCode ( ) , $ e ) ; } } if ( $ model -> isDirty ( ) ) { $ success = $ model -> save ( ) ; } foreach ( $ values as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ strategies ) ) continue ; try { $ strategies [ $ key ] -> finish ( ) ; } catch ( Exception $ e ) { $ class = get_class ( $ strategies [ $ key ] ) ; $ message = "Failed finishing strategy form field '{$key}' (using $class): \n{$e->getMessage()}" ; throw new StrategyApplicationException ( $ message , $ e -> getCode ( ) , $ e ) ; } } return $ success ; }
|
Stores filled in form field data for a model instance . Note that this will persist the model if it is a new instance .
|
52,380
|
public function make ( $ strategy ) { if ( ! $ strategy ) { return $ this -> getDefaultStrategy ( ) ; } if ( $ strategyClass = $ this -> resolveStrategyClass ( $ strategy ) ) { return app ( $ strategyClass ) ; } throw new RuntimeException ( "Could not create strategy instance for '{$strategy}'" ) ; }
|
Makes a show field strategy instance .
|
52,381
|
protected function resolveStrategyClass ( $ strategy ) { if ( ! str_contains ( $ strategy , '.' ) && $ aliasStrategy = config ( 'cms-models.strategies.show.aliases.' . $ strategy , config ( 'cms-models.strategies.list.aliases.' . $ strategy ) ) ) { $ strategy = $ aliasStrategy ; } if ( class_exists ( $ strategy ) && is_a ( $ strategy , ShowFieldInterface :: class , true ) ) { return $ strategy ; } $ strategy = $ this -> prefixStrategyNamespace ( $ strategy ) ; if ( class_exists ( $ strategy ) && is_a ( $ strategy , ShowFieldInterface :: class , true ) ) { return $ strategy ; } return false ; }
|
Resolves strategy assuming it is the class name or FQN of a show field interface implementation or an alias for one .
|
52,382
|
public function descendantFieldKeys ( ) : array { $ keys = [ ] ; foreach ( $ this -> children ( ) as $ key => $ node ) { if ( $ node instanceof ModelFormLayoutNodeInterface ) { $ keys = array_merge ( $ keys , $ node -> descendantFieldKeys ( ) ) ; continue ; } $ keys [ ] = $ node ; } return $ keys ; }
|
Returns list of keys of form fields that are descendants of this tab .
|
52,383
|
protected function getUserString ( ) { $ user = $ this -> core -> auth ( ) -> user ( ) ; if ( ! $ user ) return null ; return $ user -> getUsername ( ) ; }
|
Returns user name for currently logged in user if known .
|
52,384
|
protected function collectForeignKeys ( ) { $ keys = [ ] ; foreach ( $ this -> info -> relations as $ relation ) { if ( ! in_array ( $ relation -> type , [ RelationType :: BELONGS_TO , RelationType :: MORPH_TO , RelationType :: BELONGS_TO_THROUGH ] ) ) { continue ; } $ keys = array_merge ( $ keys , $ relation -> foreign_keys ) ; } return $ keys ; }
|
Returns list of foreign key attribute names on this model .
|
52,385
|
protected function enrichColumn ( $ key , ModelExportColumnDataInterface $ column , array & $ columns ) { if ( ! isset ( $ this -> info -> attributes [ $ key ] ) ) { if ( $ this -> isExportColumnDataComplete ( $ column ) ) { $ columns [ $ key ] = $ column ; return ; } throw new UnexpectedValueException ( "Incomplete data for for export column key that does not match known model attribute or relation method. " . "Requires at least 'source' value." ) ; } $ attributeColumnInfo = $ this -> makeModelExportColumnDataForAttributeData ( $ this -> info -> attributes [ $ key ] ) ; $ attributeColumnInfo -> merge ( $ column ) ; $ columns [ $ key ] = $ attributeColumnInfo ; }
|
Enriches a single export column and saves the data .
|
52,386
|
protected function makeModelExportColumnDataForAttributeData ( ModelAttributeData $ attribute ) { return new ModelExportColumnData ( [ 'hide' => false , 'source' => $ attribute -> name , 'strategy' => $ this -> determineExportColumnStrategyForAttribute ( $ attribute ) , ] ) ; }
|
Makes data set for export column given attribute data .
|
52,387
|
public function toArray ( ) { return [ 'name' => $ this -> getName ( ) , 'label' => $ this -> getLabel ( ) , 'width' => $ this -> getWidth ( ) , 'fixed' => $ this -> isFixed ( ) , 'minWidth' => $ this -> getMinWidth ( ) , 'sortable' => $ this -> getSortable ( ) , 'type' => $ this -> getType ( ) , ] ; }
|
The column options
|
52,388
|
public function getValue ( ) { $ value = $ this -> getModelValue ( ) ; if ( is_null ( $ value ) ) { $ value = $ this -> getDefaultValue ( ) ; } return $ value ; }
|
Get the column value
|
52,389
|
protected function storeActiveSortInSession ( ) { if ( null !== $ this -> activeSortDescending ) { $ direction = $ this -> activeSortDescending ? 'desc' : 'asc' ; } else { $ direction = null ; } $ this -> getListMemory ( ) -> setSortData ( $ this -> activeSort , $ direction ) ; }
|
Stores the currently active sort settings for the session .
|
52,390
|
protected function retrieveActiveSortFromSession ( ) { $ sessionSort = $ this -> getListMemory ( ) -> getSortData ( ) ; if ( ! is_array ( $ sessionSort ) ) return ; $ this -> activeSort = array_get ( $ sessionSort , 'column' ) ; $ direction = array_get ( $ sessionSort , 'direction' ) ; if ( null === $ direction ) { $ this -> activeSortDescending = null ; } else { $ this -> activeSortDescending = $ direction === 'desc' ; } }
|
Retrieves the sort settings from the session and restores them as active .
|
52,391
|
protected function getActualSortDirection ( $ column = null ) { $ column = $ column ? : $ this -> activeSort ; if ( null !== $ this -> activeSortDescending ) { return $ this -> activeSortDescending ? 'desc' : 'asc' ; } if ( ! isset ( $ this -> getModelInformation ( ) -> list -> columns [ $ column ] ) ) { if ( null === $ column ) { return $ this -> getActualSortDirection ( $ this -> getDefaultSort ( ) ) ; } return 'asc' ; } $ direction = $ this -> getModelInformation ( ) -> list -> columns [ $ column ] -> sort_direction ; return strtolower ( $ direction ) === 'desc' ? 'desc' : 'asc' ; }
|
Returns the sort direction that is actually active determined by the specified sort direction with a fallback to the default .
|
52,392
|
protected function getModelSortCriteria ( ) { $ sort = $ this -> getActualSort ( ) ; $ info = $ this -> getModelInformation ( ) ; if ( $ info -> list -> orderable && $ sort == $ info -> list -> getOrderableColumn ( ) && ( $ orderableStrategy = $ this -> getOrderableSortStrategy ( ) ) ) { return $ orderableStrategy ; } if ( ! isset ( $ info -> list -> columns [ $ sort ] ) ) { return false ; } $ strategy = $ info -> list -> columns [ $ sort ] -> sort_strategy ; $ source = $ info -> list -> columns [ $ sort ] -> source ? : $ sort ; return new ModelOrderStrategy ( $ strategy , $ source , $ this -> getActualSortDirection ( ) ) ; }
|
Returns the active model sorting criteria to apply to the model repository .
|
52,393
|
protected function applySort ( ) { $ sort = $ this -> getActualSort ( ) ; if ( ! $ sort ) return $ this ; $ criteria = $ this -> getModelSortCriteria ( ) ; if ( ! $ criteria ) return $ this ; $ this -> getModelRepository ( ) -> pushCriteria ( $ criteria , CriteriaKey :: ORDER ) ; return $ this ; }
|
Applies active sorting to model repository .
|
52,394
|
protected function setSortingOrder ( ) { if ( null !== $ this -> info -> list -> default_sort ) { return $ this ; } if ( $ this -> info -> list -> orderable && $ this -> info -> list -> getOrderableColumn ( ) ) { $ this -> info -> list -> default_sort = $ this -> info -> list -> getOrderableColumn ( ) ; } elseif ( $ this -> info -> timestamps ) { $ this -> info -> list -> default_sort = $ this -> info -> timestamp_created ; } elseif ( $ this -> info -> incrementing ) { $ this -> info -> list -> default_sort = $ this -> model -> getKeyName ( ) ; } return $ this ; }
|
Sets default sorting order if empty .
|
52,395
|
protected function setReferenceSource ( ) { if ( null !== $ this -> info -> reference -> source ) { return $ this ; } $ matchAttributes = config ( 'cms-models.analyzer.reference.sources' , [ ] ) ; foreach ( $ matchAttributes as $ matchAttribute ) { if ( array_key_exists ( $ matchAttribute , $ this -> info -> attributes ) ) { $ this -> info -> reference -> source = $ matchAttribute ; break ; } } return $ this ; }
|
Sets default reference source better than primary key if possible .
|
52,396
|
protected function setDefaultRowActions ( ) { $ actions = $ this -> info -> list -> default_action ? : [ ] ; if ( count ( $ actions ) ) { return $ this ; } $ addEditAction = config ( 'cms-models.defaults.default-listing-action-edit' , false ) ; $ addShowAction = config ( 'cms-models.defaults.default-listing-action-show' , false ) ; if ( ! $ addEditAction && ! $ addShowAction ) { return $ this ; } $ modelSlug = $ this -> getRouteHelper ( ) -> getRouteSlugForModelClass ( get_class ( $ this -> model ) ) ; $ permissionPrefix = $ this -> getRouteHelper ( ) -> getPermissionPrefixForModelSlug ( $ modelSlug ) ; if ( $ addEditAction ) { $ actions [ ] = [ 'strategy' => ActionReferenceType :: EDIT , 'permissions' => "{$permissionPrefix}edit" , ] ; } if ( $ addShowAction ) { $ actions [ ] = [ 'strategy' => ActionReferenceType :: SHOW , 'permissions' => "{$permissionPrefix}show" , ] ; } $ this -> info -> list -> default_action = $ actions ; return $ this ; }
|
Sets default actions if configured to and none are defined .
|
52,397
|
public function processedRules ( ) { $ decorator = $ this -> getRuleDecorator ( ) ; return $ decorator -> decorate ( $ this -> container -> call ( [ $ this , 'rules' ] ) ) ; }
|
Returns post - processed validation rules .
|
52,398
|
protected function handlePaperclipAttachments ( ) { $ attachments = $ this -> detectPaperclipAttachments ( ) ; $ inserts = [ ] ; foreach ( $ attachments as $ key => $ attachment ) { $ attribute = new ModelAttributeData ( [ 'name' => $ key , 'cast' => AttributeCast :: PAPERCLIP_ATTACHMENT , 'type' => $ attachment -> image ? 'image' : 'file' , ] ) ; $ inserts [ $ key . '_file_name' ] = $ attribute ; } if ( ! count ( $ inserts ) ) { return $ this ; } $ attributes = $ this -> info -> attributes ; foreach ( $ inserts as $ before => $ attribute ) { $ attributes = $ this -> insertInArray ( $ attributes , $ attribute -> name , $ attribute , $ before ) ; } $ this -> info -> attributes = $ attributes ; return $ this ; }
|
Handles analysis of paperclip attachments .
|
52,399
|
protected function detectPaperclipAttachments ( ) { $ model = $ this -> model ( ) ; if ( ! ( $ model instanceof PaperclippableInterface ) ) { return [ ] ; } $ files = $ model -> getAttachedFiles ( ) ; $ attachments = [ ] ; foreach ( $ files as $ attribute => $ file ) { $ variants = $ file -> variants ( ) ; $ normalizedVariants = [ ] ; foreach ( $ variants as $ variant ) { if ( $ variant === 'original' ) { continue ; } $ normalizedVariants [ $ variant ] = $ this -> extractPaperclipVariantInfo ( $ file , $ variant ) ; } $ attachments [ $ attribute ] = new PaperclipAttachmentData ( [ 'image' => ( is_array ( $ variants ) && count ( $ variants ) > 1 ) , 'resizes' => array_pluck ( $ normalizedVariants , 'dimensions' ) , 'variants' => $ variants , 'extensions' => array_pluck ( $ normalizedVariants , 'extension' ) , 'types' => array_pluck ( $ normalizedVariants , 'mimeType' ) , ] ) ; } return $ attachments ; }
|
Returns list of paperclip attachments if the model has any .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.