idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
55,100
|
protected function prepareCollectionItem ( array & $ collection_item ) { $ item = $ this -> collection_item -> getItem ( array ( 'collection_item_id' => $ collection_item [ 'collection_item_id' ] ) ) ; $ collection_item [ 'title' ] = isset ( $ item [ 'title' ] ) ? $ item [ 'title' ] : '' ; }
|
Prepare an array of collection item data
|
55,101
|
protected function setBreadcrumbListCollectionItem ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Collections' ) , 'url' => $ this -> url ( 'admin/content/collection' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the collection item overview page
|
55,102
|
public function editCollectionItem ( $ collection_id , $ collection_item_id = null ) { $ this -> setCollectionCollection ( $ collection_id ) ; $ this -> setCollectionCollectionItem ( $ collection_item_id ) ; $ this -> setTitleEditCollectionItem ( ) ; $ this -> setBreadcrumbEditCollectionItem ( ) ; $ this -> setData ( 'collection' , $ this -> data_collection ) ; $ this -> setData ( 'collection_item' , $ this -> data_collection_item ) ; $ this -> setData ( 'handler' , $ this -> getHandlerCollectionItem ( ) ) ; $ this -> setData ( 'weight' , $ this -> collection_item -> getNextWeight ( $ collection_id ) ) ; $ this -> submitEditCollectionItem ( ) ; $ this -> setJsEditCollectionItem ( ) ; $ this -> outputEditCollectionItem ( ) ; }
|
Displays the edit collection item form
|
55,103
|
protected function submitEditCollectionItem ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteCollectionItem ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditCollectionItem ( ) ) { if ( isset ( $ this -> data_collection_item [ 'collection_item_id' ] ) ) { $ this -> updateCollectionItem ( ) ; } else { $ this -> addCollectionItem ( ) ; } } }
|
Saves a submitted collection item
|
55,104
|
protected function getHandlerCollectionItem ( ) { $ handlers = $ this -> collection -> getHandlers ( ) ; if ( empty ( $ handlers [ $ this -> data_collection [ 'type' ] ] ) ) { $ this -> outputHttpStatus ( 403 ) ; } return $ handlers [ $ this -> data_collection [ 'type' ] ] ; }
|
Returns an array of handler data for the collection type
|
55,105
|
protected function validateEditCollectionItem ( ) { $ this -> setSubmitted ( 'collection_item' ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_collection_item ) ; $ this -> setSubmitted ( 'collection_id' , $ this -> data_collection [ 'collection_id' ] ) ; $ this -> validateComponent ( 'collection_item' ) ; return ! $ this -> hasErrors ( ) ; }
|
Validates a submitted collection item
|
55,106
|
protected function addCollectionItem ( ) { $ this -> controlAccess ( 'collection_item_add' ) ; if ( $ this -> collection_item -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( '' , $ this -> text ( 'Collection item has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Collection item has not been added' ) , 'warning' ) ; }
|
Adds a new collection item
|
55,107
|
protected function updateCollectionItem ( ) { $ this -> controlAccess ( 'collection_item_edit' ) ; if ( $ this -> collection_item -> update ( $ this -> data_collection_item [ 'collection_item_id' ] , $ this -> getSubmitted ( ) ) ) { $ url = "admin/content/collection-item/{$this->data_collection['collection_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Collection item has been updated' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Collection item has not been updated' ) , 'warning' ) ; }
|
Update a submitted collection item
|
55,108
|
protected function deleteCollectionItem ( ) { $ this -> controlAccess ( 'collection_item_delete' ) ; if ( $ this -> collection_item -> delete ( $ this -> data_collection_item [ 'collection_item_id' ] ) ) { $ url = "admin/content/collection-item/{$this->data_collection['collection_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Collection item has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Collection item has not been deleted' ) , 'warning' ) ; }
|
Delete a collection item
|
55,109
|
protected function setTitleEditCollectionItem ( ) { $ vars = array ( '%name' => $ this -> data_collection [ 'title' ] ) ; if ( empty ( $ this -> data_collection_item [ 'collection_item_id' ] ) ) { $ text = $ this -> text ( 'Add item to %name' , $ vars ) ; } else { $ text = $ this -> text ( 'Edit item of %name' , $ vars ) ; } $ this -> setTitle ( $ text ) ; }
|
Sets title on the edit collection item page
|
55,110
|
protected function setBreadcrumbEditCollectionItem ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/content/collection' ) , 'text' => $ this -> text ( 'Collections' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( "admin/content/collection-item/{$this->data_collection['collection_id']}" ) , 'text' => $ this -> text ( 'Items of collection %name' , array ( '%name' => $ this -> data_collection [ 'title' ] ) ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the edit collection item page
|
55,111
|
public function getList ( array $ options ) { $ sql = 'SELECT ol.*, u.name AS user_name, u.email AS user_email, u.status AS user_status' ; if ( ! empty ( $ options [ 'count' ] ) ) { $ sql = 'SELECT COUNT(ol.order_log_id)' ; } $ sql .= ' FROM order_log ol LEFT JOIN user u ON(ol.user_id=u.user_id) WHERE ol.order_id=?' ; if ( ! empty ( $ options [ 'count' ] ) ) { return ( int ) $ this -> db -> fetchColumn ( $ sql , array ( $ options [ 'order_id' ] ) ) ; } $ sql .= ' ORDER BY ol.created DESC' ; if ( ! empty ( $ options [ 'limit' ] ) ) { $ sql .= ' LIMIT ' . implode ( ',' , array_map ( 'intval' , $ options [ 'limit' ] ) ) ; } $ fetch_options = array ( 'unserialize' => 'data' , 'index' => 'order_log_id' ) ; $ list = $ this -> db -> fetchAll ( $ sql , array ( $ options [ 'order_id' ] ) , $ fetch_options ) ; $ this -> hook -> attach ( 'order.log.list' , $ list , $ this ) ; return ( array ) $ list ; }
|
Returns an array of log records
|
55,112
|
public function getWidgetAdminMenu ( $ route_class , array $ options = array ( ) ) { $ options += array ( 'parent_url' => 'admin' ) ; $ items = array ( ) ; foreach ( $ route_class -> getList ( ) as $ path => $ route ) { if ( strpos ( $ path , "{$options['parent_url']}/" ) !== 0 || empty ( $ route [ 'menu' ] [ 'admin' ] ) ) { continue ; } if ( isset ( $ route [ 'access' ] ) && ! $ this -> access ( $ route [ 'access' ] ) ) { continue ; } $ items [ $ path ] = array ( 'url' => $ this -> url ( $ path ) , 'text' => $ this -> text ( $ route [ 'menu' ] [ 'admin' ] ) , 'depth' => substr_count ( substr ( $ path , strlen ( "{$options['parent_url']}/" ) ) , '/' ) , ) ; } ksort ( $ items ) ; $ options += array ( 'items' => $ items ) ; return $ this -> getWidgetMenu ( $ options ) ; }
|
Returns rendered admin menu
|
55,113
|
public function getWidgetImages ( $ language_model , array $ options ) { $ options += array ( 'single' => false , 'languages' => $ language_model -> getList ( array ( 'in_database' => true ) ) ) ; return $ this -> render ( 'common/image' , $ options ) ; }
|
Returns rendered image widget
|
55,114
|
protected function getWidgetCollection ( array $ items ) { if ( empty ( $ items ) ) { return '' ; } $ item = reset ( $ items ) ; $ data = array ( 'items' => $ items , 'title' => $ item [ 'collection_item' ] [ 'collection_title' ] , 'collection_id' => $ item [ 'collection_item' ] [ 'collection_id' ] ) ; return $ this -> render ( $ item [ 'collection_handler' ] [ 'template' ] [ 'list' ] , $ data , true ) ; }
|
Returns a rendered collection
|
55,115
|
protected function getWidgetCartPreview ( array $ cart ) { if ( empty ( $ cart [ 'items' ] ) ) { return '' ; } $ options = array ( 'cart' => $ cart , 'limit' => $ this -> config ( 'cart_preview_limit' , 5 ) ) ; return $ this -> render ( 'cart/preview' , $ options , true ) ; }
|
Returns rendered cart preview
|
55,116
|
public function order ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateOrder ( ) ; $ this -> validateStoreId ( ) ; $ this -> validatePaymentOrder ( ) ; $ this -> validateShippingOrder ( ) ; $ this -> validateStatusOrder ( ) ; $ this -> validateShippingAddressOrder ( ) ; $ this -> validatePaymentAddressOrder ( ) ; $ this -> validateUserCartId ( ) ; $ this -> validateCreatorOrder ( ) ; $ this -> validateTotalOrder ( ) ; $ this -> validateData ( ) ; $ this -> validateComponentPricesOrder ( ) ; $ this -> validateCurrencyOrder ( ) ; $ this -> validateCommentOrder ( ) ; $ this -> validateTransactionOrder ( ) ; $ this -> validateLogOrder ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full order data validation
|
55,117
|
protected function validateOrder ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> order -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Order' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates an order to be updated
|
55,118
|
protected function validatePaymentOrder ( ) { $ field = 'payment' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Payment' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } $ method = $ this -> payment -> get ( $ value ) ; if ( empty ( $ method [ 'status' ] ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } return true ; }
|
Validates a payment method
|
55,119
|
protected function validateStatusOrder ( ) { $ field = 'status' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ statuses = $ this -> order -> getStatuses ( ) ; if ( empty ( $ statuses [ $ value ] ) ) { $ this -> setErrorUnavailable ( $ field , $ this -> translation -> text ( 'Status' ) ) ; return false ; } return true ; }
|
Validates a status
|
55,120
|
protected function validatePaymentAddressOrder ( ) { $ field = 'payment_address' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) && $ this -> isUpdating ( ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } if ( empty ( $ value ) && ! $ this -> isError ( 'shipping_address' ) ) { $ value = $ this -> getSubmitted ( 'shipping_address' ) ; } $ label = $ this -> translation -> text ( 'Payment address' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } $ address = $ this -> address -> get ( $ value ) ; if ( empty ( $ address ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } $ this -> setSubmitted ( $ field , $ value ) ; return true ; }
|
Validates a payment address
|
55,121
|
protected function validateCreatorOrder ( ) { $ field = 'creator' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) && $ this -> isUpdating ( ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } if ( empty ( $ value ) ) { return null ; } $ label = $ this -> translation -> text ( 'Creator' ) ; if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } $ user = $ this -> user -> get ( $ value ) ; if ( empty ( $ user ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } return true ; }
|
Validates a creator user ID
|
55,122
|
protected function validateTotalOrder ( ) { $ field = 'total' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Total' ) ; if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } if ( strlen ( $ value ) > 10 ) { $ this -> setErrorLengthRange ( $ field , $ label , 0 , 10 ) ; return false ; } return true ; }
|
Validates order total
|
55,123
|
protected function validateComponentPricesOrder ( ) { $ field = 'data.components' ; $ components = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ components ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Price' ) ; if ( ! is_array ( $ components ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } foreach ( $ components as $ id => $ component ) { if ( ! is_numeric ( $ component [ 'price' ] ) ) { $ this -> setErrorNumeric ( "$field.$id" , $ label ) ; continue ; } if ( strlen ( $ component [ 'price' ] ) > 10 ) { $ this -> setErrorLengthRange ( "$field.$id" , $ label , 0 , 10 ) ; } } return ! $ this -> isError ( 'components' ) ; }
|
Validates order component prices
|
55,124
|
protected function validateTransactionOrder ( ) { $ field = 'transaction_id' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Transaction' ) ; if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } if ( empty ( $ value ) ) { return true ; } $ transaction = $ this -> transaction -> get ( $ value ) ; if ( empty ( $ transaction ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } return true ; }
|
Validates a transaction ID
|
55,125
|
protected function validateLogOrder ( ) { if ( mb_strlen ( $ this -> getSubmitted ( 'log' ) ) > 255 ) { $ this -> setErrorLengthRange ( 'log' , $ this -> translation -> text ( 'Log' ) , 0 , 255 ) ; return false ; } return true ; }
|
Validates a log message
|
55,126
|
public function run ( $ handler_id , & $ submitted , array $ options = array ( ) ) { $ result = null ; $ this -> hook -> attach ( 'validator.run.before' , $ submitted , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ result = $ this -> callHandler ( $ handler_id , $ submitted , $ options ) ; $ this -> hook -> attach ( 'validator.run.after' , $ submitted , $ options , $ result , $ this ) ; if ( $ result === true ) { return true ; } return empty ( $ result ) ? $ this -> translation -> text ( 'Failed validation' ) : $ result ; }
|
Performs validation using the given handler
|
55,127
|
public function callHandler ( $ handler_id , & $ submitted , array $ options ) { try { $ handlers = $ this -> getHandlers ( ) ; $ callback = Handler :: get ( $ handlers , $ handler_id , 'validate' ) ; return call_user_func_array ( $ callback , array ( & $ submitted , $ options ) ) ; } catch ( Exception $ ex ) { return $ ex -> getMessage ( ) ; } }
|
Call a validation handler
|
55,128
|
public function addToProductCompare ( $ compare_action_model ) { $ errors = $ this -> error ( ) ; if ( empty ( $ errors ) ) { $ submitted = $ this -> getSubmitted ( ) ; $ result = $ compare_action_model -> add ( $ submitted [ 'product' ] , $ submitted ) ; } else { $ result = array ( 'redirect' => '' , 'severity' => 'warning' , 'message' => $ this -> format ( $ errors ) ) ; } if ( $ this -> isAjax ( ) ) { $ this -> outputJson ( $ result ) ; } $ this -> redirect ( $ result [ 'redirect' ] , $ result [ 'message' ] , $ result [ 'severity' ] ) ; }
|
Adds a submitted product to comparison
|
55,129
|
public function deleteFromProductCompare ( $ compare_action_model ) { $ product_id = $ this -> getSubmitted ( 'product_id' ) ; $ result = $ compare_action_model -> delete ( $ product_id ) ; if ( $ this -> isAjax ( ) ) { $ this -> outputJson ( $ result ) ; } $ this -> controlDeleteProductCompare ( $ result , $ product_id ) ; $ this -> redirect ( $ result [ 'redirect' ] , $ result [ 'message' ] , $ result [ 'severity' ] ) ; }
|
Deletes a submitted product from comparison
|
55,130
|
protected function controlDeleteProductCompare ( array & $ result , $ product_id ) { if ( empty ( $ result [ 'redirect' ] ) ) { $ segments = explode ( ',' , $ this -> path ( ) ) ; if ( isset ( $ segments [ 0 ] ) && $ segments [ 0 ] === 'compare' && ! empty ( $ segments [ 1 ] ) ) { $ ids = array_filter ( array_map ( 'trim' , explode ( ',' , $ segments [ 1 ] ) ) , 'ctype_digit' ) ; unset ( $ ids [ array_search ( $ product_id , $ ids ) ] ) ; $ result [ 'redirect' ] = $ segments [ 0 ] . '/' . implode ( ',' , $ ids ) ; } } }
|
Controls result after a product has been deleted from comparison
|
55,131
|
public static function configRoutes ( $ groupConfig ) { $ groups = '' ; $ i = 0 ; foreach ( $ groupConfig [ 'register_groups' ] as $ key => $ value ) { $ i ++ ; if ( $ i == 1 ) { $ groups .= $ value ; } else { $ groups .= '|' . $ value ; } } Route :: group ( [ 'middleware' => 'groups:' . $ groups ] , function ( $ object ) { Route :: post ( '/config/{group}/show' , '\Niku\Cms\Http\Controllers\Config\ShowConfigController@init' ) -> name ( 'show' ) ; Route :: post ( '/config/{group}/edit' , '\Niku\Cms\Http\Controllers\Config\EditConfigController@init' ) -> name ( 'edit' ) ; } ) ; }
|
Get a Cms route registrar .
|
55,132
|
protected function getSignature ( array $ options ) { $ signature = "\r\n\r\n-------------------------------------\r\n@owner\r\n@address\r\n@phone\r\n@fax\r\n@store_email\r\n@map" ; $ replacements = array ( ) ; $ replacements [ '@owner' ] = empty ( $ options [ 'owner' ] ) ? '' : $ options [ 'owner' ] ; $ replacements [ '@address' ] = empty ( $ options [ 'address' ] ) ? '' : $ options [ 'address' ] ; $ replacements [ '@phone' ] = empty ( $ options [ 'phone' ] ) ? '' : $ this -> translation -> text ( 'Tel: @phone' , array ( '@phone' => implode ( ',' , $ options [ 'phone' ] ) ) ) ; $ replacements [ '@fax' ] = empty ( $ options [ 'fax' ] ) ? '' : $ this -> translation -> text ( 'Fax: @fax' , array ( '@fax' => implode ( ',' , $ options [ 'fax' ] ) ) ) ; $ replacements [ '@store_email' ] = empty ( $ options [ 'email' ] ) ? '' : $ this -> translation -> text ( 'E-mail: @store_email' , array ( '@store_email' => implode ( ',' , $ options [ 'email' ] ) ) ) ; $ replacements [ '@map' ] = empty ( $ options [ 'map' ] ) ? '' : $ this -> translation -> text ( 'Find us on Google Maps: @map' , array ( '@map' => 'http://maps.google.com/?q=' . implode ( ',' , $ options [ 'map' ] ) ) ) ; return rtrim ( gplcart_string_format ( $ signature , $ replacements ) , "\t\n\r\0\x0B-" ) ; }
|
Returns a string containing default e - mail signature
|
55,133
|
protected function flatten ( array & $ parameters , array $ subnode = null , $ path = null ) { if ( null === $ subnode ) { $ subnode = & $ parameters ; } foreach ( $ subnode as $ key => $ value ) { if ( is_array ( $ value ) ) { $ nodePath = $ path ? $ path . '.' . $ key : $ key ; $ this -> flatten ( $ parameters , $ value , $ nodePath ) ; if ( null === $ path ) { unset ( $ parameters [ $ key ] ) ; } } elseif ( null !== $ path ) { $ parameters [ $ path . '.' . $ key ] = $ value ; } } }
|
Flattens an nested array of parameters .
|
55,134
|
public function get ( $ code ) { $ result = & gplcart_static ( "country.get.$code" ) ; if ( isset ( $ result ) ) { return $ result ; } $ this -> hook -> attach ( 'country.get.before' , $ code , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ sql = 'SELECT * FROM country WHERE code=?' ; $ result = $ this -> db -> fetch ( $ sql , array ( $ code ) , array ( 'unserialize' => 'format' ) ) ; if ( isset ( $ result [ 'format' ] ) ) { $ default_format = $ this -> getDefaultFormat ( ) ; $ result [ 'format' ] = gplcart_array_merge ( $ default_format , $ result [ 'format' ] ) ; gplcart_array_sort ( $ result [ 'format' ] ) ; } $ this -> hook -> attach ( 'country.get.after' , $ code , $ result , $ this ) ; return $ result ; }
|
Loads a country from the database
|
55,135
|
public function getFormat ( $ country , $ only_enabled = false ) { $ data = is_string ( $ country ) ? $ this -> get ( $ country ) : ( array ) $ country ; if ( empty ( $ data [ 'format' ] ) ) { $ format = $ this -> getDefaultFormat ( ) ; gplcart_array_sort ( $ format ) ; } else { $ format = $ data [ 'format' ] ; } if ( $ only_enabled ) { return array_filter ( $ format , function ( $ item ) { return ! empty ( $ item [ 'status' ] ) ; } ) ; } return $ format ; }
|
Returns an array of country format
|
55,136
|
public function add ( array $ data ) { $ result = null ; $ this -> hook -> attach ( 'country.add.before' , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ result = true ; $ this -> db -> insert ( 'country' , $ data ) ; $ this -> hook -> attach ( 'country.add.after' , $ data , $ result , $ this ) ; return ( bool ) $ result ; }
|
Adds a country
|
55,137
|
public function getIso ( $ code = null ) { $ data = ( array ) gplcart_config_get ( GC_FILE_CONFIG_COUNTRY ) ; if ( isset ( $ code ) ) { return isset ( $ data [ $ code ] ) ? $ data [ $ code ] : '' ; } return $ data ; }
|
Returns an array of country names or a country name if the code parameter is set
|
55,138
|
protected function deleteLinked ( $ code ) { $ this -> db -> delete ( 'city' , array ( 'country' => $ code ) ) ; $ this -> db -> delete ( 'state' , array ( 'country' => $ code ) ) ; }
|
Deletes all database records related to the country
|
55,139
|
public function delete ( array $ data = array ( ) ) { $ sql = 'DELETE FROM log' ; $ conditions = array ( ) ; if ( empty ( $ data [ 'log_id' ] ) ) { $ sql .= " WHERE log_id IS NOT NULL" ; } else { settype ( $ data [ 'log_id' ] , 'array' ) ; $ placeholders = rtrim ( str_repeat ( '?,' , count ( $ data [ 'log_id' ] ) ) , ',' ) ; $ sql .= " WHERE log_id IN($placeholders)" ; $ conditions = array_merge ( $ conditions , $ data [ 'log_id' ] ) ; } if ( ! empty ( $ data [ 'type' ] ) ) { settype ( $ data [ 'type' ] , 'array' ) ; $ placeholders = rtrim ( str_repeat ( '?,' , count ( $ data [ 'type' ] ) ) , ',' ) ; $ sql .= " AND type IN($placeholders)" ; $ conditions = array_merge ( $ conditions , $ data [ 'type' ] ) ; } $ this -> db -> run ( $ sql , $ conditions ) ; return true ; }
|
Delete log records
|
55,140
|
public function getSeverities ( ) { return array ( 'info' => $ this -> translation -> text ( 'Info' ) , 'danger' => $ this -> translation -> text ( 'Danger' ) , 'warning' => $ this -> translation -> text ( 'Warning' ) ) ; }
|
Returns an array of log severity types
|
55,141
|
public function checkFilesystem ( ) { $ results = array ( $ this -> checkPermissions ( GC_FILE_CONFIG_COMPILED ) ) ; if ( file_exists ( GC_FILE_CONFIG_COMPILED_OVERRIDE ) ) { $ results [ ] = $ this -> checkPermissions ( GC_FILE_CONFIG_COMPILED_OVERRIDE ) ; } $ filtered = array_filter ( $ results , 'is_string' ) ; return empty ( $ filtered ) ? true : $ filtered ; }
|
Checks file system
|
55,142
|
protected function checkPermissions ( $ file , $ permissions = '0444' ) { if ( substr ( sprintf ( '%o' , fileperms ( $ file ) ) , - 4 ) === $ permissions ) { return true ; } $ vars = array ( '%name' => $ file , '%perm' => $ permissions ) ; return $ this -> translation -> text ( 'File %name is not secure. The file permissions must be %perm' , $ vars ) ; }
|
Checks file permissions
|
55,143
|
public function setItemOrderShippingName ( & $ item , $ shipping_model ) { if ( isset ( $ item [ 'shipping' ] ) ) { $ data = $ shipping_model -> get ( $ item [ 'shipping' ] ) ; $ item [ 'shipping_name' ] = empty ( $ data [ 'title' ] ) ? 'Unknown' : $ data [ 'title' ] ; } }
|
Adds shipping_name key
|
55,144
|
public function setItemOrderPaymentName ( & $ item , $ payment_model ) { if ( isset ( $ item [ 'payment' ] ) ) { $ data = $ payment_model -> get ( $ item [ 'payment' ] ) ; $ item [ 'payment_name' ] = empty ( $ data [ 'title' ] ) ? 'Unknown' : $ data [ 'title' ] ; } }
|
Adds payment_name key
|
55,145
|
public function setItemOrderAddress ( & $ order , $ address_model ) { $ order [ 'address' ] = array ( ) ; foreach ( array ( 'shipping' , 'payment' ) as $ type ) { $ address = $ address_model -> get ( $ order [ "{$type}_address" ] ) ; if ( ! empty ( $ address ) ) { $ order [ 'address' ] [ $ type ] = $ address ; $ order [ 'address_translated' ] [ $ type ] = $ address_model -> getTranslated ( $ order [ 'address' ] [ $ type ] , true ) ; } } }
|
Adds an address information for the order item
|
55,146
|
public function setItemOrderStatusName ( & $ item , $ order_model ) { if ( isset ( $ item [ 'status' ] ) ) { $ data = $ order_model -> getStatusName ( $ item [ 'status' ] ) ; $ item [ 'status_name' ] = empty ( $ data ) ? 'Unknown' : $ data ; } }
|
Adds status_name key
|
55,147
|
public function setItemOrderStoreName ( & $ item , $ store_model ) { if ( isset ( $ item [ 'store_id' ] ) ) { $ data = $ store_model -> get ( $ item [ 'store_id' ] ) ; $ item [ 'store_name' ] = empty ( $ data [ 'name' ] ) ? 'Unknown' : $ data [ 'name' ] ; } }
|
Adds store_name key
|
55,148
|
public function listCategoryGroup ( ) { $ this -> setTitleListCategoryGroup ( ) ; $ this -> setBreadcrumbListCategoryGroup ( ) ; $ this -> setFilterListCategoryGroup ( ) ; $ this -> setPagerListCategoryGroup ( ) ; $ this -> setData ( 'category_groups' , $ this -> getListCategoryGroup ( ) ) ; $ this -> setData ( 'category_group_types' , $ this -> category_group -> getTypes ( ) ) ; $ this -> outputListCategoryGroup ( ) ; }
|
Displays the category group overview page
|
55,149
|
public function editCategoryGroup ( $ category_group_id = null ) { $ this -> setCategoryGroup ( $ category_group_id ) ; $ this -> setTitleEditCategoryGroup ( ) ; $ this -> setBreadcrumbEditCategoryGroup ( ) ; $ this -> setData ( 'category_group' , $ this -> data_category_group ) ; $ this -> setData ( 'can_delete' , $ this -> canDeleteCategoryGroup ( ) ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> setData ( 'category_group_types' , $ this -> category_group -> getTypes ( ) ) ; $ this -> submitEditCategoryGroup ( ) ; $ this -> outputEditCategoryGroup ( ) ; }
|
Displays the edit category group page
|
55,150
|
protected function canDeleteCategoryGroup ( ) { return isset ( $ this -> data_category_group [ 'category_group_id' ] ) && $ this -> category_group -> canDelete ( $ this -> data_category_group [ 'category_group_id' ] ) && $ this -> access ( 'category_group_delete' ) ; }
|
Whether the category group can be deleted
|
55,151
|
protected function setCategoryGroup ( $ category_group_id ) { $ this -> data_category_group = array ( ) ; if ( is_numeric ( $ category_group_id ) ) { $ conditions = array ( 'language' => 'und' , 'category_group_id' => $ category_group_id ) ; $ this -> data_category_group = $ this -> category_group -> get ( $ conditions ) ; if ( empty ( $ this -> data_category_group ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> prepareCategoryGroup ( $ this -> data_category_group ) ; } }
|
Sets the category group data
|
55,152
|
protected function submitEditCategoryGroup ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteCategoryGroup ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditCategoryGroup ( ) ) { if ( isset ( $ this -> data_category_group [ 'category_group_id' ] ) ) { $ this -> updateCategoryGroup ( ) ; } else { $ this -> addCategoryGroup ( ) ; } } }
|
Handles a submitted category group data
|
55,153
|
protected function validateEditCategoryGroup ( ) { $ this -> setSubmitted ( 'category_group' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_category_group ) ; $ this -> validateComponent ( 'category_group' ) ; return ! $ this -> hasErrors ( false ) ; }
|
Validates a submitted category group data
|
55,154
|
protected function deleteCategoryGroup ( ) { $ this -> controlAccess ( 'category_group_delete' ) ; if ( $ this -> category_group -> delete ( $ this -> data_category_group [ 'category_group_id' ] ) ) { $ this -> redirect ( 'admin/content/category-group' , $ this -> text ( 'Category group has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Category group has not been deleted' ) , 'warning' ) ; }
|
Deletes a category group
|
55,155
|
protected function addCategoryGroup ( ) { $ this -> controlAccess ( 'category_group_add' ) ; if ( $ this -> category_group -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/content/category-group' , $ this -> text ( 'Category group has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Category group has not been added' ) , 'warning' ) ; }
|
Adds a new category group
|
55,156
|
protected function setTitleEditCategoryGroup ( ) { if ( isset ( $ this -> data_category_group [ 'category_group_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_category_group [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add category group' ) ; } $ this -> setTitle ( $ title ) ; }
|
Sets titles on the category group edit page
|
55,157
|
protected function setBreadcrumbEditCategoryGroup ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/content/category-group' ) , 'text' => $ this -> text ( 'Category groups' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the edit category group page
|
55,158
|
public function listTrigger ( ) { $ this -> actionListTrigger ( ) ; $ this -> setTitleListTrigger ( ) ; $ this -> setBreadcrumbListTrigger ( ) ; $ this -> setFilterListTrigger ( ) ; $ this -> setPagerListTrigger ( ) ; $ this -> setData ( 'triggers' , $ this -> getListTrigger ( ) ) ; $ this -> outputListTrigger ( ) ; }
|
Displays the trigger overview page
|
55,159
|
public function editTrigger ( $ trigger_id = null ) { $ this -> setTrigger ( $ trigger_id ) ; $ this -> setTitleEditTrigger ( ) ; $ this -> setBreadcrumbEditTrigger ( ) ; $ this -> setData ( 'trigger' , $ this -> data_trigger ) ; $ this -> setData ( 'can_delete' , $ this -> canDeleteTrigger ( ) ) ; $ this -> setData ( 'conditions' , $ this -> condition -> getHandlers ( ) ) ; $ this -> setData ( 'operators' , $ this -> condition -> getOperators ( ) ) ; $ this -> submitEditTrigger ( ) ; $ this -> setDataEditTrigger ( ) ; $ this -> outputEditTrigger ( ) ; }
|
Displays the trigger edit page
|
55,160
|
protected function setTrigger ( $ trigger_id ) { $ this -> data_trigger = array ( ) ; if ( is_numeric ( $ trigger_id ) ) { $ this -> data_trigger = $ this -> trigger -> get ( $ trigger_id ) ; if ( empty ( $ this -> data_trigger ) ) { $ this -> outputHttpStatus ( 404 ) ; } } }
|
Sets a trigger data
|
55,161
|
protected function submitEditTrigger ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteTrigger ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditTrigger ( ) ) { if ( isset ( $ this -> data_trigger [ 'trigger_id' ] ) ) { $ this -> updateTrigger ( ) ; } else { $ this -> addTrigger ( ) ; } } }
|
Handles a submitted trigger data
|
55,162
|
protected function validateEditTrigger ( ) { $ this -> setSubmitted ( 'trigger' , null , false ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmittedArray ( 'data.conditions' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_trigger ) ; $ this -> validateComponent ( 'trigger' ) ; return ! $ this -> hasErrors ( ) ; }
|
Validates a submitted trigger
|
55,163
|
protected function addTrigger ( ) { $ this -> controlAccess ( 'trigger_add' ) ; if ( $ this -> trigger -> add ( $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/settings/trigger' , $ this -> text ( 'Trigger has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Trigger has not been added' ) , 'warning' ) ; }
|
Adds a new trigger
|
55,164
|
protected function setDataEditTrigger ( ) { $ conditions = $ this -> getData ( 'trigger.data.conditions' ) ; if ( empty ( $ conditions ) || ! is_array ( $ conditions ) ) { return null ; } if ( ! $ this -> isError ( ) ) { gplcart_array_sort ( $ conditions ) ; } $ modified = array ( ) ; foreach ( $ conditions as $ condition ) { $ modified [ ] = is_string ( $ condition ) ? $ condition : $ condition [ 'original' ] ; } $ this -> setData ( 'trigger.data.conditions' , implode ( "\n" , $ modified ) ) ; }
|
Converts an array of conditions into a multiline string
|
55,165
|
protected function setTitleEditTrigger ( ) { if ( isset ( $ this -> data_trigger [ 'name' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_trigger [ 'name' ] ) ) ; } else { $ title = $ this -> text ( 'Add trigger' ) ; } $ this -> setTitle ( $ title ) ; }
|
Sets title on the edit trigger page
|
55,166
|
protected function setBreadcrumbEditTrigger ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/settings/trigger' ) , 'text' => $ this -> text ( 'Triggers' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
|
Sets breadcrumbs on the edit trigger page
|
55,167
|
public function trigger ( array & $ submitted , array $ options ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateTrigger ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateName ( ) ; $ this -> validateStoreId ( ) ; $ this -> validateWeight ( ) ; $ this -> validateConditionsTrigger ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full trigger data validation
|
55,168
|
protected function validateTrigger ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> trigger -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Trigger' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates a trigger to be updated
|
55,169
|
public function validateConditionsTrigger ( ) { $ field = 'data.conditions' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isUpdating ( ) && ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Conditions' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_array ( $ value ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } $ submitted = $ this -> getSubmitted ( ) ; $ operators = array_map ( 'htmlspecialchars' , array_keys ( $ this -> condition -> getOperators ( ) ) ) ; $ errors = $ modified = array ( ) ; foreach ( $ value as $ line => $ condition ) { $ line ++ ; $ parts = gplcart_string_explode_whitespace ( $ condition , 3 ) ; $ condition_id = array_shift ( $ parts ) ; $ operator = array_shift ( $ parts ) ; $ parameters = array_filter ( explode ( ',' , implode ( '' , $ parts ) ) , function ( $ value ) { return $ value !== '' ; } ) ; if ( empty ( $ parameters ) ) { $ errors [ ] = $ line ; continue ; } if ( ! in_array ( htmlspecialchars ( $ operator ) , $ operators ) ) { $ errors [ ] = $ line ; continue ; } $ args = array ( $ parameters , $ operator , $ condition_id , $ submitted ) ; $ result = $ this -> validateConditionTrigger ( $ condition_id , $ args ) ; if ( $ result !== true ) { $ errors [ ] = $ line ; continue ; } $ modified [ ] = array ( 'weight' => $ line , 'id' => $ condition_id , 'value' => $ parameters , 'operator' => $ operator , 'original' => "$condition_id $operator " . implode ( ',' , $ parameters ) , ) ; } if ( ! empty ( $ errors ) ) { $ error = $ this -> translation -> text ( 'Error in @num definition' , array ( '@num' => implode ( ',' , $ errors ) ) ) ; $ this -> setError ( $ field , $ error ) ; } if ( $ this -> isError ( ) ) { return false ; } $ this -> setSubmitted ( $ field , $ modified ) ; return true ; }
|
Validates and modifies trigger conditions
|
55,170
|
protected function validateConditionTrigger ( $ condition_id , array $ args ) { try { $ handlers = $ this -> condition -> getHandlers ( ) ; return static :: call ( $ handlers , $ condition_id , 'validate' , $ args ) ; } catch ( Exception $ ex ) { return $ ex -> getMessage ( ) ; } }
|
Call a validator handler
|
55,171
|
public function getByProduct ( $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'rating.get.before' , $ product_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ sql = 'SELECT rating, votes FROM rating WHERE product_id=?' ; $ result = $ this -> db -> fetch ( $ sql , array ( $ product_id ) ) ; $ this -> hook -> attach ( 'rating.get.after' , $ product_id , $ result , $ this ) ; return $ result ; }
|
Returns an array of rating data for a given product
|
55,172
|
public function set ( array $ data ) { $ result = null ; $ this -> hook -> attach ( 'rating.set.before' , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ conditions = array ( 'user_id' => $ data [ 'user_id' ] , 'product_id' => $ data [ 'product_id' ] ) ; $ this -> db -> delete ( 'rating_user' , $ conditions ) ; $ this -> addByUser ( $ data ) ; $ result = $ this -> setBayesian ( $ data ) ; $ this -> hook -> attach ( 'rating.set.after' , $ data , $ result , $ this ) ; return $ result ; }
|
Sets a rating for the given user and product
|
55,173
|
protected function addByUser ( array $ data ) { $ result = null ; $ this -> hook -> attach ( 'rating.add.user.before' , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( int ) $ result ; } if ( empty ( $ data [ 'rating' ] ) ) { return 0 ; } $ result = $ this -> db -> insert ( 'rating_user' , $ data ) ; $ this -> hook -> attach ( 'rating.add.user.after' , $ data , $ result , $ this ) ; return ( int ) $ result ; }
|
Adds a user rating
|
55,174
|
protected function setBayesian ( array $ data ) { $ rating = $ this -> getBayesian ( $ data ) ; if ( empty ( $ rating [ 'bayesian_rating' ] ) ) { $ this -> db -> delete ( 'rating' , array ( 'product_id' => $ data [ 'product_id' ] ) ) ; return array ( ) ; } $ sql = 'INSERT INTO rating SET rating=:rating, votes=:votes, product_id=:product_id ON DUPLICATE KEY UPDATE rating=:rating, votes=:votes' ; $ params = array ( 'product_id' => $ data [ 'product_id' ] , 'votes' => $ rating [ 'this_num_votes' ] , 'rating' => $ rating [ 'bayesian_rating' ] ) ; $ this -> db -> run ( $ sql , $ params ) ; return $ rating ; }
|
Sets bayesian rating and votes for the given product
|
55,175
|
public function getModulesPath ( ) { $ paths = array ( ) ; foreach ( $ this -> getLoadedModules ( true ) as $ module ) { $ paths [ $ module -> getName ( ) ] = $ module -> getPath ( ) ; } return $ paths ; }
|
Returns an array of paths to modules .
|
55,176
|
public function locateResource ( $ name , $ dir = null , $ first = true ) { if ( '@' !== $ name [ 0 ] ) { throw new \ InvalidArgumentException ( sprintf ( 'A resource name must start with @ ("%s" given).' , $ name ) ) ; } if ( false !== strpos ( $ name , '..' ) ) { throw new \ RuntimeException ( sprintf ( 'File name "%s" contains invalid characters (..).' , $ name ) ) ; } $ moduleName = substr ( $ name , 1 ) ; $ path = '' ; if ( false !== strpos ( $ moduleName , '/' ) ) { list ( $ moduleName , $ path ) = explode ( '/' , $ moduleName , 2 ) ; } $ isResource = 0 === strpos ( $ path , 'Resources' ) && null !== $ dir ; $ overridePath = substr ( $ path , 9 ) ; $ resourceModule = null ; $ modules = array ( $ this -> getModule ( $ moduleName ) ) ; $ files = array ( ) ; foreach ( $ modules as $ module ) { if ( $ isResource && file_exists ( $ file = $ dir . '/' . $ module -> getName ( ) . $ overridePath ) ) { if ( null !== $ resourceModule ) { throw new \ RuntimeException ( sprintf ( '"%s" resource is hidden by a resource from the "%s" derived module. Create a "%s" file to override the module resource.' , $ file , $ resourceModule , $ dir . '/' . $ modules [ 0 ] -> getName ( ) . $ overridePath ) ) ; } if ( $ first ) { return $ file ; } $ files [ ] = $ file ; } if ( file_exists ( $ file = $ this -> getResourcesPath ( $ module ) . '/' . $ path ) ) { if ( $ first && ! $ isResource ) { return $ file ; } $ files [ ] = $ file ; $ resourceModule = $ module -> getName ( ) ; } } if ( count ( $ files ) > 0 ) { return $ first && $ isResource ? $ files [ 0 ] : $ files ; } throw new \ InvalidArgumentException ( sprintf ( 'Unable to find file "%s".' , $ name ) ) ; }
|
Returns the file path for a given resource .
|
55,177
|
protected function validate ( array $ values , $ operator ) { if ( ! in_array ( $ operator , array ( '=' , '!=' ) ) ) { return $ this -> translation -> text ( 'Unsupported operator' ) ; } if ( count ( $ values ) != 1 ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ scope = filter_var ( reset ( $ values ) , FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE ) ; if ( ! isset ( $ scope ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } return true ; }
|
Common scope validator
|
55,178
|
public function set ( $ name , $ service , $ shared = true ) { return $ this -> setService ( $ name , $ service , $ shared ) ; }
|
Register a service with the locator .
|
55,179
|
protected function createConfig ( ) { $ this -> setCliMessage ( 'Creating configuration file...' ) ; $ config = file_get_contents ( GC_FILE_CONFIG ) ; if ( empty ( $ config ) ) { $ error = $ this -> translation -> text ( 'Failed to read file @path' , array ( '@path' => GC_FILE_CONFIG ) ) ; throw new UnexpectedValueException ( $ error ) ; } $ config .= '$config[\'database\'] = ' . var_export ( $ this -> data [ 'database' ] , true ) . ';' ; $ config .= PHP_EOL . PHP_EOL ; $ config .= 'return $config;' ; $ config .= PHP_EOL ; if ( file_put_contents ( GC_FILE_CONFIG_COMPILED , $ config ) === false ) { throw new UnexpectedValueException ( $ this -> translation -> text ( 'Failed to create config.php' ) ) ; } chmod ( GC_FILE_CONFIG_COMPILED , 0444 ) ; }
|
Create the configuration file using data from a default file
|
55,180
|
protected function createPages ( ) { $ this -> setCliMessage ( 'Creating pages...' ) ; $ pages = array ( ) ; $ pages [ ] = array ( 'title' => 'Contact us' , 'description' => 'Contact information' , ) ; $ pages [ ] = array ( 'title' => 'Help' , 'description' => 'Help information. Coming soon...' , ) ; foreach ( $ pages as $ page ) { $ page += array ( 'status' => 1 , 'user_id' => $ this -> context [ 'user_id' ] , 'store_id' => $ this -> context [ 'store_id' ] ) ; $ this -> getPageModel ( ) -> add ( $ page ) ; } }
|
Creates default pages
|
55,181
|
protected function createLanguages ( ) { $ this -> setCliMessage ( 'Configuring language...' ) ; if ( ! empty ( $ this -> data [ 'store' ] [ 'language' ] ) && $ this -> data [ 'store' ] [ 'language' ] !== 'en' ) { $ this -> getLanguageModel ( ) -> update ( $ this -> data [ 'store' ] [ 'language' ] , array ( 'default' => true ) ) ; } }
|
Creates default languages
|
55,182
|
protected function createStore ( ) { $ this -> setCliMessage ( 'Creating store...' ) ; $ default = $ this -> getStoreModel ( ) -> getDefaultData ( ) ; $ default [ 'title' ] = $ this -> data [ 'store' ] [ 'title' ] ; $ default [ 'email' ] = array ( $ this -> data [ 'user' ] [ 'email' ] ) ; $ store = array ( 'status' => 0 , 'data' => $ default , 'name' => $ this -> data [ 'store' ] [ 'title' ] , 'domain' => $ this -> data [ 'store' ] [ 'host' ] , 'basepath' => $ this -> data [ 'store' ] [ 'basepath' ] ) ; $ store_id = $ this -> getStoreModel ( ) -> add ( $ store ) ; $ this -> config -> set ( 'store' , $ store_id ) ; $ this -> setContext ( 'store_id' , $ store_id ) ; }
|
Creates default store
|
55,183
|
protected function createContent ( ) { $ this -> setCliMessage ( 'Creating content...' ) ; $ this -> initConfig ( ) ; $ this -> createDbConfig ( ) ; $ this -> createStore ( ) ; $ this -> createSuperadmin ( ) ; $ this -> createCountries ( ) ; $ this -> createLanguages ( ) ; $ this -> createPages ( ) ; }
|
Create default content for the site
|
55,184
|
protected function createDbConfig ( ) { $ this -> setCliMessage ( 'Configuring database...' ) ; $ this -> config -> set ( 'intro' , 1 ) ; $ this -> config -> set ( 'installed' , GC_TIME ) ; $ this -> config -> set ( 'cron_key' , gplcart_string_random ( ) ) ; $ this -> config -> set ( 'installer' , $ this -> data [ 'installer' ] ) ; $ this -> config -> set ( 'timezone' , $ this -> data [ 'store' ] [ 'timezone' ] ) ; }
|
Create store settings in the database
|
55,185
|
protected function setContext ( $ key , $ value ) { gplcart_array_set ( $ this -> context , $ key , $ value ) ; $ this -> session -> set ( "install.context.$key" , $ value ) ; }
|
Sets the current context
|
55,186
|
protected function getContext ( $ key ) { if ( GC_CLI ) { return gplcart_array_get ( $ this -> context , $ key ) ; } return $ this -> session -> get ( "install.context.$key" ) ; }
|
Returns a value from the current context
|
55,187
|
protected function setContextError ( $ step , $ message ) { $ pos = count ( $ this -> getContext ( "errors.$step" ) ) + 1 ; $ this -> setContext ( "errors.$step.$pos" , $ message ) ; }
|
Sets context error message
|
55,188
|
protected function getContextErrors ( $ flatten = true ) { $ errors = $ this -> getContext ( 'errors' ) ; if ( empty ( $ errors ) ) { return array ( ) ; } if ( $ flatten ) { return gplcart_array_flatten ( $ errors ) ; } return $ errors ; }
|
Returns an array of context errors
|
55,189
|
protected function createCountries ( ) { $ rows = $ placeholders = array ( ) ; foreach ( ( array ) $ this -> getCountryModel ( ) -> getIso ( ) as $ code => $ country ) { $ placeholders [ ] = '(?,?,?,?,?)' ; $ native_name = empty ( $ country [ 'native_name' ] ) ? $ country [ 'name' ] : $ country [ 'native_name' ] ; $ rows = array_merge ( $ rows , array ( 0 , $ country [ 'name' ] , $ code , $ native_name , serialize ( array ( ) ) ) ) ; } $ values = implode ( ',' , $ placeholders ) ; $ sql = "INSERT INTO country (status, name, code, native_name, format) VALUES $values" ; $ this -> db -> run ( $ sql , $ rows ) ; }
|
Creates countries from ISO list
|
55,190
|
protected function start ( ) { set_time_limit ( 0 ) ; $ this -> session -> delete ( 'user' ) ; $ this -> session -> delete ( 'install' ) ; $ this -> session -> set ( 'install.data' , $ this -> data ) ; }
|
Does initial tasks before installation
|
55,191
|
protected function getSuccessMessage ( ) { if ( GC_CLI ) { $ vars = array ( '@url' => rtrim ( "{$this->data['store']['host']}/{$this->data['store']['basepath']}" , '/' ) ) ; return $ this -> translation -> text ( "Your store has been installed.\nURL: @url\nAdmin area: @url/admin\nGood luck!" , $ vars ) ; } return $ this -> translation -> text ( 'Your store has been installed. Now you can log in as superadmin' ) ; }
|
Returns success message
|
55,192
|
protected function setCliMessage ( $ message ) { if ( GC_CLI ) { $ this -> cli -> line ( $ this -> translation -> text ( $ message ) ) ; } }
|
Sets a message line in CLI mode
|
55,193
|
protected function initConfig ( ) { Container :: unregister ( ) ; $ this -> config = Container :: get ( 'gplcart\\core\\Config' ) ; $ this -> config -> init ( ) ; $ this -> db = $ this -> config -> getDb ( ) ; }
|
Init configuration It makes sure that we re using the database connection defined in the configuration file
|
55,194
|
public function country ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateCountry ( ) ; $ this -> validateWeight ( ) ; $ this -> validateBool ( 'status' ) ; $ this -> validateCodeCountry ( ) ; $ this -> validateName ( ) ; $ this -> validateNativeNameCountry ( ) ; $ this -> validateZoneCountry ( ) ; $ this -> validateFormatCountry ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
|
Performs full validation of submitted country data
|
55,195
|
protected function validateCountry ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> country -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Country' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
|
Validates the country to be updated
|
55,196
|
protected function validateFormatCountry ( ) { $ field = 'format' ; $ format = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ format ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Format' ) ; if ( ! is_array ( $ format ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } $ default = $ this -> country -> getDefaultFormat ( ) ; if ( ! array_intersect_key ( $ format , $ default ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } foreach ( $ format as $ key => $ value ) { if ( ! is_array ( $ value ) || ! array_intersect_key ( $ value , $ default [ $ key ] ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } foreach ( $ value as $ v ) { if ( ! in_array ( gettype ( $ v ) , array ( 'string' , 'integer' , 'boolean' ) ) ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } } } return true ; }
|
Validates country format
|
55,197
|
public function install ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateRequirementsInstall ( ) ; if ( $ this -> isError ( ) ) { return $ this -> getError ( ) ; } $ this -> validateUserEmailInstall ( ) ; $ this -> validateUserPasswordInstall ( ) ; $ this -> validateStoreHostInstall ( ) ; $ this -> validateStoreTitleInstall ( ) ; $ this -> validateStoreBasepathInstall ( ) ; $ this -> validateStoreTimezoneInstall ( ) ; $ this -> validateInstallerInstall ( ) ; $ this -> validateDbNameInstall ( ) ; $ this -> validateDbUserInstall ( ) ; $ this -> validateDbPasswordInstall ( ) ; $ this -> validateDbHostInstall ( ) ; $ this -> validateDbTypeInstall ( ) ; $ this -> validateDbPortInstall ( ) ; $ this -> validateDbConnectInstall ( ) ; return $ this -> getResult ( ) ; }
|
Performs full installation data validation
|
55,198
|
protected function validateRequirementsInstall ( ) { if ( $ this -> isExcluded ( 'requirements' ) ) { return null ; } if ( $ this -> config -> isInitialized ( ) ) { $ error = $ this -> translation -> text ( 'System already installed' ) ; $ this -> setError ( 'installed' , $ error ) ; return false ; } $ requirements = $ this -> install -> getRequirements ( ) ; $ errors = $ this -> install -> getRequirementErrors ( $ requirements ) ; if ( empty ( $ errors [ 'danger' ] ) ) { return true ; } $ messages = array ( ) ; $ messages [ ] = $ this -> translation -> text ( 'Please fix all critical errors in your environment' ) ; foreach ( $ requirements as $ items ) { foreach ( $ items as $ name => $ info ) { if ( in_array ( $ name , $ errors [ 'danger' ] ) ) { $ status = empty ( $ info [ 'status' ] ) ? $ this -> translation -> text ( 'No' ) : $ this -> translation -> text ( 'Yes' ) ; $ messages [ ] = " {$info['message']} - $status" ; } } } $ this -> setError ( 'requirements' , implode ( PHP_EOL , $ messages ) ) ; return false ; }
|
Checks system requirements
|
55,199
|
protected function validateStoreTimezoneInstall ( ) { $ field = 'store.timezone' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( empty ( $ value ) ) { $ this -> setSubmitted ( $ field , date_default_timezone_get ( ) ) ; return true ; } $ timezones = gplcart_timezones ( ) ; if ( empty ( $ timezones [ $ value ] ) ) { $ this -> setErrorInvalid ( $ field , $ this -> translation -> text ( 'Timezone' ) ) ; return false ; } return true ; }
|
Validates the store time zone
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.