idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
9,500
public function getPageUrl ( $ page , $ queryData = null , $ dropIndex = true ) { if ( is_array ( $ queryData ) ) { $ queryData = http_build_query ( $ queryData , '' , '&' ) ; } elseif ( ( $ queryData !== null ) && ! is_string ( $ queryData ) ) { throw new InvalidArgumentException ( 'Argument 2 passed to ' . get_called_class ( ) . '::getPageUrl() must be of the type array or string, ' . ( is_object ( $ queryData ) ? get_class ( $ queryData ) : gettype ( $ queryData ) ) . ' given' ) ; } if ( $ dropIndex ) { if ( $ page === 'index' ) { $ page = '' ; } elseif ( ( $ pagePathLength = strrpos ( $ page , '/' ) ) !== false ) { if ( substr ( $ page , $ pagePathLength + 1 ) === 'index' ) { $ page = substr ( $ page , 0 , $ pagePathLength ) ; } } } if ( $ queryData ) { $ queryData = ( $ this -> isUrlRewritingEnabled ( ) || ! $ page ) ? '?' . $ queryData : '&' . $ queryData ; } else { $ queryData = '' ; } if ( ! $ page ) { return $ this -> getBaseUrl ( ) . $ queryData ; } elseif ( ! $ this -> isUrlRewritingEnabled ( ) ) { return $ this -> getBaseUrl ( ) . '?' . rawurlencode ( $ page ) . $ queryData ; } else { return $ this -> getBaseUrl ( ) . implode ( '/' , array_map ( 'rawurlencode' , explode ( '/' , $ page ) ) ) . $ queryData ; } }
Returns the URL to a given page
9,501
public function getPageId ( $ path ) { $ contentDir = $ this -> getConfig ( 'content_dir' ) ; $ contentDirLength = strlen ( $ contentDir ) ; if ( substr ( $ path , 0 , $ contentDirLength ) !== $ contentDir ) { return null ; } $ contentExt = $ this -> getConfig ( 'content_ext' ) ; $ contentExtLength = strlen ( $ contentExt ) ; if ( substr ( $ path , - $ contentExtLength ) !== $ contentExt ) { return null ; } return substr ( $ path , $ contentDirLength , - $ contentExtLength ) ? : null ; }
Returns the page ID of a given content file
9,502
public function getBaseThemeUrl ( ) { $ themeUrl = $ this -> getConfig ( 'theme_url' ) ; if ( $ themeUrl ) { return $ themeUrl ; } if ( isset ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) && ( $ _SERVER [ 'SCRIPT_FILENAME' ] !== 'index.php' ) ) { $ basePath = dirname ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ; $ basePath = ! in_array ( $ basePath , array ( '.' , '/' , '\\' ) , true ) ? $ basePath . '/' : '/' ; $ basePathLength = strlen ( $ basePath ) ; if ( substr ( $ this -> getThemesDir ( ) , 0 , $ basePathLength ) === $ basePath ) { $ this -> config [ 'theme_url' ] = $ this -> getBaseUrl ( ) . substr ( $ this -> getThemesDir ( ) , $ basePathLength ) ; return $ this -> config [ 'theme_url' ] ; } } $ this -> config [ 'theme_url' ] = $ this -> getBaseUrl ( ) . basename ( $ this -> getThemesDir ( ) ) . '/' ; return $ this -> config [ 'theme_url' ] ; }
Returns the URL of the themes folder of this Pico instance
9,503
protected function filterVariable ( $ variable , $ filter = '' , $ options = null , $ flags = null ) { $ defaultValue = null ; if ( is_array ( $ options ) ) { $ defaultValue = isset ( $ options [ 'default' ] ) ? $ options [ 'default' ] : null ; } elseif ( $ options !== null ) { $ defaultValue = $ options ; $ options = array ( 'default' => $ defaultValue ) ; } if ( $ variable === null ) { return $ defaultValue ; } $ filter = $ filter ? ( is_string ( $ filter ) ? filter_id ( $ filter ) : ( int ) $ filter ) : false ; if ( ! $ filter ) { return false ; } $ filterOptions = array ( 'options' => $ options , 'flags' => 0 ) ; foreach ( ( array ) $ flags as $ flag ) { if ( is_numeric ( $ flag ) ) { $ filterOptions [ 'flags' ] |= ( int ) $ flag ; } elseif ( is_string ( $ flag ) ) { $ flag = strtoupper ( preg_replace ( '/[^a-zA-Z0-9_]/' , '' , $ flag ) ) ; if ( ( $ flag === 'NULL_ON_FAILURE' ) && ( $ filter === FILTER_VALIDATE_BOOLEAN ) ) { $ filterOptions [ 'flags' ] |= FILTER_NULL_ON_FAILURE ; } else { $ filterOptions [ 'flags' ] |= ( int ) constant ( 'FILTER_FLAG_' . $ flag ) ; } } } return filter_var ( $ variable , $ filter , $ filterOptions ) ; }
Filters a variable with a specified filter
9,504
public function getFiles ( $ directory , $ fileExtension = '' , $ order = self :: SORT_ASC ) { $ directory = rtrim ( $ directory , '/' ) ; $ result = array ( ) ; $ files = scandir ( $ directory , $ order ) ; $ fileExtensionLength = strlen ( $ fileExtension ) ; if ( $ files !== false ) { foreach ( $ files as $ file ) { if ( ( $ file [ 0 ] === '.' ) || in_array ( substr ( $ file , - 1 ) , array ( '~' , '#' ) , true ) ) { continue ; } if ( is_dir ( $ directory . '/' . $ file ) ) { $ result = array_merge ( $ result , $ this -> getFiles ( $ directory . '/' . $ file , $ fileExtension , $ order ) ) ; } elseif ( ! $ fileExtension || ( substr ( $ file , - $ fileExtensionLength ) === $ fileExtension ) ) { $ result [ ] = $ directory . '/' . $ file ; } } } return $ result ; }
Recursively walks through a directory and returns all containing files matching the specified file extension
9,505
public function getAbsolutePath ( $ path ) { if ( DIRECTORY_SEPARATOR === '\\' ) { if ( preg_match ( '/^(?>[a-zA-Z]:\\\\|\\\\\\\\)/' , $ path ) !== 1 ) { $ path = $ this -> getRootDir ( ) . $ path ; } } else { if ( $ path [ 0 ] !== '/' ) { $ path = $ this -> getRootDir ( ) . $ path ; } } return rtrim ( $ path , '/\\' ) . '/' ; }
Makes a relative path absolute to Pico s root dir
9,506
public function triggerEvent ( $ eventName , array $ params = array ( ) ) { foreach ( $ this -> nativePlugins as $ plugin ) { $ plugin -> handleEvent ( $ eventName , $ params ) ; } }
Triggers events on plugins using the current API version
9,507
public function feedback ( ) { $ adapterParams = [ ] ; $ adapterParams [ 'certificate' ] = $ this -> certificatePath ; $ adapterParams [ 'passPhrase' ] = $ this -> passPhrase ; $ pushManager = new PushManager ( $ this -> environment ) ; $ apnsAdapter = new ApnsAdapter ( $ adapterParams ) ; $ this -> feedback = $ pushManager -> getFeedback ( $ apnsAdapter ) ; return $ this -> feedback ; }
Use feedback to get not registered tokens from last send and remove them from your DB
9,508
protected function getOpenedServiceClient ( ) { if ( ! isset ( $ this -> openedClient ) ) { $ this -> openedClient = $ this -> getOpenedClient ( new ServiceClient ( ) ) ; } return $ this -> openedClient ; }
Get opened ServiceClient
9,509
private function getOpenedFeedbackClient ( ) { if ( ! isset ( $ this -> feedbackClient ) ) { $ this -> feedbackClient = $ this -> getOpenedClient ( new ServiceFeedbackClient ( ) ) ; } return $ this -> feedbackClient ; }
Get opened ServiceFeedbackClient
9,510
public function setAdapterParameters ( array $ config = [ ] ) { if ( ! is_array ( $ config ) || empty ( $ config ) ) { throw new InvalidArgumentException ( '$config must be an associative array with at least 1 item.' ) ; } if ( $ this -> httpClient === null ) { $ this -> httpClient = new HttpClient ( ) ; $ this -> httpClient -> setAdapter ( new HttpSocketAdapter ( ) ) ; } $ this -> httpClient -> getAdapter ( ) -> setOptions ( $ config ) ; }
Send custom parameters to the Http Adapter without overriding the Http Client .
9,511
private function getAdapterClassFromArgument ( $ argument ) { if ( ! class_exists ( $ adapterClass = $ argument ) && ! class_exists ( $ adapterClass = '\\Sly\\NotificationPusher\\Adapter\\' . ucfirst ( $ argument ) ) ) { throw new AdapterException ( sprintf ( 'Adapter class %s does not exist' , $ adapterClass ) ) ; } return $ adapterClass ; }
Get adapter class from argument .
9,512
public function push ( array $ tokens = [ ] , array $ notifications = [ ] , array $ params = [ ] ) { if ( ! $ tokens || ! $ notifications ) { return null ; } $ adapterParams = [ ] ; $ deviceParams = [ ] ; $ messageParams = [ ] ; if ( isset ( $ params ) && ! empty ( $ params ) ) { if ( isset ( $ params [ 'adapter' ] ) ) { $ adapterParams = $ params [ 'adapter' ] ; } if ( isset ( $ params [ 'device' ] ) ) { $ deviceParams = $ params [ 'device' ] ; } if ( isset ( $ params [ 'message' ] ) ) { $ messageParams = $ params [ 'message' ] ; } if ( isset ( $ params [ 'notificationData' ] ) ) { $ messageParams [ 'notificationData' ] = $ params [ 'notificationData' ] ; } } $ adapterParams [ 'apiKey' ] = $ this -> apiKey ; if ( ! $ this -> apiKey ) { throw new \ RuntimeException ( 'Android api key must be set' ) ; } $ pushManager = new PushManager ( $ this -> environment ) ; $ gcmAdapter = new GcmAdapter ( $ adapterParams ) ; $ devices = new DeviceCollection ( [ ] ) ; foreach ( $ tokens as $ token ) { $ devices -> add ( new Device ( $ token , $ deviceParams ) ) ; } foreach ( $ notifications as $ notificationText ) { $ message = new Message ( $ notificationText , $ messageParams ) ; $ push = new Push ( $ gcmAdapter , $ devices , $ message ) ; $ pushManager -> add ( $ push ) ; } $ pushes = $ pushManager -> push ( ) ; $ this -> response = $ gcmAdapter -> getResponse ( ) ; return $ this -> response ; }
params keys adapter message device
9,513
private function checkDevicesTokens ( ) { $ devices = $ this -> getDevices ( ) ; $ adapter = $ this -> getAdapter ( ) ; foreach ( $ devices as $ device ) { if ( false === $ adapter -> supports ( $ device -> getToken ( ) ) ) { throw new AdapterException ( sprintf ( 'Adapter %s does not support %s token\'s device' , ( string ) $ adapter , $ device -> getToken ( ) ) ) ; } } }
Check devices tokens .
9,514
public function addResponse ( DeviceInterface $ device , $ response ) { $ this -> getResponses ( ) -> add ( $ device -> getToken ( ) , $ response ) ; }
adds a response
9,515
public function getFeedback ( AdapterInterface $ adapter ) { if ( ! $ adapter instanceof FeedbackAdapterInterface ) { throw new AdapterException ( sprintf ( '%s adapter has no dedicated "getFeedback" method' , ( string ) $ adapter ) ) ; } $ adapter -> setEnvironment ( $ this -> getEnvironment ( ) ) ; return $ adapter -> getFeedback ( ) ; }
Get feedback .
9,516
function gdversion ( $ full = false ) { static $ gd_version = null ; static $ gd_full_version = null ; if ( $ gd_version === null ) { if ( $ this -> function_enabled ( 'gd_info' ) ) { $ gd = gd_info ( ) ; $ gd = $ gd [ "GD Version" ] ; $ regex = "/([\d\.]+)/i" ; } else { ob_start ( ) ; phpinfo ( 8 ) ; $ gd = ob_get_contents ( ) ; ob_end_clean ( ) ; $ regex = "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i" ; } if ( preg_match ( $ regex , $ gd , $ m ) ) { $ gd_full_version = ( string ) $ m [ 1 ] ; $ gd_version = ( float ) $ m [ 1 ] ; } else { $ gd_full_version = 'none' ; $ gd_version = 0 ; } } if ( $ full ) { return $ gd_full_version ; } else { return $ gd_version ; } }
Returns the version of GD
9,517
function function_enabled ( $ func ) { static $ disabled = null ; if ( $ disabled === null ) $ disabled = array_map ( 'trim' , array_map ( 'strtolower' , explode ( ',' , ini_get ( 'disable_functions' ) ) ) ) ; static $ blacklist = null ; if ( $ blacklist === null ) $ blacklist = extension_loaded ( 'suhosin' ) ? array_map ( 'trim' , array_map ( 'strtolower' , explode ( ',' , ini_get ( ' suhosin.executor.func.blacklist' ) ) ) ) : array ( ) ; return ( function_exists ( $ func ) && ! in_array ( $ func , $ disabled ) && ! in_array ( $ func , $ blacklist ) ) ; }
Checks if a function is available
9,518
function rmkdir ( $ path , $ mode = 0755 ) { return is_dir ( $ path ) || ( $ this -> rmkdir ( dirname ( $ path ) , $ mode ) && $ this -> _mkdir ( $ path , $ mode ) ) ; }
Creates directories recursively
9,519
function imagecreatenew ( $ x , $ y , $ fill = true , $ trsp = false ) { if ( $ x < 1 ) $ x = 1 ; if ( $ y < 1 ) $ y = 1 ; if ( $ this -> gdversion ( ) >= 2 && ! $ this -> image_is_palette ) { $ dst_im = imagecreatetruecolor ( $ x , $ y ) ; if ( empty ( $ this -> image_background_color ) || $ trsp ) { imagealphablending ( $ dst_im , false ) ; imagefilledrectangle ( $ dst_im , 0 , 0 , $ x , $ y , imagecolorallocatealpha ( $ dst_im , 0 , 0 , 0 , 127 ) ) ; } } else { $ dst_im = imagecreate ( $ x , $ y ) ; if ( ( $ fill && $ this -> image_is_transparent && empty ( $ this -> image_background_color ) ) || $ trsp ) { imagefilledrectangle ( $ dst_im , 0 , 0 , $ x , $ y , $ this -> image_transparent_color ) ; imagecolortransparent ( $ dst_im , $ this -> image_transparent_color ) ; } } if ( $ fill && ! empty ( $ this -> image_background_color ) && ! $ trsp ) { list ( $ red , $ green , $ blue ) = $ this -> getcolors ( $ this -> image_background_color ) ; $ background_color = imagecolorallocate ( $ dst_im , $ red , $ green , $ blue ) ; imagefilledrectangle ( $ dst_im , 0 , 0 , $ x , $ y , $ background_color ) ; } return $ dst_im ; }
Creates a container image
9,520
function imagetransfer ( $ src_im , $ dst_im ) { if ( is_resource ( $ dst_im ) ) imagedestroy ( $ dst_im ) ; $ dst_im = & $ src_im ; return $ dst_im ; }
Transfers an image from the container to the destination image
9,521
function clean ( ) { $ this -> log .= '<b>cleanup</b><br />' ; $ this -> log .= '- delete temp file ' . $ this -> file_src_pathname . '<br />' ; @ unlink ( $ this -> file_src_pathname ) ; }
Deletes the uploaded file from its temporary location
9,522
function imagebmp ( & $ im , $ filename = "" ) { if ( ! $ im ) return false ; $ w = imagesx ( $ im ) ; $ h = imagesy ( $ im ) ; $ result = '' ; if ( ! imageistruecolor ( $ im ) ) { $ tmp = imagecreatetruecolor ( $ w , $ h ) ; imagecopy ( $ tmp , $ im , 0 , 0 , 0 , 0 , $ w , $ h ) ; imagedestroy ( $ im ) ; $ im = & $ tmp ; } $ biBPLine = $ w * 3 ; $ biStride = ( $ biBPLine + 3 ) & ~ 3 ; $ biSizeImage = $ biStride * $ h ; $ bfOffBits = 54 ; $ bfSize = $ bfOffBits + $ biSizeImage ; $ result .= substr ( 'BM' , 0 , 2 ) ; $ result .= pack ( 'VvvV' , $ bfSize , 0 , 0 , $ bfOffBits ) ; $ result .= pack ( 'VVVvvVVVVVV' , 40 , $ w , $ h , 1 , 24 , 0 , $ biSizeImage , 0 , 0 , 0 , 0 ) ; $ numpad = $ biStride - $ biBPLine ; for ( $ y = $ h - 1 ; $ y >= 0 ; -- $ y ) { for ( $ x = 0 ; $ x < $ w ; ++ $ x ) { $ col = imagecolorat ( $ im , $ x , $ y ) ; $ result .= substr ( pack ( 'V' , $ col ) , 0 , 3 ) ; } for ( $ i = 0 ; $ i < $ numpad ; ++ $ i ) $ result .= pack ( 'C' , 0 ) ; } if ( $ filename == "" ) { echo $ result ; } else { $ file = fopen ( $ filename , "wb" ) ; fwrite ( $ file , $ result ) ; fclose ( $ file ) ; } return true ; }
Saves a BMP image
9,523
public function initChunks ( ) { if ( ! $ this -> t_head ) { $ this -> t_head = $ this -> template -> cloneRegion ( 'Head' ) ; $ this -> t_row_master = $ this -> template -> cloneRegion ( 'Row' ) ; $ this -> t_totals = $ this -> template -> cloneRegion ( 'Totals' ) ; $ this -> t_empty = $ this -> template -> cloneRegion ( 'Empty' ) ; $ this -> template -> del ( 'Head' ) ; $ this -> template -> del ( 'Body' ) ; $ this -> template -> del ( 'Foot' ) ; } }
initChunks method will create one column object that will be used to render all columns in the table unless you have specified a different column object .
9,524
public function setFilterColumn ( $ cols = null ) { if ( ! $ this -> model ) { throw new Exception ( 'Model need to be defined in order to use column filtering.' ) ; } if ( ! $ cols ) { foreach ( $ this -> model -> elements as $ key => $ field ) { if ( isset ( $ this -> columns [ $ key ] ) && $ this -> columns [ $ key ] ) { $ cols [ ] = $ field -> short_name ; } } } foreach ( $ cols as $ colName ) { $ col = $ this -> columns [ $ colName ] ; if ( $ col ) { $ pop = $ col -> addPopup ( new FilterPopup ( [ 'field' => $ this -> model -> getElement ( $ colName ) , 'reload' => $ this -> reload , 'colTrigger' => '#' . $ col -> name . '_ac' ] ) ) ; $ pop -> isFilterOn ( ) ? $ col -> setHeaderPopupIcon ( 'green caret square down' ) : null ; $ pop -> form -> onSubmit ( function ( $ f ) use ( $ pop ) { return new jsReload ( $ this -> reload ) ; } ) ; $ this -> model = $ pop -> setFilterCondition ( $ this -> model ) ; } } }
Set Popup action for columns filtering .
9,525
public function addDecorator ( $ name , $ seed ) { if ( ! $ this -> columns [ $ name ] ) { throw new Exception ( [ 'No such column, cannot decorate' , 'name' => $ name ] ) ; } $ decorator = $ this -> _add ( $ this -> factory ( $ seed , [ 'table' => $ this ] , 'TableColumn' ) ) ; if ( ! is_array ( $ this -> columns [ $ name ] ) ) { $ this -> columns [ $ name ] = [ $ this -> columns [ $ name ] ] ; } $ this -> columns [ $ name ] [ ] = $ decorator ; return $ decorator ; }
Add column Decorator .
9,526
public function getColumnDecorators ( $ name ) { $ dec = $ this -> columns [ $ name ] ; return is_array ( $ dec ) ? $ dec : [ $ dec ] ; }
Return array of column decorators for particular column .
9,527
public function decoratorFactory ( \ atk4 \ data \ Field $ f , $ seed = [ ] ) { $ seed = $ this -> mergeSeeds ( $ seed , isset ( $ f -> ui [ 'table' ] ) ? $ f -> ui [ 'table' ] : null , isset ( $ this -> typeToDecorator [ $ f -> type ] ) ? $ this -> typeToDecorator [ $ f -> type ] : null , [ $ this -> default_column ? $ this -> default_column : 'Generic' ] ) ; return $ this -> _add ( $ this -> factory ( $ seed , [ 'table' => $ this ] , 'TableColumn' ) ) ; }
Will come up with a column object based on the field object supplied . By default will use default column .
9,528
public function resizableColumn ( $ fx = null , $ widths = null , $ resizerOptions = null ) { $ options = [ ] ; if ( $ fx && is_callable ( $ fx ) ) { $ cb = $ this -> add ( 'jsCallBack' ) ; $ cb -> set ( $ fx , [ 'widths' => 'widths' ] ) ; $ options [ 'uri' ] = $ cb -> getJSURL ( ) ; } elseif ( $ fx && is_array ( $ fx ) ) { $ widths = $ fx ; } if ( $ widths ) { $ options [ 'widths' ] = $ widths ; } if ( $ resizerOptions ) { $ options = array_merge ( $ options , $ resizerOptions ) ; } $ this -> js ( true , $ this -> js ( ) -> atkColumnResizer ( $ options ) ) ; return $ this ; }
Make columns resizable by dragging column header .
9,529
public function addJsPaginator ( $ ipp , $ options = [ ] , $ container = null , $ scrollRegion = 'Body' ) { $ options = array_merge ( $ options , [ 'appendTo' => 'tbody' ] ) ; return parent :: addJsPaginator ( $ ipp , $ options , $ container , $ scrollRegion ) ; }
Add a dynamic paginator i . e . when user is scrolling content .
9,530
public function setModel ( \ atk4 \ data \ Model $ m , $ columns = null ) { parent :: setModel ( $ m ) ; if ( $ columns === null ) { $ columns = [ ] ; foreach ( $ m -> elements as $ name => $ element ) { if ( ! $ element instanceof \ atk4 \ data \ Field ) { continue ; } if ( $ element -> isVisible ( ) ) { $ columns [ ] = $ name ; } } } elseif ( $ columns === false ) { return $ this -> model ; } foreach ( $ columns as $ column ) { $ this -> addColumn ( $ column ) ; } return $ this -> model ; }
Sets data Model of Table .
9,531
public function updateTotals ( ) { foreach ( $ this -> totals_plan as $ key => $ val ) { if ( is_array ( $ val ) ) { $ f = $ val [ 0 ] ; if ( ! isset ( $ this -> totals [ $ key ] ) ) { $ this -> totals [ $ key ] = 0 ; } if ( $ f instanceof \ Closure ) { $ this -> totals [ $ key ] += ( $ f ( $ this -> model [ $ key ] , $ key , $ this ) ? : 0 ) ; } elseif ( is_string ( $ f ) ) { switch ( $ f ) { case 'sum' : $ this -> totals [ $ key ] += $ this -> model [ $ key ] ; break ; case 'count' : $ this -> totals [ $ key ] += 1 ; break ; case 'min' : if ( $ this -> model [ $ key ] < $ this -> totals [ $ key ] ) { $ this -> totals [ $ key ] = $ this -> model [ $ key ] ; } break ; case 'max' : if ( $ this -> model [ $ key ] > $ this -> totals [ $ key ] ) { $ this -> totals [ $ key ] = $ this -> model [ $ key ] ; } break ; default : throw new Exception ( [ 'Aggregation method does not exist' , 'method' => $ f ] ) ; } } } } }
Executed for each row if totals are enabled to add up values .
9,532
public function getHeaderRowHTML ( ) { $ output = [ ] ; foreach ( $ this -> columns as $ name => $ column ) { if ( is_array ( $ column ) ) { $ column = $ column [ 0 ] ; } if ( ! is_int ( $ name ) ) { $ field = $ this -> model -> getElement ( $ name ) ; $ output [ ] = $ column -> getHeaderCellHTML ( $ field ) ; } else { $ output [ ] = $ column -> getHeaderCellHTML ( ) ; } } return implode ( '' , $ output ) ; }
Responds with the HTML to be inserted in the header row that would contain captions of all columns .
9,533
public function getTotalsRowHTML ( ) { $ output = [ ] ; foreach ( $ this -> columns as $ name => $ column ) { if ( ! isset ( $ this -> totals_plan [ $ name ] ) ) { $ output [ ] = $ column -> getTag ( 'foot' , '-' ) ; continue ; } if ( is_array ( $ this -> totals_plan [ $ name ] ) ) { $ field = $ this -> model -> getElement ( $ name ) ; $ output [ ] = $ column -> getTotalsCellHTML ( $ field , $ this -> totals [ $ name ] ) ; continue ; } $ output [ ] = $ column -> getTag ( 'foot' , $ this -> totals_plan [ $ name ] ) ; } return implode ( '' , $ output ) ; }
Responds with HTML to be inserted in the footer row that would contain totals for all columns .
9,534
public function getDataRowHTML ( ) { $ output = [ ] ; foreach ( $ this -> columns as $ name => $ column ) { if ( ! is_int ( $ name ) ) { $ field = $ this -> model -> getElement ( $ name ) ; } else { $ field = null ; } if ( ! is_array ( $ column ) ) { $ column = [ $ column ] ; } $ cell = null ; $ cnt = count ( $ column ) ; $ td_attr = [ ] ; foreach ( $ column as $ c ) { if ( -- $ cnt ) { $ html = $ c -> getDataCellTemplate ( $ field ) ; $ td_attr = $ c -> getTagAttributes ( 'body' , $ td_attr ) ; } else { $ html = $ c -> getDataCellHTML ( $ field , $ td_attr ) ; } if ( $ cell ) { if ( $ name ) { $ cell = str_replace ( '{$' . $ name . '}' , $ cell , $ html ) ; } else { $ cell = $ cell . ' ' . $ html ; } } else { $ cell = $ html ; } } $ output [ ] = $ cell ; } return implode ( '' , $ output ) ; }
Collects cell templates from all the columns and combine them into row template .
9,535
public function _typecastSaveField ( \ atk4 \ data \ Field $ f , $ value ) { if ( $ f -> serialize ) { $ value = $ this -> serializeSaveField ( $ f , $ value ) ; } $ v = is_object ( $ value ) ? clone $ value : $ value ; switch ( $ f -> type ) { case 'boolean' : return $ v ? $ this -> yes : $ this -> no ; case 'money' : return ( $ this -> currency ? $ this -> currency . ' ' : '' ) . number_format ( $ v , 2 ) ; case 'date' : case 'datetime' : case 'time' : $ dt_class = isset ( $ f -> dateTimeClass ) ? $ f -> dateTimeClass : 'DateTime' ; $ tz_class = isset ( $ f -> dateTimeZoneClass ) ? $ f -> dateTimeZoneClass : 'DateTimeZone' ; if ( $ v instanceof $ dt_class ) { $ format = [ 'date' => $ this -> date_format , 'datetime' => $ this -> datetime_format , 'time' => $ this -> time_format ] ; $ format = $ f -> persist_format ? : $ format [ $ f -> type ] ; if ( $ f -> type == 'datetime' && isset ( $ f -> persist_timezone ) ) { $ v -> setTimezone ( new $ tz_class ( $ f -> persist_timezone ) ) ; } $ v = $ v -> format ( $ format ) ; } break ; case 'array' : case 'object' : $ v = $ f -> serialize ? $ v : json_encode ( $ v ) ; break ; } return $ v ; }
This method contains the logic of casting generic values into user - friendly format .
9,536
public function _typecastLoadField ( \ atk4 \ data \ Field $ f , $ value ) { if ( $ f -> serialize && $ value ) { try { $ new_value = $ this -> serializeLoadField ( $ f , $ value ) ; } catch ( \ Exception $ e ) { throw new Exception ( [ 'Value must be ' . $ f -> serialize , 'serializator' => $ f -> serialize , 'value' => $ value , 'field' => $ f , ] ) ; } $ value = $ new_value ; } switch ( $ f -> type ) { case 'string' : case 'text' : $ value = str_replace ( [ "\r\n" , "\r" ] , "\n" , $ value ) ; break ; case 'boolean' : $ value = ( bool ) $ value ; break ; case 'money' : return str_replace ( ',' , '' , $ value ) ; case 'date' : case 'datetime' : case 'time' : $ dt_class = isset ( $ f -> dateTimeClass ) ? $ f -> dateTimeClass : 'DateTime' ; $ tz_class = isset ( $ f -> dateTimeZoneClass ) ? $ f -> dateTimeZoneClass : 'DateTimeZone' ; $ format = [ 'date' => '!+' . $ this -> date_format , 'datetime' => '!+' . $ this -> datetime_format , 'time' => '!+' . $ this -> time_format ] ; $ format = $ f -> persist_format ? : $ format [ $ f -> type ] ; if ( $ f -> type == 'datetime' && isset ( $ f -> persist_timezone ) ) { $ v = $ dt_class :: createFromFormat ( $ format , $ value , new $ tz_class ( $ f -> persist_timezone ) ) ; if ( $ v === false ) { throw new Exception ( [ 'Incorrectly formatted datetime' , 'format' => $ format , 'value' => $ value , 'field' => $ f ] ) ; } $ v -> setTimeZone ( new $ tz_class ( date_default_timezone_get ( ) ) ) ; return $ v ; } else { $ v = $ dt_class :: createFromFormat ( $ format , $ value ) ; if ( $ v === false ) { throw new Exception ( [ 'Incorrectly formatted date/time' , 'format' => $ format , 'value' => $ value , 'field' => $ f ] ) ; } return $ v ; } break ; } if ( isset ( $ f -> reference ) ) { if ( empty ( $ value ) ) { $ value = null ; } } return $ value ; }
Interpret user - defined input for various types .
9,537
public static function factoryType ( $ field ) { $ data = [ ] ; $ persistence = new Persistence_Array ( $ data ) ; $ filterDomain = 'atk4\\ui\\TableColumn\\FilterModel\Type' ; if ( empty ( $ type = $ field -> type ) ) { $ type = 'string' ; } $ class = $ filterDomain . ucfirst ( $ type ) ; if ( ! empty ( $ field -> filterModel ) && isset ( $ field -> filterModel ) ) { if ( $ field -> filterModel instanceof Model ) { return $ field -> filterModel ; } $ class = $ field -> filterModel ; } return new $ class ( $ persistence , [ 'lookupField' => $ field ] ) ; }
Factory method that will return a FilerModel Type class .
9,538
public function afterInit ( ) { $ this -> addField ( 'name' , [ 'default' => $ this -> lookupField -> short_name , 'system' => true ] ) ; if ( isset ( $ this -> _sessionTrait ) && $ this -> _sessionTrait ) { $ this -> name = 'filter_model_' . $ this -> lookupField -> short_name ; if ( @ $ _GET [ 'atk_clear_filter' ] ) { $ this -> forget ( ) ; } if ( $ data = $ this -> recallData ( ) ) { $ this -> persistence -> data [ 'data' ] [ ] = $ data ; } $ this -> addHook ( 'afterSave' , function ( $ m ) { $ this -> memorize ( 'data' , $ m -> get ( ) ) ; } ) ; } }
Perform further initialisation .
9,539
protected function addTabMenuItem ( $ name ) { if ( is_object ( $ name ) ) { $ tab = $ name ; } else { $ tab = new Tab ( $ name ) ; } $ tab = $ this -> add ( [ $ tab , 'class' => [ 'item' ] ] , 'Menu' ) -> setElement ( 'a' ) -> setAttr ( 'data-tab' , $ tab -> name ) ; if ( empty ( $ this -> activeTabName ) ) { $ this -> activeTabName = $ tab -> name ; } return $ tab ; }
Add a tab menu item .
9,540
public function setTransition ( $ openTransition , $ closeTransition = null ) { $ this -> options [ 'openTransition' ] = $ openTransition ; if ( $ closeTransition ) { $ this -> options [ 'closeTransition' ] = $ closeTransition ; } return $ this ; }
Set open and close transition for the notifier . - any transition define in semantic ui can be used .
9,541
public function jsRender ( ) { if ( $ this -> attachTo ) { $ final = $ this -> attachTo -> js ( ) ; } else { $ final = new jsChain ( ) ; } $ final -> atkNotify ( $ this -> options ) ; return $ final -> jsRender ( ) ; }
Render the notifier .
9,542
public function set ( $ fx = [ ] , $ arg2 = null ) { if ( ! is_object ( $ fx ) && ! ( $ fx instanceof Closure ) ) { throw new Exception ( 'Error: Need to pass a function to Modal::set()' ) ; } $ this -> fx = [ $ fx ] ; $ this -> enableCallback ( ) ; return $ this ; }
Set callback function for this modal .
9,543
public function enableCallback ( ) { $ this -> cb_view = $ this -> add ( 'View' ) ; $ this -> cb_view -> stickyGet ( '__atk_m' , $ this -> name ) ; $ this -> cb = $ this -> cb_view -> add ( 'CallbackLater' ) ; $ this -> cb -> set ( function ( ) { if ( $ this -> cb -> triggered ( ) && $ this -> fx ) { $ this -> fx [ 0 ] ( $ this -> cb_view ) ; } $ modalName = isset ( $ _GET [ '__atk_m' ] ) ? $ _GET [ '__atk_m' ] : null ; if ( $ modalName === $ this -> name ) { $ this -> app -> terminate ( $ this -> cb_view -> renderJSON ( ) ) ; } } ) ; }
Add View to be loaded in this modal and attach CallbackLater to it . The cb_view only will be loaded dynamically within modal div . atk - content .
9,544
public function setOptions ( $ options ) { if ( isset ( $ this -> options [ 'modal_option' ] ) ) { $ this -> options [ 'modal_option' ] = array_merge ( $ this -> options [ 'modal_option' ] , $ options ) ; } else { $ this -> options [ 'modal_option' ] = $ options ; } return $ this ; }
Set modal options passing an array .
9,545
public function addDenyAction ( $ label , $ jsAction ) { $ b = new Button ( ) ; $ b -> set ( $ label ) -> addClass ( 'red cancel' ) ; $ this -> addButtonAction ( $ b ) ; $ this -> options [ 'modal_option' ] [ 'onDeny' ] = $ jsAction ; return $ this ; }
Add a deny action to modal .
9,546
public function onScroll ( $ fx = null ) { if ( is_callable ( $ fx ) ) { if ( $ this -> triggered ( ) ) { $ page = $ this -> getPage ( ) ; $ this -> set ( function ( ) use ( $ fx , $ page ) { return call_user_func_array ( $ fx , [ $ page ] ) ; } ) ; } } }
Callback when container has been scroll to bottom .
9,547
public function sendEvent ( $ id , $ data , $ eventName ) { $ this -> sendBlock ( $ id , $ data , $ eventName ) ; $ this -> flush ( ) ; }
Output a SSE Event .
9,548
protected function getModelFields ( \ atk4 \ data \ Model $ model ) { $ fields = [ ] ; foreach ( $ model -> elements as $ f ) { if ( ! $ f instanceof \ atk4 \ data \ Field ) { continue ; } if ( $ f -> isEditable ( ) || $ f -> isVisible ( ) ) { $ fields [ ] = $ f -> short_name ; } } return $ fields ; }
Returns array of names of fields to automatically include them in form . This includes all editable or visible fields of the model .
9,549
public function getField ( $ name ) { if ( empty ( $ this -> form ) ) { throw new Exception ( [ 'Incorrect value for $form' , 'form' => $ this -> form ] ) ; } return $ this -> form -> getField ( $ name ) ; }
Return Field decorator associated with the form s field .
9,550
protected function initDropdown ( $ chain ) { $ settings = array_merge ( [ 'fields' => [ 'name' => 'name' , 'value' => 'id' ] , 'apiSettings' => array_merge ( [ 'url' => $ this -> getCallbackURL ( ) . '&q={query}' ] , $ this -> apiConfig ) , ] , $ this -> settings ) ; $ chain -> dropdown ( $ settings ) ; }
Override this method if you want to add more logic to the initialization of the auto - complete field .
9,551
public function & getTagRef ( $ tag ) { if ( $ this -> isTopTag ( $ tag ) ) { return $ this -> template ; } $ a = explode ( '#' , $ tag ) ; $ tag = array_shift ( $ a ) ; if ( ! isset ( $ this -> tags [ $ tag ] ) ) { throw $ this -> exception ( 'Tag not found in Template' ) -> addMoreInfo ( 'tag' , $ tag ) -> addMoreInfo ( 'tags' , implode ( ', ' , array_keys ( $ this -> tags ) ) ) ; } reset ( $ this -> tags [ $ tag ] ) ; $ key = key ( $ this -> tags [ $ tag ] ) !== null ? key ( $ this -> tags [ $ tag ] ) : null ; return $ this -> tags [ $ tag ] [ $ key ] ; }
This is a helper method which returns reference to element of template array referenced by a said tag .
9,552
public function hasTag ( $ tag ) { if ( is_array ( $ tag ) ) { foreach ( $ tag as $ t ) { if ( ! $ this -> hasTag ( $ t ) ) { return false ; } } return true ; } $ a = explode ( '#' , $ tag ) ; $ tag = array_shift ( $ a ) ; return isset ( $ this -> tags [ $ tag ] ) || $ this -> isTopTag ( $ tag ) ; }
Checks if template has defined a specified tag . If multiple tags are passed in as array then return true if all of them exist .
9,553
protected function rebuildTagsRegion ( & $ template ) { foreach ( $ template as $ tag => & $ val ) { if ( is_numeric ( $ tag ) ) { continue ; } $ a = explode ( '#' , $ tag ) ; $ key = array_shift ( $ a ) ; $ ref = array_shift ( $ a ) ; $ this -> tags [ $ key ] [ $ ref ] = & $ val ; if ( is_array ( $ val ) ) { $ this -> rebuildTagsRegion ( $ val ) ; } } }
Add tags from a specified region .
9,554
public function setHTML ( $ tag , $ value = null ) { return $ this -> _setOrAppend ( $ tag , $ value , false , false , true ) ; }
Set value of a tag to a HTML content . The value is set without encoding so you must be sure to sanitize .
9,555
public function appendHTML ( $ tag , $ value ) { return $ this -> _setOrAppend ( $ tag , $ value , false , true , true ) ; }
Add more content inside a tag . The content is appended without encoding so you must be sure to sanitize .
9,556
public function eachTag ( $ tag , $ callable ) { if ( ! $ this -> hasTag ( $ tag ) ) { return $ this ; } if ( is_array ( $ tag ) ) { foreach ( $ tag as $ t ) { $ this -> eachTag ( $ t , $ callable ) ; } return $ this ; } $ template = $ this -> getTagRefList ( $ tag ) ; if ( $ template != $ this -> template ) { foreach ( $ template as $ key => $ templ ) { $ ref = $ tag . '#' . ( $ key + 1 ) ; $ this -> tags [ $ tag ] [ $ key ] = [ call_user_func ( $ callable , $ this -> recursiveRender ( $ templ ) , $ ref ) ] ; } } else { $ this -> tags [ $ tag ] [ 0 ] = [ call_user_func ( $ callable , $ this -> recursiveRender ( $ template ) , $ tag ) ] ; } return $ this ; }
Executes call - back for each matching tag in the template .
9,557
public function cloneRegion ( $ tag ) { if ( $ this -> isTopTag ( $ tag ) ) { return clone $ this ; } $ cl = get_class ( $ this ) ; $ n = new $ cl ( ) ; $ n -> app = $ this -> app ; $ n -> template = unserialize ( serialize ( [ '_top#1' => $ this -> get ( $ tag ) ] ) ) ; $ n -> rebuildTags ( ) ; $ n -> source = 'clone (' . $ tag . ') of template ' . $ this -> source ; return $ n ; }
Creates a new template using portion of existing template .
9,558
public function load ( $ filename ) { if ( $ t = $ this -> tryLoad ( $ filename ) ) { return $ t ; } throw new Exception ( [ 'Unable to read template from file' , 'cwd' => getcwd ( ) , 'file' => $ filename , ] ) ; }
Loads template from a specified file .
9,559
public function loadTemplateFromString ( $ str ) { $ this -> source = 'string: ' . $ str ; $ this -> template = $ this -> tags = [ ] ; if ( ! $ str ) { return ; } $ this -> tag_cnt = [ ] ; $ str = preg_replace ( '/{\$([-_:\w]+)}/' , '{\1}{/\1}' , $ str ) ; $ this -> parseTemplate ( $ str ) ; return $ this ; }
Initialize current template from the supplied string .
9,560
protected function parseTemplateRecursive ( & $ input , & $ template ) { if ( ! is_array ( $ input ) || empty ( $ input ) ) { return ; } while ( true ) { $ tag = current ( $ input ) ; next ( $ input ) ; if ( $ tag === false ) { break ; } $ firstChar = substr ( $ tag , 0 , 1 ) ; switch ( $ firstChar ) { case '/' : return substr ( $ tag , 1 ) ; break ; case '$' : $ tag = substr ( $ tag , 1 ) ; $ full_tag = $ this -> regTag ( $ tag ) ; $ template [ $ full_tag ] = '' ; $ this -> tags [ $ tag ] [ ] = & $ template [ $ full_tag ] ; $ chunk = current ( $ input ) ; next ( $ input ) ; if ( $ chunk !== false && $ chunk !== null ) { $ template [ ] = $ chunk ; } break ; default : $ full_tag = $ this -> regTag ( $ tag ) ; $ prefix = current ( $ input ) ; next ( $ input ) ; $ template [ $ full_tag ] = ( $ prefix === false || $ prefix === null ) ? [ ] : [ $ prefix ] ; $ this -> tags [ $ tag ] [ ] = & $ template [ $ full_tag ] ; $ this -> parseTemplateRecursive ( $ input , $ template [ $ full_tag ] ) ; $ chunk = current ( $ input ) ; next ( $ input ) ; if ( $ chunk !== false && ! empty ( $ chunk ) ) { $ template [ ] = $ chunk ; } break ; } } }
Recursively find nested tags inside a string converting them to array .
9,561
protected function parseTemplate ( $ str ) { $ tag = '/{([\/$]?[-_:\w]*)}/' ; $ input = preg_split ( $ tag , $ str , - 1 , PREG_SPLIT_DELIM_CAPTURE ) ; $ prefix = current ( $ input ) ; next ( $ input ) ; $ this -> template = [ $ prefix ] ; $ this -> parseTemplateRecursive ( $ input , $ this -> template ) ; }
Deploys parse recursion .
9,562
public function render ( $ region = null ) { if ( $ region ) { return $ this -> recursiveRender ( $ this -> get ( $ region ) ) ; } return $ this -> recursiveRender ( $ this -> template ) ; }
Render either a whole template or a specified region . Returns current contents of a template .
9,563
protected function recursiveRender ( $ template ) { $ output = '' ; foreach ( $ template as $ val ) { if ( is_array ( $ val ) ) { $ output .= $ this -> recursiveRender ( $ val ) ; } else { $ output .= $ val ; } } return $ output ; }
Walk through the template array collecting the values and returning them as a string .
9,564
public function onSelectItem ( $ fx ) { if ( is_callable ( $ fx ) ) { if ( $ this -> triggered ( ) ) { $ param = [ $ _GET [ 'id' ] , @ $ _GET [ 'item' ] ] ; $ this -> set ( function ( ) use ( $ fx , $ param ) { return call_user_func_array ( $ fx , $ param ) ; } ) ; } } }
Function to call when header menu item is select .
9,565
public function addSection ( $ title , $ callback = null , $ icon = 'dropdown' ) { $ section = parent :: addSection ( $ title , $ callback , $ icon ) ; return $ section -> add ( [ $ this -> formLayout , 'form' => $ this -> form ] ) ; }
Return an accordion section with a form layout associate with a form .
9,566
public function getSectionIdx ( $ section ) { if ( $ section instanceof \ atk4 \ ui \ AccordionSection ) { return parent :: getSectionIdx ( $ section ) ; } return parent :: getSectionIdx ( $ section -> owner ) ; }
Return a section index .
9,567
public function addJsPaginator ( $ ipp , $ options = [ ] , $ container = null , $ scrollRegion = null ) { $ this -> ipp = $ ipp ; $ this -> jsPaginator = $ this -> add ( [ 'jsPaginator' , 'view' => $ container , 'options' => $ options ] ) ; $ this -> model -> setLimit ( $ ipp ) ; $ this -> jsPaginator -> onScroll ( function ( $ p ) use ( $ ipp , $ scrollRegion ) { $ this -> model -> setLimit ( $ ipp , ( $ p - 1 ) * $ ipp ) ; $ json = $ this -> renderJSON ( true , $ scrollRegion ) ; if ( $ this -> _rendered_rows_count < $ ipp ) { $ json = json_decode ( $ json , true ) ; $ json [ 'message' ] = 'Done' ; $ json = json_encode ( $ json ) ; } $ this -> app -> terminate ( $ json ) ; } ) ; return $ this ; }
Add Dynamic paginator when scrolling content via Javascript . Will output x item in lister set per ipp until user scroll content to the end of page . When this happen content will be reload x number of items .
9,568
public function onReorder ( $ fx = null ) { if ( is_callable ( $ fx ) ) { if ( $ this -> triggered ( ) ) { $ sortOrders = explode ( ',' , @ $ _POST [ 'order' ] ) ; $ source = @ $ _POST [ 'source' ] ; $ newIdx = @ $ _POST [ 'new_idx' ] ; $ orgIdx = @ $ _POST [ 'org_idx' ] ; $ this -> set ( function ( ) use ( $ fx , $ sortOrders , $ source , $ newIdx , $ orgIdx ) { return call_user_func_array ( $ fx , [ $ sortOrders , $ source , $ newIdx , $ orgIdx ] ) ; } ) ; } } }
Callback when container has been reorder .
9,569
public function createAtkVue ( $ id , $ component , $ data = [ ] ) { return $ this -> service -> createAtkVue ( $ id , $ component , $ data ) ; }
Create a new Vue instance using a component managed by ATK .
9,570
public function createVue ( $ id , $ componentName , $ component , $ data = [ ] ) { return $ this -> service -> createVue ( $ id , $ componentName , $ component , $ data ) ; }
Create a new Vue instance using an external component . External component should be load via js file and define properly .
9,571
public function addCrumb ( $ section = null , $ link = null ) { if ( is_array ( $ link ) ) { $ link = $ this -> url ( $ link ) ; } $ this -> path [ ] = [ 'section' => $ section , 'link' => $ link , 'divider' => $ this -> dividerClass ] ; }
Adds a new link that will appear on the right .
9,572
public function addCrumbReverse ( $ section = null , $ link = null ) { array_unshift ( $ this -> path , [ 'section' => $ section , 'link' => $ link ] ) ; }
Adds a new link that will appear on the left .
9,573
protected function buildTemplate ( ) { $ this -> t_wrap -> del ( 'rows' ) ; $ this -> t_wrap -> appendHTML ( 'rows' , '{rows}' ) ; for ( $ row = 1 ; $ row <= $ this -> rows ; $ row ++ ) { $ this -> t_row -> del ( 'column' ) ; for ( $ col = 1 ; $ col <= $ this -> columns ; $ col ++ ) { $ this -> t_col -> set ( 'Content' , '{$r' . $ row . 'c' . $ col . '}' ) ; $ this -> t_row -> appendHTML ( 'column' , $ this -> t_col -> render ( ) ) ; } $ this -> t_wrap -> appendHTML ( 'rows' , $ this -> t_row -> render ( ) ) ; } $ this -> t_wrap -> appendHTML ( 'rows' , '{/rows}' ) ; $ tmp = new Template ( $ this -> t_wrap -> render ( ) ) ; $ this -> template -> template [ 'rows#1' ] = $ tmp -> template [ 'rows#1' ] ; $ this -> template -> rebuildTags ( ) ; $ this -> addClass ( $ this -> words [ $ this -> columns ] . ' column' ) ; }
Build and set view template .
9,574
public function set ( $ callback = null , $ event = null ) { if ( ! $ callback ) { throw new Exception ( 'Please specify the $callback argument' ) ; } if ( isset ( $ event ) ) { $ this -> event = $ event ; } $ this -> sse = $ this -> add ( 'jsSSE' ) ; $ this -> sse -> set ( function ( ) use ( $ callback ) { $ this -> sseInProgress = true ; if ( isset ( $ this -> app ) ) { $ old_logger = $ this -> app -> logger ; $ this -> app -> logger = $ this ; } try { ob_start ( function ( $ content ) { if ( $ this -> _output_bypass ) { return $ content ; } $ output = '' ; $ this -> sse -> echoFunction = function ( $ str ) use ( & $ output ) { $ output .= $ str ; } ; $ this -> output ( $ content ) ; $ this -> sse -> echoFunction = false ; return $ output ; } , 2 ) ; call_user_func ( $ callback , $ this ) ; } catch ( \ atk4 \ core \ Exception $ e ) { $ lines = explode ( "\n" , $ e -> getHTMLText ( ) ) ; foreach ( $ lines as $ line ) { $ this -> outputHTML ( $ line ) ; } } catch ( \ Error $ e ) { $ this -> output ( 'Error: ' . $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { $ this -> output ( 'Exception: ' . $ e -> getMessage ( ) ) ; } if ( isset ( $ this -> app ) ) { $ this -> app -> logger = $ old_logger ; } $ this -> sseInProgress = false ; } ) ; if ( $ this -> event ) { $ this -> js ( $ this -> event , $ this -> jsExecute ( ) ) ; } return $ this ; }
Set a callback method which will be executed with the output sent back to the terminal .
9,575
public function outputHTML ( $ message , $ context = [ ] ) { $ message = preg_replace_callback ( '/{([a-z0-9_-]+)}/i' , function ( $ match ) use ( $ context ) { if ( isset ( $ context [ $ match [ 1 ] ] ) && is_string ( $ context [ $ match [ 1 ] ] ) ) { return $ context [ $ match [ 1 ] ] ; } return '{' . $ match [ 1 ] . '}' ; } , $ message ) ; $ this -> _output_bypass = true ; $ this -> sse -> send ( $ this -> js ( ) -> append ( $ message . '<br/>' ) ) ; $ this -> _output_bypass = false ; return $ this ; }
Output un - escaped HTML line . Use this to send HTML .
9,576
public function send ( $ js ) { $ this -> _output_bypass = true ; $ this -> sse -> send ( $ js ) ; $ this -> _output_bypass = false ; return $ this ; }
Executes a JavaScript action .
9,577
public function exec ( $ exec , $ args = [ ] ) { if ( ! $ this -> sseInProgress ) { $ this -> set ( function ( ) use ( $ exec , $ args ) { $ a = $ args ? ( ' with ' . count ( $ args ) . ' arguments' ) : '' ; $ this -> output ( '--[ Executing ' . $ exec . $ a . ' ]--------------' ) ; $ this -> exec ( $ exec , $ args ) ; $ this -> output ( '--[ Exit code: ' . $ this -> last_exit_code . ' ]------------' ) ; } ) ; return ; } list ( $ proc , $ pipes ) = $ this -> execRaw ( $ exec , $ args ) ; stream_set_blocking ( $ pipes [ 1 ] , false ) ; stream_set_blocking ( $ pipes [ 2 ] , false ) ; while ( $ pipes ) { $ read = $ pipes ; $ j1 = $ j2 = null ; if ( stream_select ( $ read , $ j1 , $ j2 , 2 ) === false ) { throw new Exception ( [ 'stream_select() returned false.' ] ) ; } $ stat = proc_get_status ( $ proc ) ; if ( ! $ stat [ 'running' ] ) { proc_close ( $ proc ) ; break ; } foreach ( $ read as $ f ) { $ data = fgets ( $ f ) ; $ data = rtrim ( $ data ) ; if ( ! $ data ) { continue ; } if ( $ f === $ pipes [ 2 ] ) { $ this -> warning ( $ data ) ; } else { $ this -> output ( $ data ) ; } } } $ this -> last_exit_code = $ stat [ 'exitcode' ] ; return $ this -> last_exit_code ? false : $ this ; }
Executes command passing along escaped arguments .
9,578
public function set ( $ fx = null , $ arg2 = null ) { if ( ! is_object ( $ fx ) && ! ( $ fx instanceof Closure ) ) { throw new Exception ( 'Error: Need to pass a function to Popup::set()' ) ; } if ( $ arg2 ) { throw new Exception ( 'Only one argument is needed by Popup::set()' ) ; } $ this -> cb = $ this -> add ( 'Callback' ) ; if ( ! $ this -> minWidth ) { $ this -> minWidth = '120px' ; } if ( ! $ this -> minHeight ) { $ this -> minHeight = '60px' ; } if ( $ this -> cb -> triggered ( ) ) { $ content = $ this -> add ( $ this -> dynamicContent ) ; $ this -> cb -> set ( $ fx , [ $ content ] ) ; $ this -> app -> terminate ( $ content -> renderJSON ( ) ) ; } }
Set callback for loading content dynamically . Callback will reveive a view attach to this popup for adding content to it .
9,579
public function jsPopup ( ) { $ name = $ this -> triggerBy ; if ( ! is_string ( $ this -> triggerBy ) ) { $ name = '#' . $ this -> triggerBy -> name ; if ( $ this -> triggerBy instanceof FormField \ Generic ) { $ name = '#' . $ this -> triggerBy -> name . '_input' ; } } $ chain = new jQuery ( $ name ) ; $ chain -> popup ( $ this -> popOptions ) ; if ( $ this -> stopClickEvent ) { $ chain -> on ( 'click' , new jsExpression ( 'function(e){e.stopPropagation();}' ) ) ; } return $ chain ; }
Return js action need to display popup . When a grid is reloading this method can be call in order to display the popup once again .
9,580
public function setThumbnailSrc ( $ src ) { $ this -> thumbnail -> setAttr ( [ 'src' => $ src ] ) ; $ action = $ this -> thumbnail -> js ( ) ; $ action -> attr ( 'src' , $ src ) ; $ this -> addJSAction ( $ action ) ; }
Set the thumbnail img src value .
9,581
public function clearThumbnail ( $ defaultThumbnail = null ) { $ action = $ this -> thumbnail -> js ( ) ; if ( isset ( $ defaultThumbnail ) ) { $ action -> attr ( 'src' , $ defaultThumbnail ) ; } else { $ action -> removeAttr ( 'src' ) ; } $ this -> addJSAction ( $ action ) ; }
Clear the thumbnail src . You can also supply a default thumbnail src .
9,582
private function _renderArgs ( $ args = [ ] ) { return '(' . implode ( ',' , array_map ( function ( $ arg ) { if ( $ arg instanceof jsExpressionable ) { return $ arg -> jsRender ( ) ; } return $ this -> _json_encode ( $ arg ) ; } , $ args ) ) . ')' ; }
Renders JS chain arguments .
9,583
public function jsRender ( ) { $ ret = '' ; $ ret .= $ this -> _library ; if ( $ this -> _constructorArgs ) { $ ret .= $ this -> _renderArgs ( $ this -> _constructorArgs ) ; } foreach ( $ this -> _chain as $ chain ) { if ( is_array ( $ chain ) ) { $ ret .= '.' . $ chain [ 0 ] . $ this -> _renderArgs ( $ chain [ 1 ] ) ; } elseif ( is_numeric ( $ chain ) ) { $ ret .= '[' . $ chain . ']' ; } else { $ ret .= '.' . $ chain ; } } return $ ret ; }
Produce String representing this JavaScript extension .
9,584
public function flatternArray ( $ response ) { if ( ! is_array ( $ response ) ) { return [ $ response ] ; } $ out = [ ] ; foreach ( $ response as $ element ) { $ out = array_merge ( $ out , $ this -> flatternArray ( $ element ) ) ; } return $ out ; }
When multiple jsExpressionable s are collected inside an array and may have some degree of nesting convert it into a one - dimensional array so that it s easier for us to wrap it into a function body .
9,585
public function terminate ( $ ajaxec , $ msg = null , $ success = true ) { $ this -> app -> terminate ( json_encode ( [ 'success' => $ success , 'message' => $ msg , 'atkjs' => $ ajaxec ] ) ) ; }
A proper way to finish execution of AJAX response . Generates JSON which is returned to frontend .
9,586
public function set ( $ fx = [ ] , $ args = null ) { if ( ! is_callable ( $ fx ) ) { throw new Exception ( 'Error: Need to pass a callable function to Loader::set()' ) ; } $ this -> cb -> set ( function ( ) use ( $ fx ) { call_user_func ( $ fx , $ this ) ; $ this -> app -> terminate ( $ this -> renderJSON ( ) ) ; } ) ; return $ this ; }
Set callback function for this loader .
9,587
public function renderView ( ) { if ( ! $ this -> cb -> triggered ( ) ) { if ( $ this -> loadEvent ) { $ this -> js ( $ this -> loadEvent , $ this -> jsLoad ( ) ) ; } $ this -> add ( $ this -> shim ) ; } return parent :: renderView ( ) ; }
Automatically call the jsLoad on a supplied event unless it was already triggered or if user have invoked jsLoad manually .
9,588
public function addSection ( $ title , $ callback = null , $ icon = 'dropdown' ) { $ section = $ this -> add ( [ 'AccordionSection' , 'title' => $ title , 'icon' => $ icon ] ) ; if ( $ callback ) { $ section -> virtualPage = $ section -> add ( [ 'VirtualPage' , 'ui' => '' ] ) ; $ section -> virtualPage -> stickyGet ( '__atk-dyn-section' , '1' ) ; $ section -> virtualPage -> set ( $ callback ) ; } $ this -> sections [ ] = $ section ; return $ section ; }
Add an accordion section . You can add static View within your section or pass a callback for dynamic content .
9,589
public function getSectionIdx ( $ section ) { $ idx = - 1 ; foreach ( $ this -> sections as $ key => $ accordion_section ) { if ( $ accordion_section -> name === $ section -> name ) { $ idx = $ key ; break ; } } return $ idx ; }
Return the index of an accordion section in collection .
9,590
public function addMenu ( $ name ) { if ( is_array ( $ name ) ) { $ label = $ name [ 0 ] ; unset ( $ name [ 0 ] ) ; } else { $ label = $ name ; $ name = [ ] ; } $ sub_menu = $ this -> add ( [ new self ( ) , 'defaultTemplate' => 'submenu.html' , 'ui' => 'dropdown' , 'in_dropdown' => true ] ) ; $ sub_menu -> set ( 'label' , $ label ) ; if ( isset ( $ name [ 'icon' ] ) && $ name [ 'icon' ] ) { $ sub_menu -> add ( new Icon ( $ name [ 'icon' ] ) , 'Icon' ) -> removeClass ( 'item' ) ; } if ( ! $ this -> in_dropdown ) { $ sub_menu -> js ( true ) -> dropdown ( [ 'on' => 'hover' , 'action' => 'hide' ] ) ; } return $ sub_menu ; }
Adds sub - menu .
9,591
public function addGroup ( $ title ) { $ group = $ this -> add ( [ new self ( ) , 'defaultTemplate' => 'menugroup.html' , 'ui' => false ] ) ; if ( is_string ( $ title ) ) { $ group -> set ( 'title' , $ title ) ; } else { if ( isset ( $ title [ 'icon' ] ) && $ title [ 'icon' ] ) { $ group -> add ( new Icon ( $ title [ 'icon' ] ) , 'Icon' ) -> removeClass ( 'item' ) ; } $ group -> set ( 'title' , $ title [ 0 ] ) ; } return $ group ; }
Adds menu group .
9,592
public function addMenuRight ( ) { $ menu = $ this -> add ( [ new self ( ) , 'ui' => false ] , 'RightMenu' ) ; $ menu -> removeClass ( 'item' ) -> addClass ( 'right menu' ) ; return $ menu ; }
Add right positioned menu .
9,593
public function add ( $ object , $ region = null ) { $ item = parent :: add ( $ object , $ region ) ; $ item -> addClass ( 'item' ) ; return $ item ; }
Add Item .
9,594
public function setModel ( \ atk4 \ data \ Model $ m , $ defaultFields = null ) { if ( $ defaultFields !== null ) { $ this -> fieldsDefault = $ defaultFields ; } parent :: setModel ( $ m , $ this -> fieldsRead ? : $ this -> fieldsDefault ) ; $ this -> model -> unload ( ) ; if ( $ this -> canCreate ) { $ this -> initCreate ( ) ; } if ( $ this -> canUpdate ) { $ this -> initUpdate ( ) ; } if ( $ this -> canDelete ) { $ this -> initDelete ( ) ; } return $ this -> model ; }
Sets data model of CRUD .
9,595
public function initCreate ( ) { if ( ! $ this -> itemCreate ) { $ this -> itemCreate = $ this -> menu -> addItem ( $ this -> itemCreate ? : [ 'Add new' , 'icon' => 'plus' ] ) ; $ this -> itemCreate -> on ( 'click.atk_CRUD' , new jsModal ( 'Add new' , $ this -> pageCreate , [ $ this -> name . '_sort' => $ this -> getSortBy ( ) ] ) ) ; $ this -> itemCreate -> set ( 'Add New ' . $ this -> model -> getModelCaption ( ) ) ; } $ this -> pageCreate -> set ( function ( ) { if ( ! is_object ( $ this -> formCreate ) || ! $ this -> formCreate -> _initialized ) { $ this -> formCreate = $ this -> pageCreate -> add ( $ this -> formCreate ? : $ this -> formDefault ) ; } $ this -> formCreate -> setModel ( $ this -> model , $ this -> fieldsCreate ? : $ this -> fieldsDefault ) ; if ( $ sortBy = $ this -> getSortBy ( ) ) { $ this -> formCreate -> stickyGet ( $ this -> name . '_sort' , $ sortBy ) ; } if ( ! $ this -> formCreate -> hookHasCallbacks ( 'submit' ) ) { $ this -> formCreate -> onSubmit ( function ( $ form ) { $ form -> model -> save ( ) ; return $ this -> jsSaveCreate ( ) ; } ) ; } } ) ; }
Initializes interface elements for new record creation .
9,596
public function initUpdate ( ) { $ this -> addAction ( [ 'icon' => 'edit' ] , new jsModal ( 'Edit' , $ this -> pageUpdate , [ $ this -> name => $ this -> jsRow ( ) -> data ( 'id' ) , $ this -> name . '_sort' => $ this -> getSortBy ( ) ] ) ) ; $ this -> pageUpdate -> set ( function ( ) { $ this -> model -> load ( $ this -> app -> stickyGet ( $ this -> name ) ) ; if ( ! is_object ( $ this -> formUpdate ) || ! $ this -> formUpdate -> _initialized ) { $ this -> formUpdate = $ this -> pageUpdate -> add ( $ this -> formUpdate ? : $ this -> formDefault ) ; } $ this -> formUpdate -> setModel ( $ this -> model , $ this -> fieldsUpdate ? : $ this -> fieldsDefault ) ; if ( $ sortBy = $ this -> getSortBy ( ) ) { $ this -> formUpdate -> stickyGet ( $ this -> name . '_sort' , $ sortBy ) ; } if ( ! $ this -> formUpdate -> hookHasCallbacks ( 'submit' ) ) { $ this -> formUpdate -> onSubmit ( function ( $ form ) { $ form -> model -> save ( ) ; return $ this -> jsSaveUpdate ( ) ; } ) ; } } ) ; }
Initializes interface elements for editing records .
9,597
public function jsSave ( $ notifier ) { return [ new jsExpression ( '$(".atk-dialog-content").trigger("close")' ) , $ this -> factory ( $ notifier ) , $ this -> container -> jsReload ( [ $ this -> name . '_sort' => $ this -> getSortBy ( ) ] ) , ] ; }
Default js action when saving form .
9,598
public function initDelete ( ) { $ this -> addAction ( [ 'icon' => 'red trash' ] , function ( $ jschain , $ id ) { $ this -> model -> load ( $ id ) -> delete ( ) ; return $ jschain -> closest ( 'tr' ) -> transition ( 'fade left' ) ; } , 'Are you sure?' ) ; }
Initialize UI for deleting records .
9,599
public function set ( $ fileId = null , $ fileName = null , $ junk = null ) { $ this -> setFileId ( $ fileId ) ; if ( ! $ fileName ) { $ fileName = $ fileId ; } return $ this -> setInput ( $ fileName , $ junk ) ; }
Allow to set file id and file name - fileId will be the file id sent with onDelete callback . - fileName is the field value display to user .