idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
54,800
public function file ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateFile ( ) ; $ this -> validateTitleFile ( ) ; $ this -> validateDescription ( ) ; $ this -> validateWeight ( ) ; $ this -> validateTranslation ( ) ; $ this -> validateUploadFile ( ) ; $ this -> validatePathFile ( ) ; $ this -> validateEntityFile ( ) ; $ this -> validateEntityIdFile ( ) ; $ this -> validateFileTypeFile ( ) ; $ this -> validateMimeTypeFile ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
Performs full file data validation
54,801
protected function validateFile ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> file -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'File' ) ) ; return false ; } $ this -> setSubmitted ( 'update' , $ data ) ; return true ; }
Validates a file to be updated
54,802
protected function validateTitleFile ( ) { $ field = 'title' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( isset ( $ value ) && mb_strlen ( $ value ) > 255 ) { $ this -> setErrorLengthRange ( $ field , $ this -> translation -> text ( 'Title' ) , 0 , 255 ) ; return false ; } return true ; }
Validates a title field
54,803
protected function validatePathFile ( ) { $ field = 'path' ; $ value = $ this -> getSubmitted ( $ field ) ; if ( $ this -> isExcluded ( $ field ) || $ this -> isError ( ) ) { return null ; } if ( ! isset ( $ value ) && $ this -> isUpdating ( ) ) { return null ; } $ label = $ this -> translation -> text ( 'File' ) ; if ( empty ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_readable ( gplcart_file_absolute ( $ value ) ) ) { $ this -> setErrorUnavailable ( $ field , $ label ) ; return false ; } return true ; }
Validates a file path
54,804
protected function validateUploadFile ( ) { $ file = $ this -> request -> file ( 'file' ) ; if ( empty ( $ file ) ) { return null ; } $ result = $ this -> file_transfer -> upload ( $ file , null ) ; if ( $ result !== true ) { $ this -> setError ( 'path' , ( string ) $ result ) ; return false ; } $ this -> setSubmitted ( 'path' , $ this -> file_transfer -> getTransferred ( true ) ) ; return true ; }
Validates file upload
54,805
protected function validateEntityIdFile ( ) { $ field = 'entity_id' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; if ( ! isset ( $ value ) ) { $ this -> unsetSubmitted ( $ field ) ; return null ; } $ label = $ this -> translation -> text ( 'Entity ID' ) ; if ( ! is_numeric ( $ value ) ) { $ this -> setErrorInteger ( $ field , $ label ) ; return false ; } if ( strlen ( $ value ) > 10 ) { $ this -> setErrorLengthRange ( $ field , $ label , 0 , 10 ) ; return false ; } return true ; }
Validates entity ID
54,806
public function update ( $ cart_id , array $ data ) { $ result = null ; $ this -> hook -> attach ( 'cart.update.before' , $ cart_id , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ data [ 'modified' ] = GC_TIME ; $ result = ( bool ) $ this -> db -> update ( 'cart' , $ data , array ( 'cart_id' => $ cart_id ) ) ; gplcart_static_clear ( ) ; $ this -> hook -> attach ( 'cart.update.after' , $ cart_id , $ data , $ result , $ this ) ; return ( bool ) $ result ; }
Updates a cart
54,807
public function getContent ( array $ data ) { $ result = & gplcart_static ( gplcart_array_hash ( array ( 'cart.get.content' => $ data ) ) ) ; if ( isset ( $ result ) ) { return $ result ; } $ this -> hook -> attach ( 'cart.get.content.before' , $ data , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ data [ 'order_id' ] = 0 ; $ items = $ this -> getList ( $ data ) ; if ( empty ( $ items ) ) { return array ( ) ; } $ result = array ( 'store_id' => $ data [ 'store_id' ] , 'currency' => $ this -> currency -> getCode ( ) ) ; $ total = $ quantity = 0 ; foreach ( ( array ) $ items as $ item ) { $ prepared = $ this -> prepareItem ( $ item , $ result ) ; if ( ! empty ( $ prepared ) ) { $ result [ 'items' ] [ $ item [ 'sku' ] ] = $ prepared ; $ total += ( int ) $ prepared [ 'total' ] ; $ quantity += ( int ) $ prepared [ 'quantity' ] ; } } $ result [ 'total' ] = $ total ; $ result [ 'quantity' ] = $ quantity ; $ this -> hook -> attach ( 'cart.get.content.after' , $ data , $ result , $ this ) ; return $ result ; }
Returns a cart content
54,808
public function getUid ( ) { $ session_user_id = $ this -> user -> getId ( ) ; if ( ! empty ( $ session_user_id ) ) { return ( string ) $ session_user_id ; } $ cookie_name = $ this -> getCookieUserName ( ) ; $ cookie_user_id = $ this -> request -> cookie ( $ cookie_name , '' , 'string' ) ; if ( ! empty ( $ cookie_user_id ) ) { return $ cookie_user_id ; } $ generated_user_id = '_' . gplcart_string_random ( 6 ) ; $ this -> request -> setCookie ( $ cookie_name , $ generated_user_id , $ this -> getCookieLifespan ( ) ) ; return $ generated_user_id ; }
Returns the cart user ID
54,809
public function getQuantity ( array $ options , $ type = null ) { $ options += array ( 'order_id' => 0 ) ; $ result = array ( 'total' => 0 , 'sku' => array ( ) ) ; foreach ( ( array ) $ this -> getList ( $ options ) as $ item ) { $ result [ 'total' ] += ( int ) $ item [ 'quantity' ] ; $ result [ 'sku' ] [ $ item [ 'sku' ] ] = ( int ) $ item [ 'quantity' ] ; } if ( isset ( $ type ) ) { return $ result [ $ type ] ; } return $ result ; }
Returns cart quantity
54,810
public function getLimits ( $ item = null ) { $ limits = array ( 'sku' => ( int ) $ this -> config -> get ( 'cart_sku_limit' , 10 ) , 'item' => ( int ) $ this -> config -> get ( 'cart_item_limit' , 20 ) ) ; return isset ( $ item ) ? $ limits [ $ item ] : $ limits ; }
Returns cart limits
54,811
protected function prepareItem ( array $ item , array $ data ) { $ product = $ this -> product -> getBySku ( $ item [ 'sku' ] , $ item [ 'store_id' ] ) ; if ( empty ( $ product [ 'status' ] ) || $ data [ 'store_id' ] != $ product [ 'store_id' ] ) { return array ( ) ; } $ product [ 'price' ] = $ this -> currency -> convert ( $ product [ 'price' ] , $ product [ 'currency' ] , $ data [ 'currency' ] ) ; $ calculated = $ this -> product -> calculate ( $ product ) ; if ( $ calculated != $ product [ 'price' ] ) { $ item [ 'original_price' ] = $ product [ 'price' ] ; } $ item [ 'product' ] = $ product ; $ item [ 'price' ] = $ calculated ; $ item [ 'total' ] = $ item [ 'price' ] * $ item [ 'quantity' ] ; return $ item ; }
Prepare a cart item
54,812
public function routesTrigger ( ModuleEvent $ e ) { $ module = $ e -> getModule ( ) ; if ( is_callable ( array ( $ module , 'getRoutes' ) ) ) { $ routes = $ module -> getRoutes ( ) ; $ this -> routes [ $ e -> getModuleName ( ) ] = $ routes ; } return $ this ; }
Callback for routesTrigger event .
54,813
public function getServicesTrigger ( ModuleEvent $ e ) { $ module = $ e -> getModule ( ) ; if ( method_exists ( $ module , 'getServiceConfig' ) && is_callable ( array ( $ module , 'getServiceConfig' ) ) ) { $ services = $ module -> getServiceConfig ( ) ; if ( is_array ( $ services ) && isset ( $ services [ 'factories' ] ) ) { $ this -> services [ $ e -> getModuleName ( ) ] = $ services [ 'factories' ] ; } } return $ this ; }
Event callback for initServicesTrigger .
54,814
public function getServices ( ) { $ mergedModuleServices = array ( ) ; foreach ( $ this -> services as $ services ) { $ mergedModuleServices = ArrayUtils :: merge ( $ mergedModuleServices , $ services ) ; } return $ mergedModuleServices ; }
Get the registered services .
54,815
public function rating ( array & $ submitted , array $ options = array ( ) ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateProductRating ( ) ; $ this -> validateUserId ( ) ; $ this -> validateValueRating ( ) ; return $ this -> getResult ( ) ; }
Performs full rating data validation
54,816
protected function validateValueRating ( ) { $ field = 'rating' ; if ( $ this -> isExcluded ( $ field ) ) { return null ; } $ value = $ this -> getSubmitted ( $ field ) ; $ label = $ this -> translation -> text ( 'Rating' ) ; if ( ! isset ( $ value ) ) { $ this -> setErrorRequired ( $ field , $ label ) ; return false ; } if ( ! is_numeric ( $ value ) ) { $ this -> setErrorNumeric ( $ field , $ label ) ; return false ; } if ( $ value > 5 ) { $ this -> setErrorInvalid ( $ field , $ label ) ; return false ; } return true ; }
Validates a rating value
54,817
public function wishlist ( array & $ submitted , array $ options ) { $ this -> options = $ options ; $ this -> submitted = & $ submitted ; $ this -> validateWishlist ( ) ; $ this -> validateProductWishlist ( ) ; $ this -> validateUserCartId ( ) ; $ this -> validateStoreId ( ) ; $ this -> unsetSubmitted ( 'update' ) ; return $ this -> getResult ( ) ; }
Performs full wishlist data validation
54,818
protected function validateWishlist ( ) { $ id = $ this -> getUpdatingId ( ) ; if ( $ id === false ) { return null ; } $ data = $ this -> wishlist -> get ( $ id ) ; if ( empty ( $ data ) ) { $ this -> setErrorUnavailable ( 'update' , $ this -> translation -> text ( 'Wishlist' ) ) ; return false ; } $ this -> setUpdating ( $ data ) ; return true ; }
Validates wishlist data to be updated
54,819
public function listCategory ( $ category_group_id ) { $ this -> setCategoryGroup ( $ category_group_id ) ; $ this -> actionListCategory ( ) ; $ this -> setTitleListCategory ( ) ; $ this -> setBreadcrumbListCategory ( ) ; $ this -> setFilterListCategory ( ) ; $ this -> setPagerListCategory ( ) ; $ this -> setData ( 'categories' , $ this -> getListCategory ( ) ) ; $ this -> setData ( 'category_group_id' , $ category_group_id ) ; $ this -> outputListCategory ( ) ; }
Displays the category overview page
54,820
protected function setCategoryGroup ( $ category_group_id ) { $ this -> data_category_group = $ this -> category_group -> get ( $ category_group_id ) ; if ( empty ( $ this -> data_category_group ) ) { $ this -> outputHttpStatus ( 404 ) ; } }
Sets an array of category group data
54,821
protected function actionListCategory ( ) { list ( $ selected , $ action , $ value ) = $ this -> getPostedAction ( ) ; $ updated = $ deleted = 0 ; foreach ( $ selected as $ category_id ) { if ( $ action === 'status' && $ this -> access ( 'category_edit' ) ) { $ updated += ( int ) $ this -> category -> update ( $ category_id , array ( 'status' => $ value ) ) ; } if ( $ action === 'delete' && $ this -> access ( 'category_delete' ) ) { $ deleted += ( int ) $ this -> category -> delete ( $ category_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 categories
54,822
protected function getListCategory ( ) { $ conditions = $ this -> query_filter ; $ conditions [ 'category_group_id' ] = $ this -> data_category_group [ 'category_group_id' ] ; $ list = $ this -> category -> getTree ( $ conditions ) ; $ this -> prepareListCategory ( $ list ) ; return $ list ; }
Returns an array of categories for a given group
54,823
protected function setBreadcrumbListCategory ( ) { $ 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 to the category overview page
54,824
protected function canDeleteCategory ( ) { return isset ( $ this -> data_category [ 'category_id' ] ) && $ this -> category -> canDelete ( $ this -> data_category [ 'category_id' ] ) && $ this -> access ( 'category_delete' ) ; }
Whether the category can be deleted
54,825
protected function setCategory ( $ category_id ) { $ this -> data_category = array ( ) ; if ( is_numeric ( $ category_id ) ) { $ conditions = array ( 'language' => 'und' , 'category_id' => $ category_id ) ; $ this -> data_category = $ this -> category -> get ( $ conditions ) ; if ( empty ( $ this -> data_category ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> prepareCategory ( $ this -> data_category ) ; } }
Sets an array of category data
54,826
protected function prepareCategory ( array & $ category ) { $ this -> setItemAlias ( $ category , 'category' , $ this -> alias ) ; $ this -> setItemImages ( $ category , 'category' , $ this -> image ) ; $ this -> setItemTranslation ( $ category , 'category' , $ this -> translation_entity ) ; if ( ! empty ( $ category [ 'images' ] ) ) { foreach ( $ category [ 'images' ] as & $ file ) { $ this -> setItemTranslation ( $ file , 'file' , $ this -> translation_entity ) ; } } }
Prepares an array of category data
54,827
protected function submitEditCategory ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteCategory ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditCategory ( ) ) { $ this -> deleteImagesCategory ( ) ; if ( isset ( $ this -> data_category [ 'category_id' ] ) ) { $ this -> updateCategory ( ) ; } else { $ this -> addCategory ( ) ; } } }
Saves a submitted category
54,828
protected function deleteImagesCategory ( ) { $ this -> controlAccess ( 'category_edit' ) ; $ file_ids = $ this -> getPosted ( 'delete_images' , array ( ) , true , 'array' ) ; return $ this -> image -> delete ( $ file_ids ) ; }
Delete category images
54,829
protected function validateEditCategory ( ) { $ this -> setSubmitted ( 'category' , null , false ) ; $ this -> setSubmitted ( 'form' , true ) ; $ this -> setSubmittedBool ( 'status' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_category ) ; $ this -> setSubmitted ( 'category_group_id' , $ this -> data_category_group [ 'category_group_id' ] ) ; $ this -> validateComponent ( 'category' ) ; return ! $ this -> hasErrors ( ) ; }
Validates a submitted category
54,830
protected function deleteCategory ( ) { $ this -> controlAccess ( 'category_delete' ) ; if ( $ this -> category -> delete ( $ this -> data_category [ 'category_id' ] ) ) { $ url = "admin/content/category/{$this->data_category_group['category_group_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Category has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Category has not been deleted' ) , 'warning' ) ; }
Deletes a category
54,831
protected function setDataCategoriesEditCategory ( ) { $ category_id = $ this -> getData ( 'category.category_id' ) ; if ( isset ( $ category_id ) ) { $ category_group_id = $ this -> getData ( 'category_group.category_group_id' ) ; $ options = array ( 'parent_id' => $ category_id , 'category_group_id' => $ category_group_id ) ; $ children = $ this -> category -> getTree ( $ options ) ; $ exclude = array ( $ category_id ) ; foreach ( $ children as $ child ) { $ exclude [ ] = $ child [ 'category_id' ] ; } $ categories = $ this -> getData ( 'categories' ) ; $ modified = array_diff_key ( $ categories , array_flip ( $ exclude ) ) ; $ this -> setData ( 'categories' , $ modified ) ; } }
Adds list of categories on the edit category page
54,832
protected function setTitleEditCategory ( ) { if ( isset ( $ this -> data_category [ 'category_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_category [ 'title' ] ) ) ; } else { $ parent_category_id = $ this -> getQuery ( 'parent_id' ) ; $ parent_category = array ( ) ; if ( ! empty ( $ parent_category_id ) ) { $ parent_category = $ this -> category -> get ( $ parent_category_id ) ; } $ vars = array ( '%name' => $ this -> data_category_group [ 'title' ] ) ; if ( isset ( $ parent_category [ 'title' ] ) ) { $ vars [ '%category' ] = $ parent_category [ 'title' ] ; $ title = $ this -> text ( 'Add sub-category to %name / %category' , $ vars ) ; } else { $ title = $ this -> text ( 'Add category to %name' , $ vars ) ; } } $ this -> setTitle ( $ title ) ; }
Sets titles on the category edit page
54,833
protected function setBreadcrumbEditCategory ( ) { $ 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' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( "admin/content/category/{$this->data_category_group['category_group_id']}" ) , 'text' => $ this -> text ( 'Categories of group %name' , array ( '%name' => $ this -> data_category_group [ 'title' ] ) ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the category edit page
54,834
public function set ( $ product_id , $ user_id ) { $ list = ( array ) $ this -> getList ( array ( 'user_id' => $ user_id ) ) ; foreach ( $ list as $ item ) { if ( $ item [ 'product_id' ] == $ product_id ) { return $ list ; } } $ limit = $ this -> getLimit ( ) ; if ( ! empty ( $ limit ) ) { $ exceeding = array_slice ( $ list , $ limit - 1 , null , true ) ; } if ( ! empty ( $ exceeding ) ) { foreach ( array_keys ( $ exceeding ) as $ product_view_id ) { $ this -> delete ( $ product_view_id ) ; } } $ data = array ( 'user_id' => $ user_id , 'product_id' => $ product_id ) ; $ this -> add ( $ data ) ; return $ list ; }
Add a viewed product for a user
54,835
public function getAlias ( ) { $ className = get_class ( $ this ) ; if ( substr ( $ className , - 6 ) != 'Config' ) { throw new \ BadMethodCallException ( 'This Config class does not follow the naming convention; you must overwrite the getAlias() method.' ) ; } $ classBaseName = substr ( strrchr ( $ className , '\\' ) , 1 , - 6 ) ; return strtolower ( $ classBaseName ) ; }
Returns the mandatory prefix to use when using YAML .
54,836
public static function field ( $ descriptor , $ name = null ) { if ( is_a ( $ descriptor , 'frictionlessdata\\tableschema\\Fields\\BaseField' ) ) { return $ descriptor ; } else { if ( Utils :: isJsonString ( $ descriptor ) ) { $ descriptor = json_decode ( $ descriptor ) ; } elseif ( is_array ( $ descriptor ) ) { $ descriptor = json_decode ( json_encode ( $ descriptor ) ) ; } if ( ! isset ( $ descriptor -> name ) && ! is_null ( $ name ) ) { $ descriptor -> name = $ name ; } foreach ( static :: $ fieldClasses as $ fieldClass ) { if ( $ field = $ fieldClass :: inferDescriptor ( $ descriptor ) ) { return $ field ; } } throw new FieldValidationException ( [ new SchemaValidationError ( SchemaValidationError :: SCHEMA_VIOLATION , 'Could not find a valid field for descriptor: ' . json_encode ( $ descriptor ) ) , ] ) ; } }
get a new field object in the correct type according to the descriptor .
54,837
public function id ( array $ values ) { $ count = count ( $ values ) ; $ ids = array_filter ( $ values , 'ctype_digit' ) ; if ( $ count != count ( $ ids ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ existing = array_filter ( $ values , function ( $ user_id ) { if ( $ user_id == 0 ) { return true ; } $ user = $ this -> user -> get ( $ user_id ) ; return isset ( $ user [ 'user_id' ] ) ; } ) ; if ( $ count != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'User' ) ) ) ; } return true ; }
Validates the user ID condition
54,838
public function roleId ( array $ values ) { $ count = count ( $ values ) ; $ ids = array_filter ( $ values , 'ctype_digit' ) ; if ( $ count != count ( $ ids ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ exists = array_filter ( $ values , function ( $ role_id ) { if ( $ role_id == 0 ) { return true ; } $ role = $ this -> role -> get ( $ role_id ) ; return isset ( $ role [ 'role_id' ] ) ; } ) ; if ( $ count != count ( $ exists ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Role' ) ) ) ; } return true ; }
Validates the role ID condition
54,839
public function get ( $ job_id ) { $ result = null ; $ this -> hook -> attach ( 'job.get.before' , $ job_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ result = $ this -> getSession ( $ job_id ) ; $ this -> hook -> attach ( 'job.get.after' , $ job_id , $ result , $ this ) ; return $ result ; }
Returns a job array from the session
54,840
public function set ( array $ job ) { $ result = null ; $ this -> hook -> attach ( 'job.set.before' , $ job , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( array ) $ result ; } $ default = $ this -> getDefault ( ) ; $ result = gplcart_array_merge ( $ default , $ job ) ; $ existing = $ this -> getSession ( $ result [ 'id' ] ) ; if ( ! empty ( $ existing ) ) { return ( array ) $ existing ; } $ this -> setSession ( $ result ) ; $ this -> hook -> attach ( 'job.set.after' , $ job , $ result , $ this ) ; return ( array ) $ result ; }
Sets a job to the session
54,841
protected function getDefault ( ) { $ current_url = $ this -> url -> get ( ) ; return array ( 'id' => uniqid ( ) , 'status' => true , 'title' => '' , 'url' => '' , 'total' => 0 , 'errors' => 0 , 'done' => 0 , 'inserted' => 0 , 'updated' => 0 , 'context' => array ( 'offset' => 0 , 'line' => 1 , ) , 'data' => array ( ) , 'message' => array ( 'start' => $ this -> translation -> text ( 'Starting...' ) , 'finish' => $ this -> translation -> text ( 'Finished' ) , 'process' => $ this -> translation -> text ( 'Processing...' ) ) , 'redirect' => array ( 'finish' => $ current_url , 'errors' => $ current_url , 'no_results' => $ current_url ) , 'redirect_message' => array ( 'finish' => '' , 'errors' => '' , 'no_results' => '' ) , 'log' => array ( 'errors' => '' ) ) ; }
Returns an array of default job values
54,842
public function delete ( $ job_id = null ) { $ result = null ; $ this -> hook -> attach ( 'job.delete.before' , $ job_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ result = $ this -> session -> delete ( "jobs.$job_id" ) ; $ this -> hook -> attach ( 'job.delete.after' , $ job_id , $ result , $ this ) ; return ( bool ) $ result ; }
Deletes a job from the session
54,843
protected function processIteration ( array & $ job ) { try { $ handlers = $ this -> getHandlers ( ) ; $ callback = Handler :: get ( $ handlers , $ job [ 'id' ] , 'process' ) ; call_user_func_array ( $ callback , array ( & $ job ) ) ; } catch ( Exception $ ex ) { $ job [ 'status' ] = false ; $ job [ 'errors' ] ++ ; } }
Call a handler processor
54,844
public function getTotal ( $ handler_id , array $ arguments = array ( ) ) { try { $ handlers = $ this -> getHandlers ( ) ; return ( int ) Handler :: call ( $ handlers , $ handler_id , 'total' , array ( $ arguments ) ) ; } catch ( Exception $ ex ) { return 0 ; } }
Returns total number of items to be processed
54,845
protected function getResult ( array $ job , array $ result = array ( ) ) { $ result += array ( 'done' => 0 , 'errors' => 0 , 'progress' => 0 , 'finish' => false , 'message' => $ job [ 'message' ] [ 'process' ] ) ; if ( ! empty ( $ result [ 'finish' ] ) ) { $ this -> setFinishData ( $ result , $ job ) ; } $ this -> setSession ( $ job ) ; return $ result ; }
Returns an array of data to be send to the user
54,846
protected function setFinishData ( array & $ result , array & $ job ) { $ result [ 'message' ] = $ job [ 'message' ] [ 'finish' ] ; $ this -> setFinishDataErrors ( $ result , $ job ) ; $ this -> setFinishDataNoErrors ( $ result , $ job ) ; }
Sets finish redirect and message
54,847
protected function setFinishDataErrors ( array & $ result , array & $ job ) { if ( ! empty ( $ job [ 'errors' ] ) ) { if ( ! empty ( $ job [ 'redirect' ] [ 'errors' ] ) ) { $ result [ 'redirect' ] = $ job [ 'redirect' ] [ 'errors' ] ; } if ( empty ( $ job [ 'redirect_message' ] [ 'errors' ] ) ) { $ vars = array ( '%total' => $ job [ 'total' ] , '%errors' => $ job [ 'errors' ] ) ; $ message = $ this -> translation -> text ( 'Processed %total items, errors: %errors' , $ vars ) ; } else { $ vars = array ( '%total' => $ job [ 'total' ] , '%errors' => $ job [ 'errors' ] , '%inserted' => $ job [ 'inserted' ] , '%updated' => $ job [ 'updated' ] ) ; $ message = $ this -> translation -> text ( $ job [ 'redirect_message' ] [ 'errors' ] , $ vars ) ; } $ this -> session -> setMessage ( $ message , 'danger' ) ; } }
Sets finish redirect and message when an error occurred
54,848
protected function setFinishDataNoErrors ( array & $ result , array & $ job ) { if ( empty ( $ job [ 'errors' ] ) ) { if ( ! empty ( $ job [ 'redirect' ] [ 'finish' ] ) ) { $ result [ 'redirect' ] = $ job [ 'redirect' ] [ 'finish' ] ; } else if ( ! empty ( $ job [ 'redirect' ] [ 'no_results' ] ) && empty ( $ job [ 'inserted' ] ) && empty ( $ job [ 'updated' ] ) ) { $ result [ 'redirect' ] = $ job [ 'redirect' ] [ 'no_results' ] ; } if ( empty ( $ job [ 'redirect_message' ] [ 'finish' ] ) ) { $ vars = array ( '%total' => $ job [ 'total' ] ) ; $ message = $ this -> translation -> text ( 'Successfully processed %total items' , $ vars ) ; } else { $ vars = array ( '%total' => $ job [ 'total' ] , '%inserted' => $ job [ 'inserted' ] , '%updated' => $ job [ 'updated' ] ) ; $ message = $ this -> translation -> text ( $ job [ 'redirect_message' ] [ 'finish' ] , $ vars ) ; } if ( ! empty ( $ job [ 'redirect_message' ] [ 'no_results' ] ) && empty ( $ job [ 'inserted' ] ) && empty ( $ job [ 'updated' ] ) ) { $ vars = array ( '%total' => $ job [ 'total' ] ) ; $ message = $ this -> translation -> text ( $ job [ 'redirect_message' ] [ 'no_results' ] , $ vars ) ; } $ this -> session -> setMessage ( $ message , 'success' ) ; } }
Sets finish redirect and message when no errors occurred
54,849
public function submit ( $ job ) { $ this -> delete ( $ job [ 'id' ] ) ; if ( ! empty ( $ job [ 'log' ] [ 'errors' ] ) ) { file_put_contents ( $ job [ 'log' ] [ 'errors' ] , '' ) ; } $ this -> set ( $ job ) ; $ this -> url -> redirect ( '' , array ( 'job_id' => $ job [ 'id' ] ) ) ; }
Submits a new job
54,850
public function setImages ( array & $ data , $ file_model , $ entity ) { if ( empty ( $ data [ 'images' ] ) || empty ( $ data [ $ entity . '_id' ] ) ) { return false ; } foreach ( $ data [ 'images' ] as & $ image ) { if ( empty ( $ image [ 'file_id' ] ) ) { $ image [ 'entity' ] = $ entity ; $ image [ 'entity_id' ] = $ data [ $ entity . '_id' ] ; $ image [ 'file_id' ] = ( int ) $ file_model -> add ( $ image ) ; } else { $ file_model -> update ( $ image [ 'file_id' ] , $ image ) ; } } return true ; }
Set entity images
54,851
public function listFieldValue ( $ field_id ) { $ this -> setFieldFieldValue ( $ field_id ) ; $ this -> actionListFieldValue ( ) ; $ this -> setTitleListFieldValue ( ) ; $ this -> setBreadcrumbListFieldValue ( ) ; $ this -> setFilterListFieldValue ( ) ; $ this -> setPagerListFieldValue ( ) ; $ this -> setData ( 'field' , $ this -> data_field ) ; $ this -> setData ( 'values' , $ this -> getListFieldValue ( ) ) ; $ this -> outputListFieldValue ( ) ; }
Displays the field value overview page
54,852
protected function actionListFieldValue ( ) { list ( $ selected , $ action ) = $ this -> getPostedAction ( ) ; $ deleted = 0 ; foreach ( $ selected as $ field_value_id ) { if ( $ action === 'delete' && $ this -> access ( 'field_value_delete' ) ) { $ deleted += ( int ) $ this -> field_value -> delete ( $ field_value_id ) ; } } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } }
Applies an action to the selected field values
54,853
protected function getListFieldValue ( ) { $ conditions = $ this -> query_filter ; $ conditions [ 'limit' ] = $ this -> data_limit ; $ conditions [ 'field_id' ] = $ this -> data_field [ 'field_id' ] ; $ list = ( array ) $ this -> field_value -> getList ( $ conditions ) ; $ this -> prepareListFieldValue ( $ list ) ; return $ list ; }
Returns an array of field values for a given field
54,854
protected function prepareListFieldValue ( array & $ list ) { foreach ( $ list as & $ item ) { $ this -> setItemThumb ( $ item , $ this -> image , array ( 'placeholder' => false ) ) ; } }
Prepare an array of field values
54,855
protected function setBreadcrumbListFieldValue ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/content/field' ) , 'text' => $ this -> text ( 'Fields' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the field values overview page
54,856
public function editFieldValue ( $ field_id , $ field_value_id = null ) { $ this -> setFieldFieldValue ( $ field_id ) ; $ this -> setFieldValue ( $ field_value_id ) ; $ this -> setTitleEditFieldValue ( ) ; $ this -> setBreadcrumbEditFieldValue ( ) ; $ this -> setData ( 'field' , $ this -> data_field ) ; $ this -> setData ( 'field_value' , $ this -> data_field_value ) ; $ this -> setData ( 'widget_types' , $ this -> field -> getWidgetTypes ( ) ) ; $ this -> setData ( 'languages' , $ this -> language -> getList ( array ( 'enabled' => true ) ) ) ; $ this -> submitEditFieldValue ( ) ; $ this -> setDataImagesEditFieldValue ( ) ; $ this -> outputEditFieldValue ( ) ; }
Displays the field value edit form
54,857
protected function setDataImagesEditFieldValue ( ) { $ options = array ( 'single' => true , 'entity' => 'field_value' , 'images' => $ this -> getData ( 'field_value.images' , array ( ) ) ) ; $ this -> setItemThumb ( $ options , $ this -> image ) ; $ this -> setData ( 'attached_images' , $ this -> getWidgetImages ( $ this -> language , $ options ) ) ; }
Adds images on the edit field value page
54,858
protected function submitEditFieldValue ( ) { if ( $ this -> isPosted ( 'delete' ) ) { $ this -> deleteFieldValue ( ) ; } else if ( $ this -> isPosted ( 'save' ) && $ this -> validateEditFieldValue ( ) ) { $ this -> deleteImageFieldValue ( ) ; if ( isset ( $ this -> data_field_value [ 'field_value_id' ] ) ) { $ this -> updateFieldValue ( ) ; } else { $ this -> addFieldValue ( ) ; } } }
Handles a submitted field value data
54,859
protected function validateEditFieldValue ( ) { $ this -> setSubmitted ( 'field_value' ) ; $ this -> setSubmitted ( 'update' , $ this -> data_field_value ) ; $ this -> setSubmitted ( 'field_id' , $ this -> data_field [ 'field_id' ] ) ; $ this -> validateComponent ( 'field_value' ) ; return ! $ this -> hasErrors ( ) ; }
Validates a submitted field value
54,860
protected function setFieldValue ( $ field_value_id ) { $ this -> data_field_value = array ( ) ; if ( is_numeric ( $ field_value_id ) ) { $ conditions = array ( 'language' => 'und' , 'field_value_id' => $ field_value_id ) ; $ this -> data_field_value = $ this -> field_value -> get ( $ conditions ) ; if ( empty ( $ this -> data_field_value ) ) { $ this -> outputHttpStatus ( 404 ) ; } $ this -> prepareFieldValue ( $ this -> data_field_value ) ; } }
Set a field value data
54,861
protected function prepareFieldValue ( array & $ field_value ) { $ this -> setItemImages ( $ field_value , 'field_value' , $ this -> image ) ; $ this -> setItemTranslation ( $ field_value , 'field_value' , $ this -> translation_entity ) ; if ( ! empty ( $ field_value [ 'images' ] ) ) { foreach ( $ field_value [ 'images' ] as & $ file ) { $ this -> setItemTranslation ( $ file , 'file' , $ this -> translation_entity ) ; } } }
Prepare an array of field value data
54,862
protected function deleteFieldValue ( ) { $ this -> controlAccess ( 'field_value_delete' ) ; if ( $ this -> field_value -> delete ( $ this -> data_field_value [ 'field_value_id' ] ) ) { $ url = "admin/content/field/value/{$this->data_field['field_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Field value has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Field value has not been deleted' ) , 'warning' ) ; }
Deletes a field value
54,863
protected function deleteImageFieldValue ( ) { $ this -> controlAccess ( 'field_value_edit' ) ; $ file_ids = $ this -> getPosted ( 'delete_images' , array ( ) , true , 'array' ) ; if ( ! empty ( $ file_ids ) && isset ( $ this -> data_field_value [ 'field_value_id' ] ) ) { $ db = $ disk = 0 ; $ file_id = reset ( $ file_ids ) ; $ this -> file -> deleteAll ( $ file_id , $ db , $ disk , false ) ; $ this -> field_value -> update ( $ this -> data_field_value [ 'field_value_id' ] , array ( 'file_id' => 0 ) ) ; } }
Deletes a field value image
54,864
protected function addFieldValue ( ) { $ this -> controlAccess ( 'field_value_add' ) ; if ( $ this -> field_value -> add ( $ this -> getSubmitted ( ) ) ) { $ url = "admin/content/field/value/{$this->data_field['field_id']}" ; $ this -> redirect ( $ url , $ this -> text ( 'Field value has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Field value has not been added' ) , 'warning' ) ; }
Adds a new field value
54,865
protected function setTitleEditFieldValue ( ) { if ( isset ( $ this -> data_field_value [ 'field_value_id' ] ) ) { $ title = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_field_value [ 'title' ] ) ) ; } else { $ title = $ this -> text ( 'Add value for field %name' , array ( '%name' => $ this -> data_field [ 'title' ] ) ) ; } $ this -> setTitle ( $ title ) ; }
Sets titles on the edit field value page
54,866
protected function setBreadcrumbEditFieldValue ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin/content/field' ) , 'text' => $ this -> text ( 'Fields' ) ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( "admin/content/field/value/{$this->data_field['field_id']}" ) , 'text' => $ this -> text ( 'Values of %name' , array ( '%name' => $ this -> data_field [ 'title' ] ) ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; }
Sets breadcrumbs on the edit field value page
54,867
protected function sanitizeUrl ( $ url ) { $ url = $ url ; $ url = preg_replace ( '~[^\\pL0-9_]+~u' , '-' , $ url ) ; $ url = trim ( $ url , "-" ) ; $ url = iconv ( "utf-8" , "us-ascii//TRANSLIT" , $ url ) ; $ url = strtolower ( $ url ) ; $ url = preg_replace ( '~[^-a-z0-9_]+~' , '' , $ url ) ; return $ url ; }
Function for sanitizing slugs
54,868
protected function removeUnregistratedFields ( $ request , $ postTypeModel ) { $ whitelisted = [ ] ; $ whitelisted [ ] = 'template' ; foreach ( $ request -> all ( ) as $ requestKey => $ requestValue ) { $ customField = $ this -> getCustomFieldObject ( $ postTypeModel , $ requestKey ) ; if ( $ customField ) { if ( array_key_exists ( 'saveable' , $ customField ) && $ customField [ 'saveable' ] == false ) { } else { $ whitelisted [ ] = $ requestKey ; } } } $ newRequest = $ request -> only ( $ whitelisted ) ; $ request = $ this -> resetRequestValues ( $ request ) ; foreach ( $ newRequest as $ key => $ value ) { $ request [ $ key ] = $ value ; } return $ request ; }
Removing request values based on input when they are not saveable
54,869
public function savePostMetaToDatabase ( $ postmeta , $ postTypeModel , $ post , $ request = [ ] , $ customFieldKey = '' ) { $ pivotValue = [ ] ; $ object = [ ] ; $ postmeta = $ this -> removeUnrequiredMetas ( $ postmeta , $ postTypeModel ) ; if ( ! empty ( $ customFieldKey ) ) { if ( $ request -> hasFile ( 'file' ) ) { $ postmeta [ $ customFieldKey ] = '' ; } } foreach ( $ postmeta as $ key => $ value ) { $ customFieldObject = $ this -> getCustomFieldObject ( $ postTypeModel , $ key ) ; if ( $ customFieldObject ) { if ( array_key_exists ( 'saveable' , $ customFieldObject ) ) { if ( $ customFieldObject [ 'saveable' ] === false ) { continue ; } } } $ value = $ this -> saveMutator ( $ postTypeModel , $ key , $ value , $ post , $ postmeta , $ request ) ; $ customFieldObject = $ this -> getCustomFieldObject ( $ postTypeModel , $ key ) ; if ( ! is_array ( $ customFieldObject ) ) { continue ; } $ type = 'simple' ; if ( array_key_exists ( 'type' , $ customFieldObject ) ) { $ type = $ customFieldObject [ 'type' ] ; } switch ( $ type ) { case 'taxonomy' : if ( ! array_key_exists ( 'post_type' , $ customFieldObject ) && empty ( $ customFieldObject [ 'post_type' ] ) ) { continue ; } $ customfieldPostTypes = $ this -> getPostTypeIdentifiers ( $ customFieldObject [ 'post_type' ] ) ; if ( ! is_array ( $ customfieldPostTypes ) ) { continue ; } if ( ! is_array ( $ value ) ) { $ value = json_decode ( $ value , true ) ; } if ( ! is_array ( $ value ) ) { continue ; } foreach ( $ value as $ valueKey => $ valueItem ) { $ where = [ ] ; if ( $ postTypeModel -> userCanOnlySeeHisOwnPosts ) { $ where [ ] = [ 'post_author' , '=' , Auth :: user ( ) -> id ] ; } $ where [ ] = [ 'id' , '=' , $ valueItem ] ; $ taxonomyPost = NikuPosts :: where ( $ where ) -> whereIn ( 'post_type' , $ customfieldPostTypes ) -> first ( ) ; if ( $ taxonomyPost ) { $ pivotValue [ $ valueItem ] = [ 'taxonomy' => $ key ] ; } } $ post -> taxonomies ( ) -> sync ( $ pivotValue ) ; break ; default : $ object [ $ key ] = $ value ; break ; } } $ post -> saveMetas ( $ object ) ; return $ post ; }
Saving the post meta to the database
54,870
protected function getPostTypeIdentifiers ( $ postTypes ) { $ postTypeIdentifiers = [ ] ; foreach ( $ postTypes as $ postTypeKey => $ value ) { $ postTypeModel = $ this -> getPostType ( $ value ) ; if ( $ postTypeModel ) { array_push ( $ postTypeIdentifiers , $ postTypeModel -> identifier ) ; } } return $ postTypeIdentifiers ; }
Get the post type real identifiers how it is saved in the database
54,871
public function getCustomFieldObject ( $ postTypeModel , $ key ) { $ allKeys = $ this -> getValidationsKeys ( $ postTypeModel ) ; if ( array_key_exists ( $ key , $ allKeys ) ) { return $ allKeys [ $ key ] ; } return false ; }
Return the custom field object based on the identifier
54,872
public function triggerEvent ( $ action , $ postTypeModel , $ post , $ postmeta ) { if ( method_exists ( $ postTypeModel , $ action ) ) { $ postTypeModel -> $ action ( $ postTypeModel , $ post , $ postmeta ) ; } }
Integrate events based on the action
54,873
public function abort ( $ message = 'Not authorized.' , $ config = '' , $ code = 'error' ) { return response ( ) -> json ( [ 'code' => $ code , 'errors' => [ $ code => [ 0 => $ message , ] , ] , 'config' => $ config , ] , 430 ) ; }
Abort the request
54,874
protected function removeValidationsByConditionalLogic ( $ postmeta , $ postTypeModel , $ collection ) { $ allKeys = $ this -> getValidationsKeys ( $ postTypeModel ) ; foreach ( $ allKeys as $ key => $ customField ) { if ( array_key_exists ( $ key , $ postmeta ) ) { $ postmeta [ $ key ] = true ; } $ display = $ this -> validateValueForLogic ( $ customField , $ postTypeModel , $ collection ) ; if ( $ display === false ) { $ postmeta [ $ key ] = false ; } else { $ postmeta [ $ key ] = true ; } } return $ postmeta ; }
Returning false values by array keys of the items which we need to exclude out of the validation array
54,875
public function getList ( array $ options ) { $ result = null ; $ this -> hook -> attach ( 'product.related.list.before' , $ options , $ result , $ this ) ; if ( isset ( $ result ) ) { return $ result ; } $ result = array ( ) ; if ( isset ( $ options [ 'product_id' ] ) ) { $ sql = 'SELECT item_product_id FROM product_related WHERE product_id=?' ; if ( ! empty ( $ options [ 'limit' ] ) ) { $ sql .= ' LIMIT ' . implode ( ',' , array_map ( 'intval' , $ options [ 'limit' ] ) ) ; } $ result = $ this -> db -> fetchColumnAll ( $ sql , array ( $ options [ 'product_id' ] ) ) ; } $ this -> hook -> attach ( 'product.related.list.after' , $ options , $ result , $ this ) ; return $ result ; }
Returns an array of related products for the given product ID
54,876
public function delete ( $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'product.related.delete.before' , $ product_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } foreach ( array ( 'product_id' , 'item_product_id' ) as $ field ) { if ( ! $ this -> db -> delete ( 'product_related' , array ( $ field => $ product_id ) ) ) { return false ; } } $ this -> hook -> attach ( 'product.related.delete.after' , $ product_id , $ result , $ this ) ; return ( bool ) $ result ; }
Deletes product relations
54,877
public function add ( $ related_product_id , $ product_id ) { $ result = null ; $ this -> hook -> attach ( 'product.related.add.before' , $ related_product_id , $ product_id , $ result , $ this ) ; if ( isset ( $ result ) ) { return ( bool ) $ result ; } $ this -> db -> insert ( 'product_related' , array ( 'product_id' => $ product_id , 'item_product_id' => $ related_product_id ) ) ; $ this -> db -> insert ( 'product_related' , array ( 'product_id' => $ related_product_id , 'item_product_id' => $ product_id ) ) ; $ this -> hook -> attach ( 'product.related.add.after' , $ related_product_id , $ product_id , $ result , $ this ) ; return ( bool ) $ result ; }
Adds product relations
54,878
public function configureServiceManager ( ServiceManager $ serviceManager ) { $ configs = $ serviceManager -> get ( 'Config' ) ; $ configs [ 'parameters' ] = array_merge ( array ( "monolog.logger.class" => "PPI\Framework\Log\Logger" , "monolog.gelf.publisher.class" => "Gelf\MessagePublisher" , "monolog.handler.stream.class" => "Monolog\Handler\StreamHandler" , "monolog.handler.group.class" => "Monolog\Handler\GroupHandler" , "monolog.handler.buffer.class" => "Monolog\Handler\BufferHandler" , "monolog.handler.rotating_file.class" => "Monolog\Handler\RotatingFileHandler" , "monolog.handler.syslog.class" => "Monolog\Handler\SyslogHandler" , "monolog.handler.null.class" => "Monolog\Handler\NullHandler" , "monolog.handler.test.class" => "Monolog\Handler\TestHandler" , "monolog.handler.gelf.class" => "Monolog\Handler\GelfHandler" , "monolog.handler.firephp.class" => "Symfony\Bridge\Monolog\Handler\FirePHPHandler" , "monolog.handler.chromephp.class" => "Symfony\Bridge\Monolog\Handler\ChromePhpHandler" , "monolog.handler.debug.class" => "Symfony\Bridge\Monolog\Handler\DebugHandler" , "monolog.handler.swift_mailer.class" => "Monolog\Handler\SwiftMailerHandler" , "monolog.handler.native_mailer.class" => "Monolog\Handler\NativeMailerHandler" , "monolog.handler.socket.class" => "Monolog\Handler\SocketHandler" , "monolog.handler.pushover.class" => "Monolog\Handler\PushoverHandler" , "monolog.handler.fingers_crossed.class" => "Monolog\Handler\FingersCrossedHandler" , "monolog.handler.fingers_crossed.error_level_activation_strategy.class" => "Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy" , ) , $ configs [ 'parameters' ] ) ; $ config = $ this -> processConfiguration ( $ configs , $ serviceManager ) ; $ handlersToChannels = array ( ) ; if ( isset ( $ config [ 'handlers' ] ) ) { $ handlers = array ( ) ; foreach ( $ config [ 'handlers' ] as $ name => $ handler ) { $ handlers [ $ handler [ 'priority' ] ] [ ] = array ( 'id' => $ this -> buildHandler ( $ serviceManager , $ configs [ 'parameters' ] , $ name , $ handler ) , 'channels' => isset ( $ handler [ 'channels' ] ) ? $ handler [ 'channels' ] : null , ) ; } $ sortedHandlers = array ( ) ; foreach ( $ handlers as $ priorityHandlers ) { foreach ( array_reverse ( $ priorityHandlers ) as $ handler ) { $ sortedHandlers [ ] = $ handler ; } } foreach ( $ sortedHandlers as $ handler ) { if ( ! in_array ( $ handler [ 'id' ] , $ this -> nestedHandlers ) ) { $ handlersToChannels [ $ handler [ 'id' ] ] = $ handler [ 'channels' ] ; } } } $ loggerClass = $ configs [ 'parameters' ] [ 'monolog.logger.class' ] ; $ serviceManager -> setFactory ( 'monolog.logger' , function ( $ serviceManager ) use ( $ loggerClass , $ handlersToChannels ) { $ logger = new $ loggerClass ( 'app' ) ; foreach ( $ handlersToChannels as $ handler => $ channels ) { $ logger -> pushHandler ( $ serviceManager -> get ( $ handler ) ) ; } return $ logger ; } ) ; }
Create and return the logger .
54,879
public function getList ( array $ options ) { $ options += array ( 'active' => true ) ; $ sql = 'SELECT * FROM dashboard' ; $ conditions = array ( ) ; if ( isset ( $ options [ 'user_id' ] ) ) { $ sql .= ' WHERE user_id=?' ; $ conditions [ ] = $ options [ 'user_id' ] ; } $ list = $ this -> db -> fetch ( $ sql , $ conditions , array ( 'unserialize' => 'data' ) ) ; $ result = $ this -> prepareList ( $ list , $ options ) ; $ this -> hook -> attach ( 'dashboard.get.user' , $ result , $ this ) ; return $ result ; }
Returns a dashboard record by a user ID
54,880
public function callHandler ( $ handler_id , $ method = 'data' , array $ arguments = array ( ) ) { $ handlers = $ this -> getHandlers ( ) ; return Handler :: call ( $ handlers , $ handler_id , $ method , $ arguments ) ; }
Call a dashboard handler
54,881
public function createService ( ServiceLocatorInterface $ serviceLocator ) { $ parser = $ serviceLocator -> get ( 'ControllerNameParser' ) ; $ logger = $ serviceLocator -> has ( 'Logger' ) ? $ serviceLocator -> get ( 'Logger' ) : null ; return new ControllerResolver ( $ serviceLocator , $ parser , $ logger ) ; }
Create and return a ControllerResolver instance .
54,882
public function getHandlers ( ) { $ handlers = & gplcart_static ( 'install.handlers' ) ; if ( isset ( $ handlers ) ) { return $ handlers ; } $ handlers = array ( ) ; $ this -> hook -> attach ( 'install.handlers' , $ handlers , $ this ) ; foreach ( $ handlers as $ id => & $ handler ) { if ( empty ( $ handler [ 'module' ] ) ) { unset ( $ handlers [ $ id ] ) ; continue ; } $ info = $ this -> module -> getInfo ( $ handler [ 'module' ] ) ; if ( empty ( $ info [ 'type' ] ) || $ info [ 'type' ] !== 'installer' ) { unset ( $ handlers [ $ id ] ) ; continue ; } $ handler [ 'id' ] = $ id ; $ handler [ 'weight' ] = isset ( $ handler [ 'weight' ] ) ? $ handler [ 'weight' ] : 0 ; } $ handlers = array_merge ( $ handlers , $ this -> getDefaultHandler ( ) ) ; gplcart_array_sort ( $ handlers ) ; return $ handlers ; }
Returns an array of defined handlers
54,883
public function getHandler ( $ handler_id ) { $ handlers = $ this -> getHandlers ( ) ; return empty ( $ handlers [ $ handler_id ] ) ? array ( ) : $ handlers [ $ handler_id ] ; }
Returns an installer handler
54,884
public function callHandler ( $ handler_id , array $ data ) { try { $ handlers = $ this -> getHandlers ( ) ; $ method = isset ( $ data [ 'step' ] ) ? 'install_' . $ data [ 'step' ] : 'install' ; $ result = Handler :: call ( $ handlers , $ handler_id , $ method , array ( $ data , $ this -> db ) ) ; } catch ( Exception $ ex ) { $ result = array ( ) ; } return ( array ) $ result ; }
Process installation by calling a handler
54,885
public function getRequirements ( ) { $ requirements = & gplcart_static ( 'install.requirements' ) ; if ( isset ( $ requirements ) ) { return ( array ) $ requirements ; } $ requirements = ( array ) gplcart_config_get ( GC_FILE_CONFIG_REQUIREMENT ) ; $ this -> hook -> attach ( 'install.requirements' , $ requirements ) ; return ( array ) $ requirements ; }
Returns an array of requirements
54,886
public function getRequirementErrors ( array $ requirements ) { $ errors = array ( ) ; foreach ( $ requirements as $ items ) { foreach ( $ items as $ name => $ info ) { if ( empty ( $ info [ 'status' ] ) ) { $ errors [ $ info [ 'severity' ] ] [ ] = $ name ; } } } return $ errors ; }
Returns an array of requirements errors
54,887
public function connectDb ( array $ settings ) { try { $ this -> db = new Database ; $ this -> db -> init ( $ settings ) ; } catch ( Exception $ ex ) { $ this -> db = null ; return $ this -> translation -> text ( $ ex -> getMessage ( ) ) ; } return $ this -> validateDb ( ) ; }
Tries to connect to the database
54,888
public function validateDb ( ) { $ existing = $ this -> db -> query ( 'SHOW TABLES' ) -> fetchColumn ( ) ; if ( empty ( $ existing ) ) { return true ; } return $ this -> translation -> text ( 'The database you specified already has tables' ) ; }
Validate the database is ready for installation process
54,889
protected function setErrorRequired ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@field is required' , array ( '@field' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Field required error
54,890
protected function setErrorNumeric ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@field must be numeric' , array ( '@field' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Field not numeric error
54,891
protected function setErrorInteger ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@field must be integer' , array ( '@field' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Field not integer error
54,892
protected function setErrorUnavailable ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Object unavailable error
54,893
protected function setErrorLengthRange ( $ field , $ label , $ min = 1 , $ max = 255 ) { $ vars = array ( '@min' => $ min , '@max' => $ max , '@field' => $ label ) ; $ error = $ this -> translation -> text ( '@field must be @min - @max characters long' , $ vars ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Length must be between min and max error
54,894
protected function setErrorInvalid ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Invalid value error
54,895
protected function setErrorExists ( $ field , $ label ) { $ error = $ this -> translation -> text ( '@name already exists' , array ( '@name' => $ label ) ) ; return $ this -> setError ( $ field , $ error ) ; }
Set Object already exists error
54,896
public function validateInteger ( array $ values ) { if ( count ( $ values ) != 1 ) { $ vars = array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ; return $ this -> translation -> text ( '@field has invalid value' , $ vars ) ; } $ value = reset ( $ values ) ; if ( strlen ( $ value ) > 10 ) { $ vars = array ( '@max' => 10 , '@field' => $ this -> translation -> text ( 'Value' ) ) ; return $ this -> translation -> text ( '@field must not be longer than @max characters' , $ vars ) ; } if ( ctype_digit ( $ value ) ) { return true ; } $ vars = array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ; return $ this -> translation -> text ( '@field has invalid value' , $ vars ) ; }
Validates an integer value
54,897
public function id ( array $ values ) { $ count = count ( $ values ) ; $ ids = array_filter ( $ values , 'ctype_digit' ) ; if ( $ count != count ( $ ids ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ existing = array_filter ( $ values , function ( $ product_id ) { $ product = $ this -> product -> get ( $ product_id ) ; return isset ( $ product [ 'product_id' ] ) ; } ) ; if ( $ count != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Product' ) ) ) ; } return true ; }
Validates the product ID condition
54,898
public function categoryId ( array $ values ) { $ count = count ( $ values ) ; $ ids = array_filter ( $ values , 'ctype_digit' ) ; if ( $ count != count ( $ ids ) ) { return $ this -> translation -> text ( '@field has invalid value' , array ( '@field' => $ this -> translation -> text ( 'Condition' ) ) ) ; } $ existing = array_filter ( $ values , function ( $ category_id ) { $ category = $ this -> category -> get ( $ category_id ) ; return isset ( $ category [ 'category_id' ] ) ; } ) ; if ( $ count != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'Category' ) ) ) ; } return true ; }
Validates the category ID condition
54,899
public function sku ( array $ values ) { $ count = count ( $ values ) ; $ existing = array_filter ( $ values , function ( $ sku ) { $ sku = $ this -> sku -> get ( array ( 'sku' => $ sku ) ) ; return ! empty ( $ sku ) ; } ) ; if ( $ count != count ( $ existing ) ) { return $ this -> translation -> text ( '@name is unavailable' , array ( '@name' => $ this -> translation -> text ( 'SKU' ) ) ) ; } return true ; }
Validates the SKU condition