idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
49,500 | protected function files ( ) : Collection { $ storing = $ this -> pictures -> get ( 'storing' ) ; return $ this -> normalizeBag ( is_array ( $ storing ) ? $ storing : [ $ storing ] ) ; } | Returns the new files . |
49,501 | public function store ( ) : array { $ this -> validate ( ) ; if ( $ this -> files ( ) -> isEmpty ( ) ) { return [ ] ; } return $ this -> files ( ) -> flatMap ( function ( $ item ) { $ files [ ] = [ 'path' => $ item -> store ( $ this -> directory ) ] ; return $ files ; } ) -> all ( ) ; } | Store the given pictures . |
49,502 | public function update ( $ current ) { $ this -> validate ( ) ; if ( $ this -> files ( ) -> isEmpty ( ) ) { return $ this -> currentPictures ( $ current ) ; } $ result = $ this -> mapUpdatedPictures ( $ current ) ; if ( count ( $ result ) == 1 && is_array ( $ result [ 0 ] ) ) { return $ result [ 0 ] ; } return $ result ; } | Update the given pictures . |
49,503 | protected function currentPictures ( $ current ) { if ( is_string ( $ current ) || is_null ( $ current ) || count ( $ current ) == 0 ) { return [ 'id' => null , 'path' => $ current ] ; } return $ current -> map ( function ( $ item ) { $ array = [ 'id' => $ item [ 'id' ] , 'path' => $ item [ 'path' ] ] ; return $ array ; } ) -> all ( ) ; } | Map the current pictures . |
49,504 | protected function mapUpdatedPictures ( $ current ) { $ this -> deleteCurrentFiles ( $ current ) ; return $ this -> files ( ) -> flatMap ( function ( $ item , $ key ) { $ files [ ] = [ 'id' => $ key , 'path' => $ item -> store ( $ this -> directory ) ] ; return $ files ; } ) -> all ( ) ; } | Map the updated pictures . |
49,505 | protected function deleteRelatedFiles ( $ deleting ) { $ files = $ this -> deletingFilesNamesList ( $ deleting ) ; foreach ( $ files as $ file ) { foreach ( Storage :: files ( $ this -> directory ) as $ relative ) { if ( strpos ( $ relative , $ file ) !== false ) { Storage :: delete ( $ relative ) ; } } } } | Delete the files related to the ones to be delete . |
49,506 | protected function deletingFilesNamesList ( $ files ) : array { return $ files -> flatMap ( function ( $ item ) { $ path_parts = pathinfo ( $ item ) ; $ result [ ] = $ path_parts [ 'filename' ] ; return $ result ; } ) -> filter ( function ( $ item ) { return trim ( $ item ) != '' ; } ) -> all ( ) ; } | Returns a sanitized deleting files list . |
49,507 | protected function all ( ) : array { return array_merge ( [ 'category' => $ this -> forCategories ( ) , 'brands' => array_count_values ( $ this -> products -> pluck ( 'brand' ) -> all ( ) ) , 'conditions' => array_count_values ( $ this -> products -> pluck ( 'condition' ) -> all ( ) ) , ] , $ this -> forFeatures ( ) ) ; } | Returns the parsed filters . |
49,508 | protected function forCategories ( ) : array { $ categories = $ this -> products -> pluck ( 'category' ) ; return $ categories -> mapWithKeys ( function ( $ item ) use ( $ categories ) { $ result [ $ item -> id ] = [ 'id' => $ item -> id , 'name' => $ item -> name , 'qty' => $ categories -> where ( 'id' , $ item -> id ) -> count ( ) ] ; return $ result ; } ) -> all ( ) ; } | Parses the category filter . |
49,509 | protected function forFeatures ( ) : array { return Collection :: make ( $ this -> allowed ) -> mapWithKeys ( function ( $ feature ) { return [ $ feature => array_count_values ( $ this -> features ( ) [ $ feature ] ) ] ; } ) -> all ( ) ; } | Returns the mapped features with their quantities . |
49,510 | protected function features ( ) : array { $ features = $ this -> products -> pluck ( 'features' ) ; return Collection :: make ( $ this -> allowed ) -> mapWithKeys ( function ( $ allowed ) use ( $ features ) { return [ $ allowed => $ features -> pluck ( $ allowed ) -> filter ( function ( $ allowed ) { return ! is_null ( $ allowed ) ; } ) -> all ( ) ] ; } ) -> all ( ) ; } | Returns a map with the given features . |
49,511 | public function confirmEmail ( string $ token , string $ email ) { Auth :: user ( ) -> confirmPetition ( $ token , $ email ) ; Auth :: logout ( ) ; return redirect ( ) -> route ( 'user.index' ) ; } | Confirms the users s new email address . |
49,512 | public function update ( string $ action ) { $ action = mb_strtolower ( $ action ) ; if ( ! in_array ( $ action , [ 'enable' , 'disable' ] ) ) { return $ this -> respondsWithError ( trans ( 'globals.action_not_allowed' ) ) ; } Auth :: user ( ) -> $ action ( ) ; return $ this -> respondsWithSuccess ( trans ( 'user.success' ) ) ; } | Update user s profile with a given action . |
49,513 | public function store ( Request $ request , CompanyRepository $ repository ) { $ data = $ request -> validate ( [ 'name' => 'required' , 'email' => 'required|email' , 'message' => 'required' ] ) ; $ company = $ repository -> default ( ) ; Mail :: to ( $ company -> email ) -> send ( new SendContactEmail ( $ company , $ data ) ) ; return redirect ( ) -> route ( 'contact' ) -> with ( 'message' , trans ( 'company.contact.message' ) ) ; } | Sends the contact us email . |
49,514 | public function getAllUnread ( User $ user = null ) { $ user = $ user ?? Craft :: $ app -> getUser ( ) ; if ( $ user ) { $ notifications = NotificationsRecord :: find ( ) -> where ( [ 'notifiable' => $ user -> id , 'read_at' => null ] ) -> all ( ) ; return $ this -> formatNotificationData ( $ notifications ) -> toArray ( ) ; } return [ ] ; } | Get all unread notifications for a certain User |
49,515 | public function markAsRead ( $ notifications = null ) { $ user = Craft :: $ app -> getUser ( ) ; if ( $ user && is_null ( $ notifications ) ) { $ notifications = NotificationsRecord :: find ( ) -> where ( [ 'notifiable' => $ user -> getId ( ) ] ) -> all ( ) ; } $ notifications = collect ( $ notifications ) ; $ notificationIds = $ notifications -> map ( function ( $ notification ) { return is_object ( $ notification ) ? $ notification -> id : $ notification ; } ) ; if ( ! is_null ( $ notificationIds ) ) { $ now = DateTimeHelper :: currentUTCDateTime ( ) -> format ( 'Y-m-d H:i:s' ) ; NotificationsRecord :: updateAll ( [ 'read_at' => $ now ] , [ 'id' => $ notificationIds ] ) ; } } | Mark a notification as read |
49,516 | protected function formatNotificationData ( $ notifications ) { return collect ( $ notifications ) -> map ( function ( $ notification ) { $ notification -> data = json_decode ( $ notification -> data ) ; return $ notification ; } ) ; } | Decode notification data |
49,517 | protected function formatNotifiables ( $ notifiables ) { if ( is_callable ( $ notifiables ) ) { $ notifiables = $ notifiables ( ) ; } if ( ! is_array ( $ notifiables ) ) { return [ $ notifiables ] ; } return $ notifiables ; } | Format the notifiables into an array if necessary . |
49,518 | protected function channel ( $ name = null ) { if ( ! isset ( self :: channels ( ) [ $ name ] ) ) { throw new InvalidCallException ( "No channel {$name} exists." ) ; } return call_user_func ( self :: channels ( ) [ $ name ] ) ; } | Get a channel instance . |
49,519 | public function unread ( $ limit = 5 ) { $ unread = Auth :: user ( ) -> unreadNotifications -> take ( $ limit ) ; return $ unread -> map ( function ( $ item ) { return $ this -> toCollect ( $ item ) ; } ) ; } | Shows the unread user notifications formatted . |
49,520 | protected function toCollect ( $ notification ) : Collection { return Collection :: make ( [ 'hasBeenRead' => ! is_null ( $ notification -> read_at ) , 'path' => $ notification -> data [ 'source_path' ] , 'label' => $ notification -> data [ 'label' ] , 'id' => $ notification -> id , ] ) ; } | Formats the given notification to the desired array . |
49,521 | protected function emailWasChanged ( ProfileWasUpdated $ event ) : bool { $ newEmail = $ event -> request -> get ( 'email' ) ; return ! is_null ( $ newEmail ) && $ newEmail != Auth :: user ( ) -> email ; } | Checks whether the user changed his email address . |
49,522 | protected function createNewEmailPetition ( ProfileWasUpdated $ event ) { $ event -> petition = Auth :: user ( ) -> makePetitionFor ( $ event -> request [ 'email' ] ) ; unset ( $ event -> request [ 'email' ] ) ; } | Creates a new email petition . |
49,523 | protected function updateUserPorfile ( $ data ) { $ data = $ data -> except ( 'email' ) ; if ( $ data instanceof Collection ) { $ data = $ data -> toArray ( ) ; } if ( isset ( $ data [ 'password' ] ) ) { $ data [ 'password' ] = Hash :: make ( $ data [ 'password' ] ) ; } Auth :: user ( ) -> update ( $ data ) ; } | Updates the user profile with the given data . |
49,524 | public function shake ( ) { return $ this -> keys -> flatMap ( function ( $ preferenceKey ) { $ products [ $ preferenceKey ] = is_string ( $ preferenceKey ) ? $ this -> suggestFor ( $ preferenceKey ) : new Collection ; return $ products ; } ) ; } | Returns a mapped products suggestions based on the given key . |
49,525 | public static function shakeFor ( Collection $ products ) : Collection { $ suggestions = new static ( $ key = 'all' ) ; $ suggestions -> products = $ products ; $ suggestions -> excluding ( $ products ) ; return $ suggestions -> suggestFor ( $ key ) ; } | Returns a mapped products suggestions based on the given products . |
49,526 | public function excluding ( Collection $ products ) { $ ids = $ products -> pluck ( 'id' ) ; if ( $ this -> excluding -> count ( ) == 0 ) { $ this -> excluding = $ ids ; } else { foreach ( $ ids as $ id ) { $ this -> excluding -> push ( $ id ) ; } } return $ this ; } | Builds the excluding list based on the given collection . |
49,527 | protected function suggestFor ( string $ preferenceKey ) : Collection { $ suggestions = Product :: suggestionsFor ( $ preferenceKey , $ this -> resolveTagsFor ( $ preferenceKey ) ) -> whereNotIn ( 'id' , $ this -> excluding -> all ( ) ) -> orderBy ( 'rate_val' , 'desc' ) -> take ( $ this -> limit ) -> get ( ) ; if ( $ suggestions -> count ( ) < $ this -> limit ) { $ suggestions = $ suggestions -> merge ( $ this -> completeWithRandomProducts ( $ suggestions ) ) ; } $ this -> excluding ( $ suggestions ) ; return $ suggestions ; } | Returns a products suggestion for the given key . |
49,528 | protected function completeWithRandomProducts ( Collection $ products ) : Collection { $ currentLimit = $ this -> limit - $ products -> count ( ) ; return Product :: whereNotIn ( 'id' , $ this -> excluding -> all ( ) ) -> orderBy ( 'rate_val' , 'desc' ) -> take ( $ currentLimit ) -> get ( ) ; } | Completes the returned suggestion with random products . |
49,529 | protected function resolveTagsFor ( string $ preferenceKey ) : array { if ( ! is_null ( $ this -> products ) ) { return $ this -> pullTagsFromProducts ( ) ; } $ preferences = $ this -> resolveUserPreferences ( ) ; $ tags = PreferencesParser :: parse ( $ preferences ) -> all ( $ this -> keys ) ; return isset ( $ tags [ $ preferenceKey ] ) ? $ tags [ $ preferenceKey ] : [ ] ; } | Resolves the tags list for the given key . |
49,530 | protected function pullTagsFromProducts ( ) : array { return $ this -> products -> map ( function ( $ item ) { return explode ( ',' , str_replace ( '"' , '' , $ item -> tags ) ) ; } ) -> flatten ( ) -> unique ( ) -> all ( ) ; } | Returns an array with tags extracted from the products list . |
49,531 | protected function resolveUserPreferences ( ) { if ( $ this -> user ) { return $ this -> user -> preferences ; } if ( Auth :: check ( ) ) { return Auth :: user ( ) -> preferences ; } return null ; } | Resolve the user s preferences tags . |
49,532 | public function update ( ProfileRequest $ request , User $ user ) { event ( new ProfileWasUpdated ( $ request ) ) ; if ( $ request -> wantsJson ( ) ) { return $ this -> respondsWithSuccess ( 'ok' ) ; } return back ( ) ; } | Updates the user profile . |
49,533 | protected function resolve ( ) { $ key = $ this -> templatesFile . '.' . $ this -> source ; if ( Lang :: has ( $ key ) ) { return Lang :: get ( $ key ) ; } return $ this -> default ( ) ; } | Resolves the notification resources . |
49,534 | public function default ( ) { $ file = Antvel :: langPath ( ) . DIRECTORY_SEPARATOR . "en" . DIRECTORY_SEPARATOR . $ this -> templatesFile . ".php" ; $ templates = ( new Filesystem ) -> getRequire ( $ file ) ; return Arr :: get ( $ templates , $ this -> source ) ; } | Returns the default notifications resources . |
49,535 | protected function isAllowed ( ) : bool { return $ this -> request -> has ( 'referral' ) && in_array ( $ this -> request -> get ( 'referral' ) , $ this -> allowedReferral ) ; } | Checks whether the referral form is allowed to make the incoming request . |
49,536 | public function rules ( ) : array { $ referral = mb_strtolower ( $ this -> request -> get ( 'referral' ) ?? 'profile' ) ; $ resolver = 'rulesFor' . ucfirst ( $ referral ) ; return $ this -> $ resolver ( ) ; } | Resolves the validation rules for a given referral form . |
49,537 | protected function rulesForProfile ( ) : array { return [ 'first_name' => 'required' , 'last_name' => 'required' , 'gender' => 'required' , 'email' => [ Rule :: unique ( 'users' ) -> ignore ( Auth :: user ( ) -> id ) , 'required' , 'email' , ] , 'nickname' => [ Rule :: unique ( 'users' ) -> ignore ( Auth :: user ( ) -> nickname , 'nickname' ) , 'required' , 'max:20' , ] , 'pictures.storing' => [ Rule :: dimensions ( ) -> maxWidth ( 500 ) -> maxHeight ( 500 ) , 'mimes:jpeg,png,jpg' , 'image' , ] , ] ; } | Returns validation rules for the form profile . |
49,538 | public function update ( array $ attributes , $ idOrModel , array $ options = [ ] ) { $ product = $ this -> modelOrFind ( $ idOrModel ) ; $ attributes = Collection :: make ( $ attributes ) ; $ attr = $ attributes -> except ( 'features' , 'pictures' , 'default_picture' ) -> merge ( [ 'features' => \ Antvel \ Features \ Parser :: toJson ( $ attributes -> get ( 'features' ) ) , 'category_id' => $ attributes -> get ( 'category' ) , 'price' => $ attributes -> get ( 'price' ) * 100 , 'cost' => $ attributes -> get ( 'cost' ) * 100 , 'status' => $ attributes -> get ( 'status' ) , 'updated_by' => auth ( ) -> user ( ) -> id , 'tags' => $ attributes -> get ( 'name' ) , ] ) -> all ( ) ; $ this -> updatePicturesFor ( $ product , $ attributes ) ; return $ product -> update ( $ attr ) ; } | Update a Model in the database . |
49,539 | public function filter ( $ request = [ ] , $ limit = null ) { return $ this -> getModel ( ) -> with ( 'category' ) -> actives ( ) -> filter ( $ request ) -> orderBy ( 'rate_val' , 'desc' ) ; } | Filters products by a given request . |
49,540 | protected function registerServices ( ) { foreach ( Antvel :: bindings ( ) as $ key => $ value ) { is_numeric ( $ key ) ? $ this -> app -> singleton ( $ value ) : $ this -> app -> singleton ( $ key , $ value ) ; } } | Register Antvel services in the container . |
49,541 | protected function registerServicesAliases ( ) { foreach ( Antvel :: alias ( ) as $ key => $ value ) { $ this -> app -> alias ( $ value , $ key ) ; } } | Register Antvel services aliases in the container . |
49,542 | protected function rulesForBody ( ) { return [ 'name' => 'required' , 'description' => 'required' , 'cost' => 'required|numeric|max:999999999' , 'price' => 'required|numeric|max:999999999' , 'brand' => 'required' , 'stock' => 'required|integer' , 'low_stock' => 'required|integer' , 'status' => 'required|boolean' , 'category' => [ 'required' , Rule :: exists ( 'categories' , 'id' ) -> where ( 'id' , $ this -> request -> get ( 'category' ) ) , ] , 'condition' => [ 'required' , Rule :: in ( Attributes :: make ( 'condition' ) -> keys ( ) ) , ] , ] ; } | Builds the validation rules for the product information . |
49,543 | protected function forPictures ( ) : array { $ pictures = Collection :: make ( $ this -> all ( ) ) -> filter ( function ( $ item , $ key ) { return $ key == 'pictures' ; } ) -> get ( 'pictures' ) ; if ( is_null ( $ pictures ) || empty ( $ pictures [ 'storing' ] ) ) { return [ ] ; } return Collection :: make ( $ pictures [ 'storing' ] ) -> mapWithKeys ( function ( $ item , $ key ) { return [ 'pictures.storing.' . $ key => [ 'mimes:jpeg,png,jpg' , Rule :: dimensions ( ) -> maxWidth ( 1000 ) -> maxHeight ( 500 ) ] ] ; } ) -> all ( ) ; } | Builds the validation rules for the product pictures . |
49,544 | protected function createPicturesFor ( $ product , $ attr ) { $ pictures = Images :: parse ( $ attr -> get ( 'pictures' ) ) -> on ( $ this -> basePath . '/' . $ product -> id ) -> store ( ) ; $ product -> pictures ( ) -> createMany ( $ pictures ) ; } | Creates pictures for the given product . |
49,545 | protected function updatePicturesFor ( $ product , $ attr ) { $ current = $ product -> pictures ; $ images = Images :: parse ( $ pictures = $ attr -> get ( 'pictures' ) ) -> on ( $ this -> basePath . '/' . $ product -> id ) ; if ( $ images -> wantsDeletion ( ) ) { $ this -> deletePictures ( $ product , $ images -> delete ( $ current ) ) ; } if ( isset ( $ pictures [ 'storing' ] ) && count ( $ pictures [ 'storing' ] ) > 0 ) { $ current = $ current -> whereIn ( 'id' , array_keys ( $ pictures [ 'storing' ] ) ) ; $ pictures = $ images -> update ( $ current ) ; $ product -> updatePictures ( isset ( $ pictures [ 'path' ] ) ? [ $ pictures ] : $ pictures ) ; } if ( isset ( $ attr [ 'default_picture' ] ) ) { $ product -> updateDefaultPicture ( $ attr [ 'default_picture' ] ) ; } } | Updates pictures for the given product . |
49,546 | protected function all ( ) : array { $ breadcrumb = $ this -> data -> except ( 'page' ) ; if ( $ this -> data -> has ( 'category' ) ) { $ breadcrumb = $ breadcrumb -> merge ( $ this -> category ( ) ) ; } return $ breadcrumb -> all ( ) ; } | Parses the given data . |
49,547 | protected function category ( ) : array { $ category = explode ( '|' , urldecode ( $ this -> data -> get ( 'category' ) ) ) ; return [ 'category' => isset ( $ category [ 0 ] ) ? $ category [ 0 ] : 1 , 'category_name' => isset ( $ category [ 1 ] ) ? $ category [ 1 ] : '' , ] ; } | Returns the category associated with the given data . |
49,548 | public function index ( Request $ request , $ file ) { $ options = $ request -> all ( ) ; return Render :: image ( $ file , $ options ) -> cast ( ) ; } | Renders the given imagen . |
49,549 | protected function _doSend ( Swift_Mime_SimpleMessage $ message , & $ failedRecipients = null ) { $ date = date ( 'D, j F Y H:i:s O' ) ; if ( function_exists ( 'hash_hmac' ) and in_array ( 'sha1' , hash_algos ( ) ) ) { $ hmac = base64_encode ( hash_hmac ( 'sha1' , $ date , $ this -> AWSSecretKey , true ) ) ; } else { $ hmac = $ this -> calculate_RFC2104HMAC ( $ date , $ this -> AWSSecretKey ) ; } $ auth = "AWS3-HTTPS AWSAccessKeyId=" . $ this -> AWSAccessKeyId . ", Algorithm=HmacSHA1, Signature=" . $ hmac ; $ fp = $ this -> getRawSocket ( ) ; $ host = parse_url ( $ this -> endpoint , PHP_URL_HOST ) ; $ path = parse_url ( $ this -> endpoint , PHP_URL_PATH ) ; $ socket = new ChunkedTransferSocket ( $ fp , $ host , $ path , "POST" , $ this -> persistent ) ; $ socket -> header ( "Date" , $ date ) ; $ socket -> header ( "X-Amzn-Authorization" , $ auth ) ; $ socket -> write ( "Action=SendRawEmail&RawMessage.Data=" ) ; $ ais = new Swift_AWSInputByteStream ( $ socket ) ; $ message -> toByteStream ( $ ais ) ; $ ais -> flushBuffers ( ) ; $ result = $ socket -> read ( ) ; if ( ! $ this -> persistent ) { fclose ( $ fp ) ; } return $ result ; } | do send through the API |
49,550 | public function header ( $ header , $ value ) { if ( $ this -> write_started ) { throw new InvalidOperationException ( "Can not write header, body writing has started." ) ; } fwrite ( $ this -> socket , "$header: $value\r\n" ) ; fflush ( $ this -> socket ) ; } | Add an HTTP header |
49,551 | public function write ( $ chunk ) { if ( $ this -> write_finished ) { throw new InvalidOperationException ( "Can not write, reading has started." ) ; } if ( ! $ this -> write_started ) { fwrite ( $ this -> socket , "\r\n" ) ; $ this -> write_started = true ; } fwrite ( $ this -> socket , sprintf ( "%x\r\n" , strlen ( $ chunk ) ) ) ; fwrite ( $ this -> socket , $ chunk ) ; fwrite ( $ this -> socket , "\r\n" ) ; fflush ( $ this -> socket ) ; } | Write a chunk of data |
49,552 | public function read ( ) { if ( ! $ this -> write_finished ) { $ this -> finishWrite ( ) ; } $ this -> read_started = true ; $ response = new AWSResponse ( ) ; while ( ! feof ( $ this -> socket ) ) { $ line = fgets ( $ this -> socket ) ; if ( AWSResponse :: EOF == $ response -> line ( $ line ) ) { break ; } } $ response -> complete ( ) ; return $ response ; } | Read the socket for a response |
49,553 | protected function _getIndexType ( ) { $ action = $ this -> _action ( ) ; $ indexType = $ action -> getConfig ( 'scaffold.index_type' ) ; if ( empty ( $ indexType ) ) { $ indexType = 'table' ; } return $ indexType ; } | Returns the index type to show on scaffolded view |
49,554 | protected function _getIndexTitleField ( ) { $ action = $ this -> _action ( ) ; $ field = $ action -> getConfig ( 'scaffold.index_title_field' ) ; if ( $ field === null ) { $ field = $ this -> _table ( ) -> getDisplayField ( ) ; } return $ field ; } | Returns the title field to show on scaffolded view |
49,555 | protected function _getIndexBodyField ( ) { $ action = $ this -> _action ( ) ; $ field = $ action -> getConfig ( 'scaffold.index_body_field' ) ; if ( $ field === null ) { $ field = 'body' ; } return $ field ; } | Returns the body field to show on scaffolded view |
49,556 | protected function _getIndexImageField ( ) { $ action = $ this -> _action ( ) ; $ field = $ action -> getConfig ( 'scaffold.index_image_field' ) ; if ( empty ( $ field ) ) { $ field = 'image' ; } return $ field ; } | Returns the image field to show on scaffolded view |
49,557 | protected function _getIndexGalleryCssClasses ( ) { $ action = $ this -> _action ( ) ; $ field = $ action -> getConfig ( 'scaffold.index_gallery_css_classes' ) ; if ( empty ( $ field ) ) { $ field = 'col-sm-6 col-md-3' ; } return $ field ; } | Returns the css classes to use for each gallery entry |
49,558 | public function display ( $ title , array $ links = [ ] ) { if ( is_array ( $ title ) ) { $ links = $ title ; $ title = '' ; } $ this -> set ( 'title' , $ title ) ; if ( ! empty ( $ links ) ) { $ this -> set ( 'links' , $ links ) ; } } | Default display method . |
49,559 | protected function deprecatedScaffoldKeyNotice ( $ deprecatedKey , $ newKey ) { $ template = 'The configuration key %s has been deprecated. Use %s instead.' ; $ message = sprintf ( $ template , $ deprecatedKey , $ newKey ) ; trigger_error ( $ message , E_USER_DEPRECATED ) ; } | Emit a deprecation notice for deprecated configuration key use |
49,560 | protected function _loadAssets ( ) { if ( Configure :: read ( 'CrudView.useAssetCompress' ) ) { $ this -> AssetCompress -> css ( 'CrudView.crudview' , [ 'block' => true ] ) ; $ this -> AssetCompress -> script ( 'CrudView.crudview_head' , [ 'block' => 'headjs' ] ) ; $ this -> AssetCompress -> script ( 'CrudView.crudview' , [ 'block' => true ] ) ; return ; } $ config = Configure :: read ( 'CrudView' ) ; if ( ! $ config ) { return ; } if ( ! empty ( $ config [ 'css' ] ) ) { $ this -> Html -> css ( $ config [ 'css' ] , [ 'block' => true ] ) ; } if ( ! empty ( $ config [ 'js' ] ) ) { foreach ( $ config [ 'js' ] as $ block => $ scripts ) { $ this -> Html -> script ( $ scripts , [ 'block' => $ block ] ) ; } } } | Read from config which css and js files to load and add them to the output . If AssetCompress plugin is loaded use the asset_compress . ini configuration that is part of this plugin . |
49,561 | protected function _setupPaths ( ) { $ paths = Configure :: read ( 'App.paths.templates' ) ; $ extraPaths = Configure :: read ( 'CrudView.templatePaths' ) ; if ( ! empty ( $ extraPaths ) ) { $ paths = array_merge ( $ paths , ( array ) $ extraPaths ) ; } $ paths [ ] = Plugin :: classPath ( 'CrudView' ) . 'Template' . DS ; Configure :: write ( 'App.paths.templates' , $ paths ) ; } | Initializes the crud - view template paths |
49,562 | public function fetch ( $ name , $ default = '' ) { $ viewblock = '' ; $ viewblocks = $ this -> get ( 'viewblocks' , [ ] ) ; if ( ! empty ( $ viewblocks [ $ name ] ) ) { $ viewblock = $ this -> _createViewblock ( $ viewblocks [ $ name ] ) ; } $ internal = $ this -> Blocks -> get ( $ name , $ default ) ; return $ internal . $ viewblock ; } | Fetch the content for a block . If a block is empty or undefined will be returned . |
49,563 | public function exists ( $ name ) { $ viewblocks = $ this -> get ( 'viewblocks' , [ ] ) ; return ! empty ( $ viewblocks [ $ name ] ) || $ this -> Blocks -> exists ( $ name ) ; } | Check if a block exists |
49,564 | protected function _createViewblock ( $ data ) { $ output = '' ; foreach ( $ data as $ key => $ type ) { if ( $ type === 'element' ) { $ output = $ this -> element ( $ key ) ; } elseif ( $ type === 'Html::css' ) { $ output .= $ this -> Html -> css ( $ key ) ; } elseif ( $ type === 'Html::script' ) { $ output .= $ this -> Html -> script ( $ key ) ; } else { $ output .= $ key ; } } return $ output ; } | Constructs a ViewBlock from an array of configured data |
49,565 | public function afterPaginate ( Event $ event ) { $ event ; if ( ! $ this -> _table ( ) -> behaviors ( ) -> has ( 'Search' ) ) { return ; } $ enabled = $ this -> getConfig ( 'enabled' ) ? : ! $ this -> _request ( ) -> is ( 'api' ) ; if ( ! $ enabled ) { return ; } $ fields = $ this -> fields ( ) ; $ this -> _controller ( ) -> set ( 'searchInputs' , $ fields ) ; } | After paginate event callback . |
49,566 | protected function _deriveFields ( ) { $ config = $ this -> getConfig ( ) ; $ table = $ this -> _table ( ) ; if ( method_exists ( $ table , 'searchConfiguration' ) ) { $ searchManager = $ table -> searchConfiguration ( ) ; } else { $ searchManager = $ table -> searchManager ( ) ; } $ fields = [ ] ; $ schema = $ table -> getSchema ( ) ; $ request = $ this -> _request ( ) ; foreach ( $ searchManager -> getFilters ( $ config [ 'collection' ] ) as $ filter ) { if ( $ filter -> getConfig ( 'form' ) === false ) { continue ; } $ field = $ filter -> name ( ) ; $ input = [ 'required' => false , 'type' => 'text' ] ; if ( substr ( $ field , - 3 ) === '_id' && $ field !== '_id' ) { $ input [ 'type' ] = 'select' ; } $ filterFormConfig = $ filter -> getConfig ( 'form' ) ; if ( ! empty ( $ filterFormConfig ) ) { $ input = $ filterFormConfig + $ input ; } $ input [ 'value' ] = $ request -> getQuery ( $ field ) ; if ( empty ( $ input [ 'options' ] ) && $ schema -> getColumnType ( $ field ) === 'boolean' ) { $ input [ 'options' ] = [ 'No' , 'Yes' ] ; $ input [ 'type' ] = 'select' ; } if ( ! empty ( $ input [ 'options' ] ) ) { $ input [ 'empty' ] = true ; if ( empty ( $ input [ 'class' ] ) && ! $ config [ 'selectize' ] ) { $ input [ 'class' ] = 'no-selectize' ; } $ fields [ $ field ] = $ input ; continue ; } if ( empty ( $ input [ 'class' ] ) && $ config [ 'autocomplete' ] ) { $ input [ 'class' ] = 'autocomplete' ; } $ urlArgs = [ ] ; $ fieldKeys = isset ( $ input [ 'fields' ] ) ? $ input [ 'fields' ] : [ 'id' => $ field , 'value' => $ field ] ; if ( is_array ( $ fieldKeys ) ) { foreach ( $ fieldKeys as $ key => $ val ) { $ urlArgs [ $ key ] = $ val ; } } unset ( $ input [ 'fields' ] ) ; $ url = array_merge ( [ 'action' => 'lookup' , '_ext' => 'json' ] , $ urlArgs ) ; $ input [ 'data-url' ] = Router :: url ( $ url ) ; $ fields [ $ field ] = $ input ; } return $ fields ; } | Derive field options for search filter inputs based on filter collection . |
49,567 | public function getColumnChildren ( $ column ) { $ children = $ this -> get ( 'children' ) ; if ( isset ( $ children [ $ column ] ) ) { return $ children [ $ column ] ; } return [ ] ; } | Returns the children from a given column |
49,568 | public function addToColumn ( Cell $ module , $ column = 1 ) { $ children = $ this -> get ( 'children' ) ; $ children [ $ column ] [ ] = $ module ; $ this -> set ( 'children' , $ children ) ; return $ this ; } | Adds a Cell to a given column |
49,569 | protected function _setColumns ( $ value ) { $ columnMap = [ 1 => 12 , 2 => 6 , 3 => 4 , 4 => 3 , 6 => 2 , 12 => 1 , ] ; if ( ! in_array ( $ value , [ 1 , 2 , 3 , 4 , 6 , 12 ] ) ) { throw new InvalidArgumentException ( 'Valid columns value must be one of [1, 2, 3, 4, 6, 12]' ) ; } $ this -> set ( 'columnClass' , sprintf ( 'col-md-%d' , $ columnMap [ $ value ] ) ) ; return $ value ; } | columns property setter |
49,570 | public function toPsrRequest ( ) : RequestInterface { return new Psr7Request ( $ this -> method , $ this -> getUri ( ) , $ this -> Headers -> toPsr7Array ( ) , isset ( $ this -> body ) ? new Psr7Stream ( $ this -> body ) : null ) ; } | Constructs a Psr7 compliant request for use in a Psr7 client . |
49,571 | protected function _getUtilityNavigation ( ) { $ action = $ this -> _action ( ) ; $ utilityNavigation = $ action -> getConfig ( 'scaffold.utility_navigation' ) ; if ( $ utilityNavigation === null ) { $ utilityNavigation = [ new MenuItem ( 'Account' , [ 'controller' => 'Users' , 'action' => 'account' ] ) , new MenuItem ( 'Log Out' , [ 'controller' => 'Users' , 'action' => 'logout' ] ) , ] ; } return $ utilityNavigation ; } | Returns the utility navigation to show on scaffolded view |
49,572 | protected function _getFormSubmitExtraButtons ( ) { $ action = $ this -> _action ( ) ; $ buttons = $ action -> getConfig ( 'scaffold.form_submit_extra_buttons' ) ; if ( $ buttons === false ) { return [ ] ; } if ( $ buttons === null || $ buttons === true ) { $ buttons = $ this -> _getDefaultExtraButtons ( ) ; } return $ buttons ; } | Get extra form submit buttons . |
49,573 | protected function _getFormSubmitExtraLeftButtons ( ) { $ action = $ this -> _action ( ) ; $ buttons = $ action -> getConfig ( 'scaffold.form_submit_extra_left_buttons' ) ; if ( $ buttons === false ) { return [ ] ; } if ( $ buttons === null || $ buttons === true ) { $ buttons = $ this -> _getDefaultExtraLeftButtons ( ) ; } return $ buttons ; } | Get extra form submit left buttons . |
49,574 | protected function _getDefaultExtraLeftButtons ( ) { $ buttons = [ ] ; $ action = $ this -> _action ( ) ; if ( $ action instanceof EditAction ) { $ buttons [ ] = [ 'title' => __d ( 'crud' , 'Delete' ) , 'url' => [ 'action' => 'delete' ] , 'options' => [ 'block' => 'form.after_end' , 'class' => 'btn btn-danger btn-delete' , 'confirm' => __d ( 'crud' , 'Are you sure you want to delete this record?' ) , 'name' => '_delete' , 'style' => 'margin-left: 0' , ] , 'type' => 'postLink' , '_label' => 'delete' , ] ; } return $ buttons ; } | Get default extra left buttons |
49,575 | public function ServiceRegister ( AgentServiceRegistration $ agentServiceRegistration ) { $ r = new Request ( 'PUT' , 'v1/agent/service/register' , $ this -> config , $ agentServiceRegistration ) ; return $ this -> requireOK ( $ this -> doRequest ( $ r ) ) [ 2 ] ; } | Register a service within Consul |
49,576 | public function ServiceDeregister ( string $ serviceID ) { $ r = new Request ( 'PUT' , sprintf ( 'v1/agent/service/deregister/%s' , $ serviceID ) , $ this -> config ) ; return $ this -> requireOK ( $ this -> doRequest ( $ r ) ) [ 2 ] ; } | Remove a service from Consul |
49,577 | protected function _getSiteTitle ( ) { $ action = $ this -> _action ( ) ; $ title = $ action -> getConfig ( 'scaffold.site_title' ) ; if ( ! empty ( $ title ) ) { return $ title ; } return Configure :: read ( 'CrudView.siteTitle' ) ; } | Get the brand name to use in the default template . |
49,578 | protected function _getSiteTitleLink ( ) { $ action = $ this -> _action ( ) ; $ link = $ action -> getConfig ( 'scaffold.site_title_link' ) ; if ( empty ( $ link ) ) { $ link = '' ; } return $ link ; } | Returns the sites title link to show on scaffolded view |
49,579 | protected function _getSiteTitleImage ( ) { $ action = $ this -> _action ( ) ; $ image = $ action -> getConfig ( 'scaffold.site_title_image' ) ; if ( empty ( $ image ) ) { $ image = '' ; } return $ image ; } | Returns the sites title image to show on scaffolded view |
49,580 | public function process ( $ field , EntityInterface $ data , array $ options = [ ] ) { $ this -> setContext ( $ data ) ; $ value = $ this -> fieldValue ( $ data , $ field ) ; $ options += [ 'formatter' => null ] ; if ( $ options [ 'formatter' ] === 'element' ) { $ context = $ this -> getContext ( ) ; return $ this -> _View -> element ( $ options [ 'element' ] , compact ( 'context' , 'field' , 'value' , 'options' ) ) ; } if ( $ options [ 'formatter' ] === 'relation' ) { $ relation = $ this -> relation ( $ field ) ; if ( $ relation ) { return $ relation [ 'output' ] ; } } if ( is_callable ( $ options [ 'formatter' ] ) ) { return $ options [ 'formatter' ] ( $ field , $ value , $ this -> getContext ( ) , $ options , $ this -> getView ( ) ) ; } $ value = $ this -> introspect ( $ field , $ value , $ options ) ; return $ value ; } | Process a single field into an output |
49,581 | public function fieldValue ( EntityInterface $ data , $ field ) { if ( empty ( $ data ) ) { $ data = $ this -> getContext ( ) ; } return $ data -> get ( $ field ) ; } | Get the current field value |
49,582 | public function introspect ( $ field , $ value , array $ options = [ ] ) { $ output = $ this -> relation ( $ field ) ; if ( $ output ) { return $ output [ 'output' ] ; } $ type = $ this -> columnType ( $ field ) ; $ fieldFormatters = $ this -> getConfig ( 'fieldFormatters' ) ; if ( isset ( $ fieldFormatters [ $ type ] ) ) { if ( is_callable ( $ fieldFormatters [ $ type ] ) ) { return $ fieldFormatters [ $ type ] ( $ field , $ value , $ this -> getContext ( ) , $ options , $ this -> getView ( ) ) ; } return $ this -> { $ fieldFormatters [ $ type ] } ( $ field , $ value , $ options ) ; } if ( $ type === 'boolean' ) { return $ this -> formatBoolean ( $ field , $ value , $ options ) ; } if ( in_array ( $ type , [ 'datetime' , 'date' , 'timestamp' ] ) ) { return $ this -> formatDate ( $ field , $ value , $ options ) ; } if ( $ type === 'time' ) { return $ this -> formatTime ( $ field , $ value , $ options ) ; } $ value = $ this -> formatString ( $ field , $ value ) ; if ( $ field === $ this -> getViewVar ( 'displayField' ) ) { return $ this -> formatDisplayField ( $ value , $ options ) ; } return $ value ; } | Returns a formatted output for a given field |
49,583 | public function formatBoolean ( $ field , $ value , $ options ) { return ( bool ) $ value ? $ this -> Html -> label ( __d ( 'crud' , 'Yes' ) , [ 'type' => empty ( $ options [ 'inverted' ] ) ? 'success' : 'danger' ] ) : $ this -> Html -> label ( __d ( 'crud' , 'No' ) , [ 'type' => empty ( $ options [ 'inverted' ] ) ? 'danger' : 'success' ] ) ; } | Format a boolean value for display |
49,584 | public function formatDate ( $ field , $ value , array $ options ) { if ( $ value === null ) { return $ this -> Html -> label ( __d ( 'crud' , 'N/A' ) , [ 'type' => 'info' ] ) ; } if ( is_int ( $ value ) || is_string ( $ value ) || $ value instanceof DateTime || $ value instanceof DateTimeImmutable ) { return $ this -> Time -> timeAgoInWords ( $ value , $ options ) ; } return $ this -> Html -> label ( __d ( 'crud' , 'N/A' ) , [ 'type' => 'info' ] ) ; } | Format a date for display |
49,585 | public function formatTime ( $ field , $ value , array $ options ) { if ( $ value === null ) { return $ this -> Html -> label ( __d ( 'crud' , 'N/A' ) , [ 'type' => 'info' ] ) ; } $ format = isset ( $ options [ 'format' ] ) ? $ options [ 'format' ] : null ; if ( is_int ( $ value ) || is_string ( $ value ) || $ value instanceof DateTime || $ value instanceof DateTimeImmutable ) { return $ this -> Time -> nice ( $ value , $ format ) ; } return $ this -> Html -> label ( __d ( 'crud' , 'N/A' ) , [ 'type' => 'info' ] ) ; } | Format a time for display |
49,586 | public function relation ( $ field ) { $ associations = $ this -> associations ( ) ; if ( empty ( $ associations [ 'manyToOne' ] ) ) { return false ; } $ data = $ this -> getContext ( ) ; if ( empty ( $ data ) ) { return false ; } foreach ( $ associations [ 'manyToOne' ] as $ alias => $ details ) { if ( $ field !== $ details [ 'foreignKey' ] ) { continue ; } $ entityName = $ details [ 'entity' ] ; if ( empty ( $ data -> $ entityName ) ) { return false ; } $ entity = $ data -> $ entityName ; return [ 'alias' => $ alias , 'output' => $ this -> Html -> link ( $ entity -> { $ details [ 'displayField' ] } , [ 'plugin' => $ details [ 'plugin' ] , 'controller' => $ details [ 'controller' ] , 'action' => 'view' , $ entity -> { $ details [ 'primaryKey' ] } ] ) ] ; } return false ; } | Returns a formatted relation output for a given field |
49,587 | public function redirectUrl ( ) { $ redirectUrl = $ this -> getView ( ) -> getRequest ( ) -> getQuery ( '_redirect_url' ) ; $ redirectUrlViewVar = $ this -> getViewVar ( '_redirect_url' ) ; if ( ! empty ( $ redirectUrlViewVar ) ) { $ redirectUrl = $ redirectUrlViewVar ; } else { $ context = $ this -> Form -> context ( ) ; if ( $ context -> val ( '_redirect_url' ) ) { $ redirectUrl = $ context -> val ( '_redirect_url' ) ; } } if ( empty ( $ redirectUrl ) ) { return null ; } return $ this -> Form -> hidden ( '_redirect_url' , [ 'name' => '_redirect_url' , 'value' => $ redirectUrl , 'id' => null , 'secure' => FormHelper :: SECURE_SKIP ] ) ; } | Returns a hidden input for the redirect_url if it exists in the request querystring view variables form data |
49,588 | public function createRelationLink ( $ alias , $ relation , $ options = [ ] ) { return $ this -> Html -> link ( __d ( 'crud' , 'Add {0}' , [ Inflector :: singularize ( Inflector :: humanize ( Inflector :: underscore ( $ alias ) ) ) ] ) , [ 'plugin' => $ relation [ 'plugin' ] , 'controller' => $ relation [ 'controller' ] , 'action' => 'add' , '?' => [ $ relation [ 'foreignKey' ] => $ this -> getViewVar ( 'primaryKeyValue' ) , '_redirect_url' => $ this -> getView ( ) -> getRequest ( ) -> getUri ( ) -> getPath ( ) ] ] , $ options ) ; } | Create relation link . |
49,589 | public function createViewLink ( $ title , $ options = [ ] ) { return $ this -> Html -> link ( $ title , [ 'action' => 'view' , $ this -> getContext ( ) -> get ( $ this -> getViewVar ( 'primaryKey' ) ) ] , $ options ) ; } | Create view link . |
49,590 | public function getCssClasses ( ) { $ action = ( string ) $ this -> getView ( ) -> getRequest ( ) -> getParam ( 'action' ) ; $ pluralVar = $ this -> getViewVar ( 'pluralVar' ) ; $ viewClasses = ( array ) $ this -> getViewVar ( 'viewClasses' ) ; $ args = func_get_args ( ) ; return implode ( array_unique ( array_merge ( [ 'scaffold-action' , sprintf ( 'scaffold-action-%s' , $ action ) , sprintf ( 'scaffold-controller-%s' , $ pluralVar ) , sprintf ( 'scaffold-%s-%s' , $ pluralVar , $ action ) , ] , $ args , $ viewClasses ) ) , ' ' ) ; } | Get css classes |
49,591 | public function display ( $ tables = null , $ blacklist = null ) { if ( empty ( $ tables ) ) { $ connection = ConnectionManager :: get ( 'default' ) ; $ schema = $ connection -> getSchemaCollection ( ) ; $ tables = $ schema -> listTables ( ) ; ksort ( $ tables ) ; if ( ! empty ( $ blacklist ) ) { $ tables = array_diff ( $ tables , $ blacklist ) ; } } $ normal = [ ] ; foreach ( $ tables as $ table => $ config ) { if ( is_string ( $ config ) ) { $ config = [ 'table' => $ config ] ; } if ( is_int ( $ table ) ) { $ table = $ config [ 'table' ] ; } $ config += [ 'action' => 'index' , 'title' => Inflector :: humanize ( $ table ) , 'controller' => Inflector :: camelize ( $ table ) ] ; $ normal [ $ table ] = $ config ; } return $ this -> set ( 'tables' , $ normal ) ; } | Default cell method . |
49,592 | public function setFlash ( Event $ event ) { unset ( $ event -> getSubject ( ) -> params [ 'class' ] ) ; $ event -> getSubject ( ) -> element = ltrim ( $ event -> getSubject ( ) -> type ) ; } | Make sure flash messages are properly handled by BootstrapUI . FlashHelper |
49,593 | protected function _getPageTitle ( ) { $ action = $ this -> _action ( ) ; $ title = $ action -> getConfig ( 'scaffold.page_title' ) ; if ( ! empty ( $ title ) ) { return $ title ; } $ scope = $ action -> getConfig ( 'scope' ) ; $ request = $ this -> _request ( ) ; $ actionName = Inflector :: humanize ( Inflector :: underscore ( $ request -> getParam ( 'action' ) ) ) ; $ controllerName = $ this -> _controllerName ( ) ; if ( $ scope === 'table' ) { if ( $ actionName === 'Index' ) { return $ controllerName ; } return sprintf ( '%s %s' , $ controllerName , $ actionName ) ; } $ primaryKeyValue = $ this -> _primaryKeyValue ( ) ; if ( $ primaryKeyValue === null ) { return sprintf ( '%s %s' , $ actionName , $ controllerName ) ; } $ displayFieldValue = $ this -> _displayFieldValue ( ) ; if ( $ displayFieldValue === null || $ this -> _table ( ) -> getDisplayField ( ) == $ this -> _table ( ) -> getPrimaryKey ( ) ) { return sprintf ( '%s %s #%s' , $ actionName , $ controllerName , $ primaryKeyValue ) ; } return sprintf ( '%s %s #%s: %s' , $ actionName , $ controllerName , $ primaryKeyValue , $ displayFieldValue ) ; } | Returns the sites title to show on scaffolded view |
49,594 | protected function _getRelatedModels ( $ associationTypes = [ ] ) { $ models = $ this -> _action ( ) -> getConfig ( 'scaffold.relations' ) ; if ( $ models === false ) { return [ ] ; } if ( empty ( $ models ) ) { $ associations = [ ] ; if ( empty ( $ associationTypes ) ) { $ associations = $ this -> _table ( ) -> associations ( ) ; } else { foreach ( $ associationTypes as $ assocType ) { $ associations = array_merge ( $ associations , $ this -> _table ( ) -> associations ( ) -> getByType ( $ assocType ) ) ; } } $ models = [ ] ; foreach ( $ associations as $ assoc ) { $ models [ ] = $ assoc -> getName ( ) ; } } $ models = Hash :: normalize ( $ models ) ; $ blacklist = $ this -> _action ( ) -> getConfig ( 'scaffold.relations_blacklist' ) ; if ( ! empty ( $ blacklist ) ) { $ blacklist = Hash :: normalize ( $ blacklist ) ; $ models = array_diff_key ( $ models , $ blacklist ) ; } foreach ( $ models as $ key => $ value ) { if ( ! is_array ( $ value ) ) { $ models [ $ key ] = [ ] ; } } return $ models ; } | Get a list of relevant models to contain using Containable |
49,595 | protected function _getPageVariables ( ) { $ table = $ this -> _table ( ) ; $ controller = $ this -> _controller ( ) ; $ scope = $ this -> _action ( ) -> getConfig ( 'scope' ) ; $ data = [ 'modelClass' => $ controller -> modelClass , 'singularHumanName' => Inflector :: humanize ( Inflector :: underscore ( Inflector :: singularize ( $ controller -> modelClass ) ) ) , 'pluralHumanName' => Inflector :: humanize ( Inflector :: underscore ( $ controller -> getName ( ) ) ) , 'singularVar' => Inflector :: singularize ( $ controller -> getName ( ) ) , 'pluralVar' => Inflector :: variable ( $ controller -> getName ( ) ) , ] ; try { $ data += [ 'modelSchema' => $ table -> getSchema ( ) , 'displayField' => $ table -> getDisplayField ( ) , 'primaryKey' => $ table -> getPrimaryKey ( ) , ] ; } catch ( Exception $ e ) { } if ( $ scope === 'entity' ) { $ data += [ 'primaryKeyValue' => $ this -> _primaryKeyValue ( ) ] ; } return $ data ; } | Publish fairly static variables needed in the view |
49,596 | protected function _scaffoldFields ( array $ associations = [ ] ) { $ action = $ this -> _action ( ) ; $ scaffoldFields = ( array ) $ action -> getConfig ( 'scaffold.fields' ) ; if ( ! empty ( $ scaffoldFields ) ) { $ scaffoldFields = Hash :: normalize ( $ scaffoldFields ) ; } if ( empty ( $ scaffoldFields ) || $ action -> getConfig ( 'scaffold.autoFields' ) ) { $ cols = $ this -> _table ( ) -> getSchema ( ) -> columns ( ) ; $ cols = Hash :: normalize ( $ cols ) ; $ scope = $ action -> getConfig ( 'scope' ) ; if ( $ scope === 'entity' && ! empty ( $ associations [ 'manyToMany' ] ) ) { foreach ( $ associations [ 'manyToMany' ] as $ alias => $ options ) { $ cols [ sprintf ( '%s._ids' , $ options [ 'entities' ] ) ] = [ 'multiple' => true ] ; } } $ scaffoldFields = array_merge ( $ cols , $ scaffoldFields ) ; } $ blacklist = $ action -> getConfig ( 'scaffold.fields_blacklist' ) ; if ( ! empty ( $ blacklist ) ) { $ scaffoldFields = array_diff_key ( $ scaffoldFields , array_combine ( $ blacklist , $ blacklist ) ) ; } foreach ( $ scaffoldFields as $ field => $ options ) { if ( ! is_array ( $ options ) ) { $ scaffoldFields [ $ field ] = ( array ) $ options ; } $ scaffoldFields [ $ field ] += [ 'formatter' => null ] ; } $ fieldSettings = $ action -> getConfig ( 'scaffold.field_settings' ) ; if ( empty ( $ fieldSettings ) ) { $ fieldSettings = [ ] ; } $ fieldSettings = array_intersect_key ( $ fieldSettings , $ scaffoldFields ) ; $ scaffoldFields = Hash :: merge ( $ scaffoldFields , $ fieldSettings ) ; return $ scaffoldFields ; } | Returns fields to be displayed on scaffolded template |
49,597 | protected function _controllerName ( ) { $ inflections = [ 'underscore' , 'humanize' , ] ; if ( $ this -> _action ( ) -> scope ( ) === 'entity' ) { $ inflections [ ] = 'singularize' ; } $ baseName = $ this -> _controller ( ) -> getName ( ) ; foreach ( $ inflections as $ inflection ) { $ baseName = Inflector :: $ inflection ( $ baseName ) ; } return $ baseName ; } | Get the controller name based on the Crud Action scope |
49,598 | protected function _getControllerActions ( ) { $ table = $ entity = [ ] ; $ actions = $ this -> _getAllowedActions ( ) ; foreach ( $ actions as $ actionName => $ config ) { list ( $ scope , $ actionConfig ) = $ this -> _getControllerActionConfiguration ( $ actionName , $ config ) ; $ { $ scope } [ $ actionName ] = $ actionConfig ; } $ actionBlacklist = [ ] ; $ groups = $ this -> _action ( ) -> getConfig ( 'scaffold.action_groups' ) ? : [ ] ; foreach ( $ groups as $ group ) { $ group = Hash :: normalize ( $ group ) ; foreach ( $ group as $ actionName => $ config ) { if ( isset ( $ table [ $ actionName ] ) || isset ( $ entity [ $ actionName ] ) ) { continue ; } if ( $ config === null ) { $ config = [ ] ; } list ( $ scope , $ actionConfig ) = $ this -> _getControllerActionConfiguration ( $ actionName , $ config ) ; $ realAction = Hash :: get ( $ actionConfig , 'url.action' , $ actionName ) ; if ( ! isset ( $ { $ scope } [ $ realAction ] ) ) { continue ; } $ actionBlacklist [ ] = $ realAction ; $ { $ scope } [ $ actionName ] = $ actionConfig ; } } foreach ( $ actionBlacklist as $ actionName ) { unset ( $ table [ $ actionName ] ) ; unset ( $ entity [ $ actionName ] ) ; } return compact ( 'table' , 'entity' ) ; } | Returns groupings of action types on the scaffolded view Includes derived actions from scaffold . action_groups |
49,599 | protected function _getControllerActionConfiguration ( $ actionName , $ config ) { $ realAction = Hash :: get ( $ config , 'url.action' , $ actionName ) ; if ( $ this -> _crud ( ) -> isActionMapped ( $ realAction ) ) { $ action = $ this -> _action ( $ realAction ) ; $ class = get_class ( $ action ) ; $ class = substr ( $ class , strrpos ( $ class , '\\' ) + 1 ) ; if ( $ class === 'DeleteAction' ) { $ config += [ 'method' => 'DELETE' ] ; } if ( ! isset ( $ config [ 'scope' ] ) ) { $ config [ 'scope' ] = $ class === 'AddAction' ? 'table' : $ action -> scope ( ) ; } } $ scope = isset ( $ config [ 'scope' ] ) ? $ config [ 'scope' ] : 'entity' ; $ method = isset ( $ config [ 'method' ] ) ? $ config [ 'method' ] : 'GET' ; $ title = ! empty ( $ config [ 'link_title' ] ) ? $ config [ 'link_title' ] : Inflector :: humanize ( Inflector :: underscore ( $ actionName ) ) ; $ url = [ 'action' => $ realAction ] ; if ( isset ( $ config [ 'url' ] ) ) { $ url = $ config [ 'url' ] + $ url ; } $ actionConfig = [ 'title' => $ title , 'url' => $ url , 'method' => $ method , 'options' => array_diff_key ( $ config , array_flip ( [ 'method' , 'scope' , 'link_title' , 'url' , 'scaffold' , 'callback' ] ) ) ] ; if ( ! empty ( $ config [ 'callback' ] ) ) { $ actionConfig [ 'callback' ] = $ config [ 'callback' ] ; } return [ $ scope , $ actionConfig ] ; } | Returns url action configuration for a given action . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.