idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
6,900
|
public static function dispatch ( ) { $ vars = [ ] ; $ request = Request :: createFromGlobals ( ) ; $ dispatcher = new Dispatcher ( static :: instance ( ) -> getData ( ) ) ; $ routeInfo = $ dispatcher -> dispatch ( $ request -> getMethod ( ) , $ request -> getUri ( ) -> getPath ( ) ) ; $ controller = "\\Barebone\\Controller" ; $ action = "index" ; switch ( $ routeInfo [ 0 ] ) { case Dispatcher :: NOT_FOUND : $ action = 'routerError' ; $ vars [ 'error' ] = static :: ERR_NOT_FOUND ; $ vars [ 'subject' ] = $ request -> getUri ( ) -> getPath ( ) ; break ; case Dispatcher :: METHOD_NOT_ALLOWED : $ action = 'routerError' ; $ vars [ 'error' ] = static :: ERR_BAD_METHOD ; $ vars [ 'subject' ] = $ routeInfo [ 1 ] ; break ; case Dispatcher :: FOUND : $ handler = $ routeInfo [ 1 ] ; $ vars = $ routeInfo [ 2 ] ; if ( ! class_exists ( $ handler [ 0 ] ) ) { $ action = 'routerError' ; $ vars [ 'error' ] = static :: ERR_MISSING_CONTROLLER ; $ vars [ 'subject' ] = $ handler [ 0 ] ; } elseif ( ! method_exists ( $ handler [ 0 ] , $ handler [ 1 ] ) ) { $ action = 'routerError' ; $ vars [ 'error' ] = static :: ERR_MISSING_ACTION ; $ vars [ 'subject' ] = $ handler [ 0 ] . '::' . $ handler [ 1 ] ; } else { $ controller = $ handler [ 0 ] ; $ action = $ handler [ 1 ] ; } break ; } $ response = new Response ( ) ; $ request -> setAction ( $ action ) ; $ instance = new $ controller ( $ request , $ response ) ; $ instance -> initController ( ) ; $ before = $ instance -> getMiddlewareBefore ( ) ; $ after = $ instance -> getMiddlewareAfter ( ) ; $ before [ ] = function ( Request $ request , Response $ response , callable $ next = null ) use ( $ instance , $ action , $ vars ) { $ instance -> setRequest ( $ request ) ; $ instance -> setResponse ( $ response ) ; $ response = call_user_func_array ( [ $ instance , $ action ] , $ vars ) ; return $ next ( $ instance -> getRequest ( ) , $ response ) ; } ; $ middlewares = array_reverse ( array_merge ( $ before , $ after ) ) ; $ runner = \ Sirius \ Middleware \ Runner :: factory ( $ middlewares ) ; return $ runner ( $ request , $ response ) ; }
|
Start router and parse incoming requests
|
6,901
|
public static function get ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'GET' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle GET HTTP requests
|
6,902
|
public static function post ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'POST' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle POST HTTP requests
|
6,903
|
public static function put ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'PUT' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle PUT HTTP requests
|
6,904
|
public static function delete ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'DELETE' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle DELETE HTTP requests
|
6,905
|
public static function patch ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'PATCH' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle PATCH HTTP requests
|
6,906
|
public static function options ( $ path , $ callback ) { self :: instance ( ) -> addRoute ( 'OPTIONS' , $ path , self :: callback ( $ callback ) ) ; }
|
Handle OPTIONS HTTP requests
|
6,907
|
public static function map ( $ methods , $ path , $ callback ) { foreach ( $ methods as $ httpMethod ) { self :: instance ( ) -> addRoute ( $ httpMethod , $ path , self :: callback ( $ callback ) ) ; } }
|
Route that handles all HTTP request methods
|
6,908
|
public function confirmGoBack ( $ user , $ message ) { if ( self :: validationVariations ( $ message , 1 , "yes" ) ) { self :: resetUser ( $ user ) ; $ user -> menu_id = 2 ; $ user -> session = 1 ; $ user -> progress = 1 ; $ user -> save ( ) ; $ menu = ussd_menu :: find ( 2 ) ; $ menu_items = self :: getMenuItems ( $ menu -> id ) ; $ i = 1 ; $ response = $ menu -> title . PHP_EOL ; foreach ( $ menu_items as $ key => $ value ) { $ response = $ response . $ i . ": " . $ value -> description . PHP_EOL ; $ i ++ ; } self :: sendResponse ( $ response , 1 , $ user ) ; exit ; } elseif ( self :: validationVariations ( $ message , 2 , "no" ) ) { $ response = "Thank you for using our service" ; self :: sendResponse ( $ response , 3 , $ user ) ; } else { $ response = '' ; self :: sendResponse ( $ response , 2 , $ user ) ; exit ; } }
|
confirm go back
|
6,909
|
public function postUssdConfirmationProcess ( $ user ) { switch ( $ user -> confirm_from ) { case 1 : $ no = substr ( $ user -> phone , - 9 ) ; $ data [ 'email' ] = "0" . $ no . "@agin.com" ; User :: create ( $ data ) ; return true ; break ; default : return true ; break ; } }
|
post ussd confirmation define your processes
|
6,910
|
public function continueUssdMenuProcess ( $ user , $ message ) { $ menu = ussd_menu :: find ( $ user -> menu_id ) ; switch ( $ menu -> type ) { case 0 : break ; case 1 : $ response = self :: continueUssdMenu ( $ user , $ message , $ menu ) ; break ; case 2 : $ response = self :: continueSingleProcess ( $ user , $ message , $ menu ) ; break ; case 3 : self :: infoMiniApp ( $ user , $ menu ) ; break ; default : self :: resetUser ( $ user ) ; $ response = "An error occurred" ; break ; } return $ response ; }
|
continue USSD Menu Progress
|
6,911
|
public function infoMiniApp ( $ user , $ menu ) { echo "infoMiniAppbased on menu_id" ; exit ; switch ( $ menu -> id ) { case 4 : break ; case 5 : break ; case 6 : default : $ response = $ menu -> confirmation_message ; $ notify = new NotifyController ( ) ; self :: sendResponse ( $ response , 2 , $ user ) ; break ; } }
|
info mini app
|
6,912
|
public function continueUssdMenu ( $ user , $ message , $ menu ) { $ menu_items = self :: getMenuItems ( $ user -> menu_id ) ; $ i = 1 ; $ choice = "" ; $ next_menu_id = 0 ; foreach ( $ menu_items as $ key => $ value ) { if ( self :: validationVariations ( trim ( $ message ) , $ i , $ value -> description ) ) { $ choice = $ value -> id ; $ next_menu_id = $ value -> next_menu_id ; break ; } $ i ++ ; } if ( empty ( $ choice ) ) { $ response = "We could not understand your response" . PHP_EOL ; $ i = 1 ; $ response = $ menu -> title . PHP_EOL ; foreach ( $ menu_items as $ key => $ value ) { $ response = $ response . $ i . ": " . $ value -> description . PHP_EOL ; $ i ++ ; } return $ response ; } else { $ menu = ussd_menu :: find ( $ next_menu_id ) ; $ response = self :: nextMenuSwitch ( $ user , $ menu ) ; return $ response ; } }
|
continue USSD Menu
|
6,913
|
public function storeUssdResponse ( $ user , $ message ) { $ data = [ 'user_id' => $ user -> id , 'menu_id' => $ user -> menu_id , 'menu_item_id' => $ user -> menu_item_id , 'response' => $ message ] ; return ussd_response :: create ( $ data ) ; }
|
store USSD response
|
6,914
|
public function getBuffer ( array $ options = [ ] ) { $ docEol = $ this -> Document -> eol ; $ options = Hash :: merge ( [ 'safe' => true ] , $ options ) ; if ( Arr :: key ( 'block' , $ options ) ) { unset ( $ options [ 'block' ] ) ; } if ( count ( $ this -> _buffers ) ) { $ scripts = $ docEol . 'jQuery (function($) {' . $ docEol . implode ( $ docEol , $ this -> _buffers ) . $ docEol . '});' . $ docEol ; return $ this -> Html -> scriptBlock ( $ scripts , $ options ) . $ docEol ; } return null ; }
|
Get all holds in buffer scripts .
|
6,915
|
public function setBuffer ( $ script , $ top = false ) { $ script = trim ( $ script ) ; if ( $ top ) { array_unshift ( $ this -> _buffers , $ script ) ; } else { array_push ( $ this -> _buffers , $ script ) ; } return $ this ; }
|
Setup buffer script .
|
6,916
|
public function widget ( $ jSelector , $ widgetName , array $ params = [ ] , $ return = false ) { static $ included = [ ] ; $ jSelector = is_array ( $ jSelector ) ? implode ( ', ' , $ jSelector ) : $ jSelector ; $ hash = $ jSelector . ' /// ' . $ widgetName ; if ( ! Arr :: key ( $ hash , $ included ) ) { $ included [ $ hash ] = true ; $ widgetName = str_replace ( '.' , '' , $ widgetName ) ; $ initScript = '$("' . $ jSelector . '").' . $ widgetName . '(' . json_encode ( $ params ) . ');' ; if ( $ return ) { return $ this -> Html -> scriptBlock ( "\tjQuery(function($){" . $ initScript . "});" ) ; } $ this -> setBuffer ( $ initScript ) ; } return null ; }
|
Initialize java script widget .
|
6,917
|
protected function _setScriptVars ( ) { $ request = $ this -> request ; $ vars = [ 'baseUrl' => Router :: fullBaseUrl ( ) , 'alert' => [ 'ok' => __d ( 'alert' , 'Ok' ) , 'cancel' => __d ( 'alert' , 'Cancel' ) , 'sure' => __d ( 'alert' , 'Are you sure?' ) , ] , 'request' => [ 'url' => $ request -> getPath ( ) , 'params' => [ 'pass' => $ request -> getParam ( 'pass' ) , 'theme' => $ request -> getParam ( 'theme' ) , 'action' => $ request -> getParam ( 'action' ) , 'prefix' => $ request -> getParam ( 'prefix' ) , 'plugin' => $ request -> getParam ( 'plugin' ) , 'controller' => $ request -> getParam ( 'controller' ) , ] , 'query' => $ this -> request -> getQueryParams ( ) , 'base' => $ request -> getAttribute ( 'base' ) , 'here' => $ request -> getRequestTarget ( ) , ] ] ; $ this -> Html -> scriptBlock ( 'window.CMS = ' . json_encode ( $ vars ) , [ 'block' => 'css_bottom' ] ) ; }
|
Setup java script variables from server .
|
6,918
|
public function create ( \ Slender \ App $ app ) { $ loader = new ModuleLoader ( ) ; $ loader -> setResolver ( $ app [ 'module-resolver' ] ) ; $ loader -> setConfig ( $ app [ 'settings' ] ) ; $ loader -> setClassLoader ( $ app [ 'autoloader' ] ) ; return $ loader ; }
|
Create a ModuleLoader instance
|
6,919
|
public function beforeCommand ( Event $ event , Command $ command ) { $ parameters = $ command -> parseParameters ( [ ] , [ 'h' => 'help' ] ) ; if ( count ( $ parameters ) < ( $ command -> getRequiredParams ( ) + 1 ) || $ command -> isReceivedOption ( [ 'help' , 'h' , '?' ] ) || in_array ( $ command -> getOption ( 1 ) , [ 'help' , 'h' , '?' ] ) ) { $ command -> getHelp ( ) ; return false ; } if ( ! defined ( 'BASE_PATH' ) ) { throw new CommandsException ( 'Commands need a BASE_PATH constant defined.' ) ; } if ( $ command -> canBeExternal ( ) == false ) { $ path = $ command -> getOption ( 'directory' ) ; if ( ! file_exists ( $ path . '.phalcon' ) ) { throw new CommandsException ( 'This command should be invoked inside a Phalcon project directory.' ) ; } } return true ; }
|
Before command executing
|
6,920
|
public function getInfo ( ) { $ this -> info = [ 'width' => $ this -> getWidth ( ) , 'height' => $ this -> getHeight ( ) , 'file_size' => $ this -> getFileSize ( ) , ] ; return $ this -> info ; }
|
Get details about an image .
|
6,921
|
public function scale_and_crop ( $ width , $ height ) { if ( $ width === null ) { throw new \ LogicException ( '"width" must not be null for "scale_and_crop"' ) ; } if ( $ height === null ) { throw new \ LogicException ( '"height" must not be null for "scale_and_crop"' ) ; } $ scale = max ( $ width / $ this -> getWidth ( ) , $ height / $ this -> getHeight ( ) ) ; $ w = ceil ( $ this -> getWidth ( ) * $ scale ) ; $ h = ceil ( $ this -> getHeight ( ) * $ scale ) ; $ x = ( $ w - $ width ) / 2 ; $ y = ( $ h - $ height ) / 2 ; $ this -> resize ( $ w , $ h ) ; $ this -> crop ( $ x , $ y , $ width , $ height ) ; }
|
Scales an image to the exact width and height given .
|
6,922
|
public function scale ( $ width = null , $ height = null ) { if ( $ width === null && $ height === null ) { throw new \ LogicException ( 'one of "width" or "height" must be set for "scale"' ) ; } if ( $ width !== null && $ height !== null ) { $ this -> resize ( $ width , $ height ) ; return ; } if ( $ width !== null ) { $ this -> image -> widen ( $ width ) ; return ; } $ this -> image -> heighten ( $ height ) ; }
|
Scales an image to the given width and height while maintaining aspect ratio .
|
6,923
|
public function rotate ( $ degrees , $ background = null , $ random = false ) { if ( $ background ) { $ background = trim ( $ background ) ; } else { $ background = "ffffff" ; } if ( $ random ) { $ deg = abs ( ( float ) $ degrees ) ; $ degrees = rand ( - 1 * $ deg , $ deg ) ; } $ this -> image -> rotate ( $ degrees , $ background ) ; }
|
Rotate an image by the given number of degrees .
|
6,924
|
public function crop ( $ xoffset , $ yoffset , $ width , $ height ) { if ( $ xoffset === null ) { throw new \ LogicException ( '"xoffset" must not be null for "crop"' ) ; } if ( $ yoffset === null ) { throw new \ LogicException ( '"yoffset" must not be null for "crop"' ) ; } if ( $ width === null ) { throw new \ LogicException ( '"width" must not be null for "crop"' ) ; } if ( $ height === null ) { throw new \ LogicException ( '"height" must not be null for "crop"' ) ; } $ this -> image -> crop ( $ width , $ height , $ xoffset , $ yoffset ) ; }
|
Crop an image to the rectangle specified by the given rectangle .
|
6,925
|
public function save ( $ destination = null ) { if ( empty ( $ destination ) ) { $ destination = $ this -> source ; } $ this -> image -> save ( $ destination ) ; clearstatcache ( ) ; chmod ( $ destination , 0644 ) ; return new self ( $ destination ) ; }
|
Close the image and save the changes to a file .
|
6,926
|
private function buildException ( ) { if ( $ this -> isJsonRequest ( ) ) { $ this -> setException ( new ExceptionJson ( $ this -> message , $ this -> debugCode , $ this -> details , $ this -> errors ) ) ; } else { $ exception = new ExceptionView ( $ this -> message , $ this -> debugCode , $ this -> details , $ this -> errors ) ; $ exception -> setViewPath ( $ this -> getVewPath ( ) ) ; $ exception -> setRedirectPath ( $ this -> getRedirect ( ) ) ; $ this -> setException ( $ exception ) ; } }
|
Se encarga de construir el objeto de la excepcion
|
6,927
|
public function build ( int $ httpCode = 200 ) { $ this -> buildException ( ) ; if ( $ this -> log ) { $ this -> renderLog ( ) ; } if ( ! $ this -> showDetails ) { $ this -> getException ( ) -> setDetails ( null ) ; } if ( ! $ this -> showErrors ) { $ this -> getException ( ) -> setErrors ( null ) ; } $ this -> getException ( ) -> setHttpCode ( $ httpCode ) ; throw $ this -> getException ( ) ; }
|
Se encarga de le ejecucion para la contruccion de la escepcion
|
6,928
|
public function transfer ( $ fromObjectOrArray , & $ toObjectOrArray , $ mapper = null , $ fromSubset = '' , $ toSubset = '' ) { $ result = [ ] ; $ data = null ; switch ( true ) { case is_object ( $ fromObjectOrArray ) : $ fromMetadata = $ this -> metadataReader -> getMetadata ( get_class ( $ fromObjectOrArray ) , $ fromSubset ) ; $ fromHydrator = $ this -> getHydrator ( $ fromMetadata ) ; $ data = $ fromHydrator -> extract ( $ fromObjectOrArray ) ; break ; case is_array ( $ fromObjectOrArray ) : $ data = & $ fromObjectOrArray ; break ; default : throw new \ InvalidArgumentException ( 'Data transfer is possible only from object or array.' ) ; } if ( is_callable ( $ mapper ) || ( $ mapper instanceof Mapper \ MapperInterface ) ) { $ data = $ mapper ( $ data ) ; if ( ! is_array ( $ data ) ) { throw new \ LogicException ( sprintf ( 'Invalid mapping: expecting array result, not %s.' , gettype ( $ data ) ) ) ; } } switch ( true ) { case is_object ( $ toObjectOrArray ) : $ toMetadata = $ this -> metadataReader -> getMetadata ( get_class ( $ toObjectOrArray ) , $ toSubset ) ; $ toHydrator = $ this -> getHydrator ( $ toMetadata ) ; $ validator = $ this -> getValidator ( $ toMetadata ) ; $ result = $ validator -> validate ( self :: arrayTransfer ( $ toHydrator -> extract ( $ toObjectOrArray ) , $ data ) ) ; if ( empty ( $ result ) ) { $ toObjectOrArray = $ toHydrator -> hydrate ( $ data , $ toObjectOrArray ) ; } break ; case is_array ( $ toObjectOrArray ) : $ toObjectOrArray = self :: arrayTransfer ( $ toObjectOrArray , $ data ) ; break ; default : throw new \ InvalidArgumentException ( 'Data transfer is possible only to object or array.' ) ; } return $ result ; }
|
Transfers data from source to destination safely .
|
6,929
|
public function getHydrator ( Metadata $ metadata ) { if ( ! isset ( $ this -> hydrators [ $ metadata -> className ] [ $ metadata -> subset ] ) ) { $ hydrator = new Hydrator ( ) ; $ hydrator -> setStrategyPluginManager ( $ this -> strategyPluginManager ) -> setMetadata ( $ metadata ) ; $ this -> hydrators [ $ metadata -> className ] [ $ metadata -> subset ] = $ hydrator ; } return $ this -> hydrators [ $ metadata -> className ] [ $ metadata -> subset ] ; }
|
Returns hydrator required by metadata
|
6,930
|
public function getValidator ( Metadata $ metadata ) { if ( ! isset ( $ this -> validators [ $ metadata -> className ] [ $ metadata -> subset ] ) ) { $ validator = new Validator ( ) ; $ validator -> setValidatorPluginManager ( $ this -> validatorPluginManager ) -> setMetadata ( $ metadata ) ; $ this -> validators [ $ metadata -> className ] [ $ metadata -> subset ] = $ validator ; } return $ this -> validators [ $ metadata -> className ] [ $ metadata -> subset ] ; }
|
Returns validator required by metadata
|
6,931
|
static public function arrayTransfer ( array $ a , array $ b ) { if ( ArrayUtils :: isList ( $ b , ArrayUtils :: isList ( $ a ) ) ) { $ a = $ b ; } else { foreach ( $ b as $ key => $ value ) { if ( array_key_exists ( $ key , $ a ) && is_array ( $ value ) && is_array ( $ a [ $ key ] ) ) { $ a [ $ key ] = self :: arrayTransfer ( $ a [ $ key ] , $ value ) ; } else { $ a [ $ key ] = $ value ; } } } return $ a ; }
|
Simple data transfer from one array to the other
|
6,932
|
public function setImageUrl ( $ imageUrl ) { $ this -> style = null ; $ this -> subStyle = null ; $ this -> imageUrl = ( string ) $ imageUrl ; return $ this ; }
|
Set the image url
|
6,933
|
public function applyToQuad ( Quad $ quad ) { if ( $ this -> imageUrl ) { $ quad -> setImageUrl ( $ this -> imageUrl ) ; } else if ( $ this -> style ) { $ quad -> setStyles ( $ this -> style , $ this -> subStyle ) ; } return $ this ; }
|
Apply the Design to the given Quad
|
6,934
|
public function indexDataAction ( Request $ request ) { $ aRemoteApps = RemoteAppQuery :: create ( ) -> find ( ) ; $ sResult = $ this -> renderView ( 'SlashworksAppBundle:RemoteApp:data.json.twig' , array ( 'entities' => $ aRemoteApps , ) ) ; $ response = new Response ( $ sResult ) ; $ response -> headers -> set ( 'Content-Type' , 'application/json' ) ; return $ response ; }
|
Get data as json for remoteapp - list
|
6,935
|
public function detailsAction ( $ id ) { $ aRemoteApps = RemoteAppQuery :: create ( ) -> findOneById ( $ id ) ; $ aRemoteAppHistory = $ aRemoteApps -> getRemoteHistoryContaoAsArray ( ) ; return $ this -> render ( 'SlashworksAppBundle:RemoteApp:details.html.twig' , array ( 'remoteapp' => $ aRemoteApps , 'remoteappHistory' => $ aRemoteAppHistory ) ) ; }
|
show details for remoteapp
|
6,936
|
public function initInstallCallAction ( $ id ) { $ oRemoteApp = RemoteAppQuery :: create ( ) -> findOneById ( $ id ) ; $ sResult = array ( "success" => false , "message" => "" ) ; try { $ this -> get ( "API" ) ; Api :: $ _container = $ this -> container ; $ mResult = Api :: call ( "doInstall" , array ( ) , $ oRemoteApp -> getUpdateUrl ( ) , $ oRemoteApp -> getPublicKey ( ) , $ oRemoteApp ) ; if ( ! empty ( $ mResult ) ) { if ( ! isset ( $ mResult [ 'result' ] [ 'result' ] ) ) { $ this -> get ( 'logger' ) -> error ( "[INIT ERROR] " . print_r ( $ mResult , true ) ) ; throw new \ Exception ( $ this -> get ( "translator" ) -> trans ( "remote_app.api.init.error" ) ) ; } if ( $ mResult [ 'result' ] [ 'result' ] == true ) { $ sResult [ 'success' ] = true ; $ sResult [ 'message' ] = $ this -> get ( "translator" ) -> trans ( "remote_app.api.update.successful" ) ; $ this -> get ( 'logger' ) -> info ( "Api-Call successful" , array ( "Method" => __METHOD__ , "RemoteApp" => $ oRemoteApp -> getName ( ) ) ) ; $ oRemoteApp -> setWebsiteHash ( $ mResult [ 'result' ] [ 'website_hash' ] ) ; $ oRemoteApp -> save ( ) ; } else { $ this -> get ( 'logger' ) -> error ( "Unknown error in " . __FILE__ . " on line " . __LINE__ . " - Result: " . json_encode ( $ mResult ) , array ( "Method" => __METHOD__ , "RemoteApp" => $ oRemoteApp -> getName ( ) , "RemoteURL" => $ oRemoteApp -> getFullApiUrl ( ) ) ) ; throw new \ Exception ( "error in " . __FILE__ . " on line " . __LINE__ ) ; } } } catch ( \ Exception $ e ) { $ this -> get ( 'logger' ) -> error ( $ e -> getMessage ( ) , array ( "Method" => __METHOD__ , "RemoteApp" => $ oRemoteApp -> getName ( ) , "RemoteURL" => $ oRemoteApp -> getFullApiUrl ( ) ) ) ; $ sResult [ 'success' ] = false ; $ sResult [ 'message' ] = $ e -> getMessage ( ) ; } $ response = new Response ( json_encode ( $ sResult ) ) ; $ response -> headers -> set ( 'Content-Type' , 'application/json' ) ; return $ response ; }
|
initiate installation of complete monitoring module
|
6,937
|
public function createAction ( Request $ request ) { $ oRemoteApp = new RemoteApp ( ) ; $ form = $ this -> createCreateForm ( $ oRemoteApp ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ sDomain = $ oRemoteApp -> getDomain ( ) ; if ( substr ( $ sDomain , - 1 , 1 ) !== "/" ) { $ sDomain .= "/" ; $ oRemoteApp -> setDomain ( $ sDomain ) ; } $ sModulePath = $ oRemoteApp -> getApiUrl ( ) ; if ( substr ( $ sModulePath , 0 , 1 ) === "/" ) { $ sModulePath = substr ( $ sModulePath , 1 ) ; $ oRemoteApp -> setApiUrl ( $ sModulePath ) ; } $ oRemoteApp -> save ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'remote_app' ) ) ; } return $ this -> render ( 'SlashworksAppBundle:RemoteApp:new.html.twig' , array ( 'entity' => $ oRemoteApp , 'form' => $ form -> createView ( ) , ) ) ; }
|
Create new remote app
|
6,938
|
public function newAction ( ) { $ oRemoteApp = new RemoteApp ( ) ; $ oRemoteApp -> setApiUrl ( "swControl/" ) ; $ oRemoteApp -> setActivated ( true ) ; $ oRemoteApp -> setIncludelog ( true ) ; $ oRemoteApp -> setNotificationRecipient ( $ this -> getUser ( ) -> getEmail ( ) ) ; $ oRemoteApp -> setNotificationSender ( $ this -> getUser ( ) -> getEmail ( ) ) ; $ oRemoteApp -> setNotificationChange ( true ) ; $ oRemoteApp -> setNotificationError ( true ) ; $ form = $ this -> createCreateForm ( $ oRemoteApp ) ; return $ this -> render ( 'SlashworksAppBundle:RemoteApp:new.html.twig' , array ( 'entity' => $ oRemoteApp , 'form' => $ form -> createView ( ) , ) ) ; }
|
Displays a form to create a new RemoteApp entity .
|
6,939
|
public function updateAction ( Request $ request , $ id ) { $ oRemoteApp = RemoteAppQuery :: create ( ) -> findOneById ( $ id ) ; if ( count ( $ oRemoteApp ) === 0 ) { throw $ this -> createNotFoundException ( 'Unable to find RemoteApp entity.' ) ; } $ deleteForm = $ this -> createDeleteForm ( $ id ) ; $ editForm = $ this -> createEditForm ( $ oRemoteApp ) ; $ editForm -> handleRequest ( $ request ) ; if ( $ editForm -> isValid ( ) ) { $ sDomain = $ oRemoteApp -> getDomain ( ) ; if ( substr ( $ sDomain , - 1 , 1 ) !== "/" ) { $ sDomain .= "/" ; $ oRemoteApp -> setDomain ( $ sDomain ) ; } $ sModulePath = $ oRemoteApp -> getApiUrl ( ) ; if ( substr ( $ sModulePath , 0 , 1 ) === "/" ) { $ sModulePath = substr ( $ sModulePath , 1 ) ; $ oRemoteApp -> setApiUrl ( $ sModulePath ) ; } $ oRemoteApp -> save ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'remote_app' ) ) ; } return $ this -> render ( 'SlashworksAppBundle:RemoteApp:edit.html.twig' , array ( 'entity' => $ oRemoteApp , 'edit_form' => $ editForm -> createView ( ) , 'delete_form' => $ deleteForm -> createView ( ) , ) ) ; }
|
Update existing remote app
|
6,940
|
public function deleteAction ( Request $ request , $ id ) { $ oRemoteApp = RemoteAppQuery :: create ( ) -> findOneById ( $ id ) ; if ( $ oRemoteApp === null ) { throw $ this -> createNotFoundException ( 'Unable to find RemoteApp entity.' ) ; } $ aHistories = RemoteHistoryContaoQuery :: create ( ) -> findByRemoteAppId ( $ oRemoteApp -> getId ( ) ) ; foreach ( $ aHistories as $ oHistory ) { $ oHistory -> delete ( ) ; } $ oRemoteApp -> delete ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'remote_app' ) ) ; }
|
Delete remote app
|
6,941
|
public function lastLogAction ( $ id ) { $ oLog = ApiLogQuery :: create ( ) -> findOneByRemoteAppId ( $ id ) ; $ oRemoteApp = RemoteAppQuery :: create ( ) -> findOneById ( $ id ) ; return $ this -> render ( 'SlashworksAppBundle:RemoteApp:log.html.twig' , array ( 'oLog' => $ oLog , 'remote_app' => $ oRemoteApp , ) ) ; }
|
Shows last api - log entry
|
6,942
|
private function createCreateForm ( RemoteApp $ oRemoteApp ) { $ form = $ this -> createForm ( new RemoteAppType ( ) , $ oRemoteApp , array ( 'action' => $ this -> generateUrl ( 'remote_app_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , 'submit' , array ( 'label' => 'Create' ) ) ; return $ form ; }
|
Creates a form to create a RemoteApp entity .
|
6,943
|
private function prepareName ( $ languageCode ) { foreach ( $ this -> container -> getParameter ( 'chill_main.available_languages' ) as $ lang ) { $ names [ $ lang ] = Intl :: getLanguageBundle ( ) -> getLanguageName ( $ languageCode ) ; } return $ names ; }
|
prepare names for languages
|
6,944
|
public static function send ( $ recipient , $ subject , $ body , $ options = [ ] ) { if ( empty ( self :: $ mailer ) ) { self :: login ( ) ; } if ( ENVIRONMENT != 'production' ) { $ recipient = self :: protect_emailaddress ( $ recipient ) ; if ( isset ( $ options [ 'cc' ] ) ) { $ options [ 'cc' ] = self :: protect_emailaddress ( $ options [ 'cc' ] ) ; } if ( isset ( $ options [ 'bcc' ] ) ) { $ options [ 'bcc' ] = self :: protect_emailaddress ( $ options [ 'bcc' ] ) ; } if ( isset ( $ options [ 'reply_to' ] ) ) { $ options [ 'reply_to' ] = self :: protect_emailaddress ( $ options [ 'reply_to' ] ) ; } $ subject = '[' . ENVIRONMENT . '] ' . $ subject ; } $ sender = [ self :: $ config [ 'from' ] => self :: $ config [ 'name' ] ] ; $ message = new \ Swift_Message ( ) ; $ message -> setFrom ( $ sender ) ; $ message -> setTo ( $ recipient ) ; $ message -> setSubject ( $ subject ) ; $ message -> setBody ( $ body ) ; if ( isset ( $ options [ 'cc' ] ) ) { $ message -> setCc ( $ options [ 'cc' ] ) ; } if ( isset ( $ options [ 'bcc' ] ) ) { $ message -> setBcc ( $ options [ 'bcc' ] ) ; } if ( isset ( $ options [ 'reply_to' ] ) ) { $ message -> setReplyTo ( $ options [ 'reply_to' ] ) ; } if ( isset ( $ options [ 'attachment' ] ) ) { $ attachment = \ Swift_Attachment :: fromPath ( $ options [ 'attachment' ] [ 'path' ] , $ options [ 'attachment' ] [ 'mime' ] ) ; $ message -> attach ( $ attachment ) ; } self :: $ mailer -> send ( $ message ) ; }
|
sends an email directly
|
6,945
|
public static function validate ( $ emailaddress ) { try { $ message = new \ Swift_Message ( ) ; $ message -> setTo ( $ emailaddress ) ; } catch ( \ Swift_RfcComplianceException $ e ) { return false ; } return true ; }
|
check email addresses validity
|
6,946
|
public static function protect_emailaddress ( $ emailaddress , $ catchall_address = null ) { if ( empty ( $ catchall_address ) ) { if ( empty ( self :: $ config ) ) { self :: load_config ( ) ; } $ catchall_address = self :: $ config [ 'from' ] ; } $ recipient_name = null ; if ( is_array ( $ emailaddress ) ) { $ recipient_name = current ( $ emailaddress ) ; $ emailaddress = key ( $ emailaddress ) ; } if ( self :: validate ( $ emailaddress ) == false ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'can not convert invalid email address' ) ; } $ emailaddress_key = preg_replace ( '{[^a-zA-Z0-9_]}' , '_' , $ emailaddress ) ; $ emailaddress = str_replace ( '@' , '+' . $ emailaddress_key . '@' , $ catchall_address ) ; if ( $ recipient_name ) { $ emailaddress = array ( $ emailaddress => $ recipient_name ) ; } return $ emailaddress ; }
|
protect email addresses from going to real people on non - production environments
|
6,947
|
protected static function load_config ( $ config = null ) { if ( $ config ) { self :: $ config = $ config ; return ; } $ config_file = ROOT_DIR . 'config/email.ini' ; if ( file_exists ( $ config_file ) == false ) { $ exception = bootstrap :: get_library ( 'exception' ) ; throw new $ exception ( 'no email config found' ) ; } self :: $ config = parse_ini_file ( $ config_file ) ; self :: $ config [ 'pass' ] = base64_decode ( self :: $ config [ 'pass' ] ) ; }
|
collects the config for connecting from a ini file
|
6,948
|
public function header ( $ key , $ value = null ) { $ key = explode ( '-' , $ key ) ; foreach ( $ key as $ k => $ v ) { $ key [ $ k ] = ucfirst ( strtolower ( $ v ) ) ; } $ key = implode ( '-' , $ key ) ; if ( ! is_null ( $ value ) ) { $ this -> _headers [ $ key ] = $ value ; } return $ this -> _headers [ $ key ] ; }
|
header getter and setter
|
6,949
|
public function request ( $ what = 'both' ) { $ ch = curl_init ( $ this -> url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 1 ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , 1 ) ; $ headers = array ( ) ; foreach ( $ this -> _headers as $ key => $ header ) { $ headers [ ] = $ key . ': ' . $ header ; } curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; if ( $ this -> type == static :: post || $ this -> type == static :: put ) { curl_setopt ( $ ch , CURLOPT_POST , 1 ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ post_data ) ; } $ response = curl_exec ( $ ch ) ; if ( $ response === false ) { return false ; } $ header_size = curl_getinfo ( $ ch , CURLINFO_HEADER_SIZE ) ; $ header = substr ( $ response , 0 , $ header_size ) ; $ body = substr ( $ response , $ header_size ) ; curl_close ( $ ch ) ; $ arr_header = array ( ) ; $ header = explode ( "\n" , $ header ) ; foreach ( $ header as $ item ) { $ head_part = explode ( ":" , $ item ) ; if ( $ this -> _normalize_header_keys ) { $ arr_header [ strtolower ( trim ( $ head_part [ 0 ] ) ) ] = trim ( $ head_part [ 1 ] ) ; } else { $ arr_header [ trim ( $ head_part [ 0 ] ) ] = trim ( $ head_part [ 1 ] ) ; } } if ( $ what == 'both' ) { $ return = new \ stdClass ; $ return -> body = $ body ; $ return -> header = $ arr_header ; } elseif ( $ what == 'body' ) { $ return = $ body ; } elseif ( $ what == 'header' ) { $ return = $ arr_header ; } else { throw new CCException ( 'CCHTTP - param 1 in request function is invalid! Allowed are: both, header, body' ) ; } return $ return ; }
|
and finally execute the request
|
6,950
|
protected function isUtcValid ( $ utc , $ now , $ rp ) { if ( 'forever' == $ rp ) { $ nowDate = date ( 'Y-m-d' , strtotime ( $ now ) ) ; if ( strtotime ( $ utc ) >= strtotime ( $ nowDate ) ) { return false ; } } if ( 'years_5' == $ rp ) { $ min = date ( 'i' , strtotime ( $ now ) ) ; $ minutes = $ min > 45 ? 45 : ( $ min > 30 ? 30 : ( $ min > 15 ? 15 : '00' ) ) ; $ nowLimit = date ( 'Y-m-d' , strtotime ( $ now ) ) . "T" . date ( 'H' , strtotime ( $ now ) ) . ":$minutes:00Z" ; if ( strtotime ( $ utc ) >= strtotime ( $ nowLimit ) ) { return false ; } } return true ; }
|
Is valid utc
|
6,951
|
protected function isMetricValid ( $ metric ) { if ( ! isset ( $ metric ) || ! is_array ( $ metric ) || ! isset ( $ metric [ "influx" ] ) || ! isset ( $ metric [ "influx" ] [ "tags" ] ) || ! isset ( $ metric [ "mysql" ] ) || ! isset ( $ metric [ "mysql" ] [ "query" ] ) ) { return false ; } return true ; }
|
Check if metric is valid
|
6,952
|
public function addListener ( EventListener $ listener , $ priority = 0 , $ important = false ) { if ( $ listener === $ this ) { throw new EventException ( "Adding self as listener in 'Events\EventDispatcher' would cause an infinite loop" ) ; } $ priority = - $ priority ; while ( isset ( $ this -> listeners [ $ priority ] ) ) { $ priority += $ important ? - 1 : 1 ; } $ this -> listeners [ $ priority ] = $ listener ; ksort ( $ this -> listeners ) ; $ this -> processStackedEvents ( ) ; return $ this ; }
|
Adds a new listener
|
6,953
|
public function removeListener ( EventListener $ listener ) { if ( ( $ i = array_search ( $ listener , $ this -> listeners ) ) !== false ) { unset ( $ this -> listeners [ $ i ] ) ; } return $ this ; }
|
Removes a listener
|
6,954
|
public function notify ( Event $ event ) { $ processed = false ; foreach ( $ this -> listeners as $ listener ) { if ( $ listener -> match ( $ event ) ) { $ listener -> handle ( $ event ) ; $ processed = true ; if ( $ event -> isPropagationStopped ( ) ) { break ; } } } return $ processed ; }
|
Notifies the listeners of an event
|
6,955
|
public function notifyUntil ( Event $ event , $ callback = null ) { if ( $ this -> notify ( $ event ) ) { if ( $ callback ) { $ callback ( ) ; } return true ; } $ this -> stackedEvents [ ] = array ( $ event , $ callback ) ; return false ; }
|
Notifies the listeners of an event . Won t stop until the event has been handled by a listener .
|
6,956
|
public function getModuleExtension ( ) { if ( null === $ this -> extension ) { $ class = $ this -> getModuleExtensionClass ( ) ; if ( class_exists ( $ class ) ) { $ extension = new $ class ( ) ; $ basename = preg_replace ( '/Module$/' , '' , $ this -> getName ( ) ) ; $ expectedAlias = Container :: underscore ( $ basename ) ; if ( $ expectedAlias != $ extension -> getAlias ( ) ) { throw new \ LogicException ( sprintf ( 'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.' , $ expectedAlias , $ extension -> getAlias ( ) ) ) ; } $ this -> extension = $ extension ; } else { $ this -> extension = false ; } } if ( $ this -> extension ) { return $ this -> extension ; } }
|
Returns the module s extension .
|
6,957
|
public function registerTemplatesPathTwig ( MVC $ mvc ) { $ viewsPath = $ this -> getPath ( ) . '/Resources/views' ; if ( file_exists ( dirname ( $ viewsPath ) ) && file_exists ( $ viewsPath ) ) { $ mvc -> getCvpp ( 'twig.loader.filesystem' ) -> addPath ( $ viewsPath ) ; } }
|
Register Templates Path Twig
|
6,958
|
public function _MergeExpansionNode ( NodeBase $ objNewNode ) { if ( ! $ objNewNode || empty ( $ objNewNode -> objChildNodeArray ) ) { return ; } if ( $ objNewNode -> strName != $ this -> strName ) { throw new Caller ( 'Expansion node tables must match.' ) ; } if ( ! $ this -> objChildNodeArray ) { $ this -> objChildNodeArray = $ objNewNode -> objChildNodeArray ; } else { $ objChildNode = reset ( $ objNewNode -> objChildNodeArray ) ; if ( isset ( $ this -> objChildNodeArray [ $ objChildNode -> strAlias ] ) ) { if ( $ objChildNode -> blnExpandAsArray ) { $ this -> objChildNodeArray [ $ objChildNode -> strAlias ] -> blnExpandAsArray = true ; } else { $ this -> objChildNodeArray [ $ objChildNode -> strAlias ] -> _MergeExpansionNode ( $ objChildNode ) ; } } else { $ this -> objChildNodeArray [ $ objChildNode -> strAlias ] = $ objChildNode ; } } }
|
Merges a node tree into this node building the child nodes . The node being received is assumed to be specially built node such that only one child node exists if any and the last node in the chain is designated as array expansion . The goal of all of this is to set up a node chain where intermediate nodes can be designated as being array expansion nodes as well as the leaf nodes .
|
6,959
|
public function putSelectFields ( $ objBuilder , $ strPrefix = null , $ objSelect = null ) { if ( $ strPrefix ) { $ strTableName = $ strPrefix ; $ strAliasPrefix = $ strPrefix . '__' ; } else { $ strTableName = $ this -> strTableName ; $ strAliasPrefix = '' ; } if ( $ objSelect ) { if ( ! $ objSelect -> skipPrimaryKey ( ) && ! $ objBuilder -> Distinct ) { $ strFields = $ this -> primaryKeyFields ( ) ; foreach ( $ strFields as $ strField ) { $ objBuilder -> addSelectItem ( $ strTableName , $ strField , $ strAliasPrefix . $ strField ) ; } } $ objSelect -> addSelectItems ( $ objBuilder , $ strTableName , $ strAliasPrefix ) ; } else { $ strFields = $ this -> fields ( ) ; foreach ( $ strFields as $ strField ) { $ objBuilder -> addSelectItem ( $ strTableName , $ strField , $ strAliasPrefix . $ strField ) ; } } }
|
Puts the Select clause fields for this node into builder .
|
6,960
|
public function getJsonBody ( $ json_options = null ) : array { try { return phore_json_decode ( $ bodyRaw = $ this -> getBody ( ) ) ; } catch ( \ InvalidArgumentException $ e ) { throw new \ InvalidArgumentException ( "Cannot json-decode body: '$bodyRaw'" , 0 , $ e ) ; } }
|
json - decode the body
|
6,961
|
function postNotification ( Notification $ n ) { if ( $ n -> receiverName ) { if ( $ n -> isPrivate ) { return $ this -> manialinkPublisher -> postPrivateNotification ( $ n -> message , $ n -> receiverName ) ; } return $ this -> manialinkPublisher -> postPersonalNotification ( $ n -> message , $ n -> link , $ n -> iconStyle , $ n -> iconSubStyle ) ; } return $ this -> manialinkPublisher -> postPublicNotification ( $ n -> message , $ n -> link , $ n -> iconStyle , $ n -> iconSubStyle ) ; }
|
Please use the other methods which are more robust
|
6,962
|
function postPublicNotification ( Notification $ n ) { return $ this -> manialinkPublisher -> postPublicNotification ( $ n -> message , $ n -> link , $ n -> iconStyle , $ n -> iconSubStyle ) ; }
|
Send a public notification to every player that bookmarked your Manialink .
|
6,963
|
function getLobby ( $ lobbyLogin ) { return $ this -> db -> execute ( 'SELECT * FROM LobbyServers ' . 'WHERE login = %s' , $ this -> db -> quote ( $ lobbyLogin ) ) -> fetchObject ( __NAMESPACE__ . '\Lobby' ) ; }
|
Get lobby information
|
6,964
|
function getMatch ( $ matchId ) { $ match = $ this -> db -> execute ( 'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 ' . 'FROM Matches ' . 'WHERE id = %d ' , $ matchId ) -> fetchObject ( __NAMESPACE__ . '\\Match' ) ; if ( ! $ match ) return false ; $ results = $ this -> db -> execute ( 'SELECT P.login, P.teamId, P.rank, P.state ' . 'FROM Players P ' . 'WHERE P.matchId = %d ' , $ match -> id ) -> fetchArrayOfAssoc ( ) ; foreach ( $ results as $ row ) { $ match -> players [ ] = $ row [ 'login' ] ; $ match -> playersState [ $ row [ 'login' ] ] = $ row [ 'state' ] ; if ( $ row [ 'rank' ] !== null ) { $ match -> ranking [ $ row [ 'rank' ] ] [ ] = $ row [ 'login' ] ; } if ( $ row [ 'teamId' ] === null ) { continue ; } elseif ( ( int ) $ row [ 'teamId' ] === 0 ) { $ match -> team1 [ ] = $ row [ 'login' ] ; } elseif ( ( int ) $ row [ 'teamId' ] === 1 ) { $ match -> team2 [ ] = $ row [ 'login' ] ; } } uksort ( $ match -> ranking , function ( $ k1 , $ k2 ) { if ( $ k1 == 0 ) { return 1 ; } if ( $ k1 > $ k2 ) { return 1 ; } else { return $ k1 == $ k2 ? 0 : - 1 ; } } ) ; return $ match ; }
|
Get matchServer information
|
6,965
|
function getPlayersPlayingCount ( $ lobbyLogin ) { return $ this -> db -> execute ( 'SELECT COUNT(*) ' . 'FROM Players P ' . 'INNER JOIN Matches M ON P.matchId = M.id ' . 'INNER JOIN MatchServers MS ON MS.matchId = M.id ' . 'WHERE M.`state` >= %d AND P.state >= %d ' . 'AND MS.lobbyLogin = %s' , Match :: PREPARED , PlayerInfo :: PLAYER_STATE_CONNECTED , $ this -> db -> quote ( $ lobbyLogin ) ) -> fetchSingleValue ( 0 ) ; }
|
Return the number of match currently played for the lobby
|
6,966
|
function getLiveMatchServersCount ( $ lobbyLogin , $ scriptName , $ titleIdString ) { return $ this -> db -> execute ( 'SELECT COUNT(*) FROM MatchServers ' . 'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() ' . 'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s' , $ this -> db -> quote ( $ lobbyLogin ) , $ this -> db -> quote ( $ scriptName ) , $ this -> db -> quote ( $ titleIdString ) ) -> fetchSingleValue ( 0 ) ; }
|
Get the number of server the lobby can use
|
6,967
|
function getLeaveCount ( $ playerLogin , $ lobbyLogin ) { return $ this -> db -> query ( 'SELECT count(*) FROM Players P ' . 'INNER JOIN Matches M ON P.matchId = M.id ' . 'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s ' . 'AND M.state NOT IN (%s) ' . 'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()' , $ this -> db -> quote ( $ playerLogin ) , implode ( ',' , array ( PlayerInfo :: PLAYER_STATE_NOT_CONNECTED , PlayerInfo :: PLAYER_STATE_QUITTER , PlayerInfo :: PLAYER_STATE_GIVE_UP , PlayerInfo :: PLAYER_STATE_REPLACED ) ) , $ this -> db -> quote ( $ lobbyLogin ) , implode ( ',' , array ( Match :: PLAYER_CANCEL ) ) ) -> fetchSingleValue ( 0 ) ; }
|
Get the number of time the player quit a match for this lobby
|
6,968
|
function countAvailableServer ( $ lobbyLogin , $ scriptName , $ titleIdString ) { return $ this -> db -> execute ( 'SELECT count(MS.login) FROM MatchServers MS ' . 'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s ' . 'AND MS.`state` = %d AND matchId IS NULL ' . 'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() ' , $ this -> db -> quote ( $ lobbyLogin ) , $ this -> db -> quote ( $ scriptName ) , $ this -> db -> quote ( $ titleIdString ) , \ ManiaLivePlugins \ MatchMakingLobby \ Match \ Plugin :: SLEEPING ) -> fetchSingleValue ( null ) ; }
|
Get number of server available to host a match for the lobby
|
6,969
|
function getAverageTimeBetweenMatches ( $ lobbyLogin , $ scriptName , $ titleIdString ) { $ creationTimestamps = $ this -> db -> execute ( 'SELECT UNIX_TIMESTAMP(creationDate) ' . 'FROM Matches m ' . 'WHERE m.lobbyLogin = %s ' . 'AND m.scriptName = %s ' . 'AND m.titleIdString = %s ' . 'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) ' . 'ORDER BY creationDate ASC LIMIT 10' , $ this -> db -> quote ( $ lobbyLogin ) , $ this -> db -> quote ( $ scriptName ) , $ this -> db -> quote ( $ titleIdString ) , implode ( ',' , array ( Match :: PLAYER_CANCEL ) ) ) -> fetchArrayOfSingleValues ( ) ; if ( count ( $ creationTimestamps ) < 2 ) { return - 1 ; } $ sum = 0 ; for ( $ i = 1 ; $ i < count ( $ creationTimestamps ) ; $ i ++ ) { $ sum += $ creationTimestamps [ $ i ] - $ creationTimestamps [ $ i - 1 ] ; } return $ sum / ( count ( $ creationTimestamps ) - 1 ) ; }
|
Get average time between two match . This time is compute with matches over the last hour If there is not anough matches in database it returns - 1
|
6,970
|
function registerMatch ( $ serverLogin , Match $ match , $ scriptName , $ titleIdString , $ lobbyLogin ) { $ this -> db -> execute ( 'BEGIN' ) ; try { $ this -> db -> execute ( 'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) ' . 'VALUES (NOW(), -1, %s, %s, %s, %s)' , $ this -> db -> quote ( $ serverLogin ) , $ this -> db -> quote ( $ scriptName ) , $ this -> db -> quote ( $ titleIdString ) , $ this -> db -> quote ( $ lobbyLogin ) ) ; $ matchId = $ this -> db -> insertID ( ) ; $ this -> updateServerCurrentMatchId ( $ matchId , $ serverLogin , $ scriptName , $ titleIdString ) ; foreach ( $ match -> players as $ player ) { $ this -> addMatchPlayer ( $ matchId , $ player , $ match -> getTeam ( $ player ) ) ; } $ this -> db -> execute ( 'COMMIT' ) ; } catch ( \ Exception $ e ) { $ this -> db -> execute ( 'ROLLBACK' ) ; throw $ e ; } return $ matchId ; }
|
Register a match in database the match Server will use this to ready up
|
6,971
|
function updatePlayerState ( $ playerLogin , $ matchId , $ state ) { $ this -> db -> execute ( 'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d' , $ state , $ this -> db -> quote ( $ playerLogin ) , $ matchId ) ; }
|
Set the new player state
|
6,972
|
function updatePlayerRank ( $ playerLogin , $ matchId , $ rank ) { $ this -> db -> execute ( 'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d' , $ rank , $ this -> db -> quote ( $ playerLogin ) , $ matchId ) ; }
|
Register the player rank on his match
|
6,973
|
function registerMatchServer ( $ serverLogin , $ lobbyLogin , $ state , $ scriptName , $ titleIdString , $ currentMap ) { $ this -> db -> execute ( 'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) ' . 'VALUES(%s, %s, %d, NOW(), %s, %s, %s) ' . 'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)' , $ this -> db -> quote ( $ serverLogin ) , $ this -> db -> quote ( $ lobbyLogin ) , $ state , $ this -> db -> quote ( $ scriptName ) , $ this -> db -> quote ( $ titleIdString ) , $ this -> db -> quote ( $ currentMap ) ) ; }
|
Register a server as match server
|
6,974
|
function registerLobby ( $ lobbyLogin , $ readyPlayersCount , $ connectedPlayersCount , $ serverName , $ backLink ) { $ this -> db -> execute ( 'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) ' . 'ON DUPLICATE KEY UPDATE ' . 'name = VALUES(name), ' . 'backLink = VALUES(backLink), ' . 'readyPlayers = VALUES(readyPlayers), ' . 'connectedPlayers = VALUES(connectedPlayers) ' , $ this -> db -> quote ( $ lobbyLogin ) , $ this -> db -> quote ( $ serverName ) , $ this -> db -> quote ( $ backLink ) , $ readyPlayersCount , $ connectedPlayersCount ) ; }
|
Register a lobby server in the system
|
6,975
|
public function saveAsTempFile ( bool $ deleteTempFile = true ) { if ( $ this -> error != UPLOAD_ERR_OK ) { return false ; } $ tempPath = FileHelper :: getTempFilePath ( $ this -> name ) ; if ( ! $ this -> saveAs ( $ tempPath , $ deleteTempFile ) ) { return false ; } return $ tempPath ; }
|
Saves the uploaded file to a temp location .
|
6,976
|
public function getView ( ) : ViewInterface { if ( null === $ this -> view ) { $ this -> setView ( $ this -> getDefaultView ( ) ) ; } return $ this -> view ; }
|
View getter .
|
6,977
|
public function model ( $ name , $ inject = null ) { $ instance = function ( $ path ) use ( $ inject ) { if ( class_exists ( $ namespace = 'App\\Modules\\' . str_replace ( '/' , '\\' , $ path ) ) ) { return new $ namespace ( $ inject ) ; } } ; if ( strstr ( $ name , '/' ) ) { $ name = explode ( '/' , $ name ) ; return $ instance ( $ name [ 0 ] . '/Models/' . $ name [ 1 ] ) ; } if ( isset ( $ this -> module [ 'name' ] ) ) { if ( $ model = $ instance ( $ this -> module [ 'name' ] . '/Models/' . $ name ) ) { return $ model ; } } return $ instance ( $ name . '/Models/' . $ name ) ; }
|
Get model from it s module and other modules
|
6,978
|
public function getModelCacheKeys ( Cacheable $ model ) { $ cacheKeys = [ implode ( ':' , [ $ model -> getTable ( ) , 'index' ] ) , ] ; if ( ! empty ( $ model -> getPrimaryKeyValue ( ) ) ) { $ cacheKeys [ ] = implode ( ':' , [ $ model -> getTable ( ) , $ model -> getPrimaryKeyValue ( ) ] ) ; } $ this -> addAttributeCacheKeys ( $ cacheKeys , $ model ) ; return $ cacheKeys ; }
|
Get an array of possible cache keys for the given model .
|
6,979
|
public function cacheForget ( Cacheable $ model ) { foreach ( $ this -> getModelCacheKeys ( $ model ) as $ cacheKey ) { Cache :: forget ( $ cacheKey ) ; } return true ; }
|
Attempt to forget items from the cache for a given model .
|
6,980
|
protected function addAttributeCacheKeys ( array & $ cacheKeys , Cacheable $ model ) { foreach ( $ model -> getAttributeCacheKeys ( ) as $ attributeCacheKey ) { $ origAttributeValue = $ this -> getOriginalCacheKeyValue ( $ model , $ attributeCacheKey ) ; $ attributesValues = [ ] ; if ( $ origAttributeValue != null ) { array_push ( $ attributesValues , $ origAttributeValue ) ; } array_push ( $ attributesValues , $ model -> { $ attributeCacheKey } ) ; foreach ( $ attributesValues as $ attributeValue ) { if ( $ attributeValue instanceof Collection ) { $ this -> getCollectionAttributeCacheKeys ( $ cacheKeys , $ model , $ attributeCacheKey , $ attributeValue ) ; } elseif ( is_scalar ( $ attributeValue ) ) { $ cacheKeys [ ] = implode ( ':' , [ $ model -> getTable ( ) , $ attributeCacheKey , $ attributeValue ] ) ; } } } }
|
Add cache keys for each attribute of a given model .
|
6,981
|
protected function getCollectionAttributeCacheKeys ( array & $ cacheKeys , Cacheable $ model , $ attribute , $ collection ) { foreach ( $ collection as $ item ) { if ( isset ( $ item -> id ) ) { $ cacheKeys [ ] = implode ( ':' , [ $ model -> getTable ( ) , $ attribute , $ item -> id ] ) ; } } }
|
Get the attribute cache keys from a collection attribute .
|
6,982
|
protected function getOriginalCacheKeyValue ( Cacheable $ model , $ attributeCacheKey ) { if ( ! $ model instanceof Model ) { return null ; } return empty ( $ model -> getOriginal ( $ attributeCacheKey ) ) ? null : $ model -> getOriginal ( $ attributeCacheKey ) ; }
|
Get original cache key value .
|
6,983
|
public function getName ( ) { $ fqdnClassName = get_class ( $ this ) ; $ className = substr ( $ fqdnClassName , strrpos ( $ fqdnClassName , '\\' ) + 1 ) ; return str_replace ( "Service" , "" , $ className ) ; }
|
Returns base entity name
|
6,984
|
public function findEntities ( Request $ request , $ filters = array ( ) , $ addPagination = false ) { $ options = $ this -> getOptions ( $ request , $ filters , $ addPagination ) ; if ( ! $ addPagination ) { return array ( 'entities' => $ this -> getRepository ( ) -> getEntities ( $ options ) , 'options' => $ options ) ; } $ entities = $ this -> getRepository ( ) -> getPaginatedEntities ( $ options ) ; $ options [ 'elements' ] = $ entities -> count ( ) ; $ options [ 'pages' ] = ( int ) ceil ( $ options [ 'elements' ] / $ options [ 'elementsPerPage' ] ) ; return array ( 'entities' => $ entities , 'options' => $ options ) ; }
|
Returns a list of entities .
|
6,985
|
public function saveEntity ( $ entity ) { if ( ! $ this -> entityManager -> contains ( $ entity ) ) { $ this -> entityManager -> persist ( $ entity ) ; } $ this -> entityManager -> flush ( ) ; return true ; }
|
Saves the entity .
|
6,986
|
public function removeEntity ( $ entity ) { $ this -> entityManager -> remove ( $ entity ) ; $ this -> entityManager -> flush ( ) ; return true ; }
|
Removes the entity .
|
6,987
|
public function removeEntities ( array $ ids ) { foreach ( $ this -> getRepository ( ) -> getEntitiesById ( $ ids ) as $ entity ) { $ this -> entityManager -> remove ( $ entity ) ; } $ this -> entityManager -> flush ( ) ; return true ; }
|
Removes a list of entities .
|
6,988
|
public function getFilters ( Request $ request , $ overrideFilters = array ( ) , $ ignoreSession = false ) { if ( $ ignoreSession ) { return array_replace ( $ this -> getFiltersFromRequest ( $ request ) , $ overrideFilters ) ; } $ filters = array_replace ( $ this -> getFiltersFromSession ( $ request -> getSession ( ) ) , $ this -> getFiltersFromRequest ( $ request ) , $ overrideFilters ) ; $ this -> saveFilters ( $ request -> getSession ( ) , $ filters ) ; return $ filters ; }
|
Returns the current filters for the entity if any .
|
6,989
|
public function getSorting ( Request $ request , $ ignoreSession = false ) { if ( $ ignoreSession ) { return $ this -> getSortingFromRequest ( $ request ) ; } $ sorting = array_replace ( $ this -> getSortingFromSession ( $ request -> getSession ( ) ) , $ this -> getSortingFromRequest ( $ request ) ) ; $ this -> saveSorting ( $ request -> getSession ( ) , $ sorting ) ; return $ sorting ; }
|
Returns the current sorting options for the entity .
|
6,990
|
public function addFilter ( SessionInterface $ session , $ filterName , $ filterValue , $ overwrite = true ) { if ( ! $ overwrite && $ this -> hasFilter ( $ session , $ filterName ) ) { return ; } $ session -> set ( $ this -> getFilterPrefix ( ) . $ filterName , $ filterValue ) ; }
|
Adds a single filter to the session ; set the overwrite flag to false if you want to preserve an already existing value .
|
6,991
|
protected function saveFilters ( SessionInterface $ session , array $ filters ) { $ this -> saveValues ( $ filters , $ this -> getFilterPrefix ( ) , $ session ) ; }
|
Saves the filters inside the session .
|
6,992
|
protected function getFiltersFromRequest ( Request $ request ) { return $ this -> extractValues ( $ this -> getValuesFromRequest ( $ request ) , $ this -> getFilterPrefix ( ) ) ; }
|
Returns the filters from the request .
|
6,993
|
protected function getSortingFromRequest ( Request $ request ) { return $ this -> extractValues ( $ this -> getValuesFromRequest ( $ request ) , $ this -> getSortingPrefix ( ) ) ; }
|
Returns the sorting options from the request .
|
6,994
|
private function getValuesFromRequest ( Request $ request ) { $ values = array_merge ( $ request -> query -> all ( ) , $ request -> request -> all ( ) ) ; $ contentValues = json_decode ( $ request -> getContent ( ) , true ) ; if ( is_array ( $ contentValues ) ) { $ values = array_merge ( $ values , $ contentValues ) ; } return $ values ; }
|
Returns the values of the options from the request .
|
6,995
|
private function extractValues ( array $ values , $ prefix , $ removePrefixFromKeys = true ) { if ( empty ( $ values ) ) { return array ( ) ; } $ validKeys = array_filter ( array_keys ( $ values ) , function ( $ name ) use ( $ prefix ) { return ( 0 === strpos ( $ name , $ prefix ) ) ; } ) ; $ results = array_intersect_key ( $ values , array_flip ( $ validKeys ) ) ; if ( ! $ removePrefixFromKeys ) { return $ results ; } return array_combine ( array_map ( function ( $ key ) use ( $ prefix ) { return str_replace ( $ prefix , '' , $ key ) ; } , array_keys ( $ results ) ) , $ results ) ; }
|
Returns all the key - value pairs from the array whose key has the specified prefix .
|
6,996
|
private function saveValues ( array $ values , $ prefix , SessionInterface $ session ) { foreach ( $ values as $ name => $ value ) { $ session -> set ( $ prefix . $ name , $ value ) ; } }
|
Saves into the session all the key - value pairs from the array adding to their keys the specified prefix .
|
6,997
|
private function removeValues ( $ prefix , SessionInterface $ session ) { foreach ( $ session -> all ( ) as $ key => $ value ) { if ( 0 === strpos ( $ key , $ prefix ) ) { $ session -> remove ( $ key ) ; } } }
|
Removes from the session all the key - value pairs whose key has the specified prefix .
|
6,998
|
public function setCommandTimeout ( $ commandTimeout ) { if ( $ commandTimeout !== null && ! is_numeric ( $ commandTimeout ) ) { throw new InvalidArgumentException ( 'Timeout must be an integer.' ) ; } if ( is_string ( $ commandTimeout ) ) { $ commandTimeout = ( int ) $ commandTimeout ; } $ this -> commandTimeout = $ commandTimeout ; return $ this ; }
|
Set the command timeout .
|
6,999
|
public function setRetryLimit ( $ retryLimit = null ) { if ( ! is_numeric ( $ retryLimit ) && ! is_null ( $ retryLimit ) ) { throw new InvalidArgumentException ( 'Retry limit must be a number or null.' ) ; } if ( is_string ( $ retryLimit ) ) { $ retryLimit = ( int ) $ retryLimit ; } $ this -> retryLimit = $ retryLimit ; return $ this ; }
|
Set the number of times to retry a command if it fails .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.