idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
9,600 | public function addJSAction ( $ action ) { if ( is_array ( $ action ) ) { $ this -> jsActions = array_merge ( $ action , $ this -> jsActions ) ; } else { $ this -> jsActions [ ] = $ action ; } } | Add a js action to be return to server on callback . |
9,601 | public function onDelete ( $ fx = null ) { if ( is_callable ( $ fx ) ) { $ this -> hasDeleteCb = true ; if ( $ this -> cb -> triggered ( ) && @ $ _POST [ 'action' ] === 'delete' ) { $ fileName = @ $ _POST [ 'f_name' ] ; $ this -> cb -> set ( function ( ) use ( $ fx , $ fileName ) { $ this -> addJsAction ( call_user_func_array ( $ fx , [ $ fileName ] ) ) ; return $ this -> jsActions ; } ) ; } } } | onDelete callback . Call when user is removing an already upload file . |
9,602 | public function onUpload ( $ fx = null ) { if ( is_callable ( $ fx ) ) { $ this -> hasUploadCb = true ; if ( $ this -> cb -> triggered ( ) ) { $ action = @ $ _POST [ 'action' ] ; if ( $ files = @ $ _FILES ) { $ this -> fileId = $ files [ 'file' ] [ 'name' ] ; $ this -> setInput ( $ this -> fileId ) ; } if ( $ action === 'upload' && ! $ files [ 'file' ] [ 'error' ] ) { $ this -> cb -> set ( function ( ) use ( $ fx , $ files ) { $ this -> addJsAction ( call_user_func_array ( $ fx , $ files ) ) ; $ this -> addJsAction ( [ $ this -> js ( ) -> atkFileUpload ( 'updateField' , [ $ this -> fileId , $ this -> getInputValue ( ) ] ) , ] ) ; return $ this -> jsActions ; } ) ; } elseif ( $ action === null || isset ( $ files [ 'file' ] [ 'error' ] ) ) { $ this -> cb -> set ( function ( ) use ( $ fx , $ files ) { return call_user_func ( $ fx , 'error' ) ; } ) ; } } } } | onUpload callback . Call when user is uploading a file . |
9,603 | public function renderView ( ) { if ( $ this -> disabled ) { $ this -> addClass ( 'disabled' ) ; } parent :: renderView ( ) ; if ( ! $ this -> hasUploadCb || ! $ this -> hasDeleteCb ) { throw new Exception ( 'onUpload and onDelete callback must be called to use file upload' ) ; } if ( ! empty ( $ this -> accept ) ) { $ this -> template -> trySet ( 'accept' , implode ( ',' , $ this -> accept ) ) ; } if ( $ this -> multiple ) { } if ( $ this -> placeholder ) { $ this -> template -> trySet ( 'PlaceHolder' , $ this -> placeholder ) ; } $ this -> js ( true ) -> atkFileUpload ( [ 'uri' => $ this -> cb -> getJSURL ( ) , 'action' => $ this -> action -> name , 'file' => [ 'id' => $ this -> fileId ? : $ this -> field -> get ( ) , 'name' => $ this -> getInputValue ( ) ] , 'hasFocus' => $ this -> hasFocusEnable , 'submit' => ( $ this -> form -> buttonSave ) ? $ this -> form -> buttonSave -> name : null , ] ) ; } | Rendering view . |
9,604 | public function addFilter ( $ field , $ label = null ) { if ( ! $ this -> model -> hasElement ( $ field ) instanceof \ atk4 \ data \ Field ) { throw new \ atk4 \ ui \ Exception ( [ 'Unable to filter by non-existant field' , 'field' => $ field , ] ) ; } $ this -> filters [ ] = [ 'field' => $ field , 'label' => $ label ] ; } | Add filter dropdown . |
9,605 | public function applyFilters ( ) { if ( $ this -> filters ) { foreach ( $ this -> filters as $ k => $ filter ) { if ( isset ( $ _GET [ $ filter [ 'field' ] ] ) && ! empty ( $ _GET [ $ filter [ 'field' ] ] ) && $ _GET [ $ filter [ 'field' ] ] != $ this -> filterEmpty && @ $ _GET [ 'filter' ] != $ filter [ 'field' ] ) { $ this -> model -> addCondition ( $ filter [ 'field' ] , $ _GET [ $ filter [ 'field' ] ] ) ; } } } } | Check if filtering is need . |
9,606 | public function renderFilters ( ) { if ( isset ( $ _GET [ 'filter' ] ) ) { if ( isset ( $ _GET [ 'q' ] ) ) { $ this -> model -> addCondition ( $ _GET [ 'filter' ] , 'like' , '%' . $ _GET [ 'q' ] . '%' ) ; } $ this -> applyFilters ( ) ; $ action = $ this -> model -> action ( 'field' , [ $ _GET [ 'filter' ] ] ) ; $ action -> group ( $ _GET [ 'filter' ] ) ; $ rows = $ action -> get ( ) ; $ data = [ ] ; foreach ( $ rows as $ k => $ v ) { $ data [ ] = [ 'id' => $ k , 'name' => $ v [ $ _GET [ 'filter' ] ] ] ; } array_unshift ( $ data , [ 'id' => - 1 , 'name' => $ this -> filterEmpty ] ) ; $ this -> app -> terminate ( json_encode ( [ 'success' => true , 'results' => $ data , ] ) ) ; } } | Check if filtering is needed and terminate app execution . |
9,607 | public function createFilterJsDropdown ( ) { foreach ( $ this -> filters as $ k => $ filter ) { $ f_name = $ this -> name . '-ac_f' . $ k ; $ chain = new jQuery ( '#' . $ f_name ) ; $ options = [ 'fields' => [ 'name' => 'name' , 'value' => 'id' ] , 'match' => 'value' , 'apiSettings' => [ 'url' => $ this -> getCallbackURL ( ) . '&q={query}' , 'cache' => false , 'data' => array_merge ( $ this -> getFilterQuery ( ) , [ 'filter' => $ filter [ 'field' ] ] ) , 'onResponse' => new jsFunction ( [ 'resp' ] , [ new jsExpression ( 'if (!resp.success){atk.apiService.atkSuccessTest(resp);}' ) , ] ) , ] , 'onChange' => new jsFunction ( [ ( new jQuery ( ) ) -> trigger ( 'filterChanged' ) , $ this -> getJsDropdown ( ) , ] ) , ] ; $ this -> js ( true , $ chain -> dropdown ( $ options ) ) ; } $ options [ 'apiSettings' ] [ 'data' ] [ 'filter' ] = ( new jQuery ( ) ) -> find ( 'input' ) -> attr ( 'name' ) ; $ this -> filterChain = $ options ; } | For each filters we need to create js dropdown and setup proper api settings . |
9,608 | public function getFilterQuery ( ) { $ q = [ ] ; foreach ( $ this -> filters as $ key => $ filter ) { $ q [ $ filter [ 'field' ] ] = new jsExpression ( '$([input]).parent().dropdown("get text")' , [ 'input' => 'input[name=' . $ filter [ 'field' ] . ']' ] ) ; } return $ q ; } | Will create jsExpression need to add to the dropdown apiSettings data when using filters . |
9,609 | public function addGroup ( $ label = null ) { if ( ! is_array ( $ label ) ) { $ label = [ 'label' => $ label ] ; } elseif ( isset ( $ label [ 0 ] ) ) { $ label [ 'label' ] = $ label [ 0 ] ; unset ( $ label [ 0 ] ) ; } $ label [ 'form' ] = $ this -> form ; return $ this -> add ( new static ( $ label ) ) ; } | Adds field group in form layout . |
9,610 | public function addSubLayout ( $ seed = 'Generic' , $ addDivider = true ) { $ v = $ this -> add ( $ this -> factory ( $ seed , [ 'form' => $ this -> form ] , 'FormLayout/Section' ) ) ; if ( $ v instanceof \ atk4 \ ui \ FormLayout \ Section \ Generic ) { $ v = $ v -> addSection ( ) ; } if ( $ addDivider ) { $ this -> add ( [ 'ui' => 'hidden divider' ] ) ; } return $ v ; } | Add a form layout section to this layout . |
9,611 | public function set ( $ value = null , $ junk = null ) { if ( $ this -> field ) { $ this -> field -> set ( $ value ) ; return $ this ; } $ this -> content = $ value ; return $ this ; } | Sets the value of this field . If field is a part of the form and is associated with the model then the model s value will also be affected . |
9,612 | public function renderView ( ) { if ( $ this -> form ) { $ this -> template -> trySet ( 'name' , $ this -> short_name ) ; } parent :: renderView ( ) ; } | It only makes sense to have name property inside a field if it was used inside a form . |
9,613 | public function getURL ( $ mode = 'callback' ) { return $ this -> owner -> url ( [ $ this -> urlTrigger => $ mode , '__atk_callback' => 1 ] , ( bool ) $ this -> postTrigger ) ; } | Return URL that will trigger action on this call - back . If you intend to request the URL loading from inside JavaScript it s always advised to use getJSURL instead . |
9,614 | public function addStep ( $ name , $ callback ) { $ step = $ this -> factory ( [ 'Step' , 'wizard' => $ this , 'template' => clone $ this -> stepTemplate , 'sequence' => count ( $ this -> steps ) , ] , $ name ) ; $ this -> steps [ ] = $ this -> add ( $ step , 'Step' ) ; if ( ! $ this -> stepCallback -> triggered ( ) ) { $ _GET [ $ this -> stepCallback -> urlTrigger ] = 0 ; } if ( $ step -> sequence == $ this -> currentStep ) { $ step -> addClass ( 'active' ) ; $ this -> stepCallback -> set ( $ callback , [ $ this ] ) ; } elseif ( $ step -> sequence < $ this -> currentStep ) { $ step -> addClass ( 'completed' ) ; } if ( $ step -> icon == null ) { $ step -> icon = $ this -> defaultIcon ; } return $ step ; } | Adds step to the wizard . |
9,615 | public function addFinish ( $ callback ) { if ( count ( $ this -> steps ) == $ this -> currentStep + 1 ) { $ this -> buttonFinish -> link ( $ this -> stepCallback -> getURL ( count ( $ this -> steps ) ) ) ; } elseif ( $ this -> currentStep == count ( $ this -> steps ) ) { $ this -> buttonPrev -> destroy ( ) ; $ this -> buttonNext -> addClass ( 'disabled' ) -> set ( 'Completed' ) ; $ this -> buttonFinish -> destroy ( ) ; $ this -> app -> catch_runaway_callbacks = false ; call_user_func ( $ callback , $ this ) ; } else { $ this -> buttonFinish -> destroy ( ) ; } } | Adds an extra screen to show user when he goes beyond last step . There won t be back button on this step anymore . |
9,616 | public function jsRender ( ) { $ namelessCount = 0 ; $ res = preg_replace_callback ( '/\[[a-z0-9_]*\]|{[a-z0-9_]*}/' , function ( $ matches ) use ( & $ namelessCount ) { $ identifier = substr ( $ matches [ 0 ] , 1 , - 1 ) ; if ( $ identifier === '' ) { $ identifier = $ namelessCount ++ ; } if ( ! isset ( $ this -> args [ $ identifier ] ) ) { throw new Exception ( [ 'Tag not defined in template for jsExpression' , 'tag' => $ identifier , 'template' => $ this -> template , ] ) ; } $ value = $ this -> args [ $ identifier ] ; if ( $ matches [ 0 ] [ 0 ] === '{' ) { return $ value ; } if ( is_object ( $ value ) && $ value instanceof jsExpressionable ) { $ value = '(' . $ value -> jsRender ( ) . ')' ; } elseif ( is_object ( $ value ) ) { $ value = $ this -> _json_encode ( $ value -> toString ( ) ) ; } else { $ value = $ this -> _json_encode ( $ value ) ; } return $ value ; } , $ this -> template ) ; return trim ( $ res ) ; } | Converts this arbitrary JavaScript expression into string . |
9,617 | public function addPopup ( $ popup = null , $ icon = 'caret square down' ) { if ( ! $ this -> app ) { throw new Exception ( 'Columns\'s popup need to have a layout.' ) ; } $ popup = $ this -> app -> add ( $ popup ? $ popup : 'Popup' ) -> setHoverable ( ) ; $ this -> setHeaderPopup ( $ popup , $ icon ) ; return $ popup ; } | Add popup to header . |
9,618 | public function setHeaderPopup ( $ popup , $ icon = 'caret square down' ) { $ this -> hasHeaderAction = true ; $ id = $ this -> name . '_ac' ; $ this -> headerActionTag = [ 'div' , [ 'class' => 'atk-table-dropdown' ] , [ [ 'i' , [ 'id' => $ id , 'class' => $ icon . ' icon' ] ] , ] , ] ; $ popup -> triggerBy = '#' . $ id ; $ popup -> popOptions = array_merge ( $ popup -> popOptions , [ 'on' => 'click' , 'position' => 'bottom right' , 'movePopup' => false ] ) ; $ popup -> stopClickEvent = true ; if ( @ $ _GET [ '__atk_reload' ] ) { $ this -> table -> js ( true , $ popup -> jsPopup ( ) ) ; } } | Setup popup header action . |
9,619 | public function addDropdown ( $ items , $ fx , $ icon = 'caret square down' , $ menuId = null ) { $ menuITems = [ ] ; foreach ( $ items as $ key => $ item ) { if ( is_int ( $ key ) ) { $ menuITems [ ] = [ 'name' => $ item , 'value' => $ item ] ; } else { $ menuITems [ ] = [ 'name' => $ key , 'value' => $ item ] ; } } $ cb = $ this -> setHeaderDropdown ( $ menuITems , $ icon , $ menuId ) ; $ cb -> onSelectItem ( function ( $ menu , $ item ) use ( $ fx ) { return call_user_func ( $ fx , $ item , $ menu ) ; } ) ; } | Add a dropdown header menu . |
9,620 | public function setAttr ( $ attr , $ value , $ position = 'body' ) { $ this -> attr [ $ position ] [ $ attr ] = $ value ; return $ this ; } | Adds a new attribute to the cells of this column . The optional second argument may be head body or foot . If position is not defined then attribute will be applied on all cells . |
9,621 | public function getTag ( $ position , $ value , $ attr = [ ] ) { $ attr = $ this -> getTagAttributes ( $ position , $ attr ) ; if ( isset ( $ attr [ 'class' ] ) ) { $ attr [ 'class' ] = implode ( ' ' , $ attr [ 'class' ] ) ; } return $ this -> app -> getTag ( $ position == 'body' ? 'td' : 'th' , $ attr , $ value ) ; } | Returns a suitable cell tag with the supplied value . Applies modifiers added through addClass and setAttr . |
9,622 | public function getTotalsCellHTML ( \ atk4 \ data \ Field $ f , $ value ) { return $ this -> getTag ( 'foot' , $ this -> app -> ui_persistence -> typecastSaveField ( $ f , $ value ) ) ; } | Return HTML for a total value of a specific field . |
9,623 | public function getValue ( ) { return isset ( $ this -> field ) ? $ this -> app -> ui_persistence -> typecastSaveField ( $ this -> field , $ this -> field -> get ( ) ) : ( isset ( $ this -> content ) ? $ this -> content : '' ) ; } | Returns presentable value to be inserted into input tag . |
9,624 | public function addAction ( $ defaults = [ ] ) { if ( ! is_array ( $ defaults ) ) { $ defaults = [ $ defaults ] ; } $ this -> action = $ this -> add ( new Button ( $ defaults ) , 'AfterInput' ) ; $ this -> addClass ( 'action' ) ; return $ this -> action ; } | Adds new action button . |
9,625 | public function setModel ( \ atk4 \ data \ Model $ model ) { parent :: setModel ( $ model ) ; $ this -> field = $ this -> field ? $ this -> field : $ this -> model -> title_field ; if ( $ this -> autoSave && $ this -> model -> loaded ( ) ) { if ( $ this -> cb -> triggered ( ) ) { $ value = $ _POST [ 'value' ] ? $ _POST [ 'value' ] : null ; $ this -> cb -> set ( function ( ) use ( $ value ) { try { $ this -> model [ $ this -> field ] = $ this -> app -> ui_persistence -> typecastLoadField ( $ this -> model -> getElement ( $ this -> field ) , $ value ) ; $ this -> model -> save ( ) ; return $ this -> jsSuccess ( 'Update successfully' ) ; } catch ( ValidationException $ e ) { $ this -> app -> terminate ( json_encode ( [ 'success' => true , 'hasValidationError' => true , 'atkjs' => $ this -> jsError ( call_user_func ( $ this -> formatErrorMsg , $ e , $ value ) ) -> jsRender ( ) , ] ) ) ; } } ) ; } } return $ this -> model ; } | Set Model of this View . |
9,626 | public function renderView ( ) { parent :: renderView ( ) ; $ type = ( $ this -> model && $ this -> field ) ? $ this -> model -> elements [ $ this -> field ] -> type : 'text' ; $ type = ( $ type === 'string' ) ? 'text' : $ type ; if ( $ type != 'text' && $ type != 'number' ) { throw new Exception ( 'Error: Only string or number field can be edited inline. Field Type = ' . $ type ) ; } if ( $ this -> model && $ this -> model -> loaded ( ) ) { $ initValue = $ this -> model -> get ( $ this -> field ) ; } else { $ initValue = $ this -> initValue ; } $ fieldName = $ this -> field ? $ this -> field : 'name' ; $ this -> template -> set ( 'inputCss' , $ this -> inputCss ) ; $ this -> template -> trySet ( 'fieldName' , $ fieldName ) ; $ this -> template -> trySet ( 'fieldType' , $ type ) ; $ this -> vue ( 'atk-inline-edit' , [ 'initValue' => $ initValue , 'url' => $ this -> cb -> getJSURL ( ) , 'saveOnBlur' => $ this -> saveOnBlur , ] ) ; } | Renders View . |
9,627 | public function setModelCondition ( $ m ) { $ q = $ this -> getQuery ( ) ; if ( $ q && ( $ _GET [ '__atk_reload' ] ? $ _GET [ '__atk_reload' ] : null ) === $ this -> reload -> name ) { $ m -> addCondition ( 'name' , 'like' , '%' . $ q . '%' ) ; } return $ m ; } | Set model condition base on search request . |
9,628 | public function set ( $ fx = [ ] , $ junk = null ) { if ( ! $ fx ) { return $ this ; } if ( $ this -> fx ) { throw new Exception ( [ 'Callback for this Virtual Page is already defined' , 'vp' => $ this , 'old_fx' => $ this -> fx , 'new_fx' => $ fx , ] ) ; } $ this -> fx = $ fx ; return $ this ; } | Set callback function of virtual page . |
9,629 | public function getHTML ( ) { $ this -> cb -> set ( function ( ) { if ( $ type = $ this -> cb -> triggered ( ) ) { if ( $ this -> fx ) { call_user_func ( $ this -> fx , $ this ) ; } if ( $ type == 'popup' ) { $ this -> app -> html -> template -> set ( 'title' , $ this -> app -> title ) ; $ this -> app -> html -> template -> setHTML ( 'Content' , parent :: getHTML ( ) ) ; $ this -> app -> html -> template -> appendHTML ( 'HEAD' , $ this -> getJS ( ) ) ; $ this -> app -> terminate ( $ this -> app -> html -> template -> render ( ) ) ; } if ( isset ( $ _GET [ 'json' ] ) ) { $ this -> app -> terminate ( $ this -> renderJSON ( ) ) ; } if ( $ type != 'callback' ) { $ this -> app -> terminate ( $ this -> render ( ) ) ; } } foreach ( $ this -> app -> layout -> elements as $ key => $ view ) { if ( $ view instanceof View && $ view -> region == 'Content' ) { unset ( $ this -> app -> layout -> elements [ $ key ] ) ; } } $ this -> app -> layout -> template -> setHTML ( 'Content' , parent :: getHTML ( ) ) ; $ this -> app -> layout -> _js_actions = array_merge ( $ this -> app -> layout -> _js_actions , $ this -> _js_actions ) ; $ this -> app -> html -> template -> setHTML ( 'Content' , $ this -> app -> layout -> getHTML ( ) ) ; $ this -> app -> html -> template -> appendHTML ( 'HEAD' , $ this -> app -> layout -> getJS ( ) ) ; $ this -> app -> terminate ( $ this -> app -> html -> template -> render ( ) ) ; } ) ; } | VirtualPage is not rendered normally . It s invisible . Only when it is triggered it will exclusively output it s content . |
9,630 | public function setIpp ( $ ipp , $ label = 'Item per pages:' ) { if ( is_array ( $ ipp ) ) { $ this -> addItemsPerPageSelector ( $ ipp , $ label ) ; if ( @ $ _GET [ 'ipp' ] ) { $ this -> ipp = $ _GET [ 'ipp' ] ; } else { $ this -> ipp = $ ipp [ 0 ] ; } } else { $ this -> ipp = $ ipp ; } } | Set item per page value . |
9,631 | public function addItemsPerPageSelector ( $ items = [ 10 , 25 , 50 , 100 ] , $ label = 'Item per pages:' ) { if ( $ ipp = $ this -> container -> stickyGet ( 'ipp' ) ) { $ this -> ipp = $ ipp ; } else { $ this -> ipp = $ items [ 0 ] ; } $ pageLength = $ this -> paginator -> add ( [ 'ItemsPerPageSelector' , 'pageLengthItems' => $ items , 'label' => $ label , 'currentIpp' => $ this -> ipp ] , 'afterPaginator' ) ; $ this -> paginator -> template -> trySet ( 'PaginatorType' , 'ui grid' ) ; if ( $ sortBy = $ this -> getSortBy ( ) ) { $ pageLength -> stickyGet ( $ this -> name . '_sort' , $ sortBy ) ; } $ pageLength -> onPageLengthSelect ( function ( $ ipp ) use ( $ pageLength ) { $ this -> ipp = $ ipp ; $ this -> setModelLimitFromPaginator ( ) ; if ( $ this -> quickSearch instanceof jsSearch ) { $ this -> container -> js ( true , $ this -> quickSearch -> js ( ) -> atkJsSearch ( 'setUrlArgs' , [ 'ipp' , $ this -> ipp ] ) ) ; } $ this -> applySort ( ) ; return $ this -> container ; } ) ; return $ this ; } | Add ItemsPerPageSelector View in grid menu or paginator in order to dynamically setup number of item per page . |
9,632 | public function addJsPaginator ( $ ipp , $ options = [ ] , $ container = null , $ scrollRegion = 'Body' ) { if ( $ this -> paginator ) { $ this -> paginator -> destroy ( ) ; $ this -> paginator = null ; } if ( $ sortBy = $ this -> getSortBy ( ) ) { $ this -> stickyGet ( $ this -> name . '_sort' , $ sortBy ) ; } $ this -> applySort ( ) ; $ this -> table -> addJsPaginator ( $ ipp , $ options , $ container , $ scrollRegion ) ; return $ this ; } | Add dynamic scrolling paginator . |
9,633 | public function addJsPaginatorInContainer ( $ ipp , $ containerHeight , $ options = [ ] , $ container = null , $ scrollRegion = 'Body' ) { $ this -> table -> hasCollapsingCssActionColumn = false ; $ options = array_merge ( $ options , [ 'hasFixTableHeader' => true , 'tableContainerHeight' => $ containerHeight , ] ) ; $ options = array_merge ( [ 'stateContext' => '#' . $ this -> container -> name ] , $ options ) ; return $ this -> addJsPaginator ( $ ipp , $ options , $ container , $ scrollRegion ) ; } | Add dynamic scrolling paginator in container . Use this to make table headers fixed . |
9,634 | public function addAction ( $ button , $ action , $ confirm = false ) { if ( ! $ this -> actions ) { $ this -> actions = $ this -> table -> addColumn ( null , $ this -> actionDecorator ) ; } return $ this -> actions -> addAction ( $ button , $ action , $ confirm ) ; } | Adds a new button into the action column on the right . For CRUD this column will already contain delete and edit buttons . |
9,635 | public function addFilterColumn ( $ names = null ) { $ this -> menu -> addItem ( [ 'Clear Filters' ] , new \ atk4 \ ui \ jsReload ( $ this -> table -> reload , [ 'atk_clear_filter' => 1 ] ) ) ; $ this -> table -> setFilterColumn ( $ names ) ; return $ this ; } | An array of column name where filter is needed . Leave empty to include all column in grid . |
9,636 | public function addDropdown ( $ columnName , $ items , $ fx , $ icon = 'caret square down' , $ menuId = null ) { $ column = $ this -> table -> columns [ $ columnName ] ; if ( ! isset ( $ column ) ) { throw new Exception ( 'The column where you want to add dropdown does not exist: ' . $ columnName ) ; } if ( ! $ menuId ) { $ menuId = $ columnName ; } $ column -> addDropdown ( $ items , function ( $ item ) use ( $ fx ) { return call_user_func ( $ fx , [ $ item ] ) ; } , $ icon , $ menuId ) ; } | Add a dropdown menu to header column . |
9,637 | public function addPopup ( $ columnName , $ popup = null , $ icon = 'caret square down' ) { $ column = $ this -> table -> columns [ $ columnName ] ; if ( ! isset ( $ column ) ) { throw new Exception ( 'The column where you want to add popup does not exist: ' . $ columnName ) ; } return $ column -> addPopup ( $ popup , $ icon ) ; } | Add a popup to header column . |
9,638 | public function setModel ( \ atk4 \ data \ Model $ model , $ columns = null ) { $ this -> model = $ this -> table -> setModel ( $ model , $ columns ) ; if ( $ this -> quickSearch && is_array ( $ this -> quickSearch ) ) { $ this -> addQuickSearch ( $ this -> quickSearch ) ; } return $ this -> model ; } | Sets data Model of Grid . |
9,639 | public function addSelection ( ) { $ this -> selection = $ this -> table -> addColumn ( null , 'CheckBox' ) ; $ k = array_search ( $ this -> selection , $ this -> table -> columns ) ; $ this -> table -> columns = [ $ k => $ this -> table -> columns [ $ k ] ] + $ this -> table -> columns ; return $ this -> selection ; } | Makes rows of this grid selectable by creating new column on the left with checkboxes . |
9,640 | public function addDragHandler ( ) { $ handler = $ this -> table -> addColumn ( null , 'DragHandler' ) ; array_unshift ( $ this -> table -> columns , array_pop ( $ this -> table -> columns ) ) ; return $ handler ; } | Add column with drag handler on each row . Drag handler allow to reorder table via drag n drop . |
9,641 | private function setModelLimitFromPaginator ( ) { $ this -> paginator -> setTotal ( ceil ( $ this -> model -> action ( 'count' ) -> getOne ( ) / $ this -> ipp ) ) ; $ this -> model -> setLimit ( $ this -> ipp , ( $ this -> paginator -> page - 1 ) * $ this -> ipp ) ; } | Will set model limit according to paginator value . |
9,642 | public function recursiveRender ( ) { if ( $ this -> paginator ) { $ this -> setModelLimitFromPaginator ( ) ; } if ( $ this -> quickSearch instanceof jsSearch ) { if ( $ sortBy = $ this -> getSortBy ( ) ) { $ this -> container -> js ( true , $ this -> quickSearch -> js ( ) -> atkJsSearch ( 'setUrlArgs' , [ $ this -> name . '_sort' , $ sortBy ] ) ) ; } } return parent :: recursiveRender ( ) ; } | Recursively renders view . |
9,643 | public function onPageLengthSelect ( $ fx = null ) { if ( is_callable ( $ fx ) ) { if ( $ this -> cb -> triggered ( ) ) { $ this -> cb -> set ( function ( ) use ( $ fx ) { $ ipp = @ $ _GET [ 'ipp' ] ; $ this -> set ( $ ipp ) ; $ reload = call_user_func ( $ fx , $ ipp ) ; if ( $ reload ) { $ this -> app -> terminate ( $ reload -> renderJSON ( ) ) ; } } ) ; } } } | Run callback when an item is select via dropdown menu . The callback should return a View to be reload after an item has been select . |
9,644 | protected function isJsonRequest ( ) { $ ajax = false ; if ( ! empty ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) && strtolower ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) == 'xmlhttprequest' ) { $ ajax = true ; } return $ ajax && ! isset ( $ _GET [ '__atk_tab' ] ) ; } | Most of the ajax request will require sending exception in json instead of html except for tab . |
9,645 | public function terminate ( $ output = null ) { if ( $ output !== null ) { echo $ output ; } $ this -> run_called = true ; $ this -> callExit ( ) ; } | Will perform a preemptive output and terminate . Do not use this directly instead call it form Callback jsCallback or similar other classes . |
9,646 | public function initLayout ( $ seed ) { $ layout = $ this -> factory ( $ seed , null , 'Layout' ) ; $ layout -> app = $ this ; if ( ! $ this -> html ) { $ this -> html = new View ( [ 'defaultTemplate' => 'html.html' ] ) ; $ this -> html -> app = $ this ; $ this -> html -> init ( ) ; } $ this -> layout = $ this -> html -> add ( $ layout ) ; $ this -> initIncludes ( ) ; return $ this ; } | Initializes layout . |
9,647 | public function initIncludes ( ) { $ url = isset ( $ this -> cdn [ 'jquery' ] ) ? $ this -> cdn [ 'jquery' ] : '../public' ; $ this -> requireJS ( $ url . '/jquery.min.js' ) ; $ url = isset ( $ this -> cdn [ 'semantic-ui' ] ) ? $ this -> cdn [ 'semantic-ui' ] : '../public' ; $ this -> requireJS ( $ url . '/semantic.min.js' ) ; $ this -> requireCSS ( $ url . '/semantic.min.css' ) ; $ url = isset ( $ this -> cdn [ 'serialize-object' ] ) ? $ this -> cdn [ 'serialize-object' ] : '../public' ; $ this -> requireJS ( $ url . '/jquery.serialize-object.min.js' ) ; $ url = isset ( $ this -> cdn [ 'atk' ] ) ? $ this -> cdn [ 'atk' ] : '../public' ; $ this -> requireJS ( $ url . '/atkjs-ui.min.js' ) ; $ this -> requireCSS ( $ url . '/agileui.css' ) ; } | Initialize JS and CSS includes . |
9,648 | public function add ( $ seed , $ region = null ) { if ( ! $ this -> layout ) { throw new Exception ( [ 'If you use $app->add() you should first call $app->setLayout()' ] ) ; } return $ this -> layout -> add ( $ seed , $ region ) ; } | Add a new object into the app . You will need to have Layout first . |
9,649 | public function run ( ) { $ this -> run_called = true ; $ this -> hook ( 'beforeRender' ) ; $ this -> is_rendering = true ; if ( ! isset ( $ this -> html ) ) { throw new Exception ( [ 'App layout should be set.' ] ) ; } $ this -> html -> template -> set ( 'title' , $ this -> title ) ; $ this -> html -> renderAll ( ) ; $ this -> html -> template -> appendHTML ( 'HEAD' , $ this -> html -> getJS ( ) ) ; $ this -> is_rendering = false ; $ this -> hook ( 'beforeOutput' ) ; if ( isset ( $ _GET [ '__atk_callback' ] ) && $ this -> catch_runaway_callbacks ) { $ this -> terminate ( '!! Callback requested, but never reached. You may be missing some arguments in ' . $ _SERVER [ 'REQUEST_URI' ] ) ; } echo $ this -> html -> template -> render ( ) ; } | Runs app and echo rendered template . |
9,650 | public function loadTemplate ( $ name ) { $ template = new Template ( ) ; $ template -> app = $ this ; if ( in_array ( $ name [ 0 ] , [ '.' , '/' , '\\' ] ) || strpos ( $ name , ':\\' ) !== false ) { return $ template -> load ( $ name ) ; } else { $ dir = is_array ( $ this -> template_dir ) ? $ this -> template_dir : [ $ this -> template_dir ] ; foreach ( $ dir as $ td ) { if ( $ t = $ template -> tryLoad ( $ td . '/' . $ name ) ) { return $ t ; } } } throw new Exception ( [ 'Can not find template file' , 'name' => $ name , 'template_dir' => $ this -> template_dir ] ) ; } | Load template by template file name . |
9,651 | public function jsURL ( $ page = [ ] , $ needRequestUri = false , $ extra_args = [ ] ) { return $ this -> url ( $ page , $ needRequestUri , $ extra_args ) ; } | Build a URL that application can use for js call - backs . Some framework integration will use a different routing mechanism for NON - HTML response . |
9,652 | public function url ( $ page = [ ] , $ needRequestUri = false , $ extra_args = [ ] ) { if ( $ needRequestUri ) { return $ _SERVER [ 'REQUEST_URI' ] ; } $ sticky = $ this -> sticky_get_arguments ; $ result = $ extra_args ; if ( $ this -> page === null ) { $ uri = $ this -> getRequestURI ( ) ; if ( substr ( $ uri , - 1 , 1 ) == '/' ) { $ this -> page = 'index' ; } else { $ this -> page = basename ( $ uri , '.php' ) ; } } if ( is_string ( $ page ) ) { return $ page ; } if ( ! isset ( $ page [ 0 ] ) ) { $ page [ 0 ] = $ this -> page ; } if ( is_array ( $ sticky ) && ! empty ( $ sticky ) ) { foreach ( $ sticky as $ key => $ val ) { if ( $ val === true ) { if ( isset ( $ _GET [ $ key ] ) ) { $ val = $ _GET [ $ key ] ; } else { continue ; } } if ( ! isset ( $ result [ $ key ] ) ) { $ result [ $ key ] = $ val ; } } } foreach ( $ page as $ arg => $ val ) { if ( $ arg === 0 ) { continue ; } if ( $ val === null || $ val === false ) { unset ( $ result [ $ arg ] ) ; } else { $ result [ $ arg ] = $ val ; } } $ args = http_build_query ( $ result ) ; $ url = ( $ page [ 0 ] ? $ page [ 0 ] . '.php' : '' ) . ( $ args ? '?' . $ args : '' ) ; return $ url ; } | Build a URL that application can use for loading HTML data . |
9,653 | public function stickyGet ( $ name ) { if ( isset ( $ _GET [ $ name ] ) ) { $ this -> sticky_get_arguments [ $ name ] = $ _GET [ $ name ] ; return $ _GET [ $ name ] ; } } | Make current get argument with specified name automatically appended to all generated URLs . |
9,654 | public function requireJS ( $ url , $ isAsync = false , $ isDefer = false ) { $ this -> html -> template -> appendHTML ( 'HEAD' , $ this -> getTag ( 'script' , [ 'src' => $ url , 'defer' => $ isDefer , 'async' => $ isAsync ] , '' ) . "\n" ) ; return $ this ; } | Adds additional JS script include in aplication template . |
9,655 | public function requireCSS ( $ url ) { $ this -> html -> template -> appendHTML ( 'HEAD' , $ this -> getTag ( 'link/' , [ 'rel' => 'stylesheet' , 'type' => 'text/css' , 'href' => $ url ] ) . "\n" ) ; return $ this ; } | Adds additional CSS stylesheet include in aplication template . |
9,656 | public function redirect ( $ page ) { header ( 'Location: ' . $ this -> url ( $ page ) ) ; $ this -> run_called = true ; $ this -> callExit ( ) ; } | A convenient wrapper for sending user to another page . |
9,657 | public function useSuiVue ( ) { if ( ! $ this -> is_sui_init ) { $ this -> requireJS ( 'https://unpkg.com/semantic-ui-vue/dist/umd/semantic-ui-vue.min.js' ) ; $ this -> layout -> js ( true , ( new jsVueService ( ) ) -> useComponent ( 'SemanticUIVue' ) ) ; $ this -> is_sui_init = true ; } } | Allow to use semantic - ui - vue components . |
9,658 | public function set ( $ callback , $ args = [ ] ) { if ( ! $ this -> app ) { throw new Exception ( [ 'Call-back must be part of a RenderTree' ] ) ; } if ( $ this -> app -> is_rendering ) { return parent :: set ( $ callback , $ args ) ; } $ this -> app -> addHook ( 'beforeRender' , function ( ... $ args ) use ( $ callback ) { array_shift ( $ args ) ; return parent :: set ( $ callback , $ args ) ; } , $ args ) ; } | Executes user - specified action before rendering or if App is already in rendering state then before output . |
9,659 | public function setPath ( $ path ) { if ( ! is_string ( $ path ) ) { $ path = $ this -> app -> url ( $ path ) ; } $ this -> path = $ path . '#' ; return $ this ; } | Sets path for tab . |
9,660 | public function renderView ( ) { if ( $ this -> path ) { $ this -> js ( true ) -> tab ( [ 'cache' => false , 'auto' => true , 'path' => $ this -> path , 'apiSettings' => [ 'data' => [ '__atk_tab' => 1 ] ] ] ) ; } else { $ this -> js ( true ) -> tab ( ) ; } if ( $ this -> owner -> activeTabName == $ this -> name ) { $ this -> js ( true ) -> click ( ) ; } parent :: renderView ( ) ; } | Rendering one tab view . |
9,661 | public function setSource ( array $ data , $ fields = null ) { $ this -> setModel ( new \ atk4 \ data \ Model ( new \ atk4 \ data \ Persistence_Static ( $ data ) ) , $ fields ) ; } | Sets source of the View . |
9,662 | public function init ( ) { if ( ! $ this -> name ) { if ( ! $ this -> id ) { $ this -> id = $ this -> name = 'atk' ; } else { $ this -> name = $ this -> id ; } } elseif ( ! $ this -> id ) { $ this -> id = $ this -> name ; } $ this -> _init ( ) ; if ( ! $ this -> app ) { $ this -> initDefaultApp ( ) ; } if ( $ this -> region && ! $ this -> template && ! $ this -> defaultTemplate && $ this -> owner && $ this -> owner -> template ) { $ this -> template = $ this -> owner -> template -> cloneRegion ( $ this -> region ) ; $ this -> owner -> template -> del ( $ this -> region ) ; } else { if ( is_string ( $ this -> defaultTemplate ) && is_null ( $ this -> template ) ) { $ this -> template = $ this -> app -> loadTemplate ( $ this -> defaultTemplate ) ; } if ( ! $ this -> region ) { $ this -> region = 'Content' ; } } if ( $ this -> template && ! isset ( $ this -> template -> app ) && isset ( $ this -> app ) ) { $ this -> template -> app = $ this -> app ; } foreach ( $ this -> _add_later as list ( $ object , $ region ) ) { $ this -> add ( $ object , $ region ) ; } $ this -> _add_later = [ ] ; } | Called when view becomes part of render tree . You can override it but avoid placing any heavy processing here . |
9,663 | protected function initDefaultApp ( ) { $ this -> app = new App ( [ 'skin' => $ this -> skin , 'catch_exceptions' => false , 'always_run' => false , 'catch_runaway_callbacks' => false , ] ) ; $ this -> app -> init ( ) ; } | For the absence of the application we would add a very simple one . |
9,664 | public function add ( $ seed , $ region = null ) { if ( $ this -> _rendered ) { throw new Exception ( 'You cannot add anything into the view after it was rendered' ) ; } if ( ! $ this -> app ) { $ this -> _add_later [ ] = [ $ seed , $ region ] ; return $ seed ; } if ( is_array ( $ region ) ) { $ args = $ region ; if ( isset ( $ args [ 'region' ] ) ) { $ region = [ 'region' => $ args [ 'region' ] ] ; unset ( $ args [ 'region' ] ) ; } } elseif ( $ region ) { $ args = null ; $ region = [ 'region' => $ region ] ; } else { $ args = null ; $ region = null ; } $ object = $ this -> factory ( $ this -> mergeSeeds ( $ seed , [ 'View' ] ) , $ region ) ; $ object = $ this -> _add ( $ object , $ args ) ; return $ object ; } | In addition to adding a child object sets up it s template and associate it s output with the region in our template . |
9,665 | public function getClosestOwner ( $ object , $ class ) { if ( ! isset ( $ object -> owner ) ) { return ; } if ( $ object -> owner instanceof $ class ) { return $ object -> owner ; } return $ this -> getClosestOwner ( $ object -> owner , $ class ) ; } | Get objects closest owner which is instance of particular class . |
9,666 | public function set ( $ arg1 = null , $ arg2 = null ) { if ( is_string ( $ arg1 ) && $ arg2 !== null ) { $ this -> template -> set ( $ arg1 , $ arg2 ) ; return $ this ; } if ( $ arg2 !== null ) { throw new Exception ( [ 'Second argument to set() can be only passed if the first one is a string' , 'arg1' => $ arg1 , 'arg2' => $ arg2 , ] ) ; } if ( is_scalar ( $ arg1 ) ) { $ this -> content = $ arg1 ; return $ this ; } if ( is_array ( $ arg1 ) ) { if ( isset ( $ arg1 [ 0 ] ) ) { $ this -> content = $ arg1 [ 0 ] ; } $ this -> setDefaults ( $ arg1 ) ; return $ this ; } throw new Exception ( [ 'Not sure what to do with argument' , 'this' => $ this , 'arg1' => $ arg1 , 'arg2' => $ arg2 , ] ) ; } | Override this method without compatibility with parent if you wish to set your own things your own way for your view . |
9,667 | public function removeAttr ( $ property ) { if ( is_array ( $ property ) ) { foreach ( $ property as $ v ) { unset ( $ this -> attr [ $ v ] ) ; } return $ this ; } unset ( $ this -> attr [ $ property ] ) ; return $ this ; } | Remove attribute . |
9,668 | public function recursiveRender ( ) { foreach ( $ this -> elements as $ view ) { if ( ! $ view instanceof self ) { continue ; } $ this -> template -> appendHTML ( $ view -> region , $ view -> getHTML ( ) ) ; if ( $ view -> _js_actions ) { $ this -> _js_actions = array_merge_recursive ( $ this -> _js_actions , $ view -> _js_actions ) ; } } if ( isset ( $ this -> content ) && $ this -> content !== false ) { $ this -> template -> append ( 'Content' , $ this -> content ) ; } } | Recursively render all children placing their output in our template . |
9,669 | public function renderAll ( ) { if ( ! $ this -> _initialized ) { $ this -> init ( ) ; } if ( ! $ this -> _rendered ) { $ this -> renderView ( ) ; $ this -> recursiveRender ( ) ; $ this -> _rendered = true ; } } | Render everything recursively render ourselves but don t return anything just yet . |
9,670 | public function render ( $ force_echo = true ) { $ this -> renderAll ( ) ; return $ this -> getJS ( $ force_echo ) . $ this -> template -> render ( ) ; } | This method is for those cases when developer want to simply render his view and grab HTML himself . |
9,671 | public function renderJSON ( $ force_echo = true , $ region = null ) { try { $ this -> renderAll ( ) ; return json_encode ( [ 'success' => true , 'message' => 'Success' , 'atkjs' => $ this -> getJS ( $ force_echo ) , 'html' => $ this -> template -> render ( $ region ) , 'id' => $ this -> name , ] ) ; } catch ( \ Exception $ exception ) { $ this -> _rendered = false ; $ l = $ this -> add ( new self ( ) ) ; if ( $ exception instanceof \ atk4 \ core \ Exception ) { $ l -> template -> setHTML ( 'Content' , $ exception -> getHTML ( ) ) ; } elseif ( $ exception instanceof \ Error ) { $ l -> add ( new self ( [ 'ui' => 'message' , get_class ( $ exception ) . ': ' . $ exception -> getMessage ( ) . ' (in ' . $ exception -> getFile ( ) . ':' . $ exception -> getLine ( ) . ')' , 'error' , ] ) ) ; $ l -> add ( new Text ( ) ) -> set ( nl2br ( $ exception -> getTraceAsString ( ) ) ) ; } else { $ l -> add ( new self ( [ 'ui' => 'message' , get_class ( $ exception ) . ': ' . $ exception -> getMessage ( ) , 'error' ] ) ) ; } return json_encode ( [ 'success' => false , 'message' => $ l -> getHTML ( ) , ] ) ; } } | Render View using json format . |
9,672 | public function vue ( $ component , $ initData = [ ] , $ componentDefinition = null , $ selector = null ) { if ( ! $ selector ) { $ selector = '#' . $ this -> name ; } if ( $ componentDefinition ) { $ chain = ( new jsVueService ( ) ) -> createVue ( $ selector , $ component , $ componentDefinition , $ initData ) ; } else { $ chain = ( new jsVueService ( ) ) -> createAtkVue ( $ selector , $ component , $ initData ) ; } $ this -> _js_actions [ true ] [ ] = $ chain ; return $ this ; } | Create Vue . js instance . Vue . js instance can be create from atk4 \ ui \ View . |
9,673 | public function jsVueEmit ( $ eventName , $ eventData = [ ] ) { if ( ! $ eventData [ 'id' ] ) { $ eventData [ 'id' ] = $ this -> name ; } return ( new jsVueService ( ) ) -> emitEvent ( $ eventName , $ eventData ) ; } | Emit an event on the Vue event bus . vueService has a dedicated Vue instance for registering event that allow communication between external view like button or even separate vue component in order to communicate to each other . |
9,674 | public function getJS ( $ force_echo = false ) { $ actions = [ ] ; foreach ( $ this -> _js_actions as $ eventActions ) { foreach ( $ eventActions as $ action ) { $ actions [ ] = $ action ; } } if ( ! $ actions ) { return '' ; } $ actions [ 'indent' ] = '' ; if ( ! $ force_echo && $ this -> app && $ this -> app -> hasMethod ( 'jsReady' ) ) { $ this -> app -> jsReady ( $ actions ) ; return '' ; } if ( $ this -> app && $ this -> app -> hasMethod ( 'getViewJS' ) ) { return $ this -> app -> getViewJS ( $ actions ) ; } $ ready = new jsFunction ( $ actions ) ; return "<script>\n" . ( new jQuery ( $ ready ) ) -> jsRender ( ) . '</script>' ; } | Get JavaScript objects from this render tree . |
9,675 | protected function initLayout ( ) { if ( $ this -> layout === null ) { $ this -> layout = 'Generic' ; } if ( is_string ( $ this -> layout ) || is_array ( $ this -> layout ) ) { $ this -> layout = $ this -> factory ( $ this -> layout , [ 'form' => $ this ] , 'FormLayout' ) ; $ this -> layout = $ this -> add ( $ this -> layout ) ; } elseif ( is_object ( $ this -> layout ) ) { $ this -> layout -> form = $ this ; $ this -> add ( $ this -> layout ) ; } else { throw new Exception ( [ 'Unsupported specification of form layout. Can be array, string or object' , 'layout' => $ this -> layout ] ) ; } if ( $ this -> buttonSave ) { $ this -> buttonSave = $ this -> layout -> addButton ( $ this -> buttonSave ) ; $ this -> buttonSave -> setAttr ( 'tabindex' , 0 ) ; $ this -> buttonSave -> on ( 'click' , $ this -> js ( ) -> form ( 'submit' ) ) ; $ this -> buttonSave -> on ( 'keypress' , new jsExpression ( 'if (event.keyCode === 13){$([name]).form("submit");}' , [ 'name' => '#' . $ this -> name ] ) ) ; } } | initialize form layout . You can inject custom layout if you layout = > .. to constructor . |
9,676 | public function setGroupDisplayRules ( $ rules = [ ] , $ selector = '.atk-form-group' ) { if ( is_object ( $ selector ) && isset ( $ selector -> name ) ) { $ selector = '#' . $ selector -> name ; } $ this -> fieldsDisplayRules = $ rules ; $ this -> fieldDisplaySelector = $ selector ; return $ this ; } | Set display rule for a group collection . |
9,677 | public function setModel ( \ atk4 \ data \ Model $ model , $ fields = null ) { try { $ model = parent :: setModel ( $ model ) ; $ this -> layout -> setModel ( $ model , $ fields ) ; return $ model ; } catch ( Exception $ e ) { throw $ e -> addMoreInfo ( 'model' , $ model ) ; } } | Associates form with the model but also specifies which of Model fields should be added automatically . |
9,678 | public function error ( $ fieldName , $ str ) { if ( $ this -> hookHasCallbacks ( 'displayError' ) ) { return $ this -> hook ( 'displayError' , [ $ fieldName , $ str ] ) ; } $ jsError = [ $ this -> js ( ) -> form ( 'add prompt' , $ fieldName , $ str ) ] ; return $ jsError ; } | Causes form to generate error . |
9,679 | public function success ( $ str = 'Success' , $ sub_header = null ) { if ( $ this -> hookHasCallbacks ( 'displaySuccess' ) ) { return $ this -> hook ( 'displaySuccess' , [ $ str , $ sub_header ] ) ; } $ success = $ this -> app -> loadTemplate ( $ this -> successTemplate ) ; $ success [ 'header' ] = $ str ; if ( $ sub_header ) { $ success [ 'message' ] = $ sub_header ; } else { $ success -> del ( 'p' ) ; } $ js = $ this -> js ( ) -> html ( $ success -> render ( ) ) ; return $ js ; } | Causes form to generate success message . |
9,680 | public function addField ( $ name , $ decorator = null , $ field = null ) { if ( ! $ this -> model ) { $ this -> model = new \ atk4 \ ui \ misc \ ProxyModel ( ) ; } return $ this -> layout -> addField ( $ name , $ decorator , $ field ) ; } | Add field into current layout . If no layout create one . If no model create blank one . |
9,681 | public function addFields ( $ fields ) { foreach ( $ fields as $ field ) { if ( is_array ( $ field ) ) { $ this -> addField ( ... $ field ) ; } else { $ this -> addField ( $ field ) ; } } return $ this ; } | Add more than one field in one shot . |
9,682 | public function loadPOST ( ) { $ post = $ _POST ; $ this -> hook ( 'loadPOST' , [ & $ post ] ) ; $ errors = [ ] ; foreach ( $ this -> fields as $ key => $ field ) { try { $ value = isset ( $ post [ $ key ] ) ? $ post [ $ key ] : null ; if ( ! $ field -> readonly && ! $ field -> disabled ) { $ this -> model [ $ key ] = $ this -> app -> ui_persistence -> typecastLoadField ( $ field -> field , $ value ) ; } } catch ( \ atk4 \ core \ Exception $ e ) { $ errors [ $ key ] = $ e -> getMessage ( ) ; } } if ( $ errors ) { throw new \ atk4 \ data \ ValidationException ( $ errors ) ; } } | Looks inside the POST of the request and loads it into a current model . |
9,683 | public function ajaxSubmit ( ) { $ this -> _add ( $ cb = new jsCallback ( ) , [ 'desired_name' => 'submit' , 'postTrigger' => true ] ) ; $ this -> add ( new View ( [ 'element' => 'input' ] ) ) -> setAttr ( 'name' , $ cb -> postTrigger ) -> setAttr ( 'value' , 'submit' ) -> setStyle ( [ 'display' => 'none' ] ) ; $ cb -> set ( function ( ) { $ caught = function ( $ e , $ useWindow ) { $ html = '<div class="header"> ' . htmlspecialchars ( get_class ( $ e ) ) . ' </div> <div class="content"> ' . ( $ e instanceof \ atk4 \ core \ Exception ? $ e -> getHTML ( ) : nl2br ( htmlspecialchars ( $ e -> getMessage ( ) ) ) ) . ' </div>' ; $ this -> app -> terminate ( json_encode ( [ 'success' => false , 'message' => $ html , 'useWindow' => $ useWindow ] ) ) ; } ; try { $ this -> loadPOST ( ) ; ob_start ( ) ; $ response = $ this -> hook ( 'submit' ) ; $ output = ob_get_clean ( ) ; if ( $ output ) { $ message = new Message ( 'Direct Output Detected' ) ; $ message -> init ( ) ; $ message -> addClass ( 'error' ) ; $ message -> text -> set ( $ output ) ; return $ message ; } if ( ! $ response ) { if ( ! $ this -> model instanceof \ atk4 \ ui \ misc \ ProxyModel ) { $ this -> model -> save ( ) ; return $ this -> success ( 'Form data has been saved' ) ; } return new jsExpression ( 'console.log([])' , [ 'Form submission is not handled' ] ) ; } } catch ( \ atk4 \ data \ ValidationException $ val ) { $ response = [ ] ; foreach ( $ val -> errors as $ field => $ error ) { $ response [ ] = $ this -> error ( $ field , $ error ) ; } return $ response ; } catch ( \ Error $ e ) { return $ caught ( $ e , false ) ; } catch ( \ Exception $ e ) { return $ caught ( $ e , true ) ; } return $ response ; } ) ; $ this -> js ( true ) -> api ( array_merge ( [ 'url' => $ cb -> getJSURL ( ) , 'method' => 'POST' , 'serializeForm' => true ] , $ this -> apiConfig ) ) -> form ( array_merge ( [ 'inline' => true , 'on' => 'blur' ] , $ this -> formConfig ) ) ; $ this -> on ( 'change' , 'input' , $ this -> js ( ) -> form ( 'remove prompt' , new jsExpression ( '$(this).attr("name")' ) ) ) ; } | Does ajax submit . |
9,684 | public function addParagraph ( $ text ) { $ this -> content .= isset ( $ this -> app ) ? $ this -> app -> getTag ( 'p' , $ text ) : '<p>' . htmlspecialchars ( $ text ) . '</p>' ; return $ this ; } | Adds HTML paragraph . |
9,685 | public function getDataCellTemplate ( \ atk4 \ data \ Field $ f = null ) { $ caption = $ f ? $ f -> getCaption ( ) : $ this -> short_name ; return '<img src="' . parent :: getDataCellTemplate ( $ f ) . '" alt="' . $ caption . '" border="0" />' ; } | Extend parent method . |
9,686 | public function setOption ( $ options , $ value = null ) { if ( is_array ( $ options ) ) { foreach ( $ options as $ key => $ value ) { $ this -> args [ 'arg' ] [ $ key ] = $ value ; } } else { $ this -> args [ 'arg' ] [ $ options ] = $ value ; } return $ this ; } | Set additionnal option for this jsModal . |
9,687 | public function linkCart ( Cart $ cart , $ jsAction = null ) { $ this -> on ( 'click' , '.item' , function ( $ a , $ b ) use ( $ cart , $ jsAction ) { $ cart -> addItem ( $ b ) ; return $ jsAction ; } , [ ( new \ atk4 \ ui \ jQuery ( ) ) -> text ( ) ] ) ; } | Associate your shelf with cart so that when item is clicked the content of a cart is updated . |
9,688 | public function init ( ) { if ( $ this -> runEvent ) { $ chain = new jsChain ( ) ; $ this -> app -> html -> js ( true , $ chain -> atkServerEvent ( [ 'uri' => $ this -> getUrl ( ) ] ) ) ; $ this -> isRunning = true ; } $ this -> _initialized = true ; } | Allow chunked encoding |
9,689 | public function actionRequestPasswordReset ( ) { $ model = new PasswordResetRequest ( ) ; if ( $ model -> load ( Yii :: $ app -> getRequest ( ) -> post ( ) ) && $ model -> validate ( ) ) { if ( $ model -> sendEmail ( ) ) { Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , 'Check your email for further instructions.' ) ; return $ this -> goHome ( ) ; } else { Yii :: $ app -> getSession ( ) -> setFlash ( 'error' , 'Sorry, we are unable to reset password for email provided.' ) ; } } return $ this -> render ( 'requestPasswordResetToken' , [ 'model' => $ model , ] ) ; } | Request reset password |
9,690 | public function getRoutePrefix ( ) { if ( ! $ this -> _routePrefix ) { $ this -> _routePrefix = Configs :: instance ( ) -> advanced ? self :: PREFIX_ADVANCED : self :: PREFIX_BASIC ; } return $ this -> _routePrefix ; } | Returns route prefix depending on the configuration . |
9,691 | public function getPermissionName ( $ route ) { if ( self :: PREFIX_BASIC == $ this -> routePrefix ) { return self :: PREFIX_BASIC . trim ( $ route , self :: PREFIX_BASIC ) ; } else { return self :: PREFIX_ADVANCED . ltrim ( trim ( $ route , self :: PREFIX_BASIC ) , self :: PREFIX_ADVANCED ) ; } } | Returns the correct permission name depending on the configuration . |
9,692 | protected function getControllerActions ( $ type , $ id , $ module , & $ result ) { $ token = "Create controller with cofig=" . VarDumper :: dumpAsString ( $ type ) . " and id='$id'" ; Yii :: beginProfile ( $ token , __METHOD__ ) ; try { $ controller = Yii :: createObject ( $ type , [ $ id , $ module ] ) ; $ this -> getActionRoutes ( $ controller , $ result ) ; $ all = "/{$controller->uniqueId}/*" ; $ result [ $ all ] = $ all ; } catch ( \ Exception $ exc ) { Yii :: error ( $ exc -> getMessage ( ) , __METHOD__ ) ; } Yii :: endProfile ( $ token , __METHOD__ ) ; } | Get list action of controller |
9,693 | protected function getActionRoutes ( $ controller , & $ result ) { $ token = "Get actions of controller '" . $ controller -> uniqueId . "'" ; Yii :: beginProfile ( $ token , __METHOD__ ) ; try { $ prefix = '/' . $ controller -> uniqueId . '/' ; foreach ( $ controller -> actions ( ) as $ id => $ value ) { $ result [ $ prefix . $ id ] = $ prefix . $ id ; } $ class = new \ ReflectionClass ( $ controller ) ; foreach ( $ class -> getMethods ( ) as $ method ) { $ name = $ method -> getName ( ) ; if ( $ method -> isPublic ( ) && ! $ method -> isStatic ( ) && strpos ( $ name , 'action' ) === 0 && $ name !== 'actions' ) { $ name = strtolower ( preg_replace ( '/(?<![A-Z])[A-Z]/' , ' \0' , substr ( $ name , 6 ) ) ) ; $ id = $ prefix . ltrim ( str_replace ( ' ' , '-' , $ name ) , '-' ) ; $ result [ $ id ] = $ id ; } } } catch ( \ Exception $ exc ) { Yii :: error ( $ exc -> getMessage ( ) , __METHOD__ ) ; } Yii :: endProfile ( $ token , __METHOD__ ) ; } | Get route of action |
9,694 | public function getMenus ( ) { if ( $ this -> _normalizeMenus === null ) { $ mid = '/' . $ this -> getUniqueId ( ) . '/' ; $ this -> _normalizeMenus = [ ] ; $ config = components \ Configs :: instance ( ) ; $ conditions = [ 'user' => $ config -> db && $ config -> db -> schema -> getTableSchema ( $ config -> userTable ) , 'assignment' => ( $ userClass = Yii :: $ app -> getUser ( ) -> identityClass ) && is_subclass_of ( $ userClass , 'yii\db\BaseActiveRecord' ) , 'menu' => $ config -> db && $ config -> db -> schema -> getTableSchema ( $ config -> menuTable ) , ] ; foreach ( $ this -> _coreItems as $ id => $ lable ) { if ( ! isset ( $ conditions [ $ id ] ) || $ conditions [ $ id ] ) { $ this -> _normalizeMenus [ $ id ] = [ 'label' => Yii :: t ( 'rbac-admin' , $ lable ) , 'url' => [ $ mid . $ id ] ] ; } } foreach ( array_keys ( $ this -> controllerMap ) as $ id ) { $ this -> _normalizeMenus [ $ id ] = [ 'label' => Yii :: t ( 'rbac-admin' , Inflector :: humanize ( $ id ) ) , 'url' => [ $ mid . $ id ] ] ; } foreach ( $ this -> _menus as $ id => $ value ) { if ( empty ( $ value ) ) { unset ( $ this -> _normalizeMenus [ $ id ] ) ; continue ; } if ( is_string ( $ value ) ) { $ value = [ 'label' => $ value ] ; } $ this -> _normalizeMenus [ $ id ] = isset ( $ this -> _normalizeMenus [ $ id ] ) ? array_merge ( $ this -> _normalizeMenus [ $ id ] , $ value ) : $ value ; if ( ! isset ( $ this -> _normalizeMenus [ $ id ] [ 'url' ] ) ) { $ this -> _normalizeMenus [ $ id ] [ 'url' ] = [ $ mid . $ id ] ; } } } return $ this -> _normalizeMenus ; } | Get available menu . |
9,695 | public function setMenus ( $ menus ) { $ this -> _menus = array_merge ( $ this -> _menus , $ menus ) ; $ this -> _normalizeMenus = null ; } | Set or add available menu . |
9,696 | public function assign ( $ items ) { $ manager = Configs :: authManager ( ) ; $ success = 0 ; foreach ( $ items as $ name ) { try { $ item = $ manager -> getRole ( $ name ) ; $ item = $ item ? : $ manager -> getPermission ( $ name ) ; $ manager -> assign ( $ item , $ this -> id ) ; $ success ++ ; } catch ( \ Exception $ exc ) { Yii :: error ( $ exc -> getMessage ( ) , __METHOD__ ) ; } } Helper :: invalidate ( ) ; return $ success ; } | Grands a roles from a user . |
9,697 | private static function requiredParent ( $ assigned , & $ menus ) { $ l = count ( $ assigned ) ; for ( $ i = 0 ; $ i < $ l ; $ i ++ ) { $ id = $ assigned [ $ i ] ; $ parent_id = $ menus [ $ id ] [ 'parent' ] ; if ( $ parent_id !== null && ! in_array ( $ parent_id , $ assigned ) ) { $ assigned [ $ l ++ ] = $ parent_id ; } } return $ assigned ; } | Ensure all item menu has parent . |
9,698 | public static function filter ( $ items , $ user = null ) { if ( $ user === null ) { $ user = Yii :: $ app -> getUser ( ) ; } return static :: filterRecursive ( $ items , $ user ) ; } | Filter menu items |
9,699 | public static function getTypeName ( $ type = null ) { $ result = [ Item :: TYPE_PERMISSION => 'Permission' , Item :: TYPE_ROLE => 'Role' , ] ; if ( $ type === null ) { return $ result ; } return $ result [ $ type ] ; } | Get type name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.