idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
14,600
final public static function validatePresence ( array $ requiredFields = [ ] , string $ option = NULL ) : bool { $ option = static :: checkGlobal ( $ option ) ; $ fieldsWithError = "" ; foreach ( $ requiredFields as $ field ) : if ( ! isset ( $ option [ $ field ] ) || ! static :: hasValue ( $ option [ $ field ] ) ) $ f...
Validates presences for required fields ...
14,601
final public static function checkGlobal ( $ option = '' ) : array { if ( ! static :: hasValue ( $ option ) ) new ErrorCode ( 1001 ) ; $ fieldGlobals = [ "POST" , "GET" , "REQUEST" , "FILES" , "COOKIE" , "SESSION" ] ; if ( ! in_array ( strtoupper ( $ option ) , $ fieldGlobals ) ) new ErrorCode ( 1001 ) ; else return $ ...
Used for selecting super global .
14,602
final public static function setError ( string $ errorMessage = NULL ) : bool { static :: $ error = "" ; if ( ! static :: hasValue ( $ errorMessage ) ) return FALSE ; static :: $ error = "Check the following field(s) " . stripComma ( $ errorMessage ) . " and try again." ; return TRUE ; }
Set error .
14,603
final public static function setUserOtpToken ( string $ username , string $ tokenValue ) { if ( $ username ) { $ tokenTime = time ( ) ; $ _SESSION [ 'otp_token' ] = $ tokenValue ; $ _SESSION [ 'otp_token_time' ] = $ tokenTime ; return $ tokenValue ; } else { return FALSE ; } }
Sets user OTP token to a session ...
14,604
final public static function isOtpTokenRecent ( ) : bool { $ maxElapsed = 60 ; if ( isset ( $ _SESSION [ 'otp_token_time' ] ) ) { $ storedTime = $ _SESSION [ 'otp_token_time' ] ; return ( $ storedTime + $ maxElapsed ) >= time ( ) ; } else { return FALSE ; } }
Checks if user OTP token is recent ...
14,605
final public static function createOtpToken ( string $ username ) { $ token = self :: setOtpToken ( ) ; return self :: setUserOtpToken ( $ username , $ token ) ; }
Add a new reset token to the user ...
14,606
final public static function deleteOtpToken ( string $ username ) { if ( $ username == $ _SESSION [ 'username' ] ) { $ tokenValue = NULL ; $ tokenTime = NULL ; $ _SESSION [ 'otp_token' ] = NULL ; $ _SESSION [ 'otp_token_time' ] = NULL ; } return self :: setUserOtpToken ( $ username , $ tokenValue ) ; }
Remove any reset token for this user ...
14,607
private function initializeMediator ( ) { if ( is_null ( $ this -> mediator ) ) { $ this -> mediator = $ this -> getObjectManager ( ) -> get ( MediatorInterface :: class ) ; } }
Initializes a mediator instance
14,608
public function addCustomFields ( $ customFields ) { if ( ! $ this -> getCustomFields ( ) ) { return $ this -> setCustomFields ( array ( $ customFields ) ) ; } else { return $ this -> setCustomFields ( array_merge ( $ this -> getCustomFields ( ) , array ( $ customFields ) ) ) ; } }
Append CustomFields to the list .
14,609
public function Start ( ) { if ( ! $ this -> definitions_path ) { throw new \ Exception ( t ( "Your are trying to export definitions without setting a path first." ) ) ; } elseif ( ! file_exists ( $ this -> definitions_path ) ) { FileSystem :: MakeDir ( $ this -> definitions_path , 0755 , true ) ; } $ this -> definitio...
Begin exporting definitions from the symbols object specified on constructor .
14,610
private function SaveToPHP ( $ path ) { $ this -> definitions_path = rtrim ( $ path , "/\\" ) . "/" ; $ this -> export_type = Type :: PHP ; $ this -> SendMessage ( t ( "Creating constants.php" ) ) ; $ this -> SaveConstantsToPHP ( ) ; $ this -> SendMessage ( t ( "Creating enumerations.php" ) ) ; $ this -> SaveEnumeratio...
Saves all symbols into php files .
14,611
private function SaveEnumerationsToPHP ( ) { $ output_file = fopen ( $ this -> definitions_path . "enumerations.php" , "w" ) ; fwrite ( $ output_file , "<?php\n\n" ) ; fwrite ( $ output_file , "use Peg\Lib\Definitions\Element\Enumeration;\n" ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> ...
Save enumeration symbols into a enumerations . php file .
14,612
private function SaveTypeDefToPHP ( ) { $ output_file = fopen ( $ this -> definitions_path . "type_definitions.php" , "w" ) ; fwrite ( $ output_file , "<?php\n\n" ) ; fwrite ( $ output_file , "use Peg\Lib\Definitions\Element\TypeDef;\n" ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> HasTy...
Save typedef symbols into a type_definitions . php file .
14,613
private function SaveGloablVariablesToPHP ( ) { $ output_file = fopen ( $ this -> definitions_path . "variables.php" , "w" ) ; fwrite ( $ output_file , "<?php\n\n" ) ; fwrite ( $ output_file , "use Peg\Lib\Definitions\Element\GlobalVariable;\n" ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header ...
Save global variable symbols into a variables . php file .
14,614
private function SaveToJSON ( $ path ) { $ this -> definitions_path = rtrim ( $ path , "/\\" ) . "/" ; $ this -> export_type = Type :: JSON ; $ this -> SendMessage ( t ( "Creating constants.json" ) ) ; $ this -> SaveConstantsToJson ( ) ; $ this -> SendMessage ( t ( "Creating enumerations.json" ) ) ; $ this -> SaveEnume...
Saves all symbols into json files .
14,615
private function SaveEnumerationsToJson ( ) { $ enumerations = array ( ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> HasEnumerations ( ) ) continue ; foreach ( $ header -> namespaces as $ namespace ) { if ( ! $ namespace -> HasEnumerations ( ) ) continue ; foreach ( $ namespace -> enumer...
Save enumeration symbols into enumerations . json .
14,616
private function SaveTypeDefToJson ( ) { $ typedefs = array ( ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> HasTypeDefs ( ) ) continue ; foreach ( $ header -> namespaces as $ namespace ) { if ( ! $ namespace -> HasTypeDefs ( ) ) continue ; foreach ( $ namespace -> type_definitions as $ t...
Save typedef symbols into type_definitions . json .
14,617
private function SaveGlobalVariablesToJson ( ) { $ variables = array ( ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> HasGlobalVariables ( ) ) continue ; foreach ( $ header -> namespaces as $ namespace ) { if ( ! $ namespace -> HasGlobalVariables ( ) ) continue ; foreach ( $ namespace -> ...
Save global variable symbols into variables . json .
14,618
private function SaveFunctionsToJson ( ) { $ functions = array ( ) ; foreach ( $ this -> symbols -> headers as $ header ) { if ( ! $ header -> HasFunctions ( ) ) continue ; foreach ( $ header -> namespaces as $ namespace ) { if ( ! $ namespace -> HasFunctions ( ) ) continue ; foreach ( $ namespace -> functions as $ fun...
Save function symbols into functions . json .
14,619
final public function run ( ) { if ( $ this -> admin === false && \ is_admin ( ) === true ) { return ; } if ( $ this -> public === false && \ is_admin ( ) === false ) { return ; } $ this -> parse_filters ( ) ; $ this -> parse_actions ( ) ; if ( \ method_exists ( $ this , 'boot' ) ) { $ this -> boot ( ) ; } }
Boot up the class .
14,620
public function getControllersModules ( ) : array { $ result = self :: $ cached_modules [ $ this -> controller_data [ 'module_code' ] ] [ 'module_ids' ] ; foreach ( $ result as $ k => $ v ) { $ action = $ this -> method_code == 'Edit' ? 'Record_View' : 'List_View' ; if ( ! $ this -> can ( $ action , $ this -> method_co...
Get controllers modules
14,621
public function setProperties ( array $ properties ) { foreach ( $ properties as $ key => $ value ) $ this -> parseProperty ( $ key , $ value ) ; return $ this ; }
Set multiple properties for this route
14,622
public function parseProperty ( $ key , $ value ) { if ( isset ( self :: $ aliases [ $ key ] ) ) $ key = self :: $ aliases [ $ key ] ; $ method = 'set' . ucwords ( $ key ) ; $ this -> { $ method } ( $ value ) ; return $ this ; }
Manual setter based on string .
14,623
public function getPath ( $ absolute = false ) { if ( ! $ absolute ) return $ this -> properties [ 'path' ] ; $ routes = $ this -> getFullRoutes ( ) ; $ paths = array ( ) ; foreach ( $ routes as $ route ) { $ path = $ route -> getProperty ( 'path' ) ; if ( $ path == '' ) continue ; $ paths [ ] = $ path ; } return trim ...
Get uri path property for this route .
14,624
public function getFullRoutes ( ) { if ( $ this -> fullRoutes !== null ) return $ this -> fullRoutes ; $ routes = array ( ) ; $ routes [ ] = $ this ; $ group = $ this -> group ; while ( $ route = $ group -> getUpperRoute ( ) ) { $ routes [ ] = $ route ; $ group = $ route -> getGroup ( ) ; } $ this -> fullRoutes = array...
Return all of the related routes .
14,625
public function getFailRouteName ( ) { if ( $ this -> group -> hasFailRoute ( ) ) return $ this -> group -> getFailRoute ( ) ; $ group = $ this -> group ; while ( $ route = $ group -> getUpperRoute ( ) ) { $ group = $ route -> getGroup ( ) ; if ( $ group -> hasFailRoute ( ) ) return $ group -> getFailRoute ( ) ; } retu...
Recursively find all the fail route reversely
14,626
public function setAsFailRoute ( $ bool = true ) { if ( ! $ bool ) return $ this ; $ name = $ this -> name ; if ( ! $ name ) throw new InvalidArgumentException ( 'This route has to be named first.' ) ; $ this -> group -> setFailRoute ( $ name ) ; return $ this ; }
set this route as a fail route for the current group .
14,627
public function getParentRouteName ( ) { $ absoluteRoute = $ this -> getAbsoluteName ( ) ; $ absoluteRoutes = explode ( '.' , $ absoluteRoute ) ; if ( count ( $ absoluteRoutes ) == 1 ) return null ; array_pop ( $ absoluteRoutes ) ; $ parentRoute = implode ( '.' , $ absoluteRoutes ) ; return $ parentRoute ; }
Get parent route name after substracted the current route name .
14,628
public function match ( ServerRequestInterface $ request , $ path ) { if ( isset ( $ this -> properties [ 'method' ] ) ) { if ( ! in_array ( strtolower ( $ request -> getMethod ( ) ) , $ this -> properties [ 'method' ] ) ) return array ( 'route' => false , 'parameter' => false , 'continue' => false ) ; } if ( isset ( $...
Validate uri path against the request
14,629
protected function matchValidators ( ServerRequestInterface $ request , $ path , array & $ parameters = array ( ) ) { foreach ( $ this -> properties [ 'validators' ] as $ validation ) { if ( is_string ( $ validation ) ) { if ( ! isset ( static :: $ classCaches [ $ validation ] ) ) { $ validationObj = new $ validation ;...
Do a custom validation matching
14,630
public function getRemainingPath ( $ path ) { $ paths = explode ( '/' , $ path ) ; $ newPaths = array ( ) ; for ( $ i = count ( explode ( '/' , $ this -> properties [ 'path' ] ) ) ; $ i < count ( $ paths ) ; $ i ++ ) $ newPaths [ ] = $ paths [ $ i ] ; return $ this -> properties [ 'path' ] != '' ? implode ( '/' , $ new...
Get remaining uri path extracted from the passed one .
14,631
protected function refreshAbsoluteName ( ) { $ group = $ this -> group ; $ name = $ this -> name ; $ this -> absoluteName = $ group -> getUpperRoute ( ) ? $ group -> getUpperRoute ( ) -> getAbsoluteName ( ) . '.' . $ name : $ name ; }
Rebuild absolute name
14,632
public function setPath ( $ path ) { if ( $ path !== false ) $ path = trim ( $ path , '/' ) ; $ this -> setProperty ( 'path' , $ path ) ; return $ this ; }
Set uri path pattern for this route .
14,633
public function setMethod ( $ method ) { if ( $ method == 'any' ) $ method = array ( 'get' , 'post' , 'put' , 'delete' , 'patch' , 'options' ) ; else if ( ! is_array ( $ method ) ) $ method = explode ( '|' , $ method ) ; $ method = array_map ( function ( $ value ) { return trim ( strtolower ( $ value ) ) ; } , $ method...
Set method for this route .
14,634
public function middleware ( $ middleware , $ name = null ) { if ( $ name ) $ this -> properties [ 'middleware' ] [ $ name ] = $ middleware ; else $ this -> properties [ 'middleware' ] [ ] = $ middleware ; return $ this ; }
Alias to addMiddleware
14,635
public function setDependencies ( $ dependencies ) { if ( ! is_array ( $ dependencies ) ) $ dependencies = array ( $ dependencies ) ; $ this -> setProperty ( 'dependencies' , $ dependencies ) ; return $ this ; }
Set dependencies for execute arguments
14,636
public function method ( $ method , $ path = null ) { if ( $ path !== null ) $ this -> setPath ( $ path ) ; return $ this -> setMethod ( $ method ) ; }
Alias to setMethod with path settable
14,637
public function prependPackage ( $ package ) { $ package = $ this -> handlePackage ( $ package ) ; $ this -> packages -> unshift ( $ package ) ; return $ package ; }
Prepend the package
14,638
public function appendPackage ( $ package ) { $ package = $ this -> handlePackage ( $ package ) ; $ this -> packages [ ] = $ package ; return $ package ; }
Append the package
14,639
protected function handlePackage ( $ package ) { if ( $ package instanceof Package ) { return $ package ; } $ package = new Package ( $ package , $ this -> basePath , $ this -> baseUrl , $ this -> metadataManager ) ; if ( $ this -> hashAppend ) { $ package -> setHashAppend ( true ) ; } return $ package ; }
Handle the package
14,640
public function performAjaxValidation ( $ post = null ) { $ request = Yii :: $ app -> getRequest ( ) ; if ( $ request -> isAjax && $ this -> load ( isset ( $ post ) ? $ post : $ request -> post ( ) ) ) { $ response = Yii :: $ app -> getResponse ( ) ; $ response -> format = $ response :: FORMAT_JSON ; if ( is_null ( $ t...
Realizes perform ajax validation for related model
14,641
public static function validateSiteAccessName ( string $ siteaccess = null ) : string { if ( empty ( $ siteaccess ) ) { return '' ; } if ( ! preg_match ( '/^[a-z][a-z0-9_]*$/' , $ siteaccess ) ) { throw new InvalidArgumentException ( 'Siteaccess name is not valid.' ) ; } self :: validateReservedKeywords ( $ siteaccess ...
Validates siteaccess name .
14,642
public static function validateLanguageCode ( string $ languageCode = null ) : string { if ( empty ( $ languageCode ) ) { return '' ; } if ( ! preg_match ( '/^[a-z][a-z][a-z]-[A-Z][A-Z]$/' , $ languageCode ) ) { throw new InvalidArgumentException ( 'Language code name is not valid.' ) ; } return $ languageCode ; }
Validates language code .
14,643
public static function validateReservedKeywords ( string $ value ) : void { if ( in_array ( mb_strtolower ( $ value ) , self :: getReservedWords ( ) , true ) ) { throw new InvalidArgumentException ( sprintf ( 'The value cannot contain PHP reserved words ("%s").' , $ value ) ) ; } }
Validates if value is one of PHP reserved keywords .
14,644
public static function getCurrentSlug ( ) { $ slug = self :: get ( 'post_type' , '' ) ; if ( empty ( $ slug ) ) { $ post = self :: get ( 'post' , 0 ) ; if ( ! empty ( $ post ) ) { return get_post_type ( $ post ) ; } global $ pagenow ; if ( in_array ( $ pagenow , [ 'admin.php' ] ) ) { return 'admin' ; } if ( in_array ( ...
Get used slug in current admin panel page .
14,645
public function run ( $ data ) { if ( ( $ data instanceof Eloquent ) || ( $ data instanceof Arrayable ) ) { return $ data -> toArray ( ) ; } elseif ( $ data instanceof Renderable ) { return \ e ( $ data -> render ( ) ) ; } elseif ( \ is_array ( $ data ) ) { return \ array_map ( [ $ this , 'run' ] , $ data ) ; } return ...
Run data transformation .
14,646
protected function _canSubtractQty ( \ Magento \ CatalogInventory \ Api \ Data \ StockItemInterface $ stockItem ) { $ result = $ stockItem -> getManageStock ( ) && $ this -> configStock -> canSubtractQty ( ) ; return $ result ; }
Check if is possible subtract value from item qty
14,647
public function aroundRegisterProductsSale ( \ Magento \ CatalogInventory \ Model \ StockManagement $ subject , \ Closure $ proceed , array $ items , $ websiteId ) { $ stockId = $ this -> manStock -> getCurrentStockId ( ) ; $ lockedItems = $ this -> resourceStock -> lockProductsStock ( array_keys ( $ items ) , $ stockI...
Update stock item on the stock and distribute qty by lots .
14,648
public function get ( ) { if ( $ this -> page_count <= 1 ) { return '' ; } $ output = '' ; $ output .= $ this -> get_opening_links ( ) ; $ output .= $ this -> get_links ( ) ; $ output .= $ this -> get_closing_links ( ) ; if ( ! empty ( $ output ) ) { $ output = $ this -> args [ 'before_output' ] . $ output . $ this -> ...
Return pagination HTML .
14,649
private function get_defaults ( ) { return [ 'echo' => true , 'range' => 5 , 'custom_query' => false , 'show_first_last' => true , 'show_previous_next' => true , 'active_link_wrapper' => '<li class="active">%s</li>' , 'link_wrapper' => '<li><a href="%s" itemprop="url"><span itemprop="name">%s</span></a></li>' , 'first_...
Return Pagination default arguments .
14,650
private function set_ranges ( ) { $ this -> args [ 'range' ] = ( int ) $ this -> args [ 'range' ] - 1 ; $ this -> args [ 'ceil' ] = absint ( \ ceil ( $ this -> args [ 'range' ] / 2 ) ) ; }
Sets the ranges used when calculating how many links to display .
14,651
private function get_min_max ( ) { if ( $ this -> page_count > $ this -> args [ 'range' ] ) { if ( $ this -> current_page <= $ this -> args [ 'range' ] ) { return [ 1 , $ this -> args [ 'range' ] + 1 , ] ; } if ( $ this -> current_page >= ( $ this -> page_count - $ this -> args [ 'ceil' ] ) ) { return [ $ this -> page_...
Returns the min and max ranges used when calculating the page links .
14,652
private function get_links ( ) { list ( $ min , $ max ) = $ this -> get_min_max ( ) ; $ output = '' ; if ( ! empty ( $ min ) && ! empty ( $ max ) && $ this -> args [ 'range' ] >= 0 ) { for ( $ i = $ min ; $ i <= $ max ; $ i ++ ) { if ( $ this -> current_page == $ i ) { $ output .= \ sprintf ( $ this -> args [ 'active_l...
Create HTML for the pagination links .
14,653
public static function add2 ( & $ arg1 , $ arg2 , $ scale = null ) : string { $ arg1 = self :: add ( $ arg1 , $ arg2 , $ scale ) ; return $ arg1 ; }
Add with reference
14,654
public static function subtract2 ( & $ arg1 , $ arg2 , $ scale = null ) : string { $ arg1 = self :: subtract ( $ arg1 , $ arg2 , $ scale ) ; return $ arg1 ; }
Subtract with reference
14,655
private static function __operator ( $ function , $ arg1 , $ arg2 , $ scale ) : string { if ( is_array ( $ arg1 ) ) { $ arg1_temp = $ arg1 ; $ temp1 = array_shift ( $ arg1_temp ) ; foreach ( $ arg1_temp as $ v ) { $ temp1 = call_user_func_array ( $ function , [ $ temp1 , $ v . '' , $ scale ] ) ; } } else { $ temp1 = $ ...
Wrapper for bcmath functions
14,656
public static function floor ( $ arg1 , $ scale = 0 ) : string { if ( $ arg1 [ 0 ] != '-' ) { return bcadd ( $ arg1 , '0' , $ scale ) ; } else { $ value = '1' ; if ( $ scale != 0 ) { $ value = self :: divide ( '1' , 10 ** $ scale , $ scale ) ; } return bcsub ( $ arg1 , $ value , $ scale ) ; } }
Floor round fractions down
14,657
public function remove_comments_meta_boxes ( ) { if ( \ is_admin ( ) && \ current_user_can ( 'manage_options' ) ) { $ post_types = \ get_post_types ( [ 'public' => true ] ) ; foreach ( $ post_types as $ post_type ) { \ remove_meta_box ( 'commentstatusdiv' , $ post_type , 'normal' ) ; \ remove_meta_box ( 'commentsdiv' ,...
Remove comment meta boxes from all post types .
14,658
public function setProjectDirectory ( string $ dir ) : Application { if ( is_dir ( $ dir ) ) { $ this -> projectDir = $ dir ; } return $ this ; }
Set the project directory . Used in determining version .
14,659
private function findComposerVersion ( string $ packageName , string $ projectDir ) : ? string { if ( file_exists ( "$projectDir/vendor" ) ) { return $ this -> findGitVersion ( $ projectDir ) ; } $ composerFile = "$projectDir/../../../composer.lock" ; if ( ! file_exists ( $ composerFile ) ) { return null ; } $ composer...
Reads the composer lock file based on the project directory and parses the version for the specified package name .
14,660
private function findGitVersion ( string $ projectDir ) : ? string { $ branch = static :: revParse ( '--abbrev-ref HEAD' , $ projectDir ) ; if ( empty ( $ branch ) ) { return null ; } return $ branch . ' ' . static :: revParse ( '--short HEAD' , $ projectDir ) ; }
Returns the current git branch name and revision or null if git repo cannot be found .
14,661
public function create ( $ definition , array $ args = array ( ) ) { $ className = $ definition ; if ( is_array ( $ definition ) ) { $ className = $ definition [ 'class' ] ; if ( isset ( $ definition [ 'arguments' ] ) ) $ args = array_merge ( $ args , $ definition [ 'arguments' ] ) ; } else { $ className = $ definition...
Create the instance
14,662
public function writeRow ( iterable $ row ) : void { $ row = Bag :: from ( $ row ) ; if ( $ row -> isIndexed ( ) ) { $ this -> writer -> writeRow ( $ row ) ; return ; } if ( $ this -> headers === null ) { $ this -> headers = $ row -> keys ( ) ; } $ extra = $ row -> omit ( ... $ this -> headers ) ; if ( ! $ extra -> isE...
Write a row .
14,663
protected function formatBytes ( $ bytes ) : string { $ suffix = [ 'B' , 'KB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ; $ p = min ( ( int ) log ( $ bytes , 1024 ) , count ( $ suffix ) - 1 ) ; return sprintf ( '%1.2f%s' , ( $ bytes / pow ( 1024 , $ p ) ) , $ suffix [ $ p ] ) ; }
Format bytes to human readable format
14,664
public function setUserLoggedIn ( AdminUser $ user ) : string { $ _SESSION [ 'admin_logged' ] = true ; $ _SESSION [ 'admin_id' ] = $ user -> getId ( ) ; $ _SESSION [ 'admin_login' ] = $ user -> getLogin ( ) ; $ _SESSION [ 'admin_sid' ] = Users :: getInstance ( ) -> startSession ( $ user -> getId ( ) ) ; if ( ! defined ...
After that user is logged - in
14,665
public function startSession ( $ user_id ) { $ this -> deleteOldSessions ( ) ; $ user_id = ( int ) $ user_id ; $ sid = $ this -> generateUserSid ( $ user_id ) ; $ session = UsersSessionEntityRepository :: findOneEntityByCriteria ( [ 'sid' => $ sid , 'user_id' => $ user_id , ] ) ; if ( ! $ session ) { $ session = new Us...
Starts session for admin user
14,666
private function deleteOldSessions ( ) { if ( mt_rand ( 0 , 49 ) ) { return false ; } $ sessions = new UsersSessionEntityRepository ( ) ; $ sessions -> setOnlyOutdated ( ) ; $ sessions -> deleteObjectCollection ( ) ; return true ; }
Delete outdated sessions for users that are no longer logged - in
14,667
public function deleteSession ( $ user_id ) { if ( ! isset ( $ _SESSION [ 'admin_sid' ] ) ) { return true ; } $ user_id = ( int ) $ user_id ; $ sessions = new UsersSessionEntityRepository ( ) ; $ sessions -> setWhereUserId ( $ user_id ) ; $ sessions -> setWhereSid ( $ _SESSION [ 'admin_sid' ] ) ; $ sessions -> deleteOb...
Removes current session logs out admin user
14,668
public function getUserLng ( $ user_id = 0 ) { $ user_id = ( int ) $ user_id ; $ preferred_language = $ this -> getUserData ( 'lng' , $ user_id ) ; $ languages = Languages :: getPairs ( ) ; if ( ! isset ( $ languages [ $ preferred_language ] ) ) { $ preferred_language = key ( $ languages ) ; } return $ preferred_langua...
Get admin user currently selected language
14,669
public function getUserData ( $ key , $ id = 0 ) { if ( ! $ id ) { if ( defined ( 'USER_ID' ) ) { $ id = USER_ID ; } else { return NULL ; } } else { $ id = abs ( ( int ) $ id ) ; } if ( ! isset ( self :: $ cached_user_data [ $ id ] ) ) { $ user = AdminUserRepository :: findOneEntityById ( $ id ) ; if ( ! $ user ) { ret...
Get User s data by key
14,670
public function getGroupsPairs ( ) { if ( ! self :: $ cached_group_pairs ) { $ user_collection = new AdminUserGroupRepository ; $ user_collection -> addOrderByField ( 'title' ) ; $ pairs = $ user_collection -> getPairs ( 'title' ) ; self :: $ cached_group_pairs = $ pairs ; } return self :: $ cached_group_pairs ; }
Get key - value array of groups
14,671
public function checkAccess ( $ p = P , $ do = P_DO , $ user_id = 0 ) { if ( $ p === 'guest' ) { return true ; } if ( ! $ this -> isLogged ( ) ) { return false ; } if ( ! $ user_id ) { $ user_id = USER_ID ; } $ group_id = $ this -> getUserData ( 'group_id' , $ user_id ) ; if ( self :: getInstance ( ) -> getGroupData ( ...
Check whether user have access to open selected page
14,672
public function isLogged ( ) { return self :: $ is_logged || self :: $ is_logged = ( bool ) ( isset ( $ _SESSION [ 'admin_logged' ] , $ _SESSION [ 'admin_id' ] , $ _SESSION [ 'admin_sid' ] ) && $ _SESSION [ 'admin_logged' ] && $ _SESSION [ 'admin_id' ] && $ this -> checkSession ( $ _SESSION [ 'admin_id' ] , $ _SESSION ...
Check that current user is logged - in
14,673
private function checkSession ( $ user_id , $ user_sid , $ touch = false ) { $ user_id = ( int ) $ user_id ; if ( ! defined ( 'USER_ID' ) ) { define ( 'USER_ID' , $ user_id ) ; } if ( $ touch ) { $ sessions = new UsersSessionEntityRepository ( ) ; $ sessions -> setWhereSid ( $ user_sid ) ; $ session = $ sessions -> get...
Check whether user is logged - in
14,674
public function getGroupData ( $ key , $ id = 0 ) { if ( ! $ id ) { $ id = $ this -> getUserData ( 'group_id' ) ; } else { $ id = abs ( ( int ) $ id ) ; } if ( ! isset ( self :: $ cached_group_data [ $ id ] ) ) { $ group = new AdminUserGroup ( $ id ) ; self :: $ cached_group_data [ $ id ] = $ group -> getAsArray ( ) ; ...
Get Group s data by key
14,675
public function checkSitePagePermissions ( $ page_id , $ action ) { $ group_id = self :: getInstance ( ) -> getUserData ( 'group_id' ) ; if ( self :: getInstance ( ) -> getGroupData ( 'structure_permissions' , $ group_id ) ) { return true ; } if ( ! self :: $ _structure_permissions ) { $ structure_pages = new Structure...
Permissions for site structure
14,676
public function recreateDefaults ( ) { $ group = AdminUserGroupRepository :: findOneEntityById ( 1 ) ; if ( ! $ group || ! $ group -> getUndeletable ( ) || ! $ group -> getCanSetPermissions ( ) || ! $ group -> getFullAccess ( ) ) { if ( $ group ) { $ group -> is_super_admin = true ; $ group -> setField ( 'undeletable' ...
Installing new database . Use only when auto - creating new site
14,677
public function initializeLayout ( $ page , \ LayoutModel $ layout ) { static :: $ pageLayout = $ layout ; if ( ! static :: isEnabled ( ) ) { return ; } static :: $ pageLayout -> framework = null ; $ templates = $ GLOBALS [ 'BOOTSTRAP' ] [ 'templates' ] [ 'dynamicLoad' ] ; foreach ( $ templates as $ path => $ templates...
only load templates if bootstrap is activated so diverent layouts will work instead of template changes
14,678
public static function getLayout ( ) { if ( self :: $ pageLayout === null ) { global $ objPage ; if ( $ objPage !== null ) { self :: $ pageLayout = \ LayoutModel :: findByPk ( $ objPage -> layout ) ; } } return self :: $ pageLayout ; }
get current layout of current page
14,679
public function oauthAuthenticate ( HTTPRequest $ request , $ scopes = [ ] ) { $ headers = $ request -> getHeaders ( ) ; if ( empty ( $ headers [ 'oauth_client_id' ] ) ) { return false ; } if ( ! empty ( $ scopes ) ) { $ matchedScopes = [ ] ; $ requestScopes = ! empty ( $ headers [ 'oauth_scopes' ] ) ? explode ( ',' , ...
Check request has oauth headers and optionally check for scopes .
14,680
public function enabled ( ) : bool { if ( $ this -> isEnabled !== null ) { return $ this -> isEnabled ; } if ( ! $ this -> config -> get ( "antispam.{$this->instanceType}.enabled" , true ) ) { return $ this -> isEnabled = false ; } $ disabledEnv = ( array ) $ this -> config -> get ( "antispam.{$this->instanceType}.disa...
Check enabled status .
14,681
public function redirect ( ) : ? RedirectResponse { if ( ! $ this -> enabled ( ) ) { return null ; } return redirect ( ) -> back ( ) -> withErrors ( [ 'form-verify-error' => $ this -> redirectMessage , ] ) -> withInput ( ) ; }
Redirect on failed form submission
14,682
public function getShipmentStateLabel ( $ stateOrShipment ) { $ state = $ stateOrShipment instanceof ShipmentInterface ? $ stateOrShipment -> getState ( ) : $ stateOrShipment ; return $ this -> translator -> trans ( ShipmentStates :: getLabel ( $ state ) ) ; }
Returns the shipment state label .
14,683
public function getShipmentStateBadge ( $ stateOrShipment ) { $ state = $ stateOrShipment instanceof ShipmentInterface ? $ stateOrShipment -> getState ( ) : $ stateOrShipment ; return sprintf ( '<span class="label label-%s">%s</span>' , ShipmentStates :: getTheme ( $ state ) , $ this -> getShipmentStateLabel ( $ state ...
Returns the shipment state badge .
14,684
private function store ( ) { $ settings = [ ] ; foreach ( $ this -> settings as $ key => $ value ) { $ settings [ $ key ] = serialize ( $ value ) ; } file_put_contents ( $ this -> cacheFile , json_encode ( $ settings ) ) ; }
Stores all settings to the cache file
14,685
public function forget ( $ key ) { if ( array_key_exists ( $ key , $ this -> settings ) ) { unset ( $ this -> settings [ $ key ] ) ; } $ this -> store ( ) ; }
Removes a value
14,686
public function setOutputPath ( $ path ) { $ dir = pathinfo ( $ path , PATHINFO_DIRNAME ) ; $ dir = $ this -> normalizePath ( $ dir ) ; if ( ! is_dir ( $ dir ) ) { throw new InvalidPath ( 'Invalid directory: "' . $ dir . '"' ) ; } if ( ! is_writable ( $ dir ) ) { throw new InvalidPath ( 'The directory: "' . $ dir . '" ...
Set the path to the output file
14,687
public function append ( $ path ) { $ path = $ this -> normalizePath ( $ path ) ; $ this -> inputFiles -> push ( $ path ) ; return $ this ; }
Append the file
14,688
public function prepend ( $ path ) { $ path = $ this -> normalizePath ( $ path ) ; $ this -> inputFiles -> unshift ( $ path ) ; return $ this ; }
Prepend the file
14,689
public function assemble ( ) { if ( $ this -> inputFiles -> isEmpty ( ) ) { throw new OperationError ( 'Nothing to assemble, you should add at least one item' ) ; } $ result = '' ; foreach ( $ this -> inputFiles as $ path ) { $ content = file_get_contents ( $ path ) ; if ( $ content === false ) { throw new OperationErr...
Assemble the files chain
14,690
public function write ( $ forceAssemble = false ) { if ( $ this -> outputFile === null ) { throw new OperationError ( 'Path to the output file must be set first' ) ; } if ( ! $ forceAssemble && $ this -> reassembleByMTime && ! $ this -> isOutputExpired ( ) ) { return ; } $ result = file_put_contents ( $ this -> outputF...
Assemble and write the file
14,691
protected function isOutputExpired ( ) { if ( $ this -> inputFiles -> isEmpty ( ) ) { throw new OperationError ( 'Nothing to assemble, you should add at least one item' ) ; } if ( ! is_file ( $ this -> outputFile ) ) { return true ; } $ outputMtime = $ this -> getFileMTime ( $ this -> outputFile ) ; foreach ( $ this ->...
Is output file expired ?
14,692
protected function getFileMTime ( $ path ) { $ mtime = filemtime ( $ path ) ; if ( $ mtime === false ) { throw new OperationError ( 'Unable to determine modification time of the file: "' . $ path . '"' ) ; } return $ mtime ; }
Get the file s modification time
14,693
public function setFileInfo ( $ flag = true , $ template = null ) { $ this -> fileInfo = ( bool ) $ flag ; if ( $ template !== null ) { $ this -> fileInfoTemplate = ( string ) $ template ; } return $ this ; }
Set additional file info
14,694
private function getAllChildKeys ( $ data , $ maps , $ parent_keys , $ parent_types , & $ result , & $ keys , $ current_key = [ ] , $ current_type = null ) { if ( $ current_type == '11' ) { $ data = [ '__11__' => $ data ] ; } foreach ( $ data as $ k => $ v ) { $ new_key = $ current_key ; if ( $ current_type != '11' ) {...
Get all child keys
14,695
public static function collectionToModel ( $ collection ) { if ( is_string ( $ collection ) ) { return \ Factory :: model ( $ collection ) ; } else if ( ! empty ( $ collection [ 'model' ] ) ) { return new \ Object \ Collection ( [ 'data' => $ collection , 'skip_acl' => $ collection [ 'skip_acl' ] ?? false ] ) ; } else ...
Convert collection to model
14,696
private function createMailTemplate ( string $ mailKey , array $ mailVars = [ ] ) { $ mailTemplate = \ Yii :: $ app -> get ( 'emailTemplates' ) -> getTemplate ( $ mailKey , Language :: getCurrent ( ) -> id ) ; if ( ! empty ( $ mailVars ) && ! empty ( $ mailTemplate ) ) { $ mailTemplate -> parseSubject ( $ mailVars ) ; ...
Uses emailTemplates component which parses variables and inserts values to email subject and body
14,697
public function sendPartnerRequestToManager ( array $ mailVars , $ sendFrom , $ sendTo ) { $ mailTemplate = $ this -> createMailTemplate ( 'partner-request-manager' , $ mailVars ) ; if ( ! empty ( $ mailTemplate ) ) { $ subject = $ mailTemplate -> getSubject ( ) ; $ bodyParams = [ 'bodyContent' => $ mailTemplate -> get...
Sends mail about partner request to manager
14,698
public function sendPartnerAcceptance ( string $ partnerEmail ) { $ mailTemplate = $ this -> createMailTemplate ( 'partner-request-accept' ) ; if ( ! empty ( $ mailTemplate ) ) { $ subject = $ mailTemplate -> getSubject ( ) ; $ bodyParams = [ 'bodyContent' => $ mailTemplate -> getBody ( ) ] ; $ sendFrom = [ \ Yii :: $ ...
Sends mail to partner if his request was approved
14,699
public function sendNewProductToManagerAndOwner ( Product $ product ) { $ productOwner = $ product -> productOwner ; $ mailVars = [ '{productId}' => $ product -> id , '{title}' => $ product -> translation -> title , '{ownerId}' => $ productOwner -> id , '{ownerEmail}' => $ productOwner -> email , '{owner}' => ! ( empty...
If user which has not createProductWithoutModeration permission email to manager and this user will be sent