idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
51,500
public function format_datetime ( $ field ) { $ d = $ this -> current_row [ $ field ] ; if ( ! $ d ) { $ this -> current_row [ $ field ] = '-' ; } else { if ( $ d instanceof MongoDate ) { $ this -> current_row [ $ field ] = date ( $ this -> app -> getConfig ( 'locale/datetime' , 'd/m/Y H:i:s' ) , $ d -> sec ) ; } elseif ( is_numeric ( $ d ) ) { $ this -> current_row [ $ field ] = date ( $ this -> app -> getConfig ( 'locale/datetime' , 'd/m/Y H:i:s' ) , $ d ) ; } elseif ( $ d instanceof \ DateTime ) { $ this -> current_row [ $ field ] = $ d -> format ( $ this -> app -> getConfig ( 'locale/datetime' , 'd/m/Y H:i:s' ) ) ; } else { $ d = strtotime ( $ d ) ; $ this -> current_row [ $ field ] = $ d ? date ( $ this -> app -> getConfig ( 'locale/datetime' , 'd/m/Y H:i:s' ) , $ d ) : '-' ; } } }
Format field as datetime .
51,501
public function format_shorttext ( $ field ) { $ text = $ this -> current_row [ $ field ] ; if ( strlen ( $ text ) > 60 ) { $ a = explode ( PHP_EOL , wordwrap ( $ text , 28 , PHP_EOL , true ) , 2 ) ; $ b = explode ( PHP_EOL , wordwrap ( strrev ( $ text ) , 28 , PHP_EOL , true ) , 2 ) ; $ text = $ a [ 0 ] . ' ~~~ ' . strrev ( $ b [ 0 ] ) ; } $ this -> current_row [ $ field ] = $ text ; $ this -> setTDParam ( $ field , 'title' , $ this -> app -> encodeHtmlChars ( strip_tags ( $ this -> current_row [ $ field . '_original' ] ) , ENT_QUOTES ) ) ; }
Format shorttext field .
51,502
public function format_checkbox ( $ field ) { $ this -> current_row_html [ $ field ] = '<input type="checkbox" ' . 'id="cb_' . $ this -> current_id . '" ' . 'name="cb_' . $ this -> current_id . '" ' . 'value="' . $ this -> current_id . '" ' . ( $ this -> current_row [ 'selected' ] == 'Y' ? 'checked ' : '' ) . '/>' ; $ this -> setTDParam ( $ field , 'width' , '10' ) ; $ this -> setTDParam ( $ field , 'align' , 'center' ) ; }
Format field as checkbox .
51,503
public function init_button ( $ field ) { $ this -> on ( 'click' , '.do-' . $ field ) -> univ ( ) -> ajaxec ( array ( $ this -> app -> url ( ) , $ field => $ a = $ this -> js ( ) -> _selectorThis ( ) -> data ( 'id' ) , $ this -> name . '_' . $ field => $ a , ) ) ; }
Initialize buttons column .
51,504
public function format_button ( $ field ) { $ class = $ this -> columns [ $ field ] [ 'button_class' ] ; $ icon = $ this -> columns [ $ field ] [ 'icon' ] ; if ( $ icon ) { if ( $ icon [ 0 ] != '<' ) { $ icon = '<span class="icon-' . $ icon . '"></span>' ; } $ icon .= '&nbsp;' ; } $ this -> current_row_html [ $ field ] = '<button class="atk-button-small do-' . $ field . ' ' . $ class . '" data-id="' . $ this -> model -> id . '">' . $ icon . $ this -> columns [ $ field ] [ 'descr' ] . '</button>' ; }
Format field as button .
51,505
public function format_prompt ( $ field ) { $ class = $ this -> columns [ $ field ] [ 'button_class' ] . ' button_' . $ field ; $ icon = isset ( $ this -> columns [ $ field ] [ 'icon' ] ) ? $ this -> columns [ $ field ] [ 'icon' ] : '' ; $ message = 'Enter value: ' ; $ this -> current_row_html [ $ field ] = '<button type="button" class="' . $ class . '" ' . 'onclick="value=prompt(\'' . $ message . '\');$(this).univ().ajaxec(\'' . $ this -> app -> url ( null , array ( $ field => $ this -> current_id , $ this -> name . '_' . $ field => $ this -> current_id , ) ) . '&value=\'+value)"' . '>' . $ icon . $ this -> columns [ $ field ] [ 'descr' ] . '</button>' ; }
Format field as prompt button .
51,506
public function init_delete ( $ field ) { $ this -> columns [ $ field ] [ 'button_class' ] = 'atk-effect-danger atk-delete-button' ; $ this -> columns [ $ field ] [ 'icon' ] = 'trash' ; if ( $ id = $ _GET [ $ this -> name . '_' . $ field ] ) { $ this -> _performDelete ( $ id ) ; $ this -> js ( ) -> univ ( ) -> successMessage ( 'Deleted Successfully' ) -> reload ( ) -> execute ( ) ; } $ self = $ this ; $ this -> app -> addHook ( 'post-init' , function ( ) use ( $ self , $ field ) { if ( $ self -> hasColumn ( $ field ) ) { $ self -> addOrder ( ) -> move ( $ field , 'last' ) -> now ( ) ; } } ) ; $ this -> init_confirm ( $ field ) ; }
Initialize column with delete buttons .
51,507
public function _performDelete ( $ id ) { if ( $ this -> model ) { $ this -> model -> delete ( $ id ) ; } else { $ this -> dq -> where ( 'id' , $ id ) -> delete ( ) ; } }
Delete record from DB .
51,508
public function setTemplate ( $ template , $ field = null ) { if ( $ field === null ) { $ field = $ this -> last_column ; } $ gi = $ this -> add ( 'GiTemplate' ) ; $ this -> columns [ $ field ] [ 'template' ] = $ gi -> loadTemplateFromString ( $ template ) ; return $ this ; }
This allows you to use Template .
51,509
public function format_template ( $ field ) { if ( ! ( $ t = $ this -> columns [ $ field ] [ 'template' ] ) ) { throw new BaseException ( 'use setTemplate() for field ' . $ field ) ; } $ this -> current_row_html [ $ field ] = $ t -> trySet ( 'id' , $ this -> current_id ) -> set ( $ this -> current_row ) -> trySet ( '_value_' , $ this -> current_row [ $ field ] ) -> render ( ) ; }
Format field using template .
51,510
public function format_link ( $ field ) { $ page = $ this -> columns [ $ field ] [ 'page' ] ? : './' . $ field ; $ attr = $ this -> columns [ $ field ] [ 'id_field' ] ? : 'id' ; $ this -> current_row [ '_link' ] = $ this -> app -> url ( $ page , array ( $ attr => $ this -> columns [ $ field ] [ 'id_value' ] ? ( $ this -> model [ $ this -> columns [ $ field ] [ 'id_value' ] ] ? : $ this -> current_row [ $ this -> columns [ $ field ] [ 'id_value' ] . '_original' ] ) : $ this -> current_id , ) ) ; if ( ! $ this -> current_row [ $ field ] ) { $ this -> current_row [ $ field ] = $ this -> columns [ $ field ] [ 'descr' ] ; } return $ this -> format_template ( $ field ) ; }
Format field as link .
51,511
public function isCurrent ( $ inc_parent = false , $ inc_args = false ) { if ( $ inc_args ) { return $ this -> app -> url ( ) -> getURL ( ) == $ this -> getURL ( ) ; } return $ this -> _current || ( $ inc_parent && $ this -> _current_sub ) ; }
Detects if the URL matches current page .
51,512
public function set ( $ argument , $ value = null ) { if ( ! is_array ( $ argument ) ) { $ argument = array ( $ argument => $ value ) ; } return $ this -> setArguments ( $ argument ) ; }
Set additional arguments
51,513
public function setArguments ( $ arguments = array ( ) ) { if ( ! $ arguments ) { $ arguments = array ( ) ; } if ( ! is_array ( $ arguments ) ) { throw new BaseException ( 'Arguments must be always an array' ) ; } $ this -> arguments = $ args = array_merge ( $ this -> arguments , $ arguments ) ; foreach ( $ args as $ arg => $ val ) { if ( is_null ( $ val ) ) { unset ( $ this -> arguments [ $ arg ] ) ; } } return $ this ; }
Set arguments to specified array .
51,514
protected function escape ( $ value ) { if ( $ value === null ) { return 'NULL' ; } if ( is_integer ( $ value ) || is_float ( $ value ) ) { return $ value ; } return $ this -> pdo -> quote ( $ value ) ; }
Escapes a value for a use in a SQL statement .
51,515
protected function dump ( ) { $ this -> write ( '-- ' . date ( 'c' ) . ' - ' . $ this -> config -> dsn , false ) ; if ( $ this -> config -> disableAutoCommit === true ) { $ this -> write ( 'SET AUTOCOMMIT = 0' ) ; } if ( $ this -> config -> disableForeignKeyChecks === true ) { $ this -> write ( 'SET FOREIGN_KEY_CHECKS = 0' ) ; } if ( $ this -> config -> disableUniqueKeyChecks === true ) { $ this -> write ( 'SET UNIQUE_CHECKS = 0' ) ; } if ( $ this -> config -> createDatabase ) { if ( $ this -> config -> createDatabase === true ) { $ database = $ this -> database ; } else { $ database = ( string ) $ this -> config -> createDatabase ; } $ this -> write ( 'CREATE DATABASE IF NOT EXISTS `' . $ database . '` ' . 'DEFAULT CHARACTER SET = ' . $ this -> escape ( $ this -> config -> encoding ) ) ; $ this -> write ( 'USE `' . $ database . '`' ) ; } $ this -> dumpTables ( ) ; $ this -> dumpViews ( ) ; $ this -> dumpTriggers ( ) ; $ this -> dumpEvents ( ) ; if ( $ this -> config -> disableForeignKeyChecks === true ) { $ this -> write ( 'SET FOREIGN_KEY_CHECKS = 1' ) ; } if ( $ this -> config -> disableUniqueKeyChecks === true ) { $ this -> write ( 'SET UNIQUE_CHECKS = 1' ) ; } if ( $ this -> config -> disableAutoCommit === true ) { $ this -> write ( 'COMMIT' ) ; $ this -> write ( 'SET AUTOCOMMIT = 1' ) ; } $ this -> write ( "\n-- Completed on: " . date ( 'c' ) , false ) ; }
Dumps database contents to a temporary file .
51,516
protected function dumpTables ( ) { $ this -> tables -> execute ( ) ; foreach ( $ this -> tables -> fetchAll ( \ PDO :: FETCH_ASSOC ) as $ a ) { $ table = current ( $ a ) ; if ( isset ( $ a [ 'Table_type' ] ) && $ a [ 'Table_type' ] === 'VIEW' ) { continue ; } if ( in_array ( $ table , ( array ) $ this -> config -> ignore , true ) ) { continue ; } if ( ( string ) $ this -> config -> prefix !== '' && strpos ( $ table , $ this -> config -> prefix ) !== 0 ) { continue ; } if ( $ this -> config -> structure === true ) { $ structure = $ this -> pdo -> query ( 'SHOW CREATE TABLE `' . $ table . '`' ) -> fetch ( \ PDO :: FETCH_ASSOC ) ; $ this -> write ( "\n-- Table structure for table `{$table}`\n" , false ) ; $ this -> write ( 'DROP TABLE IF EXISTS `' . $ table . '`' ) ; $ this -> write ( end ( $ structure ) ) ; } if ( $ this -> config -> data === true ) { $ this -> write ( "\n-- Dumping data for table `{$table}`\n" , false ) ; $ this -> write ( "LOCK TABLES `{$table}` WRITE" ) ; if ( isset ( $ this -> config -> select [ $ table ] ) ) { $ query = $ this -> config -> select [ $ table ] ; } else { $ query = 'SELECT * FROM `' . $ table . '`' ; } $ rows = $ this -> pdo -> prepare ( $ query ) ; $ rows -> execute ( ) ; while ( $ a = $ rows -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ this -> write ( "INSERT INTO `{$table}` VALUES (" . implode ( ',' , array_map ( array ( $ this , 'escape' ) , $ a ) ) . ")" ) ; } $ this -> write ( 'UNLOCK TABLES' ) ; } } }
Dumps tables .
51,517
protected function dumpViews ( ) { $ this -> tables -> execute ( ) ; foreach ( $ this -> tables -> fetchAll ( \ PDO :: FETCH_ASSOC ) as $ a ) { $ view = current ( $ a ) ; if ( ! isset ( $ a [ 'Table_type' ] ) || $ a [ 'Table_type' ] !== 'VIEW' ) { continue ; } if ( in_array ( $ view , ( array ) $ this -> config -> ignore , true ) ) { continue ; } if ( ( string ) $ this -> config -> prefix !== '' && strpos ( $ view , $ this -> config -> prefix ) !== 0 ) { continue ; } $ structure = $ this -> pdo -> query ( 'SHOW CREATE VIEW `' . $ view . '`' ) ; if ( $ structure = $ structure -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( isset ( $ structure [ 'Create View' ] ) ) { $ this -> write ( "\n-- Structure for view `{$view}`\n" , false ) ; $ this -> write ( 'DROP VIEW IF EXISTS `' . $ view . '`' ) ; $ this -> write ( $ structure [ 'Create View' ] ) ; } } } }
Dumps views .
51,518
protected function dumpTriggers ( ) { if ( $ this -> config -> triggers === true && version_compare ( $ this -> version , '5.0.10' ) >= 0 ) { $ triggers = $ this -> pdo -> prepare ( 'SHOW TRIGGERS' ) ; $ triggers -> execute ( ) ; while ( $ a = $ triggers -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( in_array ( $ a [ 'Table' ] , ( array ) $ this -> config -> ignore , true ) ) { continue ; } if ( ( string ) $ this -> config -> prefix !== '' && strpos ( $ a [ 'Table' ] , $ this -> config -> prefix ) !== 0 ) { continue ; } $ this -> write ( "\n-- Trigger structure `{$a['Trigger']}`\n" , false ) ; $ this -> write ( 'DROP TRIGGER IF EXISTS `' . $ a [ 'Trigger' ] . '`' ) ; $ query = "CREATE TRIGGER `{$a['Trigger']}`" . " {$a['Timing']} {$a['Event']} ON `{$a['Table']}`" . " FOR EACH ROW\n{$a['Statement']}" ; $ delimiter = $ this -> getDelimiter ( '//' , $ query ) ; $ this -> write ( "DELIMITER {$delimiter}\n{$query}\n{$delimiter}\nDELIMITER ;" , false ) ; } } }
Dumps triggers .
51,519
protected function dumpEvents ( ) { if ( $ this -> config -> events === true && version_compare ( $ this -> version , '5.1.12' ) >= 0 ) { $ events = $ this -> pdo -> prepare ( 'SHOW EVENTS' ) ; $ events -> execute ( ) ; foreach ( $ events -> fetchAll ( \ PDO :: FETCH_ASSOC ) as $ a ) { $ event = $ a [ 'Name' ] ; if ( in_array ( $ event , ( array ) $ this -> config -> ignore , true ) ) { continue ; } if ( ( string ) $ this -> config -> prefix !== '' && strpos ( $ event , $ this -> config -> prefix ) !== 0 ) { continue ; } $ structure = $ this -> pdo -> query ( 'SHOW CREATE EVENT `' . $ event . '`' ) ; if ( $ structure = $ structure -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( isset ( $ structure [ 'Create Event' ] ) ) { $ query = $ structure [ 'Create Event' ] ; $ delimiter = $ this -> getDelimiter ( '//' , $ query ) ; $ this -> write ( "\n-- Structure for event `{$event}`\n" , false ) ; $ this -> write ( 'DROP EVENT IF EXISTS `' . $ event . '`' ) ; $ this -> write ( "DELIMITER {$delimiter}\n{$query}\n{$delimiter}\nDELIMITER ;" , false ) ; } } } } }
Dumps events .
51,520
public function updateSelectQuery ( $ select ) { $ p = null ; if ( ! empty ( $ this -> owner -> relations ) ) { $ p = $ this -> owner -> table_alias ? : $ this -> owner -> table ; } if ( $ this -> relation ) { $ select -> field ( $ this -> actual_field ? : $ this -> short_name , $ this -> relation -> short_name , $ this -> short_name ) ; } elseif ( ! ( is_null ( $ this -> actual_field ) ) && $ this -> actual_field != $ this -> short_name ) { $ select -> field ( $ this -> actual_field , $ p , $ this -> short_name ) ; return $ this ; } else { $ select -> field ( $ this -> short_name , $ p ) ; } return $ this ; }
Modifies specified query to include this particular field .
51,521
public function updateInsertQuery ( $ insert ) { if ( $ this -> relation ) { $ insert = $ this -> relation -> dsql ; } $ insert -> set ( $ this -> actual_field ? : $ this -> short_name , $ this -> getSQL ( ) ) ; return $ this ; }
Modify insert query to set value of this field .
51,522
public function updateModifyQuery ( $ modify ) { if ( $ this -> relation ) { $ modify = $ this -> relation -> dsql ; } $ modify -> set ( $ this -> actual_field ? : $ this -> short_name , $ this -> getSQL ( ) ) ; return $ this ; }
Modify update query to set value of this field .
51,523
public function getSQL ( ) { $ val = $ this -> owner -> get ( $ this -> short_name ) ; if ( $ this -> type == 'boolean' ) { $ val = $ this -> getBooleanValue ( $ val ) ; } if ( $ val == '' && ! $ this -> mandatory && ( $ this -> listData || $ this instanceof Field_Reference ) && $ this -> type != 'boolean' ) { $ val = null ; } return $ val ; }
Get value of this field formatted for SQL . Redefine if you need to convert .
51,524
public function getExpr ( ) { $ q = $ this -> owner -> _dsql ( ) ; return $ q -> bt ( $ this -> relation ? $ this -> relation -> short_name : $ q -> main_table ) . '.' . $ q -> bt ( $ this -> actual_field ? : $ this -> short_name ) ; }
Returns field of this model .
51,525
public function loadCurrent ( $ model , & $ cursor ) { $ model -> data = array_shift ( $ cursor ) ; $ model -> id = $ model -> data [ $ model -> id_field ] ; }
Load next data row from cursor .
51,526
public function beforeLoad ( $ m , $ q = null ) { if ( is_null ( $ q ) ) { return ; } if ( $ this -> m2 && $ this -> m2 != $ this -> owner -> id_field ) { $ q -> field ( $ this -> m2 , $ this -> m1 , $ this -> short_name ) ; } elseif ( $ this -> m2 ) { $ q -> field ( $ this -> f2 , $ this -> fa ? : $ this -> f1 , $ this -> short_name ) ; } }
Add query for the relation s ID but then remove it from results . Remove ID when unloading .
51,527
public function addGrandTotals ( $ fields = UNDEFINED ) { if ( ! $ this -> getIterator ( ) instanceof SQL_Model ) { throw $ this -> exception ( 'Grand Totals can be used only with SQL_Model data source' ) ; } return $ this -> _addTotals ( $ fields , 'onRequest' ) ; }
Enable totals calculation for specified array of fields .
51,528
public function renderRows ( ) { $ this -> odd_even = null ; $ this -> total_rows = 0 ; $ this -> template -> del ( $ this -> container_tag ) ; $ iter = $ this -> getIterator ( ) ; foreach ( $ iter as $ this -> current_id => $ this -> current_row ) { if ( $ this -> current_row instanceof Model || $ this -> current_row instanceof \ atk4 \ data \ Model ) { $ this -> current_row = ( array ) $ this -> current_row -> get ( ) ; } elseif ( ! is_array ( $ this -> current_row ) && ! ( $ this -> current_row instanceof ArrayAccess ) ) { $ this -> current = $ this -> current_row ; $ this -> current_row = get_object_vars ( $ this -> current ) ; } $ this -> current_row_html = array ( ) ; if ( ! empty ( $ this -> sep_html ) && $ this -> total_rows ) { $ this -> renderSeparator ( ) ; } ++ $ this -> total_rows ; if ( $ this -> totals_type == 'onRender' ) { $ this -> updateTotals ( ) ; } $ this -> renderDataRow ( ) ; } if ( $ this -> totals_type == 'onRequest' ) { $ this -> updateGrandTotals ( ) ; } $ this -> totals [ 'row_count' ] = $ this -> total_rows ; $ this -> renderTotalsRow ( ) ; }
Render lister rows .
51,529
public function renderDataRow ( ) { $ this -> formatRow ( ) ; $ this -> template -> appendHTML ( $ this -> container_tag , $ this -> rowRender ( $ this -> row_t ) ) ; }
Render data row .
51,530
public function renderTotalsRow ( ) { $ this -> current_row = $ this -> current_row_html = array ( ) ; if ( $ this -> totals !== false && is_array ( $ this -> totals ) && $ this -> totals_t ) { $ this -> current_row = $ this -> totals ; $ this -> formatTotalsRow ( ) ; $ this -> template -> appendHTML ( $ this -> container_tag , $ this -> rowRender ( $ this -> totals_t ) ) ; } else { $ this -> template -> tryDel ( 'totals' ) ; } }
Render Totals row .
51,531
public function formatRow ( ) { parent :: formatRow ( ) ; if ( is_array ( $ this -> current_row ) || $ this -> current_row instanceof ArrayAccess ) { $ this -> odd_even = $ this -> odd_even == $ this -> odd_css_class ? $ this -> even_css_class : $ this -> odd_css_class ; $ this -> current_row [ 'odd_even' ] = $ this -> odd_even ; } }
Format lister row .
51,532
public function updateTotals ( ) { if ( is_array ( $ this -> totals ) ) { foreach ( $ this -> totals as $ key => $ val ) { if ( is_object ( $ this -> current_row [ $ key ] ) ) { continue ; } $ this -> totals [ $ key ] = $ val + $ this -> current_row [ $ key ] ; } } }
Add current rendered row values to totals .
51,533
public function updateGrandTotals ( ) { $ m = $ this -> getIterator ( ) ; $ fields = array_keys ( $ this -> totals ) ; $ sub_q = $ m -> dsql ( ) -> del ( 'limit' ) -> del ( 'order' ) ; $ q = $ this -> app -> db -> dsql ( ) ; $ q -> table ( $ sub_q , 'grandTotals' ) ; foreach ( $ fields as $ field ) { $ q -> field ( $ q -> sum ( $ field ) , $ field ) ; } $ q -> field ( $ q -> count ( ) , 'total_cnt' ) ; $ data = $ q -> getHash ( ) ; $ this -> total_rows = $ data [ 'total_cnt' ] ; unset ( $ data [ 'total_cnt' ] ) ; $ this -> totals = $ data ; }
Calculate grand totals of all rows .
51,534
protected function validateRequest ( ) { $ data = $ _POST ; $ url = $ this -> url ; $ signature = $ _SERVER [ 'X-Plivo-Signature' ] ; $ authToken = $ this -> authToken ; if ( ! $ this -> plivo -> validate_signature ( $ url , $ data , $ signature , $ authToken ) ) { throw new \ InvalidArgumentException ( 'This request was not able to verify it came from Plivo.' ) ; } return true ; }
Checks if a message is authentic from Plivo .
51,535
public function composeMessage ( ) { try { return $ this -> views -> make ( $ this -> view , $ this -> data ) -> render ( ) ; } catch ( \ InvalidArgumentException $ e ) { return $ this -> view ; } }
Composes a message .
51,536
public function attachImage ( $ image ) { $ this -> mms = true ; if ( is_array ( $ image ) ) { $ this -> attachImages = array_merge ( $ this -> attachImages , $ image ) ; } else { $ this -> attachImages [ ] = $ image ; } }
Attaches an image to a message .
51,537
public function addButton ( $ label , $ options = array ( ) ) { $ position = 'after' ; if ( is_string ( $ options ) ) { $ position = $ options ; } else { if ( isset ( $ options [ 'position' ] ) ) { $ position = $ options [ 'position' ] ; } } if ( $ position == 'after' ) { $ button = $ this -> afterField ( ) -> add ( 'Button' , $ options ) ; $ button -> set ( $ label ) ; } else { $ button = $ this -> beforeField ( ) -> add ( 'Button' , $ options ) ; $ button -> set ( $ label ) ; } $ this -> js ( 'change' , $ button -> js ( ) -> data ( 'val' , $ this -> js ( ) -> val ( ) ) ) ; return $ button ; }
Position can be either before or after
51,538
public function validate ( $ rule = null ) { if ( is_null ( $ rule ) ) { throw $ this -> exception ( 'Incorrect usage of field validation' ) ; } if ( is_string ( $ rule ) ) { $ rule = $ this -> short_name . '|' . $ rule ; } elseif ( is_array ( $ rule ) ) { array_unshift ( $ rule , $ this -> short_name ) ; $ rule = array ( $ rule ) ; } elseif ( is_callable ( $ rule ) ) { $ rule = array ( array ( $ this -> short_name , $ rule ) ) ; } $ this -> form -> validate ( $ rule ) ; return $ this ; }
This method has been refactored to integrate with Controller_Validator .
51,539
public function validateNotNULL ( $ msg = null ) { $ this -> setMandatory ( ) ; if ( $ msg && $ msg !== true ) { $ msg = $ this -> app -> _ ( $ msg ) ; } else { $ msg = sprintf ( $ this -> app -> _ ( '%s is a mandatory field' ) , $ this -> caption ) ; } $ this -> validateField ( array ( $ this , '_validateNotNull' ) , $ msg ) ; return $ this ; }
Adds X is a mandatory field message
51,540
public function postInit ( ) { foreach ( $ this -> elements as $ x => $ field ) { if ( $ field instanceof Form_Field ) { $ field -> set ( $ this -> recall ( $ x ) ) ; if ( $ field -> no_save || ! $ field -> get ( ) ) { continue ; } if ( $ this -> view -> model && $ this -> view -> model -> hasElement ( $ x ) ) { $ this -> view -> model -> addCondition ( $ x , $ field -> get ( ) ) ; } } } $ this -> hook ( 'applyFilter' , array ( $ this -> view -> model ) ) ; }
Remembers values and uses them as condition .
51,541
public function memorizeAll ( ) { foreach ( $ this -> get ( ) as $ field => $ value ) { if ( ( isset ( $ this -> reset ) && $ this -> isClicked ( $ this -> reset ) ) || is_null ( $ value ) ) { $ this -> forget ( $ field ) ; } else { $ this -> memorize ( $ field , $ value ) ; } } }
Memorize filtering parameters .
51,542
public function addButtons ( ) { $ this -> save = $ this -> addSubmit ( 'Save' ) ; $ this -> reset = $ this -> addSubmit ( 'Reset' ) ; return $ this ; }
Add Save and Reset buttons .
51,543
public function submitted ( ) { if ( parent :: submitted ( ) ) { if ( isset ( $ this -> reset ) && $ this -> isClicked ( $ this -> reset ) ) { $ this -> forget ( ) ; $ this -> js ( null , $ this -> view -> js ( ) -> reload ( ) ) -> reload ( ) -> execute ( ) ; } else { $ this -> memorizeAll ( ) ; } $ this -> view -> js ( ) -> reload ( ) -> execute ( ) ; } }
On form submit memorize or forget filtering parameters .
51,544
protected function processReceive ( $ rawMessage ) { $ incomingMessage = $ this -> createIncomingMessage ( ) ; $ incomingMessage -> setRaw ( $ rawMessage ) ; $ incomingMessage -> setFrom ( $ rawMessage [ 'PhoneNumber' ] ) ; $ incomingMessage -> setMessage ( $ rawMessage [ 'Message' ] ) ; $ incomingMessage -> setId ( $ rawMessage [ 'ID' ] ) ; $ incomingMessage -> setTo ( '313131' ) ; return $ incomingMessage ; }
Returns an IncomingMessage object with it s properties filled out .
51,545
public function setNoText ( $ icon = null ) { $ this -> options [ 'text' ] = false ; if ( $ icon !== null ) { $ this -> setIcon ( $ icon ) ; } return $ this ; }
Set button without text and optionally with icon .
51,546
public function setIcon ( $ icon ) { if ( $ icon [ 0 ] != '<' ) { $ icon = '<i class="icon-' . $ icon . '"></i>' ; } $ this -> template -> trySetHTML ( 'icon' , $ icon ) ; return $ this ; }
Sets icon for button .
51,547
public function setLabel ( $ label ) { if ( is_array ( $ label ) && $ label [ 'icon' ] ) { $ this -> setIcon ( $ label [ 'icon' ] ) ; } elseif ( is_string ( $ label ) ) { return $ this -> setText ( $ label ) ; } return $ this ; }
Sets label of button .
51,548
public function addSplitButton ( $ options = null ) { $ options = array_merge ( array ( 'text' => false , 'icons' => array ( 'primary' => $ this -> js_triangle_class , ) , ) , $ options ? : array ( ) ) ; $ but = $ this -> owner -> add ( 'Button' , array ( 'options' => $ options ) , $ this -> spot ) ; $ order = $ this -> owner -> add ( 'Order' ) ; $ order -> move ( $ but , 'after' , $ this ) -> now ( ) ; $ but -> js ( true ) -> removeClass ( 'ui-corner-all' ) -> addClass ( 'ui-corner-right' ) -> css ( 'margin-left' , '-2px' ) ; $ this -> js ( true ) -> removeClass ( 'ui-corner-all' ) -> addClass ( 'ui-corner-left' ) -> css ( 'margin-right' , '-2px' ) ; return $ but ; }
Adds another button after this one with an arrow and returns it .
51,549
public function addMenu ( $ options = array ( ) , $ vertical = false ) { $ this -> options [ 'icons' ] [ 'secondary' ] = $ this -> js_triangle_class ; $ this -> menu = $ this -> owner -> add ( $ this -> menu_class , $ options , $ this -> spot ) ; $ this -> menu -> addStyle ( 'display' , 'none' ) ; $ this -> js ( 'click' , array ( $ this -> js ( ) -> toggleClass ( $ this -> js_active_class ) , $ this -> menu -> js ( ) -> toggle ( ) -> position ( $ this -> getPosition ( $ vertical ) ) , ) ) ; $ this -> js ( true ) -> _selectorDocument ( ) -> bind ( 'click' , $ this -> js ( null , array ( $ this -> js ( ) -> removeClass ( $ this -> js_active_class ) , $ this -> menu -> js ( ) -> hide ( ) , ) ) -> _enclose ( ) ) ; return $ this -> menu ; }
Show menu when clicked . For example dropdown menu .
51,550
public function isClicked ( $ message = null ) { $ cl = $ this -> js ( 'click' ) -> univ ( ) ; if ( $ message !== null ) { $ cl -> confirm ( $ message ) ; } $ cl -> ajaxec ( $ this -> app -> url ( null , array ( $ this -> name => 'clicked' ) ) , true ) ; return isset ( $ _GET [ $ this -> name ] ) ; }
Add click handler on button and returns true if button was clicked .
51,551
public function onClickConsole ( $ callback , $ title = null ) { if ( is_null ( $ title ) ) { $ title = $ this -> template -> get ( 'Content' ) ; } $ this -> virtual_page = $ this -> add ( 'VirtualPage' , [ 'type' => 'frameURL' ] ) ; $ this -> virtual_page -> bindEvent ( $ title ) -> set ( function ( $ p ) use ( $ callback ) { $ console = $ p -> add ( 'View_Console' ) ; $ console -> set ( $ callback ) ; } ) ; }
Add click handler on button that will execute callback . Similar to onClick however output from callback execution will appear in a dialog window with a console .
51,552
public function convertDate ( $ date , $ from = null , $ to = 'Y-m-d' ) { if ( ! $ date ) { return null ; } if ( $ from === null ) { $ from = $ this -> app -> getConfig ( 'locale/date' , null ) ; } if ( $ from === null ) { $ date = new DateTime ( $ date ) ; } else { $ date = date_create_from_format ( $ from , ( string ) $ date ) ; } if ( $ to === null ) { $ to = $ this -> app -> getConfig ( 'locale/date' , 'Y-m-d' ) ; } if ( $ date === false ) { throw $ this -> exception ( 'Date format is not correct' ) ; } return date_format ( $ date , $ to ) ; }
Convert date from one format to another .
51,553
public function getIdsFromConditions ( $ rows , $ conditions , $ limit = null ) { $ withLimit = ! is_null ( $ limit ) && ( is_array ( $ limit ) && ! is_null ( $ limit [ 0 ] ) ) ; if ( $ withLimit ) { $ max = is_null ( $ limit [ 1 ] ) ? $ limit [ 0 ] : ( $ limit [ 0 ] + $ limit [ 1 ] ) ; } $ ids = array ( ) ; foreach ( $ rows as $ id => $ row ) { if ( $ id === '__ids__' ) { continue ; } $ valid = true ; foreach ( $ conditions as $ c ) { if ( ! $ this -> isValid ( $ row , $ c ) ) { $ valid = false ; break ; } } if ( $ valid === true ) { $ ids [ ] = $ id ; if ( $ withLimit && isset ( $ max ) && count ( $ ids ) > $ max ) { break ; } } } if ( $ withLimit ) { if ( $ limit [ 1 ] === null ) { $ ids = array_slice ( $ ids , 0 , $ limit [ 0 ] ) ; } else { $ ids = array_slice ( $ ids , $ limit [ 0 ] , $ limit [ 1 ] ) ; } } return $ ids ; }
resolve all conditions
51,554
public function encodeOutput ( $ data ) { if ( $ _GET [ 'format' ] == 'xml' ) { throw $ this -> exception ( 'only JSON format is supported' , null , 406 ) ; } if ( $ _GET [ 'format' ] == 'json_pretty' ) { header ( 'Content-type: application/json' ) ; echo json_encode ( $ data , JSON_PRETTY_PRINT ) ; return ; } if ( $ _GET [ 'format' ] == 'html' ) { echo '<pre>' ; echo json_encode ( $ data , JSON_PRETTY_PRINT ) ; return ; } header ( 'Content-type: application/json' ) ; if ( $ data === null ) { $ data = array ( ) ; } echo json_encode ( $ data ) ; }
Output will be properly fromatted .
51,555
public function setAttr ( $ attribute , $ value = null ) { if ( is_array ( $ attribute ) && is_null ( $ value ) ) { foreach ( $ attribute as $ k => $ v ) { $ this -> setAttr ( $ k , $ v ) ; } return $ this ; } $ this -> template -> appendHTML ( 'attributes' , ' ' . $ attribute . '="' . $ value . '"' ) ; return $ this ; }
Add attribute to element . Previously added attributes are not affected .
51,556
public function removeClass ( $ class ) { $ cl = ' ' . $ this -> template -> get ( 'class' ) . ' ' ; $ cl = str_replace ( ' ' . trim ( $ class ) . ' ' , ' ' , $ cl ) ; $ this -> template -> set ( 'class' , trim ( $ cl ) ) ; return $ this ; }
Remove CSS class from element if it was added with setClass or addClass .
51,557
public function setStyle ( $ property , $ style = null ) { $ this -> template -> del ( 'style' ) ; $ this -> addStyle ( $ property , $ style ) ; return $ this ; }
Set inline CSS style of element . Old styles will be removed . Multiple CSS styles can also be set if passed as array .
51,558
public function removeStyle ( $ property ) { $ st = $ this -> template -> get ( 'style' ) ; if ( ! $ st ) { return $ this ; } if ( ! is_array ( $ st ) ) { $ st = array ( $ st ) ; } $ this -> template -> del ( 'style' ) ; foreach ( $ st as $ k => $ rule ) { if ( strpos ( $ rule , ';' . $ property . ':' ) === false ) { $ this -> template -> append ( 'style' , $ rule ) ; } } return $ this ; }
Remove inline CSS style from element if it was added with setStyle or addStyle .
51,559
public function getFields ( ) { $ models = array ( ) ; foreach ( $ this -> field_associations as $ form_field => $ model_field ) { $ v = $ this -> form -> get ( $ form_field ) ; $ model_field -> set ( $ v ) ; if ( ! isset ( $ models [ $ model_field -> owner -> name ] ) ) { $ models [ $ model_field -> owner -> name ] = $ model_field -> owner ; } } return $ models ; }
Returns array of models model_name = > Model used in this form .
51,560
public function rule_if ( $ a ) { $ b = $ this -> pullRule ( ) ; if ( ! $ this -> get ( $ b ) ) { $ this -> stop ( ) ; } return $ a ; }
Advanced logic .
51,561
public function set ( $ fx ) { $ p = $ this -> add ( 'VirtualPage' ) ; $ p -> set ( $ fx ) ; $ this -> setURL ( $ p -> getURL ( ) ) ; return $ this ; }
If callable is passed it will be executed when the dialog is popped through the use of VirtualPage .
51,562
public function showJS ( $ options = null , $ options_compat = array ( ) ) { if ( ! empty ( $ options_compat ) ) { $ options = $ options_compat ; } $ loader_js = $ this -> url ? $ this -> js ( ) -> atk4_load ( array ( $ this -> url ) ) : $ options [ 'open_js' ] ? : null ; $ this -> js ( true ) -> dialog ( array_extend ( array ( 'modal' => true , 'dialogClass' => ( $ options [ 'class' ] ? : 'atk-popover' ) . $ this -> pop_class . ' atk-popover-' . ( $ options [ 'tip' ] ? : 'top-center' ) , 'dragable' => false , 'resizable' => false , 'minHeight' => 'auto' , 'autoOpen' => false , 'width' => 250 , 'open' => $ this -> js ( null , array ( $ this -> js ( ) -> _selector ( '.ui-dialog-titlebar:last' ) -> hide ( ) , $ loader_js , ) ) -> click ( $ this -> js ( ) -> dialog ( 'close' ) -> _enclose ( ) ) -> _selector ( '.ui-widget-overlay:last' ) -> _enclose ( ) -> css ( 'opacity' , '0' ) , ) , $ options ) ) -> parent ( ) -> append ( '<div class="atk-popover-arrow"></div>' ) ; return $ this -> js ( ) -> dialog ( 'open' ) -> dialog ( 'option' , array ( 'position' => $ p = array ( 'my' => $ options [ 'my' ] ? : 'center top' , 'at' => $ options [ 'at' ] ? : 'center bottom+8' , 'of' => $ this -> js ( ) -> _selectorThis ( ) , ) , ) ) ; }
Returns JS which will position this element and show it .
51,563
public function getMessage ( ) { if ( ! is_a ( $ this -> container , 'PhpBotFramework\Entities\Message' ) ) { $ this -> container [ 'message' ] = new Message ( $ this -> container [ 'message' ] ) ; } return $ this -> container [ 'message' ] ; }
\ brief Get message attached to this callback .
51,564
public function connect ( array $ params ) : bool { $ params = $ this -> addDefaultValue ( $ params ) ; $ config = $ this -> getDns ( $ params ) ; try { $ this -> pdo = new \ PDO ( $ config , $ params [ 'username' ] , $ params [ 'password' ] , $ params [ 'options' ] ) ; $ this -> pdo -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; return true ; } catch ( \ PDOException $ e ) { echo 'Unable to connect to database, an error occured:' . $ e -> getMessage ( ) ; } return false ; }
\ brief Open a database connection using PDO . \ details Provides a simple way to initialize a database connection and create a PDO instance .
51,565
public function getFcm ( ) { if ( ! isset ( $ this -> _fcm ) ) { $ this -> _fcm = $ this -> createFcm ( ) ; } return $ this -> _fcm ; }
Returns FCM client
51,566
protected function createFcm ( ) { $ client = new \ paragraph1 \ phpFCM \ Client ( ) ; $ client -> setApiKey ( $ this -> apiKey ) ; $ client -> setProxyApiUrl ( $ this -> proxyApiUrl ) ; $ client -> injectHttpClient ( $ this -> getHttpClient ( ) ) ; return $ client ; }
Creates FCM client
51,567
public function getHttpClient ( ) { if ( ! isset ( $ this -> _httpClient ) ) { $ this -> _httpClient = Yii :: createObject ( $ this -> guzzleClass , [ $ this -> guzzleConfig ] ) ; } return $ this -> _httpClient ; }
Returns Guzzle client
51,568
public function createMessage ( $ deviceTokens = [ ] ) { $ message = new Message ( ) ; if ( is_string ( $ deviceTokens ) ) { $ deviceTokens = [ $ deviceTokens ] ; } if ( ! is_array ( $ deviceTokens ) ) { throw new InvalidParamException ( "\$deviceTokens must be string or array" ) ; } foreach ( $ deviceTokens as $ token ) { $ message -> addRecipient ( $ this -> createDevice ( $ token ) ) ; } return $ message ; }
Creates Message object
51,569
public function setLanguageDatabase ( string $ language ) : bool { $ pdo = $ this -> bot -> getPDO ( ) ; $ sth = $ pdo -> prepare ( 'UPDATE ' . $ this -> user_table . ' SET language = :language WHERE ' . $ this -> id_column . ' = :id' ) ; $ sth -> bindParam ( ':language' , $ language ) ; $ chat_id = $ this -> bot -> chat_id ; $ sth -> bindParam ( ':id' , $ chat_id ) ; try { $ sth -> execute ( ) ; } catch ( \ PDOException $ e ) { throw new BotException ( $ e -> getMessage ( ) ) ; } $ this -> language = $ language ; return true ; }
\ brief Set the current user language in database and internally . \ details Save it into database first .
51,570
public function setLanguageRedis ( string $ language , int $ expiring_time = 86400 ) : bool { $ redis = $ this -> bot -> getRedis ( ) ; if ( $ this -> setLanguageDatabase ( $ language ) ) { $ redis -> setEx ( $ this -> bot -> chat_id . ':language' , $ expiring_time , $ language ) ; return true ; } return false ; }
\ brief Set the current user language in both Redis database and internally . \ details Save it into database first then create the expiring key on Redis .
51,571
public function setPayment ( string $ provider_token , string $ currency = 'EUR' ) { if ( ! $ provider_token ) { $ this -> logger -> warning ( 'setPayment expects a valid provider token, an invalid one given.' ) ; throw new BotException ( 'Invalid provider token given to "setPayment"' ) ; } $ this -> _provider_token = $ provider_token ; $ this -> _payment_currency = $ currency ; }
\ brief Set data for bot payments used across sendInvoice .
51,572
private function generateLabeledPrices ( array $ prices ) { $ response = [ ] ; foreach ( $ prices as $ item => $ price ) { if ( $ price < 1 ) { $ this -> logger -> warning ( 'Invalid or negative price passed to "sendInvoice"' ) ; throw new \ Exception ( 'Invalid or negative price passed to "sendInvoice"' ) ; } $ formatted_price = intval ( $ price * 100 ) ; array_push ( $ response , [ 'label' => $ item , 'amount' => $ formatted_price ] ) ; } return json_encode ( $ response ) ; }
\ brief Convert a matrix of prices in a JSON string object accepted by sendInvoice .
51,573
public function submitAction ( Request $ request ) { $ template = 'EnhavoSearchBundle:Admin:Search/result.html.twig' ; $ term = $ request -> get ( 'q' , '' ) ; $ filter = new Filter ( ) ; $ filter -> setTerm ( $ term ) ; $ results = $ this -> searchEngine -> searchPaginated ( $ filter ) ; $ results = $ this -> resultConverter -> convert ( $ results , $ term ) ; return $ this -> render ( $ template , [ 'results' => $ results , 'term' => $ term ] ) ; }
Handle search submit
51,574
public function init ( string $ file , string $ format_name ) { $ this -> file = $ file ; $ this -> format_name = $ format_name ; }
\ brief Fill this object with another file .
51,575
public function get ( bool $ clear_keyboard = true ) : string { if ( empty ( $ this -> inline_keyboard ) ) { throw new BotException ( "Inline keyboard is empty" ) ; } $ reply_markup = [ 'inline_keyboard' => $ this -> inline_keyboard ] ; $ reply_markup = json_encode ( $ reply_markup ) ; if ( $ clear_keyboard ) { $ this -> clearKeyboard ( ) ; } return $ reply_markup ; }
\ brief Get a JSON object containing the inline keyboard .
51,576
public function getArray ( bool $ clean_keyboard = true ) : array { if ( empty ( $ this -> inline_keyboard ) ) { throw new BotException ( "Inline keyboard is empty" ) ; } $ reply_markup = [ 'inline_keyboard' => $ this -> inline_keyboard ] ; if ( $ clean_keyboard ) { $ this -> clearKeyboard ( ) ; } return $ reply_markup ; }
\ brief Get the array containing the buttons . \ details Use this method when adding keyboard to inline query results .
51,577
private function isEmailValid ( $ email ) { $ constraints = array ( new \ Symfony \ Component \ Validator \ Constraints \ Email ( ) , new \ Symfony \ Component \ Validator \ Constraints \ NotBlank ( ) ) ; $ errors = $ this -> validator -> validate ( $ email , $ constraints ) ; return count ( $ errors ) === 0 ; }
Validate single email
51,578
public function newArticle ( string $ title , string $ message_text , string $ description = '' , array $ reply_markup = null , $ parse_mode = 'HTML' , $ disable_web_preview = false ) : int { array_push ( $ this -> results , [ 'type' => 'article' , 'id' => ( string ) $ this -> id_result , 'title' => $ title , 'message_text' => $ message_text , 'description' => $ description , 'parse_mode' => $ parse_mode , 'reply_markup' => $ reply_markup , 'disable_web_page_preview' => $ disable_web_preview ] ) ; if ( is_null ( $ reply_markup ) ) { unset ( $ this -> results [ $ this -> id_result ] [ 'reply_markup' ] ) ; } return $ this -> id_result ++ ; }
\ brief Add a result of type Article . \ details Add a result that will be show to the user .
51,579
public function get ( ) { $ encoded_results = json_encode ( $ this -> results ) ; $ this -> results = [ ] ; $ this -> id_result = 0 ; return $ encoded_results ; }
\ brief Get all results created .
51,580
public function buildView ( FormView $ view , FormInterface $ form , array $ options ) { $ view -> vars [ 'translation' ] = isset ( $ options [ 'translation' ] ) && $ options [ 'translation' ] === true ; $ view -> vars [ 'currentLocale' ] = $ this -> defaultLocale ; if ( $ view -> vars [ 'translation' ] ) { $ parent = $ form -> getParent ( ) ; if ( $ parent instanceof Form ) { $ property = new Property ( $ form -> getPropertyPath ( ) ) ; $ entity = $ parent -> getConfig ( ) -> getDataClass ( ) ; if ( is_object ( $ parent -> getData ( ) ) ) { $ entity = $ parent -> getData ( ) ; } $ translations = $ this -> translator -> getTranslationData ( $ entity , $ property ) ; if ( $ translations === null ) { $ view -> vars [ 'translation' ] = false ; return ; } $ view -> vars [ 'translations' ] = $ translations ; } } }
Pass the image URL to the view
51,581
public function simplify ( $ text ) { $ text = html_entity_decode ( $ text , ENT_QUOTES , 'UTF-8' ) ; $ text = mb_strtolower ( $ text , 'UTF-8' ) ; $ text = preg_replace ( '/([' . $ this -> getClassNumbers ( ) . ']+)[' . $ this -> getClassPunctuation ( ) . ']+(?=[' . $ this -> getClassNumbers ( ) . '])/u' , '\1' , $ text ) ; $ text = preg_replace ( '/[.-]{2,}/' , ' ' , $ text ) ; $ text = preg_replace ( '/[._-]+/' , '' , $ text ) ; $ text = preg_replace ( '/[' . $ this -> getClassWordBoundary ( ) . ']+/u' , ' ' , $ text ) ; return trim ( $ text ) ; }
Simplifies and preprocesses text for searching .
51,582
public function deleteFile ( FileInterface $ file ) { $ this -> storage -> deleteFile ( $ file ) ; $ this -> formatManager -> deleteFormats ( $ file ) ; $ this -> em -> remove ( $ file ) ; $ this -> em -> flush ( ) ; }
Deletes file and associated formats .
51,583
public function saveFile ( FileInterface $ file ) { $ this -> em -> persist ( $ file ) ; $ this -> em -> flush ( ) ; $ this -> storage -> saveFile ( $ file ) ; }
Save file to system .
51,584
public function postLoad ( LifecycleEventArgs $ args ) { $ object = $ args -> getObject ( ) ; if ( get_class ( $ object ) === $ this -> targetClass ) { $ this -> loadEntity ( $ object ) ; } }
Insert target class on load
51,585
public function preFlush ( PreFlushEventArgs $ args ) { $ uow = $ args -> getEntityManager ( ) -> getUnitOfWork ( ) ; $ result = $ uow -> getIdentityMap ( ) ; if ( isset ( $ result [ $ this -> targetClass ] ) ) { foreach ( $ result [ $ this -> targetClass ] as $ entity ) { $ this -> updateEntity ( $ entity ) ; } } }
Update entity before flush to prevent a possible after flush
51,586
public function postFlush ( PostFlushEventArgs $ args ) { $ change = false ; $ em = $ args -> getEntityManager ( ) ; $ uow = $ args -> getEntityManager ( ) -> getUnitOfWork ( ) ; $ result = $ uow -> getIdentityMap ( ) ; if ( isset ( $ result [ $ this -> targetClass ] ) ) { foreach ( $ result [ $ this -> targetClass ] as $ entity ) { $ updated = $ this -> updateEntity ( $ entity ) ; if ( $ updated ) { $ change = true ; } $ propertyAccessor = PropertyAccess :: createPropertyAccessor ( ) ; $ targetProperty = $ propertyAccessor -> getValue ( $ entity , $ this -> targetProperty ) ; if ( $ targetProperty && $ uow -> getEntityState ( $ targetProperty ) !== UnitOfWork :: STATE_MANAGED ) { $ em -> persist ( $ targetProperty ) ; $ change = true ; } } } if ( $ change ) { $ em -> flush ( ) ; } }
Check if entity is not up to date an trigger flush again if needed
51,587
private function updateEntity ( $ entity ) { $ change = false ; $ propertyAccessor = PropertyAccess :: createPropertyAccessor ( ) ; $ targetProperty = $ propertyAccessor -> getValue ( $ entity , $ this -> targetProperty ) ; if ( $ entity instanceof Proxy && $ targetProperty === null ) { $ this -> loadEntity ( $ entity ) ; $ targetProperty = $ propertyAccessor -> getValue ( $ entity , $ this -> targetProperty ) ; } if ( $ targetProperty ) { $ idProperty = $ propertyAccessor -> getValue ( $ entity , $ this -> idProperty ) ; $ id = $ propertyAccessor -> getValue ( $ targetProperty , 'id' ) ; if ( $ idProperty != $ id ) { $ propertyAccessor -> setValue ( $ entity , $ this -> idProperty , $ id ) ; $ change = true ; } $ classProperty = $ propertyAccessor -> getValue ( $ entity , $ this -> classProperty ) ; $ class = $ this -> targetClassResolver -> resolveClass ( $ targetProperty ) ; if ( $ classProperty != $ class ) { $ propertyAccessor -> setValue ( $ entity , $ this -> classProperty , $ class ) ; $ change = true ; } } else { if ( null !== $ propertyAccessor -> getValue ( $ entity , $ this -> idProperty ) ) { $ propertyAccessor -> setValue ( $ entity , $ this -> idProperty , null ) ; $ change = true ; } if ( null !== $ propertyAccessor -> getValue ( $ entity , $ this -> classProperty ) ) { $ propertyAccessor -> setValue ( $ entity , $ this -> classProperty , null ) ; $ change = true ; } } return $ change ; }
Update entity values
51,588
public function answerPreCheckoutQuery ( bool $ ok = true , string $ error = null ) { if ( ! isset ( $ this -> _pre_checkout_query_id ) ) { throw new BotException ( 'Callback query ID not set, wrong update' ) ; } $ parameters = [ 'pre_checkout_query_id' => $ this -> _pre_checkout_query_id , 'ok' => $ ok , 'error_message' => $ error ] ; return $ this -> execRequest ( 'answerPreCheckoutQuery?' . http_build_query ( $ parameters ) ) ; }
\ brief Send an update once the user has confirmed their payment .
51,589
public function answerShippingQuery ( bool $ ok = true , string $ error = null , array $ shipping_options ) { if ( ! isset ( $ this -> _shipping_query_id ) ) { throw new BotException ( 'Callback query ID not set, wrong update' ) ; } $ parameters = [ 'shipping_query_id' => $ this -> _shipping_query_id , 'ok' => $ ok , 'error_message' => $ error , 'shipping_options' => $ this -> generateShippingOptions ( $ shipping_options ) ] ; return $ this -> execRequest ( 'answerShippingQuery?' . http_build_query ( $ parameters ) ) ; }
\ brief Send an update once the user has confirmed their shipping details .
51,590
private function generateShippingOptions ( array $ shipping_options ) { $ response = [ ] ; $ option_index = 1 ; foreach ( $ shipping_options as $ option => $ prices ) { array_push ( $ response , [ 'id' => strval ( $ option_index ) , 'title' => $ option , 'prices' => [ ] ] ) ; foreach ( $ prices as $ service => $ price ) { if ( $ price < 0 ) { throw new Exception ( 'Invalid negative price passed to "answerShippingQuery"' ) ; } $ formatted_price = intval ( $ price * 100 ) ; array_push ( $ response [ $ option_index - 1 ] [ 'prices' ] , [ 'label' => $ service , 'amount' => $ formatted_price ] ) ; } $ option_index ++ ; } return json_encode ( $ response ) ; }
\ brief Generate shipping options to pass to answerShippingQuery .
51,591
public function answerInlineQuery ( string $ results = '' , string $ switch_pm_text = '' , $ switch_pm_parameter = '' , bool $ is_personal = true , int $ cache_time = 300 ) : bool { if ( ! isset ( $ this -> _inline_query_id ) ) { throw new BotException ( "Inline query id not set, wrong update" ) ; } $ parameters = [ 'inline_query_id' => $ this -> _inline_query_id , 'switch_pm_text' => $ switch_pm_text , 'is_personal' => $ is_personal , 'switch_pm_parameter' => $ switch_pm_parameter , 'cache_time' => $ cache_time ] ; if ( isset ( $ results ) && $ results !== '' ) { $ parameters [ 'results' ] = $ results ; } return $ this -> execRequest ( 'answerInlineQuery?' . http_build_query ( $ parameters ) ) ; }
\ brief Answer a inline query ( when the user write
51,592
public function findUser ( $ userId ) { $ query = $ this -> database -> pdo -> prepare ( 'SELECT username, points FROM users WHERE userId = :userId' ) ; $ query -> bindParam ( ':userId' , $ userId ) ; $ query -> execute ( ) ; return ( object ) $ query -> fetch ( PDO :: FETCH_ASSOC ) ; }
Find the user by her user ID .
51,593
public function storeUserIfMissing ( $ message ) { $ userId = $ message [ 'from' ] [ 'id' ] ; $ username = strtolower ( $ message [ 'from' ] [ 'username' ] ) ; $ query = $ this -> database -> pdo -> prepare ( 'SELECT username FROM users WHERE userId = :userId' ) ; $ query -> bindParam ( ':userId' , $ userId ) ; $ query -> execute ( ) ; $ user = $ query -> fetch ( PDO :: FETCH_ASSOC ) ?? false ; if ( ! $ user ) { $ query = $ this -> database -> pdo -> prepare ( 'INSERT INTO users (userId, username, points) VALUES(:userId, :username, 0)' ) ; $ query -> bindParam ( ':userId' , $ userId ) ; $ query -> bindParam ( ':username' , $ username ) ; $ query -> execute ( ) ; return ; } if ( $ username !== $ user [ 'username' ] ) { $ query = $ this -> database -> pdo -> prepare ( 'UPDATE users SET username = :username WHERE userId = :userId' ) ; $ query -> bindParam ( ':userId' , $ userId ) ; $ query -> bindParam ( ':username' , $ username ) ; $ query -> execute ( ) ; } }
Checks if the user is already registered . If yes checks if her username is changed and update it . Otherwise register the new user .
51,594
public function resolveGroups ( $ formType ) { $ formGroups = null ; if ( isset ( $ this -> formConfig [ $ formType ] [ 'default_groups' ] ) ) { $ formGroups = $ this -> formConfig [ $ formType ] [ 'default_groups' ] ; } if ( is_array ( $ formGroups ) ) { $ groups = $ formGroups ; } else { $ groups = $ this -> defaultGroups ; } return $ this -> groupManager -> getGroupsByCodes ( $ groups ) ; }
Return groups by form type
51,595
protected function write ( array $ record ) { $ chat_id = $ this -> bot -> getChatLog ( ) ; if ( $ chat_id !== "" ) { $ this -> bot -> withChatId ( $ chat_id , 'sendMessage' , $ record [ 'message' ] ) ; } }
\ brief Send the message to telegram chat
51,596
public function clearLock ( $ name ) { if ( ! isset ( $ this -> locks [ $ name ] ) ) { return false ; } unset ( $ this -> locks [ $ name ] ) ; return true ; }
Clear lock without releasing it Do not use this method unless you know what you do
51,597
protected function setAssoc ( $ handle , $ assoc ) { $ oldSession = session_id ( ) ; session_commit ( ) ; session_id ( $ assoc [ 'handle' ] ) ; session_start ( ) ; $ _SESSION [ 'assoc' ] = $ assoc ; session_commit ( ) ; if ( $ oldSession ) { session_id ( $ oldSession ) ; session_start ( ) ; } }
Stores an association . If you want to use php sessions in your provider code you have to replace it .
51,598
protected function getAssoc ( $ handle ) { $ oldSession = session_id ( ) ; session_commit ( ) ; session_id ( $ handle ) ; session_start ( ) ; $ assoc = null ; if ( ! empty ( $ _SESSION [ 'assoc' ] ) ) { $ assoc = $ _SESSION [ 'assoc' ] ; } session_commit ( ) ; if ( $ oldSession ) { session_id ( $ oldSession ) ; session_start ( ) ; } return $ assoc ; }
Retreives association data . If you want to use php sessions in your provider code you have to replace it .
51,599
protected function delAssoc ( $ handle ) { $ oldSession = session_id ( ) ; session_commit ( ) ; session_id ( $ handle ) ; session_start ( ) ; session_destroy ( ) ; if ( $ oldSession ) { session_id ( $ oldSession ) ; session_start ( ) ; } }
Deletes an association . If you want to use php sessions in your provider code you have to replace it .