idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
14,700
public function sendAcceptProductToOwner ( Product $ product ) { $ productOwner = $ product -> productOwner ; $ ownerEmail = $ productOwner -> email ; $ mailVars = [ '{title}' => $ product -> translation -> title , '{ownerEmail}' => $ ownerEmail , '{owner}' => ! ( empty ( $ productOwner -> profile -> name . ' ' . $ pro...
If a product has successfully passed moderation this email to product owner will be sent
14,701
public function load ( ) { $ themes = $ this -> config -> get ( 'themer.themes' ) ; if ( $ themes === null ) { throw new NullValueException ( 'Theme list is empty' ) ; } return $ this -> parseThemes ( $ themes ) ; }
Load all themes
14,702
public function add ( ThemeSettings $ settings , string $ key = null ) : ? Theme { if ( $ key !== null ) { $ settings -> key = $ key ; } if ( $ this -> has ( $ settings -> key ) ) { throw new KeyExistsException ( "Theme with key '{$settings->key}' already exists" ) ; } if ( $ settings -> enabled ) { $ theme = new Theme...
Add a theme if enabled
14,703
public function has ( ? string $ key ) : bool { return $ key === null ? false : isset ( $ this -> themes [ $ key ] ) ; }
Check if theme exists
14,704
public function setDefault ( $ theme ) : Theme { if ( $ theme instanceof Theme ) { $ default = $ theme ; } elseif ( $ this -> has ( $ theme ) ) { $ default = $ this -> get ( $ theme ) ; } if ( ! isset ( $ default ) ) { throw new NullValueException ( "Cannot set default theme when theme does not exist" ) ; } if ( ! $ de...
Set default theme
14,705
public function setOverride ( $ theme = null ) : ? Theme { if ( $ theme === null ) { return $ this -> override = null ; } if ( $ theme instanceof Theme ) { $ this -> override = $ theme ; } elseif ( $ this -> has ( $ theme ) ) { $ this -> override = $ this -> get ( $ theme ) ; } if ( $ this -> override === null || ( $ t...
Set override theme
14,706
public static function __callstatic ( $ index , $ params = false ) { if ( array_key_exists ( $ index , self :: $ instances ) ) { self :: setCurrentID ( $ index ) ; $ that = self :: getInstance ( ) ; return $ that ; } array_unshift ( $ params , $ index ) ; return call_user_func_array ( [ __CLASS__ , 'getOption' ] , $ pa...
Access the configuration parameters .
14,707
public static function setOption ( $ option , $ value ) { $ that = self :: getInstance ( ) ; if ( ! is_array ( $ value ) ) { return $ that -> settings [ $ option ] = $ value ; } if ( array_key_exists ( $ option , $ that -> settings ) ) { $ that -> settings [ $ option ] = array_merge_recursive ( is_array ( $ that -> set...
Define new configuration settings .
14,708
public static function setCurrentID ( $ id ) { if ( array_key_exists ( $ id , self :: $ instances ) ) { self :: $ id = $ id ; return true ; } return false ; }
Define the current application ID .
14,709
private function setPaths ( $ baseDirectory ) { $ this -> setOption ( 'ROOT' , rtrim ( $ baseDirectory , '/' ) . '/' ) ; $ this -> setOption ( 'CORE' , dirname ( dirname ( dirname ( __DIR__ ) ) ) . '/' ) ; $ this -> setOption ( 'PUBLIC' , self :: ROOT ( ) . 'public/' ) ; $ this -> setOption ( 'TEMPLATES' , self :: ROOT...
Set application paths .
14,710
private function setUrls ( $ baseDirectory , $ type ) { switch ( $ type ) { case 'wordpress-plugin' : $ pluginUrl = plugins_url ( basename ( $ baseDirectory ) ) ; $ baseUrl = Url :: addBackSlash ( $ pluginUrl ) ; break ; default : $ baseUrl = Url :: getBaseUrl ( ) ; break ; } $ this -> setOption ( 'ROOT_URL' , $ baseUr...
Set url depending where the framework is launched .
14,711
private function setIp ( ) { if ( class_exists ( $ Ip = 'Josantonius\Ip\Ip' ) ) { $ ip = $ Ip :: get ( ) ; $ this -> setOption ( 'IP' , ( $ ip ) ? $ ip : 'unknown' ) ; } }
Set ip .
14,712
private function runHooks ( ) { if ( class_exists ( $ Hook = 'Josantonius\Hook\Hook' ) ) { $ Hook :: getInstance ( self :: $ id ) ; if ( isset ( $ this -> settings [ 'hooks' ] ) ) { $ Hook :: addActions ( $ this -> settings [ 'hooks' ] ) ; unset ( $ this -> settings [ 'hooks' ] ) ; } $ Hook :: doAction ( 'after-load-ho...
Load hooks .
14,713
private function runComplements ( ) { $ complement = 'Eliasis\Complement\\' ; if ( class_exists ( $ complement . 'Complement' ) ) { call_user_func ( $ complement . 'Type\Component::run' ) ; call_user_func ( $ complement . 'Type\Plugin::run' ) ; call_user_func ( $ complement . 'Type\Module::run' ) ; call_user_func ( $ c...
Load complements .
14,714
private function runRoutes ( ) { if ( class_exists ( $ Router = 'Josantonius\Router\Router' ) ) { if ( isset ( $ this -> settings [ 'routes' ] ) ) { $ Router :: add ( $ this -> settings [ 'routes' ] ) ; unset ( $ this -> settings [ 'routes' ] ) ; } $ Router :: dispatch ( ) ; } }
Load Routes .
14,715
public function call ( $ method , $ params = [ ] ) { if ( null === $ this -> client ) { $ this -> client = new Client ( [ 'base_uri' => static :: API_URL , 'content-type' => 'application/json' , ] ) ; } $ requestParams = array_merge ( $ this -> defaultParams , [ $ method => [ $ params ] , ] ) ; if ( $ this -> sandbox )...
Makes api call
14,716
protected function prepare_args ( array $ args , array $ required ) { $ required = \ wp_parse_args ( $ required , [ 'tab_id' ] ) ; foreach ( $ required as $ property ) { if ( ! isset ( $ args [ $ property ] ) ) { throw new \ InvalidArgumentException ( "Missing argument '$property'." ) ; } } $ defaults = [ 'section' => ...
Prepares keyowrd arguments passed via an array for usage .
14,717
public function get_value ( ) { $ key = $ this -> options_key ? : $ this -> id ; $ options = $ this -> options -> get ( $ key ) ; if ( $ key === $ this -> id ) { return $ options ; } elseif ( isset ( $ options [ $ this -> id ] ) ) { return $ options [ $ this -> id ] ; } else { return null ; } }
Retrieve the current value for the control . May be overridden by subclasses .
14,718
protected function get_html_attributes ( array $ attributes ) { $ html_attributes = '' ; if ( ! empty ( $ attributes ) ) { foreach ( $ attributes as $ attr => $ val ) { $ html_attributes .= \ esc_attr ( $ attr ) . '="' . \ esc_attr ( $ val ) . '" ' ; } } return $ html_attributes ; }
Retrieves additional HTML attributes as a string ready for inclusion in markup .
14,719
public function get_label ( ) { if ( $ this -> label_has_placeholder ( ) ) { return sprintf ( $ this -> label , $ this -> get_element_markup ( ) ) ; } else { return $ this -> label ; } }
Retrieves the label . If the label text contains a string placeholder it is replaced by the control element markup .
14,720
public function register ( $ option_group ) { if ( empty ( $ this -> grouped_with ) ) { \ add_settings_field ( $ this -> get_id ( ) , $ this -> short , [ $ this , 'render' ] , $ option_group . $ this -> tab_id , $ this -> section , $ this -> settings_args ) ; } }
Register the control with the settings API .
14,721
public function add_grouped_control ( Control $ control ) { if ( $ this !== $ control ) { $ this -> grouped_controls [ ] = $ control ; $ control -> group_with ( $ this ) ; } }
Group another control with this one .
14,722
public function sanitize ( $ value ) { $ sanitize = $ this -> sanitize_callback ; if ( \ is_callable ( $ sanitize ) ) { return $ sanitize ( $ value ) ; } return $ value ; }
Sanitizes an option value .
14,723
public function addChildren ( array $ children , $ type = self :: TYPE_DEFAULT ) { foreach ( $ children as $ name => $ child ) { if ( is_string ( $ name ) ) { $ this -> addChild ( $ child , $ name , $ type ) ; continue ; } $ this -> addChild ( $ child , null , $ type ) ; } return $ this ; }
Add the children
14,724
public function addChild ( $ child , $ name = null , $ type = self :: TYPE_DEFAULT ) { if ( ! $ child instanceof Descriptor ) { $ child = new static ( $ child , $ type ) ; } if ( $ name === null ) { $ this -> _children [ ] = $ child ; return $ child ; } $ this -> _children [ $ name ] = $ child ; return $ child ; }
Add the child
14,725
public function offsetSet ( $ offset , $ value ) { if ( is_array ( $ value ) ) { $ this -> addChildren ( $ value , is_string ( $ offset ) ? $ offset : null ) ; return ; } $ this -> addChild ( $ value , $ offset ) ; }
Add the child or the array of children
14,726
public function resetCoordinates ( $ resetMax = false ) { $ this -> currentColumn = reset ( $ this -> columns ) ; $ this -> currentRow = 1 ; if ( $ resetMax ) { $ this -> maxColumn = reset ( $ this -> columns ) ; $ this -> maxRow = 1 ; } return $ this ; }
Reset the coordinates back to initial values
14,727
public function writeRow ( array $ data = [ ] , $ finalize = true ) { $ lastDataKey = $ this -> getLastArrayKey ( $ data ) ; foreach ( $ data as $ key => $ value ) { $ coordinate = sprintf ( '%s%d' , $ this -> getCurrentColumn ( ) , $ this -> getCurrentRow ( ) ) ; $ this -> worksheet -> setCellValue ( $ coordinate , $ ...
Write a row in the sheet
14,728
protected function getUsedColumns ( ) { if ( strlen ( $ this -> maxColumn ) == 2 ) { $ usedColumns = range ( 'A' , 'Z' ) ; $ max = $ this -> maxColumn [ 0 ] ; $ upperRange = range ( 'A' , $ max ) ; foreach ( $ upperRange as $ x ) { $ end = $ max == $ x ? $ this -> maxColumn [ 1 ] : 'Z' ; foreach ( range ( 'A' , $ end )...
Get all used columns based on the maxColumn
14,729
public function nextColumn ( ) { $ this -> currentColumn = next ( $ this -> columns ) ; $ this -> updateMaxColumn ( $ this -> currentColumn ) ; return true ; }
Set the pointer to the next column
14,730
public function nextRow ( $ reset = true ) { $ this -> currentRow += 1 ; $ this -> updateMaxRow ( $ this -> currentRow ) ; if ( $ reset ) { $ this -> currentColumn = reset ( $ this -> columns ) ; } return true ; }
Set the pointer to the next row by default reset to first column
14,731
private function updateMaxColumn ( $ currentColumn ) { $ max = $ this -> maxColumn ; if ( strlen ( $ currentColumn ) > strlen ( $ max ) ) { return $ this -> maxColumn = $ currentColumn ; } elseif ( strlen ( $ currentColumn ) < strlen ( $ max ) ) { } elseif ( strlen ( $ currentColumn ) == 1 && strlen ( $ max ) == 1 ) { ...
Update the max column
14,732
public function setHeaders ( iterable $ headers , bool $ skipFirstLine ) : void { $ this -> headers = Bag :: from ( $ headers ) ; $ this -> associativeRows = true ; $ this -> skipFirstLine = $ skipFirstLine ; }
Manually set the headers .
14,733
public static function fromConstructs ( array $ constructs ) : self { $ exception = new self ( \ sprintf ( "Multiple definitions have been found for the following constructs:\n\n%s" , \ implode ( "\n" , \ array_map ( static function ( Construct $ construct ) { return \ sprintf ( ' - "%s" defined in "%s"' , $ construct ...
Returns a new exception from constructs .
14,734
public function get ( string $ group , string $ key ) { return $ this -> values [ $ group ] [ $ key ] ?? null ; }
Retrieve a value from cache
14,735
public function remove ( string $ group = "" , string $ key = "" ) : ArrayCache { $ isGroupEmpty = ( $ group === "" ) ; $ isKeyEmpty = ( $ key === "" ) ; if ( $ isGroupEmpty && ! $ isKeyEmpty ) { throw new \ LogicException ( "removing a value by key is only possible when a group " . "is provided" ) ; } if ( $ isKeyEmpt...
Remove a value or an entire group of values from storage
14,736
public function addLogoutItem ( MenuCollectionEvent $ event ) : void { $ menu = $ event -> getMenu ( ) ; $ separator = $ this -> factory -> createItem ( 'separator' , [ 'extras' => [ 'separator' => true , 'translation_domain' => false , ] , ] ) ; $ menu -> addChild ( $ separator ) ; $ logout = $ this -> factory -> crea...
Create the logout menu item .
14,737
public function assemble ( ) { $ encTag = new Tag ( 'meta' ) ; $ encTag -> setClosed ( ) ; $ encTag -> charset = $ this -> encoding ; return $ encTag -> render ( ) ; }
Assemble the encoding tag
14,738
protected function getSessionNamespace ( $ name = null ) { if ( $ name === null ) { $ name = str_replace ( '\\' , '_' , get_class ( $ this ) ) ; } if ( isset ( $ this -> _namespacesInstances [ $ name ] ) ) { return $ this -> _namespacesInstances [ $ name ] ; } $ namespace = $ this -> getNamespaceFactory ( ) -> createNa...
Get the namespace of the session
14,739
public function getNamespaceFactory ( ) { if ( $ this -> _namespacesFactory === null ) { if ( $ this instanceof LocatorAwareInterface && $ this -> hasLocator ( ) ) { $ this -> _namespacesFactory = $ this -> getLocator ( ) -> get ( $ this -> getSessionNamespaceFactoryServiceId ( ) ) ; if ( ! $ this -> _namespacesFactory...
Get the namespaces factory
14,740
public function hasNamespaceFactory ( ) { if ( $ this -> _namespacesFactory !== null ) { return true ; } if ( $ this instanceof LocatorAwareInterface && $ this -> hasLocator ( ) && $ this -> getLocator ( ) -> has ( $ this -> getSessionNamespaceFactoryServiceId ( ) ) ) { return true ; } return false ; }
Has the namespaces factory
14,741
public function actionReply ( $ id ) { $ comment = $ this -> findModel ( $ id ) ; if ( ! \ Yii :: $ app -> user -> can ( 'replyStranger' , [ 'comment' => $ comment ] ) ) return $ this -> alert ( \ Yii :: t ( 'app' , 'Access denied.' ) ) ; $ model = $ this -> newModel ( ) ; $ model -> model = $ comment -> model ; $ mode...
Reply on a comment . If creation is successful the browser will be redirected to the index page .
14,742
public function head ( $ options = null ) { if ( $ options !== null ) { $ this -> setOptions ( $ options , false , false ) ; } return $ this ; }
The helper main
14,743
public function setBaseStaticUrl ( $ url ) { if ( $ url === '/' || $ url === '//' ) { $ this -> staticBaseUrl = $ url ; return ; } $ this -> staticBaseUrl = rtrim ( $ url , '/' ) ; return $ this ; }
Set the base URL of the static files
14,744
public function getBaseStaticPath ( ) { if ( $ this -> staticBasePath === null ) { if ( isset ( $ _SERVER [ 'DOCUMENT_ROOT' ] ) ) { $ this -> staticBasePath = $ _SERVER [ 'DOCUMENT_ROOT' ] ; } else { $ this -> staticBasePath = realpath ( '.' ) ; } } return $ this -> staticBasePath ; }
Get the base path of the static files
14,745
public function getMetadataManager ( ) { if ( $ this -> metadataManager === null ) { $ path = sys_get_temp_dir ( ) . DIRECTORY_SEPARATOR . '.zstaticmeta' ; $ this -> metadataManager = new Head \ MetadataManager ( $ path ) ; } return $ this -> metadataManager ; }
Get the metadata manager
14,746
public function render ( ) { $ parts = [ ] ; if ( empty ( $ this -> elements ) ) { return '' ; } foreach ( $ this -> elements as $ element ) { if ( ! $ element -> isEmpty ( ) ) { $ parts [ ] = $ element -> assemble ( ) ; } } return implode ( PHP_EOL , $ parts ) ; }
Render the meta tags
14,747
public function getElement ( $ name ) { if ( isset ( $ this -> elements [ $ name ] ) ) { return $ this -> elements [ $ name ] ; } $ class = 'ZExt\Mvc\View\Helpers\Head\Element' . ucfirst ( $ name ) ; $ element = new $ class ( $ this -> getBaseStaticPath ( ) , $ this -> getBaseStaticUrl ( ) , $ this -> getMetadataManage...
Get the element
14,748
public function getPath ( $ key , $ isFlushable ) { $ cmd = $ this -> client -> getCommand ( 'GetObject' , [ 'Bucket' => $ this -> bucket , 'Key' => $ key , ] ) ; $ request = $ this -> client -> createPresignedRequest ( $ cmd , '+20 minutes' ) ; return ( string ) $ request -> getUri ( ) ; }
Return the base path .
14,749
protected function isLimited ( array $ record ) { if ( $ this -> rateLimit <= 0 ) { return false ; } $ key = 'logger:lock:' . $ this -> identifyRecord ( $ record ) ; return ! ( bool ) $ this -> redis -> set ( $ key , '' , 'EX' , $ this -> rateLimit , 'NX' ) ; }
Returns whether a record as been limited or not .
14,750
public function log ( $ msg , array $ data = [ ] , $ level = Logger :: INFO ) : void { $ this -> mgr -> log ( $ msg , $ data , $ level ) ; }
output log message
14,751
public function registerPortEvents ( ) : void { foreach ( ( array ) $ this -> options [ 'events' ] as $ event => $ method ) { if ( \ is_int ( $ event ) ) { $ event = substr ( $ method , 2 ) ; } if ( method_exists ( $ this , $ method ) ) { $ this -> port -> on ( $ event , [ $ this , $ method ] ) ; } } }
register Swoole Port Events
14,752
public static function formatToInteger ( $ value , $ decimals = 2 ) { if ( trim ( $ value ) != null ) { return number_format ( $ value , $ decimals , '.' , '' ) * 100 ; } return null ; }
Format the input data without decimal places
14,753
public static function formatToPrice ( $ value , $ currency = null ) { $ decimals = 2 ; $ currencyDecimals = array ( 'JPY' => 0 , 'TWD' => 0 ) ; if ( $ currency && array_key_exists ( $ currency , $ currencyDecimals ) ) { if ( strpos ( $ value , "." ) !== false && ( floor ( $ value ) != $ value ) ) { throw new \ Invalid...
Helper method to format price values with associated currency information .
14,754
private function generate_code ( ) { $ length = rand ( $ this -> min_length , $ this -> max_length ) ; $ numChars = strlen ( $ this -> chars ) ; $ str = [ ] ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ str [ ] = substr ( $ this -> chars , rand ( 1 , $ numChars ) - 1 , 1 ) ; } $ str = implode ( '' , $ str ) ; $ array...
Generates code for visitor
14,755
private function getImage ( $ code ) { if ( ! is_dir ( DIR_CACHE . 'captcha/' ) ) { FileSystem :: mkDir ( DIR_CACHE . 'captcha/' ) ; } $ filename_url = DIR_CACHE_URL . 'captcha/' . VISITOR_HASH . md5 ( $ code ) . '.png' ; $ filename = DIR_BASE . $ filename_url ; if ( file_exists ( $ filename ) ) { return $ filename_url...
Generates image with code
14,756
public function send ( ) { $ this -> sendHeader ( ) ; $ body = $ this -> getBody ( ) ; $ body -> rewind ( ) ; echo $ body -> getContents ( ) ; }
Send header and print response
14,757
public function createWrapper ( $ namespace = null ) { if ( ! isset ( $ this -> _wrappers [ $ namespace ] ) ) { $ wrapper = new Wrapper ( $ this -> getBackend ( ) , $ namespace ) ; $ lifetime = $ this -> getDefaultLifetime ( ) ; if ( $ lifetime !== null ) { $ wrapper -> setDefaultLifetime ( $ lifetime ) ; } $ this -> _...
Create the namespaced wrapper
14,758
public function createCollectionHandler ( DatagateInterface $ datagate ) { $ namespace = md5 ( $ datagate -> getModelClass ( ) ) ; if ( ! isset ( $ this -> _collectionHandlers [ $ namespace ] ) ) { $ handler = new CollectionHandler ( $ this -> getBackend ( ) , $ datagate , $ namespace ) ; $ lifetime = $ this -> getDefa...
Create the collection handler for the datagate
14,759
public static function workshopTimeString ( $ arrRow ) { $ str = '' ; $ arrTimes = array ( 'All' => 'all' , 'A' => 'a' , 'B' => 'b' ) ; foreach ( $ arrTimes as $ caps => $ nocaps ) { if ( $ arrRow [ 'is' . $ caps ] == 1 ) { if ( $ str != '' ) $ str .= ' / ' ; $ str .= $ GLOBALS [ 'TL_LANG' ] [ 'wbgym' ] [ 'weekdayShort...
Get Date and Time String of a workshop array
14,760
private function handleResource ( TranslationResource $ resource , $ translationMode , $ allLanguages , OutputInterface $ output ) { if ( substr ( $ resource -> getSlug ( ) , 0 , strlen ( $ this -> prefix ) ) != $ this -> prefix ) { $ this -> writelnVerbose ( $ output , sprintf ( 'Received resource <info>%s</info> is n...
Handle a single resource .
14,761
private function handleLanguage ( TranslationResource $ resource , $ code , $ translationMode , OutputInterface $ output ) { $ this -> writeln ( $ output , sprintf ( 'Updating language <info>%s</info>' , $ code ) ) ; $ data = $ resource -> fetchTranslation ( $ code , $ translationMode ) ; if ( $ data ) { $ local = $ th...
Handle a language for a resource .
14,762
private function isHandlingLanguage ( $ code , $ allLanguages ) { if ( $ code == $ this -> baselanguage ) { return false ; } if ( $ allLanguages ) { return true ; } return in_array ( substr ( $ code , 0 , 2 ) , $ this -> languages ) ; }
Check if we want to handle the given language code .
14,763
private function getLocalXliffFile ( TranslationResource $ resource , $ languageCode ) { $ domain = substr ( $ resource -> getSlug ( ) , strlen ( $ this -> prefix ) ) ; $ localFile = $ this -> txlang . DIRECTORY_SEPARATOR . substr ( $ languageCode , 0 , 2 ) . DIRECTORY_SEPARATOR . $ domain . '.xlf' ; $ local = new Xlif...
Create a xliff instance for the passed resource .
14,764
public function getTables ( $ db = NULL , $ use_cache = true ) : array { if ( ! $ db ) { $ db = Configuration :: getInstance ( ) -> get ( 'db' ) [ 'name' ] ; if ( ! $ db ) { return [ ] ; } } if ( Settings :: isCacheEnabled ( ) ) { $ cache_key = 'db_table_list_all' ; $ cacher = Cacher :: getInstance ( ) -> getDefaultCac...
Show tables in database
14,765
public function sqlQueryCheck ( $ q ) { if ( \ stripos ( $ q , 'union' ) !== false ) { dump ( 'UNION usage is limited.' ) ; } if ( \ stripos ( $ q , ' like \'%\'' ) !== false ) { dump ( 'LIKE \'%\' usage is limited.' ) ; } if ( \ strpos ( $ q , '/*' ) !== false || \ strpos ( $ q , '--' ) !== false ) { dump ( 'Comments ...
Check for abuse parameters in query
14,766
public function getFunctions ( $ db = NULL ) : array { if ( ! $ db ) { $ db = Configuration :: getInstance ( ) -> get ( 'db' ) [ 'name' ] ; } $ res = [ ] ; foreach ( q_assoc_iterator ( 'SHOW FUNCTION STATUS WHERE `Db` = "' . $ db . '"' ) as $ v ) { $ res [ ] = $ v [ 'Name' ] ; } return $ res ; }
Show functions in database
14,767
public static function q_check ( string $ table , string $ where = '' ) : bool { return ( bool ) self :: getInstance ( ) -> sql_query ( 'SELECT NULL FROM `' . $ table . '`' . ( $ where ? ' WHERE ' . $ where : '' ) . ' LIMIT 1' ) -> rowCount ( ) ; }
Check entry exists in DB
14,768
public static function q_column ( $ q , $ column = 0 ) : array { $ qh = self :: getInstance ( ) -> sql_query ( $ q ) ; return $ qh -> fetchAll ( PDO :: FETCH_COLUMN , $ column ) ; }
Return one dimensional array with one column for example IDs list
14,769
public static function getCreateFunction ( $ tbl ) : string { $ sql = self :: getInstance ( ) -> sql_query ( "SHOW CREATE FUNCTION `$tbl`" ) ; $ q = $ sql -> fetch ( PDO :: FETCH_ASSOC ) ; return strtr ( $ q [ 'Create Function' ] , [ "\r" => '' , "\n" => '' , "\t" => '' ] ) ; }
Get create sql for function
14,770
public static function getFields ( $ tbl ) : array { if ( Settings :: isCacheEnabled ( ) ) { $ cache_key = 'db_table_columns_' . $ tbl ; $ cacher = Cacher :: getInstance ( ) -> getDefaultCacher ( ) ; if ( ! isset ( self :: $ _cached_tbl_columns [ $ tbl ] ) ) { self :: $ _cached_tbl_columns [ $ tbl ] = $ cacher -> get (...
Show all columns in table
14,771
public static function getFieldsWithAllData ( $ tbl ) : array { if ( isset ( self :: $ _cached_tbl_fields [ $ tbl ] ) ) { return self :: $ _cached_tbl_fields [ $ tbl ] ; } return self :: $ _cached_tbl_fields = self :: q_assoc_id ( "SHOW FIELDS FROM `$tbl`" ) ; }
Show all columns in table with all data like type
14,772
public static function getRows ( $ tbl , $ where = '' ) : array { $ res = [ ] ; $ sql = self :: getInstance ( ) -> sql_query ( 'SELECT * FROM `' . self :: sql_prepare ( $ tbl ) . '`' . ( $ where ? ' WHERE ' . $ where : '' ) ) ; while ( $ q = $ sql -> fetch ( PDO :: FETCH_ASSOC ) ) { $ res [ ] = $ q ; } return $ res ; }
Get all rows with data from table
14,773
public static function sql_prepare ( $ str , $ used_in_like = false ) { if ( ! self :: getInstance ( ) -> pdo_db ) { self :: getInstance ( ) -> connect ( ) ; } if ( is_array ( $ str ) ) { foreach ( $ str as & $ v ) { $ v = self :: sql_prepare ( $ v ) ; } } else { $ str = substr ( self :: getInstance ( ) -> pdo_db -> qu...
retrieve value from associative array
14,774
public static function makeInserts ( $ tbl , $ rows , array $ fields = [ ] , $ implode = ";\n" , $ query_max_len = 524288 ) : array { if ( $ query_max_len > 1048575 ) { throw new InvalidArgumentException ( 'Each query should be shorter than 1MB.' ) ; } if ( $ fields ) { foreach ( $ fields as & $ v ) { $ v = '`' . $ v ....
Insert a lot of values at once using multiple queries to prevent memory overflow
14,775
public static function swapTable ( $ tbl ) : string { $ tmp_tbl = $ tbl . '_' . NOW ; $ new_tbl = $ tmp_tbl . '_new' ; self :: getInstance ( ) -> sql_query ( str_replace ( '`' . $ tbl . '`' , '`' . $ new_tbl . '`' , self :: getCreateTable ( $ tbl ) ) ) ; self :: getInstance ( ) -> sql_query ( 'RENAME TABLE `' . $ tbl ....
Create new empty table with same name and save old with content with unique name Useful saving logs and achieving
14,776
public static function getCreateTable ( $ tbl ) : string { if ( isset ( self :: $ cached_create_table_statements [ $ tbl ] ) ) { return self :: $ cached_create_table_statements [ $ tbl ] ; } $ sql = self :: getInstance ( ) -> sql_query ( "SHOW CREATE TABLE `$tbl`" ) ; $ q = $ sql -> fetch ( PDO :: FETCH_ASSOC ) ; $ str...
Get create table or create view statement
14,777
public static function usesAllIndexes ( $ sql ) : bool { $ qh = self :: getInstance ( ) -> sql_query ( 'EXPLAIN ' . $ sql ) ; if ( ! $ qh -> rowCount ( ) ) { return false ; } while ( $ q = $ qh -> fetch ( PDO :: FETCH_ASSOC ) ) { if ( ! $ q [ 'key' ] ) { return false ; } } return true ; }
Check if query uses all possible db table indexes
14,778
public static function storeEditableCmsTable ( $ table , array $ data ) : array { $ res = [ 'add' => 0 , 'update' => 0 , 'delete' => 0 ] ; if ( isset ( $ data [ 'update' ] ) && \ is_array ( $ data [ 'update' ] ) ) { foreach ( $ data [ 'update' ] as $ id => $ v ) { $ res [ 'update' ] += self :: update ( $ table , $ v , ...
This function saves all table data when using table with form inputs
14,779
public static function getEnumPairs ( $ table , $ column ) : array { $ result = self :: q_assoc_row ( 'SHOW COLUMNS FROM `' . self :: sql_prepare ( $ table ) . '` WHERE `field` = "' . self :: sql_prepare ( $ column ) . '"' ) ; $ result = str_replace ( [ "enum('" , "')" , "''" ] , [ '' , '' , "'" ] , $ result [ 'Type' ]...
Get values available for column in table
14,780
public function addPrimaryAutoIncrementIdFieldToTable ( $ table ) : bool { @ $ this -> sql_query ( 'ALTER IGNORE TABLE `' . $ table . '` DROP PRIMARY KEY' ) ; $ this -> sql_query ( 'ALTER IGNORE TABLE `' . $ table . '` ADD `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST' ) ; return true ; }
Create ID field for table - required for Entity management
14,781
public function addMessage ( AddMessageEvent $ event ) { $ messageAdapter = $ this -> framework -> getAdapter ( Message :: class ) ; $ messageAdapter -> add ( $ event -> getContent ( ) , 'TL_' . strtoupper ( $ event -> getType ( ) ) ) ; }
Add a message to the contao message array in the session .
14,782
static public function read ( $ file ) { if ( ! $ file instanceof FileInterface ) { $ file = new File ( $ file ) ; } return static :: parse ( $ file -> getContent ( ) ) ; }
Read and parse XML from file
14,783
public function addObservation ( $ x ) { $ x = ( float ) $ x ; $ this -> min = min ( $ this -> min , $ x ) ; $ this -> max = max ( $ this -> max , $ x ) ; $ n1 = $ this -> n ; $ this -> n += 1 ; $ delta = $ x - $ this -> m1 ; $ delta_n = $ delta / $ this -> n ; $ this -> m1 += $ delta_n ; $ this -> m2 += $ delta * $ de...
Add a number to the data set .
14,784
public function getVariance ( ) { if ( $ this -> n === 0 ) { return NAN ; } elseif ( $ this -> n === 1 ) { return 0.0 ; } else { return $ this -> m2 / ( $ this -> n - 1.0 ) ; } }
Get the estimated variance .
14,785
public function merge ( RunningStat $ other ) { if ( $ other -> n === 0 ) { return ; } if ( $ this -> n === 0 ) { $ this -> n = $ other -> n ; $ this -> m1 = $ other -> m1 ; $ this -> m2 = $ other -> m2 ; $ this -> min = $ other -> min ; $ this -> max = $ other -> max ; return ; } $ n = $ this -> n + $ other -> n ; $ d...
Merge another RunningStat instance into this instance .
14,786
public function get_value ( ) { $ config = $ this -> options -> get ( $ this -> options_key ) ; $ value = $ config [ $ this -> id ] ; if ( isset ( $ this -> option_values ) && ! isset ( $ this -> option_values [ $ value ] ) ) { $ value = null ; } return $ value ; }
Retrieve the current value for the select control .
14,787
protected function get_element_markup ( ) { $ select_markup = "<select {$this->get_id_and_class_markup()}>" ; $ value = $ this -> get_value ( ) ; foreach ( $ this -> option_values as $ option_value => $ display ) { $ select_markup .= '<option value="' . \ esc_attr ( $ option_value ) . '" ' . \ selected ( $ value , $ op...
Retrieves the control - specific HTML markup .
14,788
public static function create ( Options $ options , $ options_key , $ id , array $ args ) { return new static ( $ options , $ options_key , $ id , $ args ) ; }
Creates a new select control
14,789
public function setCallCenterRepIds ( $ callCenterRepId ) { if ( ! is_array ( $ callCenterRepId ) ) $ callCenterRepId = array ( $ callCenterRepId ) ; $ this -> callCenterRepId = $ callCenterRepId ; return $ this ; }
Call center representative Id . Must be set to one of the IDs specified in the merchant config callcenter . allowed . reps list . If there are no IDs in the callcenter . allowed . reps list the callCenterRepId can be an empty string .
14,790
public static function jsonPreloadData ( \ Object \ Table $ model , array $ where , array $ columns , array & $ values ) { $ result = $ model -> get ( [ 'where' => $ where , 'pk' => null ] ) ; foreach ( $ columns as $ a => $ c ) { if ( is_array ( $ c ) ) { $ only_columns = $ c ; $ c = $ a ; } else { $ only_columns = fa...
Preload json data
14,791
public static function jsonSaveData ( \ Object \ Table $ model , array $ values , \ Object \ Form \ Base & $ form , string $ id_column ) : bool { if ( ! empty ( $ form -> values [ $ id_column ] ) ) { $ values [ $ id_column ] = $ form -> values [ $ id_column ] ; } $ result = $ model -> collection ( ) -> merge ( $ values...
Save json data
14,792
public function aroundAddFilter ( \ Magento \ CatalogInventory \ Ui \ DataProvider \ Product \ AddQuantityFilterToCollection $ subject , \ Closure $ proceed , \ Magento \ Catalog \ Model \ ResourceModel \ Product \ Collection $ collection , $ field , $ condition = null ) { $ regKey = print_r ( $ condition , true ) ; if...
Replace WHERE - filtering by HAVING - filtering .
14,793
public function addAdminTheme ( $ key , $ args ) { if ( empty ( $ args ) ) { return ; } $ defaults = [ 'name' => $ key , 'url' => $ key , 'colors' => [ ] , 'icons' => [ ] ] ; $ opts = array_merge ( $ defaults , $ args ) ; if ( ! isset ( $ opts [ 'name' ] , $ opts [ 'url' ] , $ opts [ 'colors' ] ) ) { return ; } if ( 3 ...
Add admin theme .
14,794
public function getFinder ( ) { if ( null === $ this -> finder ) { $ this -> finder = new Finder ( ) ; $ this -> finder -> files ( ) ; } return $ this -> finder ; }
Returns the Finder instance .
14,795
public function getProcessor ( ) { if ( null === $ this -> processor ) { if ( null !== $ this -> width ) { return self :: PROCESSOR_FIXED ; } return self :: PROCESSOR_DYNAMIC ; } return $ this -> processor ; }
Returns the name of the image ProcessorInterface instance to use .
14,796
protected function setError ( string $ msg ) { $ this -> error = $ msg ; $ lastError = error_get_last ( ) ; if ( $ lastError !== null ) { $ this -> errorDetail = sprintf ( "'%s' in %s on line %s" , $ lastError [ 'message' ] , $ lastError [ 'file' ] , $ lastError [ 'line' ] ) ; } }
Set an error message
14,797
public static function loadData ( ) { if ( static :: $ arrDBCalendar === null ) { $ years = \ Database :: getInstance ( ) -> prepare ( "SELECT * FROM tl_schoolyear" ) -> execute ( ) ; while ( $ arrSY = $ years -> fetchAssoc ( ) ) { static :: $ arrDBCalendar [ $ arrSY [ 'id' ] ] = $ arrSY ; } $ holidays = \ Database :: ...
Load School Years and Holidays
14,798
public static function schoolYear ( ) { static :: loadData ( ) ; foreach ( static :: $ arrDBCalendar as $ sy ) { if ( $ sy [ 'start' ] < time ( ) && $ sy [ 'end' ] > time ( ) ) return date ( 'Y' , $ sy [ 'end' ] ) ; elseif ( $ sy [ 'start' ] > time ( ) && date ( 'Y' , $ sy [ 'start' ] ) == date ( 'Y' ) ) return date ( ...
Get graduation year of current school year
14,799
public static function schoolYearAtTime ( $ year = null ) { static :: loadData ( ) ; if ( is_null ( $ year ) ) return static :: schoolYear ( ) ; foreach ( static :: $ arrDBCalendar as $ sy ) { if ( $ sy [ 'start' ] < $ year && $ sy [ 'end' ] > $ year ) return date ( 'Y' , $ sy [ 'end' ] ) ; elseif ( $ sy [ 'start' ] > ...
Get graduation year of any school year