idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
55,200
protected function validateInstallerInstall ( ) { $ field = 'installer' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setSubmitted ( 'installer' , 'default' ) ; return null ; } $ installer = $ this -> install -> getHandler ( $ value ) ; if ( empty ( $ installer ) ) { $ this -> setErrorInvalid ( 'installer' , $ this -> translation -> text ( 'Installer' ) ) ; return false ; } return true ; }
Validates an installer ID
55,201
protected function validateDbNameInstall ( ) { $ field = 'database.name' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ this -> translation -> text ( 'Database name' ) ) ; return false ; } return true ; }
Validates a database name
55,202
protected function validateDbPasswordInstall ( ) { $ field = 'database.password' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> setSubmitted ( $ field , '' ) ; return null ; } return true ; }
Validates a database password
55,203
protected function validateDbTypeInstall ( ) { $ field = 'database.type' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ this -> translation -> text ( 'Database type' ) ) ; return false ; } $ drivers = \ PDO :: getAvailableDrivers ( ) ; if ( in_array ( $ value , $ drivers ) ) { return true ; } $ error = $ this -> translation -> text ( 'Unsupported database driver. Available drivers: @list' , array ( '@list' => implode ( ',' , $ drivers ) ) ) ; $ this -> setError ( $ field , $ error ) ; return false ; }
Validates a database driver
55,204
protected function validateDbPortInstall ( ) { $ field = 'database.port' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; $ label = $ this -> translation -> text ( 'Database port' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } return true ; }
Validates a database port
55,205
protected function validateDbConnectInstall ( ) { if ( $ this -> isError ( ) ) { return null ; } $ field = 'database.connect' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ settings = $ this -> getSubmitted ( 'database' ) ; $ result = $ this -> install -> connectDb ( $ settings ) ; if ( $ result === true ) { return true ; } if ( empty ( $ result ) ) { $ result = $ this -> translation -> text ( 'Could not connect to database' ) ; } $ this -> setError ( $ field , ( string ) $ result ) ; return false ; }
Validates database connection
55,206
protected function setAssets ( Controller $ controller ) { $ controller -> addAssetLibrary ( 'jquery_ui' ) ; $ controller -> addAssetLibrary ( 'bootstrap' ) ; $ controller -> addAssetLibrary ( 'html5shiv' , array ( 'condition' => 'if lt IE 9' ) ) ; $ controller -> addAssetLibrary ( 'respond' , array ( 'condition' => 'if lt IE 9' ) ) ; $ controller -> addAssetLibrary ( 'font_awesome' ) ; $ controller -> setJs ( __DIR__ . '/js/common.js' ) ; $ controller -> setCss ( __DIR__ . '/css/common.css' ) ; }
Adds theme specific assets
55,207
protected function setMetaTags ( Controller $ controller ) { $ controller -> setMeta ( array ( 'charset' => 'utf-8' ) ) ; $ controller -> setMeta ( array ( 'http-equiv' => 'X-UA-Compatible' , 'content' => 'IE=edge' ) ) ; $ controller -> setMeta ( array ( 'name' => 'viewport' , 'content' => 'width=device-width, initial-scale=1' ) ) ; $ controller -> setMeta ( array ( 'name' => 'author' , 'content' => 'GPLCart' ) ) ; }
Adds meta tags
55,208
public function boot ( ) { $ config = dirname ( __DIR__ ) . '/config/form.php' ; $ this -> mergeConfigFrom ( $ config , 'form' ) ; $ this -> publishes ( [ $ config => config_path ( 'form.php' ) ] , 'config' ) ; $ presenter = config ( 'form.presenter' , 'Laraplus\Form\Presenters\Bootstrap3Presenter' ) ; $ this -> app -> bind ( 'Laraplus\Form\Contracts\FormPresenter' , $ presenter ) ; $ this -> app -> singleton ( 'laraplus.form' , 'Laraplus\Form\Form' ) ; }
Boot the service provider
55,209
public function get ( $ role_id ) { $ result = & gplcart_static ( "user.role.get.$role_id" ) ; if ( isset ( $ result ) ) { return $ result ; } $ this -> hook -> attach ( 'user.role.get.before' , $ role_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ sql = 'SELECT * FROM role WHERE role_id=?' ; $ result = $ this -> db -> fetch ( $ sql , array ( $ role_id ) , array ( 'unserialize' => 'permissions' ) ) ; $ this -> hook -> attach ( 'user.role.get.after' , $ role_id , $ result , $ this ) ; return $ result ; }
Loads a role from the database
55,210
public function update ( $ role_id , array $ data ) { $ result = null ; $ this -> hook -> attach ( 'user.role.update.before' , $ role_id , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ result = ( bool ) $ this -> db -> update ( 'role' , $ data , array ( 'role_id' => $ role_id ) ) ; $ this -> hook -> attach ( 'user.role.update.after' , $ role_id , $ data , $ result , $ this ) ; return ( bool ) $ result ; }
Updates a role
55,211
public function getPermissions ( ) { $ permissions = & gplcart_static ( 'user.role.permissions' ) ; if ( isset ( $ permissions ) ) { return $ permissions ; } $ permissions = ( array ) gplcart_config_get ( GC_FILE_CONFIG_PERMISSION ) ; asort ( $ permissions ) ; $ this -> hook -> attach ( 'user.role.permissions' , $ permissions , $ this ) ; return $ permissions ; }
Returns an array of all defined permissions
55,212
public function log ( $ type , $ data , $ severity = 'info' , $ translatable = true ) { $ message = '' ; if ( is_string ( $ data ) ) { $ message = $ data ; } elseif ( isset ( $ data [ 'message' ] ) ) { $ message = ( string ) $ data [ 'message' ] ; } $ values = array ( 'text' => $ message , 'data' => ( array ) $ data , 'translatable' => $ translatable , 'type' => mb_substr ( $ type , 0 , 255 ) , 'severity' => mb_substr ( $ severity , 0 , 255 ) ) ; return $ this -> add ( $ values ) ; }
Writes a log message to the database
55,213
public function add ( array $ data ) { if ( ! $ this -> isDb ( ) ) { return false ; } $ data += array ( 'created' => GC_TIME , 'log_id' => gplcart_string_random ( 6 ) ) ; try { $ result = ( bool ) $ this -> db -> insert ( 'log' , $ data ) ; } catch ( Exception $ ex ) { $ result = false ; } return $ result ; }
Adds a log record
55,214
public function selectErrors ( $ limit = null ) { if ( ! $ this -> isDb ( ) ) { return array ( ) ; } $ sql = "SELECT * FROM log WHERE type LIKE ? ORDER BY created DESC" ; if ( isset ( $ limit ) ) { settype ( $ limit , 'integer' ) ; $ sql .= " LIMIT 0,$limit" ; } try { $ results = $ this -> db -> fetchAll ( $ sql , array ( 'php_%' ) , array ( 'unserialize' => 'data' ) ) ; } catch ( Exception $ ex ) { return array ( ) ; } $ list = array ( ) ; foreach ( $ results as $ result ) { $ list [ ] = $ result [ 'data' ] ; } return $ list ; }
Returns an array of logged PHP errors from the database
55,215
public function exceptionHandler ( Exception $ exc ) { $ error = array ( 'code' => $ exc -> getCode ( ) , 'file' => $ exc -> getFile ( ) , 'line' => $ exc -> getLine ( ) , 'message' => $ exc -> getMessage ( ) , 'backtrace' => $ this -> log_backtrace ? gplcart_backtrace ( ) : array ( ) ) ; $ this -> log ( 'php_exception' , $ error , 'danger' , false ) ; echo $ this -> getFormattedError ( $ error , 'Exception' ) ; }
Common exception handler
55,216
public function getFormattedError ( array $ error , $ header = '' ) { $ output = "<table style='background:#fcf8e3; color:#8a6d3b; width:100%; margin-bottom:10px; border: 1px solid #faebcc; border-collapse: collapse;'>" ; if ( ! empty ( $ header ) ) { $ output .= "<tr> <td colspan='2' style='border-bottom: 1px solid #faebcc;'><b>$header</b></td> </tr>\n" ; } $ output .= "<tr> <td style='background-color: #faebcc;'>Message </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['message']}</td> </tr>\n" ; if ( isset ( $ error [ 'code' ] ) ) { $ output .= "<tr> <td style='background-color: #faebcc;'>Code </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['code']}</td> </tr>\n" ; } if ( isset ( $ error [ 'type' ] ) ) { $ output .= "<tr> <td style='background-color: #faebcc;'>Type </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['type']}</td> </tr>\n" ; } $ output .= "<tr> <td style='background-color: #faebcc;'>File </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['file']}</td> </tr> <tr> <td style='background-color: #faebcc;'>Line </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['line']}</td> </tr>\n" ; if ( $ this -> print_backtrace && ! empty ( $ error [ 'backtrace' ] ) ) { $ error [ 'backtrace' ] = implode ( "<br>\n" , $ error [ 'backtrace' ] ) ; $ output .= "<tr> <td style='background-color: #faebcc;'>Backtrace </td> <td style='border-bottom: 1px solid #faebcc;'>{$error['backtrace']}</td> </tr>\n" ; } $ output .= '</table>' ; return GC_CLI ? preg_replace ( "/(\n| )+/" , "$1" , trim ( strip_tags ( $ output ) ) ) : $ output ; }
Formats an error message
55,217
public function getErrors ( $ format = true ) { if ( ! $ format ) { return $ this -> errors ; } $ formatted = array ( ) ; foreach ( $ this -> errors as $ error ) { $ formatted [ ] = $ this -> getFormattedError ( $ error ) ; } return $ formatted ; }
Returns an array of collected PHP errors
55,218
public function set ( $ entity , $ entity_id , $ created , $ user_id = null ) { if ( ! isset ( $ user_id ) ) { $ user_id = $ this -> user -> getId ( ) ; } if ( $ this -> exists ( $ entity , $ entity_id , $ user_id ) ) { return true ; } if ( ( GC_TIME - $ created ) >= $ this -> getLifespan ( ) ) { return true ; } $ data = array ( 'entity' => $ entity , 'user_id' => $ user_id , 'entity_id' => $ entity_id ) ; return $ this -> add ( $ data ) ; }
Set a history record
55,219
public function exists ( $ entity , $ entity_id , $ user_id ) { $ sql = 'SELECT history_id FROM history WHERE entity=? AND entity_id=? AND user_id=?' ; return ( bool ) $ this -> db -> fetchColumn ( $ sql , array ( $ entity , $ entity_id , $ user_id ) ) ; }
Whether a record exists in the history table
55,220
public function isNew ( $ entity_creation_time , $ history_creation_time ) { $ lifespan = $ this -> getLifespan ( ) ; if ( empty ( $ history_creation_time ) ) { return ( GC_TIME - $ entity_creation_time ) <= $ lifespan ; } return ( GC_TIME - $ history_creation_time ) > $ lifespan ; }
Whether an entity is new
55,221
public static function call ( $ handlers , $ handler_id , $ method , $ arguments = array ( ) ) { $ callback = static :: get ( $ handlers , $ handler_id , $ method ) ; return call_user_func_array ( $ callback , $ arguments ) ; }
Call a handler
55,222
public static function get ( $ handlers , $ handler_id , $ name ) { $ callable = static :: getCallable ( $ handlers , $ handler_id , $ name ) ; if ( is_array ( $ callable ) ) { if ( is_callable ( $ callable ) ) { $ callable [ 0 ] = Container :: get ( $ callable [ 0 ] ) ; return $ callable ; } throw new BadMethodCallException ( implode ( '::' , $ callable ) . ' is not callable' ) ; } if ( $ callable instanceof \ Closure ) { return $ callable ; } throw new UnexpectedValueException ( 'Unexpected handler format' ) ; }
Returns a handler
55,223
protected static function getCallable ( $ handlers , $ handler_id , $ name ) { if ( isset ( $ handler_id ) ) { if ( empty ( $ handlers [ $ handler_id ] [ 'handlers' ] [ $ name ] ) ) { throw new OutOfRangeException ( "Unknown handler ID $handler_id and/or method name $name" ) ; } return $ handlers [ $ handler_id ] [ 'handlers' ] [ $ name ] ; } if ( empty ( $ handlers [ 'handlers' ] [ $ name ] ) ) { throw new OutOfRangeException ( "Unknown handler method name $name" ) ; } return $ handlers [ 'handlers' ] [ $ name ] ; }
Returns a callable data from the handler array
55,224
public function notifyCreated ( array $ order ) { $ this -> mail -> set ( 'order_created_admin' , array ( $ order ) ) ; if ( is_numeric ( $ order [ 'user_id' ] ) && ! empty ( $ order [ 'user_email' ] ) ) { return $ this -> mail -> set ( 'order_created_customer' , array ( $ order ) ) ; } return false ; }
Notify when an order has been created
55,225
public function notifyUpdated ( array $ order ) { if ( is_numeric ( $ order [ 'user_id' ] ) && ! empty ( $ order [ 'user_email' ] ) ) { return $ this -> mail -> set ( 'order_updated_customer' , array ( $ order ) ) ; } return false ; }
Notify when an order has been updated
55,226
protected function setBundledProducts ( array $ order , array $ data ) { $ update = false ; foreach ( $ data [ 'cart' ] [ 'items' ] as $ item ) { if ( empty ( $ item [ 'product' ] [ 'bundled_products' ] ) ) { continue ; } foreach ( $ item [ 'product' ] [ 'bundled_products' ] as $ product ) { $ cart = array ( 'sku' => $ product [ 'sku' ] , 'user_id' => $ data [ 'user_id' ] , 'quantity' => $ item [ 'quantity' ] , 'store_id' => $ data [ 'store_id' ] , 'order_id' => $ order [ 'order_id' ] , 'product_id' => $ product [ 'product_id' ] , ) ; $ this -> cart -> add ( $ cart ) ; $ update = true ; $ order [ 'data' ] [ 'components' ] [ 'cart' ] [ 'items' ] [ $ product [ 'sku' ] ] [ 'price' ] = 0 ; } } if ( $ update ) { $ this -> order -> update ( $ order [ 'order_id' ] , array ( 'data' => $ order [ 'data' ] ) ) ; } }
Adds bundled products
55,227
protected function cloneCart ( array $ order , array $ cart ) { foreach ( $ cart [ 'items' ] as $ item ) { $ cart_id = $ item [ 'cart_id' ] ; unset ( $ item [ 'cart_id' ] ) ; $ item [ 'user_id' ] = $ order [ 'user_id' ] ; $ item [ 'order_id' ] = $ order [ 'order_id' ] ; $ this -> cart -> add ( $ item ) ; $ this -> cart -> delete ( $ cart_id ) ; } }
Clone an order
55,228
protected function updateCart ( array $ order , array $ cart ) { foreach ( $ cart [ 'items' ] as $ item ) { $ data = array ( 'user_id' => $ order [ 'user_id' ] , 'order_id' => $ order [ 'order_id' ] ) ; $ this -> cart -> update ( $ item [ 'cart_id' ] , $ data ) ; } }
Update cart items after order was created
55,229
protected function setPriceRules ( array $ order ) { foreach ( array_keys ( $ order [ 'data' ] [ 'components' ] ) as $ component_id ) { if ( is_numeric ( $ component_id ) ) { $ rule = $ this -> price_rule -> get ( $ component_id ) ; if ( isset ( $ rule [ 'code' ] ) && $ rule [ 'code' ] !== '' ) { $ this -> price_rule -> setUsed ( $ rule [ 'price_rule_id' ] ) ; } } } }
Sets price rules after the order was created
55,230
public function getSupportedFormats ( ) { $ formats = array ( ) ; foreach ( gd_info ( ) as $ name => $ status ) { if ( strpos ( $ name , 'Support' ) !== false && $ status ) { $ formats [ ] = strtolower ( strtok ( $ name , ' ' ) ) ; } } return array_unique ( $ formats ) ; }
Returns an array of supported image formats
55,231
protected function callFunction ( $ prefix , $ format , array $ arguments ) { $ function = "$prefix$format" ; if ( ! in_array ( $ format , $ this -> getSupportedFormats ( ) ) ) { throw new RuntimeException ( "Unsupported image format $format" ) ; } if ( ! function_exists ( $ function ) ) { throw new BadFunctionCallException ( "Function $function does not exist" ) ; } return call_user_func_array ( $ function , $ arguments ) ; }
Call a function which name is constructed from prefix and image format
55,232
public function thumbnail ( $ width , $ height = null ) { if ( ! isset ( $ height ) ) { $ height = $ width ; } if ( ( $ height / $ width ) > ( $ this -> height / $ this -> width ) ) { $ this -> fitToHeight ( $ height ) ; } else { $ this -> fitToWidth ( $ width ) ; } $ left = floor ( ( $ this -> width / 2 ) - ( $ width / 2 ) ) ; $ top = floor ( ( $ this -> height / 2 ) - ( $ height / 2 ) ) ; return $ this -> crop ( $ left , $ top , $ width + $ left , $ height + $ top ) ; }
Create image thumbnail keeping aspect ratio
55,233
public function fitToHeight ( $ height ) { $ width = $ height / ( $ this -> height / $ this -> width ) ; return $ this -> resize ( $ width , $ height ) ; }
Proportionally resize to the specified height
55,234
public function fitToWidth ( $ width ) { $ height = $ width * ( $ this -> height / $ this -> width ) ; return $ this -> resize ( $ width , $ height ) ; }
Proportionally resize to the specified width
55,235
public function resize ( $ width , $ height ) { $ new = imagecreatetruecolor ( $ width , $ height ) ; if ( empty ( $ new ) ) { throw new UnexpectedValueException ( 'Failed to create an image identifier' ) ; } if ( $ this -> format === 'gif' ) { $ transparent_index = imagecolortransparent ( $ this -> image ) ; $ palletsize = imagecolorstotal ( $ this -> image ) ; if ( $ transparent_index >= 0 && $ transparent_index < $ palletsize ) { $ transparent_color = imagecolorsforindex ( $ this -> image , $ transparent_index ) ; $ transparent_index = imagecolorallocate ( $ new , $ transparent_color [ 'red' ] , $ transparent_color [ 'green' ] , $ transparent_color [ 'blue' ] ) ; imagefill ( $ new , 0 , 0 , $ transparent_index ) ; imagecolortransparent ( $ new , $ transparent_index ) ; } } else { imagealphablending ( $ new , false ) ; imagesavealpha ( $ new , true ) ; } if ( ! imagecopyresampled ( $ new , $ this -> image , 0 , 0 , 0 , 0 , $ width , $ height , $ this -> width , $ this -> height ) ) { throw new UnexpectedValueException ( 'Failed to copy and resize part of an image with resampling' ) ; } $ this -> image = $ new ; $ this -> width = $ width ; $ this -> height = $ height ; return $ this ; }
Resize an image to the specified dimensions
55,236
public function indexDashboard ( ) { $ this -> toggleIntroIndexDashboard ( ) ; $ this -> setDashboard ( true ) ; $ this -> setTitleIndexDashboard ( ) ; $ this -> setDataContentIndexDashboard ( ) ; $ this -> outputIndexDashboard ( ) ; }
Displays the dashboard page
55,237
protected function setDataContentIndexDashboard ( ) { $ columns = $ this -> config ( 'dashboard_columns' , 2 ) ; $ this -> setData ( 'columns' , $ columns ) ; $ this -> setData ( 'dashboard' , gplcart_array_split ( $ this -> data_dashboard [ 'data' ] , $ columns ) ) ; $ stores = $ this -> store -> getList ( array ( 'status' => 1 ) ) ; $ this -> setData ( 'no_enabled_stores' , empty ( $ stores ) ) ; if ( $ this -> config ( 'intro' , false ) && $ this -> isSuperadmin ( ) ) { $ this -> setData ( 'intro' , $ this -> render ( 'dashboard/intro' ) ) ; } }
Sets a dashboard template data
55,238
public function editDashboard ( ) { $ this -> setDashboard ( false ) ; $ this -> setTitleEditDashboard ( ) ; $ this -> setBreadcrumbEditDashboard ( ) ; $ this -> setData ( 'dashboard' , $ this -> data_dashboard ) ; $ this -> submitEditDashboard ( ) ; $ this -> outputEditDashboard ( ) ; }
Displays the edit dashboard page
55,239
protected function setDashboard ( $ active ) { $ dashboard = $ this -> dashboard -> getList ( array ( 'user_id' => $ this -> uid , 'active' => $ active ) ) ; $ this -> data_dashboard = $ this -> prepareDashboard ( $ dashboard ) ; }
Sets an array of dashboard items
55,240
protected function submitEditDashboard ( ) { if ( $ this -> isPosted ( 'save' ) ) { $ this -> validateEditDashboard ( ) ; $ this -> saveDashboard ( ) ; } else if ( $ this -> isPosted ( 'delete' ) && isset ( $ this -> data_dashboard [ 'dashboard_id' ] ) ) { $ this -> deleteDashboard ( ) ; } }
Handles an array of submitted data
55,241
protected function validateEditDashboard ( ) { $ submitted = $ this -> setSubmitted ( 'dashboard' ) ; foreach ( $ submitted as & $ item ) { $ item [ 'status' ] = ! empty ( $ item [ 'status' ] ) ; $ item [ 'weight' ] = intval ( $ item [ 'weight' ] ) ; } $ this -> setSubmitted ( null , $ submitted ) ; }
Validates an array of submitted data
55,242
protected function saveDashboard ( ) { $ this -> controlAccess ( 'dashboard_edit' ) ; if ( $ this -> dashboard -> set ( $ this -> uid , $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( '' , $ this -> text ( 'Your dashboard has been updated' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Your dashboard has not been updated' ) , 'warning' ) ; }
Saves submitted data
55,243
protected function deleteDashboard ( ) { $ this -> controlAccess ( 'dashboard_edit' ) ; if ( $ this -> dashboard -> delete ( $ this -> data_dashboard [ 'dashboard_id' ] ) ) { $ message = $ this -> text ( 'Your dashboard has been reset' ) ; $ this -> redirect ( '' , $ message , 'success' ) ; } $ this -> redirect ( 'admin' , $ this -> text ( 'Your dashboard has not been reset' ) , 'warning' ) ; }
Deletes a saved a dashboard record
55,244
public function set ( $ path , array $ data ) { $ data += array ( 'path' => $ path ) ; $ bookmark = $ this -> get ( $ data ) ; return empty ( $ bookmark ) ? ( bool ) $ this -> add ( $ data ) : false ; }
Add a bookmark if it doesn t exists for the path
55,245
public function sendPhpResponse ( $ exception ) { if ( ! $ exception instanceof FlattenException ) { $ exception = FlattenException :: create ( $ exception ) ; } header ( sprintf ( 'HTTP/1.0 %s' , $ exception -> getStatusCode ( ) ) ) ; foreach ( $ exception -> getHeaders ( ) as $ name => $ value ) { header ( $ name . ': ' . $ value , false ) ; } echo $ this -> decorate ( $ this -> getContent ( $ exception , $ this -> showAllExceptions ) , $ this -> getStylesheet ( $ exception ) ) ; }
Sends the error associated with the given Exception as a plain PHP response .
55,246
private function _loadDatabase ( ) { if ( ! isset ( self :: $ db [ $ this -> name ] ) ) { $ config = Config :: config ( ) -> { $ this -> name } ; if ( ! is_array ( $ config ) ) throw new \ Exception ( $ config . ' not a valid db config' ) ; $ db = new Database ( $ config ) ; self :: $ db [ $ this -> name ] = $ db ; self :: $ prefix = isset ( $ config [ 'prefix' ] ) ? $ config [ 'prefix' ] : '' ; } return $ this -> getDb ( ) ; }
Load database connection
55,247
public function addRows ( $ rows ) { foreach ( $ rows as $ row ) { $ this -> inputRows [ ] = $ row ; $ inferredRow = $ this -> inferRow ( $ row ) ; foreach ( $ this -> getFieldNames ( ) as $ fieldName ) { $ inferredField = $ inferredRow [ $ fieldName ] ; $ inferredFieldType = $ inferredField -> getInferIdentifier ( $ this -> lenient ) ; if ( ! array_key_exists ( $ fieldName , $ this -> fieldsPopularity ) ) { $ this -> fieldsPopularity [ $ fieldName ] = [ ] ; $ this -> fieldsPopularityObjects [ $ fieldName ] = [ ] ; } if ( ! array_key_exists ( $ inferredFieldType , $ this -> fieldsPopularity [ $ fieldName ] ) ) { $ this -> fieldsPopularity [ $ fieldName ] [ $ inferredFieldType ] = 0 ; $ this -> fieldsPopularityObjects [ $ fieldName ] [ $ inferredFieldType ] = $ inferredField ; } ++ $ this -> fieldsPopularity [ $ fieldName ] [ $ inferredFieldType ] ; arsort ( $ this -> fieldsPopularity [ $ fieldName ] ) ; } } }
add rows and updates the fieldsPopularity array - to make the inferred fields more accurate .
55,248
public function infer ( ) { $ bestInferredFields = [ ] ; foreach ( $ this -> fieldsPopularity as $ fieldName => $ fieldTypesPopularity ) { $ bestInferredFields [ $ fieldName ] = $ this -> inferField ( $ fieldName , $ fieldTypesPopularity ) ; } return $ bestInferredFields ; }
return the best inferred fields along with the best value casting according to the rows received so far .
55,249
protected function inferRow ( $ row ) { $ rowFields = [ ] ; foreach ( $ row as $ k => $ v ) { $ rowFields [ $ k ] = FieldsFactory :: infer ( $ v , ( object ) [ 'name' => $ k ] , $ this -> lenient ) ; } return $ rowFields ; }
infer field objects for the given row raises exception if fails to infer a field .
55,250
protected function inferField ( $ fieldName , $ fieldTypesPopularity ) { $ inferredField = null ; foreach ( array_keys ( $ fieldTypesPopularity ) as $ inferredFieldType ) { $ inferredField = $ this -> fieldsPopularityObjects [ $ fieldName ] [ $ inferredFieldType ] ; try { $ rowNum = 0 ; foreach ( $ this -> inputRows as $ inputRow ) { if ( ! array_key_exists ( $ rowNum , $ this -> castRows ) ) { $ this -> castRows [ $ rowNum ] = [ ] ; } $ this -> castRows [ $ rowNum ] [ $ fieldName ] = $ inferredField -> castValue ( $ inputRow [ $ fieldName ] ) ; ++ $ rowNum ; } break ; } catch ( FieldValidationException $ e ) { continue ; } } return $ inferredField ; }
finds the best inferred fields for the given field name according to the popularity also updates the castRows array with the latest cast values .
55,251
public static function exec ( $ command , array $ params = array ( ) , $ mergeStdErr = true ) { if ( empty ( $ command ) ) { throw new \ InvalidArgumentException ( 'Command line is empty' ) ; } $ command = self :: bindParams ( $ command , $ params ) ; if ( $ mergeStdErr ) { $ command .= ' 2>&1' ; } exec ( $ command , $ output , $ code ) ; if ( count ( $ output ) === 0 ) { $ output = $ code ; } else { $ output = implode ( PHP_EOL , $ output ) ; } if ( $ code !== 0 ) { throw new CommandException ( $ command , $ output , $ code ) ; } return $ output ; }
Execute command with params .
55,252
public static function bindParams ( $ command , array $ params ) { $ wrappers = array ( ) ; $ converters = array ( ) ; foreach ( $ params as $ key => $ value ) { $ wrappers [ ] = '{' . $ key . '}' ; $ converters [ ] = escapeshellarg ( is_array ( $ value ) ? implode ( ' ' , $ value ) : $ value ) ; $ wrappers [ ] = '{!' . $ key . '!}' ; $ converters [ ] = is_array ( $ value ) ? implode ( ' ' , $ value ) : $ value ; } return str_replace ( $ wrappers , $ converters , $ command ) ; }
Bind params to command .
55,253
public function listSection ( $ parent ) { $ this -> controlAccess ( 'admin' ) ; $ this -> setTitleListSection ( $ parent ) ; $ this -> setBreadcrumbListSection ( ) ; $ this -> setDataListSection ( $ parent ) ; $ this -> outputListSection ( ) ; }
Displays the admin section page
55,254
protected function setDataListSection ( $ parent ) { $ options = array ( 'parent_url' => $ parent , 'template' => 'section/menu' ) ; $ this -> setData ( 'menu' , $ this -> getWidgetAdminMenu ( $ this -> route , $ options ) ) ; }
Sets template data on the admin section page
55,255
protected function setTitleListSection ( $ parent ) { foreach ( $ this -> route -> getList ( ) as $ route ) { if ( isset ( $ route [ 'menu' ] [ 'admin' ] ) && isset ( $ route [ 'arguments' ] ) && in_array ( $ parent , $ route [ 'arguments' ] ) ) { $ this -> setTitle ( $ route [ 'menu' ] [ 'admin' ] ) ; break ; } } }
Sets titles on the admin section page
55,256
protected function findTemplate ( $ template ) { $ logicalName = ( string ) $ template ; if ( isset ( $ this -> cache [ $ logicalName ] ) ) { return $ this -> cache [ $ logicalName ] ; } $ file = null ; $ previous = null ; try { $ template = $ this -> parser -> parse ( $ template ) ; try { $ file = $ this -> locator -> locate ( $ template ) ; } catch ( \ InvalidArgumentException $ e ) { $ previous = $ e ; } } catch ( \ Exception $ e ) { try { $ file = parent :: findTemplate ( $ template ) ; } catch ( \ Twig_Error_Loader $ e ) { $ previous = $ e ; } } if ( false === $ file || null === $ file ) { throw new \ Twig_Error_Loader ( sprintf ( 'Unable to find template "%s".' , $ logicalName ) , - 1 , null , $ previous ) ; } return $ this -> cache [ $ logicalName ] = $ file ; }
Returns the path to the template file .
55,257
public function listUser ( ) { $ this -> actionListUser ( ) ; $ this -> setTitleListUser ( ) ; $ this -> setBreadcrumbListUser ( ) ; $ this -> setFilterListUser ( ) ; $ this -> setPagerListUser ( ) ; $ this -> setData ( 'roles' , $ this -> role -> getList ( ) ) ; $ this -> setData ( 'users' , $ this -> getListUser ( ) ) ; $ this -> outputListUser ( ) ; }
Displays the users overview page
55,258
protected function actionListUser ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ deleted = $ updated = 0 ; foreach ( $ selected as $ uid ) { if ( $ this -> isSuperadmin ( $ uid ) ) { continue ; } if ( $ action === 'status' && $ this -> access ( 'user_edit' ) ) { $ updated += ( int ) $ this -> user -> update ( $ uid , array ( 'status' => $ value ) ) ; } if ( $ action === 'delete' && $ this -> access ( 'user_delete' ) ) { $ deleted += ( int ) $ this -> user -> delete ( $ uid ) ; } } if ( $ updated > 0 ) { $ text = $ this -> text ( 'Updated %num item(s)' , array ( '%num' => $ updated ) ) ; $ this -> setMessage ( $ text , 'success' ) ; } if ( $ deleted > 0 ) { $ text = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ text , 'success' ) ; } }
Applies an action to the selected users
55,259
protected function prepareListUser ( array & $ list ) { $ stores = $ this -> store -> getList ( ) ; foreach ( $ list as & $ item ) { $ item [ 'url' ] = '' ; if ( isset ( $ stores [ $ item [ 'store_id' ] ] ) ) { $ item [ 'url' ] = $ this -> store -> getUrl ( $ stores [ $ item [ 'store_id' ] ] ) . "/account/{$item['user_id']}" ; } } }
Prepare an array of users
55,260
public function editUser ( $ user_id = null ) { $ this -> setUser ( $ user_id ) ; $ this -> setTitleEditUser ( ) ; $ this -> setBreadcrumbEditUser ( ) ; $ this -> controlAccessEditUser ( $ user_id ) ; $ this -> setData ( 'user' , $ this -> data_user ) ; $ this -> setData ( 'roles' , $ this -> role -> getList ( ) ) ; $ this -> setData ( 'can_delete' , $ this -> canDeleteUser ( ) ) ; $ this -> setData ( 'is_superadmin' , $ this -> isSuperadminUser ( ) ) ; $ this -> setData ( 'password_limit' , $ this -> user -> getPasswordLength ( ) ) ; $ this -> submitEditUser ( ) ; $ this -> outputEditUser ( ) ; }
Displays the user edit page
55,261
protected function submitEditUser ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteUser ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditUser ( ) ) { if ( isset ( $ this -> data_user [ 'user_id' ] ) ) { $ this -> updateUser ( ) ; } else { $ this -> addUser ( ) ; } } }
Handles a submitted user data
55,262
protected function validateEditUser ( ) { $ this -> setSubmitted ( 'user' ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_user ) ; $ this -> validateComponent ( 'user' , array ( 'admin' => $ this -> access ( 'user_edit' ) ) ) ; return ! $ this -> hasErrors ( ) ; }
Validates a submitted user data
55,263
protected function addUser ( ) { $ this -> controlAccess ( 'user_add' ) ; if ( $ this -> user -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/user/list' , $ this -> text ( 'User has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'User has not been added' ) , 'warning' ) ; }
Adds a new user
55,264
protected function setTitleEditUser ( ) { if ( isset ( $ this -> data_user [ 'name' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_user [ 'name' ] ) ) ; } else { $ title = $ this -> text ( 'Add user' ) ; } $ this -> setTitle ( $ title ) ; }
Sets title on the edit user page
55,265
protected function setBreadcrumbEditUser ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Users' ) , 'url' => $ this -> url ( 'admin/user/list' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the edit user page
55,266
public function get ( $ command = null ) { if ( isset ( $ command ) ) { $ routes = $ this -> getList ( ) ; return isset ( $ routes [ $ command ] ) ? $ routes [ $ command ] : array ( ) ; } return $ this -> route ; }
Returns the current CLI route
55,267
public function getList ( ) { $ routes = & gplcart_static ( 'cli.route.list' ) ; if ( isset ( $ routes ) ) { return $ routes ; } $ routes = ( array ) gplcart_config_get ( GC_FILE_CONFIG_ROUTE_CLI ) ; $ this -> hook -> attach ( 'cli.route.list' , $ routes , $ this ) ; $ this -> setAliases ( $ routes ) ; return $ routes ; }
Returns an array of CLI routes
55,268
protected function setAliases ( array $ routes ) { foreach ( $ routes as $ command => $ route ) { if ( ! isset ( $ route [ 'alias' ] ) ) { continue ; } if ( isset ( $ this -> aliases [ $ route [ 'alias' ] ] ) ) { throw new OverflowException ( "Command alias '{$route['alias']}' is not unique" ) ; } $ this -> aliases [ $ route [ 'alias' ] ] = $ command ; } }
Sets an array of commands keyed by their aliases
55,269
public function set ( $ route = null ) { if ( ! isset ( $ route ) ) { $ routes = $ this -> getList ( ) ; $ command = array_shift ( $ this -> params ) ; if ( isset ( $ this -> aliases [ $ command ] ) ) { $ command = $ this -> aliases [ $ command ] ; } if ( empty ( $ routes [ $ command ] ) ) { $ command = 'help' ; $ this -> params = array ( ) ; } if ( empty ( $ routes [ $ command ] ) ) { throw new OutOfBoundsException ( 'Unknown command' ) ; } if ( isset ( $ routes [ $ command ] [ 'status' ] ) && empty ( $ routes [ $ command ] [ 'status' ] ) ) { throw new OutOfBoundsException ( 'Disabled command' ) ; } $ route = $ routes [ $ command ] ; $ route [ 'command' ] = $ command ; $ route [ 'params' ] = $ this -> params ; } $ this -> route = ( array ) $ route ; return $ this ; }
Sets the current route
55,270
public function callController ( $ route = null ) { if ( ! isset ( $ route ) ) { $ route = $ this -> route ; } $ callback = Handler :: get ( $ route , null , 'controller' ) ; if ( ! $ callback [ 0 ] instanceof CliController ) { throw new LogicException ( 'Controller must be instance of \gplcart\core\CliController' ) ; } call_user_func ( $ callback ) ; throw new LogicException ( 'The command was completed incorrectly' ) ; }
Call a route controller
55,271
public function currency ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateCurrency ( ) ; $ this -> validateBool ( 'default' ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateCodeCurrency ( ) ; $ this -> validateName ( ) ; $ this -> validateNumericCodeCurrency ( ) ; $ this -> validateSymbolCurrency ( ) ; $ this -> validateMajorUnitCurrency ( ) ; $ this -> validateMinorUnitCurrency ( ) ; $ this -> validateConvertionRateCurrency ( ) ; $ this -> validateDecimalsCurrency ( ) ; $ this -> validateRoundingStepCurrency ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
Performs full currency data validation
55,272
protected function validateCurrency ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> currency -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Currency' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
Validates a currency to be updated
55,273
protected function validateMajorUnitCurrency ( ) { $ field = 'major_unit' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } if ( empty ( $ value ) || mb_strlen ( $ value ) > 50 ) { $ this -> setErrorLengthRange ( $ field , $ this -> translation -> text ( 'Major unit' ) , 1 , 50 ) ; return false ; } return true ; }
Validates currency major unit
55,274
protected function validateConvertionRateCurrency ( ) { $ field = 'conversion_rate' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { return null ; } $ label = $ this -> translation -> text ( 'Conversion rate' ) ; if ( empty ( $ value ) || strlen ( $ value ) > 10 ) { $ this -> setErrorLengthRange ( $ field , $ label , 1 , 10 ) ; return false ; } if ( preg_match ( '/^[0-9]\d*(\.\d+)?$/' , $ value ) !== 1 ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } return true ; }
Validates currency conversion rate
55,275
protected function validateDecimalsCurrency ( ) { $ field = 'decimals' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } if ( preg_match ( '/^[0-2]+$/' , $ value ) !== 1 ) { $ this -> setErrorInvalid ( $ field , $ this -> translation -> text ( 'Decimals' ) ) ; return false ; } return true ; }
Validates currency decimals
55,276
protected function validateNumericCodeCurrency ( ) { $ field = 'numeric_code' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Numeric code' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( preg_match ( '/^[0-9]{3}$/' , $ value ) !== 1 ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } $ updating = $ this -> getUpdating ( ) ; if ( isset ( $ updating [ 'numeric_code' ] ) && $ updating [ 'numeric_code' ] == $ value ) { return true ; } foreach ( $ this -> currency -> getList ( ) as $ currency ) { if ( $ currency [ 'numeric_code' ] == $ value ) { $ this -> setErrorExists ( $ field , $ label ) ; return false ; } } return true ; }
Validates currency numeric code
55,277
protected function validateCodeCurrency ( ) { $ field = 'code' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Code' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( preg_match ( '/^[a-zA-Z]{3}$/' , $ value ) !== 1 ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } $ code = strtoupper ( $ value ) ; $ updating = $ this -> getUpdating ( ) ; if ( isset ( $ updating [ 'code' ] ) && $ updating [ 'code' ] === $ code ) { return true ; } $ existing = $ this -> currency -> get ( $ code ) ; if ( ! empty ( $ existing ) ) { $ this -> setErrorExists ( $ field , $ label ) ; return false ; } $ this -> setSubmitted ( $ field , $ code ) ; return true ; }
Validates currency code
55,278
public function listTransaction ( ) { $ this -> actionListTransaction ( ) ; $ this -> setTitleListTransaction ( ) ; $ this -> setBreadcrumbListTransaction ( ) ; $ this -> setFilterListTransaction ( ) ; $ this -> setPagerListTransaction ( ) ; $ this -> setData ( 'transactions' , $ this -> getListTransaction ( ) ) ; $ this -> setData ( 'payment_methods' , $ this -> payment -> getList ( ) ) ; $ this -> outputListTransaction ( ) ; }
Displays the transaction overview page
55,279
protected function actionListTransaction ( ) { list ( $ selected , $ action ) = $ this -> getPostedAction ( ) ; $ deleted = 0 ; foreach ( $ selected as $ id ) { if ( $ action === 'delete' && $ this -> access ( 'transaction_delete' ) ) { $ deleted += ( int ) $ this -> transaction -> delete ( $ id ) ; } } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } }
Applies an action to the selected transactions
55,280
protected function getListTransaction ( ) { $ conditions = $ this -> query_filter ; $ conditions [ 'limit' ] = $ this -> data_limit ; return ( array ) $ this -> transaction -> getList ( $ conditions ) ; }
Returns an array of transactions
55,281
public function run ( $ text , $ filter ) { if ( is_string ( $ filter ) ) { $ filter = $ this -> get ( $ filter ) ; } $ filtered = null ; $ this -> hook -> attach ( 'filter' , $ text , $ filter , $ filtered , $ this ) ; if ( isset ( $ filtered ) ) { return ( string ) $ filtered ; } return $ this -> filter ( $ text ) ; }
Filter a text string
55,282
public function get ( $ filter_id ) { $ filters = $ this -> getHandlers ( ) ; return empty ( $ filters [ $ filter_id ] ) ? array ( ) : $ filters [ $ filter_id ] ; }
Returns a filter
55,283
public function getByRole ( $ role_id ) { foreach ( $ this -> getHandlers ( ) as $ filter ) { if ( in_array ( $ role_id , ( array ) $ filter [ 'role_id' ] ) ) { return $ filter ; } } return array ( ) ; }
Returns a filter for the given user role ID
55,284
public function getHandlers ( ) { $ filters = & gplcart_static ( 'filter.handlers' ) ; if ( isset ( $ filters ) ) { return $ filters ; } $ filters = array ( ) ; $ this -> hook -> attach ( 'filter.handlers' , $ filters , $ this ) ; foreach ( $ filters as $ id => & $ filter ) { $ filter [ 'filter_id' ] = $ id ; $ filter += array ( 'role_id' => array ( ) , 'status' => true , 'module' => null ) ; } return $ filters ; }
Returns an array of defined filters
55,285
protected function limitList ( array & $ list , array $ limit ) { list ( $ from , $ to ) = $ limit ; $ list = array_slice ( $ list , $ from , $ to , true ) ; }
Limit the list using the limit
55,286
protected function sortList ( array & $ list , array $ allowed , array $ query , array $ default = array ( ) ) { if ( empty ( $ default ) ) { $ default = array ( 'sort' => '' , 'order' => '' ) ; } else { $ order = reset ( $ default ) ; $ field = key ( $ default ) ; $ default = array ( 'sort' => $ field , 'order' => $ order ) ; } $ query += $ default ; if ( in_array ( $ query [ 'sort' ] , $ allowed ) ) { uasort ( $ list , function ( $ a , $ b ) use ( $ query ) { return $ this -> callbackSortList ( $ a , $ b , $ query ) ; } ) ; } }
Sort the list by a field
55,287
protected function filterList ( array & $ list , array $ allowed_fields , array $ query ) { $ filter = array_intersect_key ( $ query , array_flip ( $ allowed_fields ) ) ; if ( ! empty ( $ filter ) ) { $ list = array_filter ( $ list , function ( $ item ) use ( $ filter ) { return $ this -> callbackFilterList ( $ item , $ filter ) ; } ) ; } }
Filter the list by a field
55,288
public function getMessage ( ) { switch ( $ this -> code ) { case self :: LOAD_FAILED : return $ this -> extraDetails ; case self :: SCHEMA_VIOLATION : return $ this -> extraDetails ; case self :: FIELD_VALIDATION : $ field = $ this -> extraDetails [ 'field' ] ; $ error = $ this -> extraDetails [ 'error' ] ; $ value = json_encode ( $ this -> extraDetails [ 'value' ] ) ; return "{$field}: {$error} ({$value})" ; case self :: ROW_FIELD_VALIDATION : $ row = $ this -> extraDetails [ 'row' ] ; $ field = $ this -> extraDetails [ 'field' ] ; $ error = $ this -> extraDetails [ 'error' ] ; $ value = $ this -> extraDetails [ 'value' ] ; return "row {$row} {$field}: {$error} ({$value})" ; case self :: ROW_VALIDATION : $ row = $ this -> extraDetails [ 'row' ] ; $ error = $ this -> extraDetails [ 'error' ] ; return "row {$row}: {$error}" ; default : throw new \ Exception ( "Invalid schema validation code: {$this->code}" ) ; } }
returns a string representation of the error .
55,289
public function listReportRoute ( ) { $ this -> setTitleListReportRoute ( ) ; $ this -> setBreadcrumbListReportRoute ( ) ; $ this -> setFilterListReportRoute ( ) ; $ this -> setPagerListReportRoute ( ) ; $ this -> setData ( 'routes' , ( array ) $ this -> getListReportRoute ( ) ) ; $ this -> setData ( 'permissions' , $ this -> getPermissionsReportRole ( ) ) ; $ this -> outputListReportRoute ( ) ; }
Displays the route overview page
55,290
protected function getListReportRoute ( $ count = false ) { $ list = $ this -> route -> getList ( ) ; $ this -> prepareListReportRoute ( $ list ) ; $ allowed = $ this -> getAllowedFiltersReportRoute ( ) ; $ this -> filterList ( $ list , $ allowed , $ this -> query_filter ) ; $ this -> sortList ( $ list , $ allowed , $ this -> query_filter , array ( 'pattern' => 'asc' ) ) ; if ( $ count ) { return count ( $ list ) ; } $ this -> limitList ( $ list , $ this -> data_limit ) ; return $ list ; }
Returns an array of routes or counts them
55,291
protected function prepareListReportRoute ( array & $ routes ) { $ permissions = $ this -> getPermissionsReportRole ( ) ; foreach ( $ routes as $ pattern => & $ route ) { if ( strpos ( $ pattern , 'admin' ) === 0 && ! isset ( $ route [ 'access' ] ) ) { $ route [ 'access' ] = 'admin' ; } if ( ! isset ( $ route [ 'access' ] ) ) { $ route [ 'access' ] = GC_PERM_PUBLIC ; } $ access_names = array ( ) ; if ( isset ( $ permissions [ $ route [ 'access' ] ] ) ) { $ access_names [ $ route [ 'access' ] ] = $ this -> text ( $ permissions [ $ route [ 'access' ] ] ) ; } else { $ access_names [ '' ] = $ this -> text ( $ permissions [ GC_PERM_PUBLIC ] ) ; } if ( $ route [ 'access' ] === GC_PERM_SUPERADMIN ) { $ access_names = array ( GC_PERM_SUPERADMIN => $ this -> text ( $ permissions [ GC_PERM_SUPERADMIN ] ) ) ; } $ route [ 'pattern' ] = $ pattern ; $ route [ 'access_name' ] = implode ( ' + ' , $ access_names ) ; $ route [ 'access' ] = implode ( '' , array_keys ( $ access_names ) ) ; $ route [ 'status' ] = ! isset ( $ route [ 'status' ] ) || ! empty ( $ route [ 'status' ] ) ; } }
Prepares an array of routes
55,292
public function current ( array $ condition ) { $ value = strtotime ( reset ( $ condition [ 'value' ] ) ) ; return empty ( $ value ) ? false : $ this -> compare ( GC_TIME , $ value , $ condition [ 'operator' ] ) ; }
Whether the date condition is met
55,293
protected function initPresenter ( ) { if ( $ this -> name && $ this -> open -> isSubmitted ( ) ) { $ this -> error = $ this -> dataStore -> getError ( $ this -> name ) ; } $ this -> presenter -> setElement ( $ this ) ; }
Inject the element into presenter
55,294
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ config = $ serviceLocator -> get ( 'ApplicationConfig' ) ; $ config = isset ( $ config [ 'module_listener_options' ] ) ? $ config [ 'module_listener_options' ] : array ( ) ; if ( ! isset ( $ config [ 'module_paths' ] ) ) { $ paths = array ( ) ; $ cwd = getcwd ( ) . '/' ; foreach ( array ( 'modules' , 'vendor' ) as $ dir ) { if ( is_dir ( $ dir = $ cwd . $ dir ) ) { $ paths [ ] = $ dir ; } } $ config [ 'module_paths' ] = $ paths ; } if ( isset ( $ config [ 'extra_module_paths' ] ) ) { $ config [ 'module_paths' ] = array_merge ( $ config [ 'module_paths' ] , $ config [ 'extra_module_paths' ] ) ; } $ listenerOptions = new ListenerOptions ( $ config ) ; $ defaultListeners = new DefaultListenerAggregate ( $ listenerOptions ) ; return $ defaultListeners ; }
Creates and returns the default module listeners providing them configuration from the module_listener_options key of the ApplicationConfig service . Also sets the default config glob path .
55,295
public function listStore ( ) { $ this -> actionListStore ( ) ; $ this -> setTitleListStore ( ) ; $ this -> setBreadcrumbListStore ( ) ; $ this -> setFilterListStore ( ) ; $ this -> setPagerListStore ( ) ; $ this -> setData ( 'stores' , $ this -> getListStore ( ) ) ; $ this -> setData ( 'default_store' , $ this -> store -> getDefault ( ) ) ; $ this -> outputListStore ( ) ; }
Displays the store overview page
55,296
protected function actionListStore ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ updated = $ deleted = 0 ; foreach ( $ selected as $ id ) { if ( $ action === 'status' && $ this -> access ( 'store_edit' ) ) { $ updated += ( int ) $ this -> store -> update ( $ id , array ( 'status' => ( int ) $ value ) ) ; } if ( $ action === 'delete' && $ this -> access ( 'store_delete' ) && ! $ this -> store -> isDefault ( $ id ) ) { $ deleted += ( int ) $ this -> store -> delete ( $ id ) ; } } if ( $ updated > 0 ) { $ message = $ this -> text ( 'Updated %num item(s)' , array ( '%num' => $ updated ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } }
Applies an action to the selected stores
55,297
public function editStore ( $ store_id = null ) { $ this -> setStore ( $ store_id ) ; $ this -> seTitleEditStore ( ) ; $ this -> setBreadcrumbEditStore ( ) ; $ this -> setData ( 'store' , $ this -> data_store ) ; $ this -> setData ( 'themes' , $ this -> getListThemeStore ( ) ) ; $ this -> setData ( 'is_default' , $ this -> isDefaultStore ( ) ) ; $ this -> setData ( 'can_delete' , $ this -> canDeleteStore ( ) ) ; $ this -> setData ( 'countries' , $ this -> getCountriesStore ( ) ) ; $ this -> setData ( 'collections' , $ this -> getListCollectionStore ( ) ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> submitEditStore ( ) ; $ this -> setDataEditStore ( ) ; $ this -> setJsEditStore ( ) ; $ this -> outputEditStore ( ) ; }
Displays the store settings form
55,298
protected function setStore ( $ store_id ) { $ this -> data_store = array ( ) ; if ( is_numeric ( $ store_id ) ) { $ this -> data_store = $ this -> store -> get ( $ store_id ) ; if ( empty ( $ this -> data_store ) ) { $ this -> outputHttpStatus ( 404 ) ; } } $ this -> prepareStore ( $ this -> data_store ) ; }
Sets a store data
55,299
protected function getListThemeStore ( ) { $ themes = $ this -> module -> getByType ( 'theme' , true ) ; unset ( $ themes [ $ this -> theme_backend ] ) ; return $ themes ; }
Returns an array of available theme modules excluding backend theme