idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
29,900
public function getAssetFile ( $ file ) { if ( is_file ( $ file ) ) { return new AssetFile ( $ file ) ; } $ ext = pathinfo ( $ file , PATHINFO_EXTENSION ) ; if ( strpos ( $ file , '@' ) === 0 && ( $ ext == 'js' || $ ext == 'css' ) ) { $ file = $ ext . '/' . substr ( $ file , 1 ) ; } return new AssetFile ( Factory :: public_path ( ) -> file ( $ this -> assetsDirectory . $ file ) ) ; }
GET ASSET FILE
29,901
public function initializeDataSourceManager ( ) { $ dataSources = $ this -> dataSourceObjectBackend -> loadObject ( ) ; if ( ! is_array ( $ dataSources ) ) { $ dataSources = array ( ) ; } $ this -> dataSources = $ dataSources ; }
Initializes the data source manager . The function loads all saved events from the object backend .
29,902
public function addDataSource ( $ interfaceName , $ driver , $ className ) { if ( ! isset ( $ this -> dataSources [ $ interfaceName ] ) || ! is_array ( $ this -> dataSources [ $ interfaceName ] ) ) { $ this -> dataSources [ $ interfaceName ] = array ( ) ; } $ this -> dataSources [ $ interfaceName ] [ $ driver ] = $ className ; $ this -> saveDataSources ( ) ; return true ; }
Adds a data source to the repository
29,903
public function removeDataSource ( $ interfaceName , $ driver , $ className ) { if ( ! isset ( $ this -> dataSources [ $ interfaceName ] [ $ driver ] ) ) { return false ; } unset ( $ this -> dataSources [ $ interfaceName ] [ $ driver ] ) ; $ this -> saveDataSources ( ) ; return true ; }
Removes a data source from the repository
29,904
public function removeDefinition ( $ selector ) { if ( ! isset ( $ this -> definitions [ $ selector ] ) ) { return false ; } unset ( $ this -> definitions [ $ selector ] ) ; return true ; }
Removes a definition
29,905
public function getDataSource ( $ typeClass ) { $ driver = $ this -> getDriver ( $ typeClass ) ; if ( $ driver === false ) { throw new Exception ( 'Cannot find a driver for the given type class "' . $ typeClass . '".' ) ; } $ dataSourceClass = $ this -> searchDataSourceClass ( $ typeClass , $ driver ) ; if ( $ dataSourceClass === false ) { throw new Exception ( 'Cannot find a data source for the given type class "' . $ typeClass . '" (selected driver: "' . $ driver . '").' ) ; } return $ this -> framework -> getInstance ( $ dataSourceClass ) ; }
Returns the data source for the given type class .
29,906
protected function getDriver ( $ typeClass ) { $ bestDriver = false ; $ numberOfParts = 0 ; foreach ( $ this -> definitions as $ selector => $ driver ) { if ( $ selector === '*' || $ selector === $ typeClass ) { $ bestDriver = $ driver ; $ numberOfParts = $ this -> countNumberOfParts ( $ selector ) ; } else if ( substr ( $ selector , - 1 ) === '*' ) { $ selectorWithoutWildcard = substr ( $ selector , 0 , - 1 ) ; if ( strpos ( $ selector , $ selectorWithoutWildcard ) === 0 || $ numberOfParts < $ this -> countNumberOfParts ( $ selector ) ) { $ bestDriver = $ driver ; $ numberOfParts = $ this -> countNumberOfParts ( $ selector ) ; } } } return $ bestDriver ; }
Returns the driver for the given type class or false if no driver is available .
29,907
protected function searchDataSourceClass ( $ typeClass , $ driver ) { if ( isset ( $ this -> dataSources [ $ typeClass ] [ $ driver ] ) ) { return $ this -> dataSources [ $ typeClass ] [ $ driver ] ; } return false ; }
Returns the DataSource class for the given type class and driver
29,908
public function setMaxFilesize ( $ maxFilesize = 'auto' ) { switch ( $ maxFilesize ) { case 'auto' : $ maxFilesize = $ this -> convertToBytes ( ini_get ( 'upload_max_filesize' ) ) ; break ; } $ this -> maxFilesize = $ maxFilesize ; $ this -> setAttribute ( 'filesize' , $ maxFilesize ) ; }
Sets the maximum size in bytes a file is allowed to have .
29,909
public function renderMenu ( $ slug , $ view = 'VinceCmsBundle:Component:menu.html.twig' , array $ parameters = array ( ) ) { $ menu = $ this -> repositories [ 'menu' ] -> findOneBy ( array ( 'slug' => $ slug , 'lvl' => 0 ) ) ; if ( ! $ menu || ! $ menu -> getChildren ( ) -> count ( ) || ( ! $ menu -> isPublished ( ) && ! $ this -> security -> isGranted ( 'ROLE_ADMIN' ) ) ) { return ; } return $ this -> environment -> render ( $ view , array_merge ( array ( 'menu' => $ menu ) , $ parameters ) ) ; }
Render a Menu
29,910
public function renderMeta ( ArticleMeta $ meta ) { $ template = $ this -> environment -> loadTemplate ( 'VinceCmsBundle::meta.html.twig' ) ; $ blockname = str_ireplace ( array ( ':' , '-' ) , array ( '_' , '_' ) , Inflector :: tableize ( $ meta -> getMeta ( ) -> getName ( ) ) ) . '_meta' ; if ( $ template -> hasBlock ( $ blockname ) ) { return $ template -> renderBlock ( $ blockname , array ( 'name' => $ meta -> getMeta ( ) -> getName ( ) , 'contents' => $ meta -> getContents ( ) , ) ) ; } return $ template -> renderBlock ( 'meta' , array ( 'name' => $ meta -> getMeta ( ) -> getName ( ) , 'contents' => $ meta -> getContents ( ) , ) ) ; }
Render a meta
29,911
public function renderMetas ( Article $ article ) { $ html = '' ; foreach ( $ article -> getMetas ( ) as $ meta ) { $ html .= $ this -> renderMeta ( $ meta ) ; } return $ html ; }
Render article metas
29,912
public function renderContents ( Article $ article , $ name ) { $ content = $ article -> getContent ( $ name ) ; return $ content ? $ content -> getContents ( ) : null ; }
Render an Article content
29,913
public function renderBlock ( $ name ) { $ block = $ this -> repositories [ 'block' ] -> findOneBy ( array ( 'name' => $ name ) ) ; if ( ! $ block || ( ! $ block -> isPublished ( ) && ! $ this -> security -> isGranted ( 'ROLE_ADMIN' ) ) ) { return ; } return $ block -> getContents ( ) ; }
Render a Block
29,914
public function cacheSet ( $ key , $ value ) { return $ this -> cache ( ) ? $ this -> cache ( ) -> set ( $ key , $ value ) : null ; }
Set a value for selected key in the selected cache object .
29,915
public function getHandler ( $ node , $ index = - 1 ) { if ( $ node instanceof \ DOMElement ) { return $ this -> getElementHandler ( $ node , $ this , $ index ) ; } elseif ( $ node instanceof \ DOMAttr ) { return $ this -> getAttributeHandler ( $ node , $ this , $ index ) ; } elseif ( $ node instanceof \ DOMNameSpaceNode ) { return new NameSpaceHandler ( $ node , $ this , $ index ) ; } return $ this -> getNodeHandler ( $ node , $ this , $ index ) ; }
Return the matching node handler based on current \ DomNode type
29,916
public function setData ( array $ data , $ expires = 0 , $ path = null , $ domain = null , $ secure = false , $ httponly = false ) { Argument :: i ( ) -> test ( 2 , 'int' ) -> test ( 3 , 'string' , 'null' ) -> test ( 4 , 'string' , 'null' ) -> test ( 5 , 'bool' ) -> test ( 6 , 'bool' ) ; foreach ( $ data as $ key => $ value ) { $ this -> set ( $ key , $ value , $ expires , $ path , $ domain , $ secure , $ httponly ) ; } return $ this ; }
Sets a set of cookies .
29,917
public function setSecure ( $ key , $ data = null , $ expires = 0 , $ path = null , $ domain = null ) { Argument :: i ( ) -> test ( 1 , 'string' ) -> test ( 2 , 'string' , 'numeric' , 'null' ) -> test ( 3 , 'int' ) -> test ( 4 , 'string' , 'null' ) -> test ( 5 , 'string' , 'null' ) ; return $ this -> set ( $ key , $ data , $ expires , $ path , $ domain , true , false ) ; }
Sets a secure cookie .
29,918
public function setSecureData ( array $ data , $ expires = 0 , $ path = null , $ domain = null ) { Argument :: i ( ) -> test ( 2 , 'int' ) -> test ( 3 , 'string' , 'null' ) -> test ( 4 , 'string' , 'null' ) ; $ this -> setData ( $ data , $ expires , $ path , $ domain , true , false ) ; return $ this ; }
Sets a set of secure cookies .
29,919
public static function find ( $ request , $ match ) { $ pag = new Pluf_Paginator ( new User_Role ( ) ) ; $ pag -> list_filters = array ( 'name' , 'code_name' , 'application' ) ; $ search_fields = array ( 'name' , 'code_name' , 'description' , 'application' ) ; $ sort_fields = array ( 'id' , 'name' , 'code_name' , 'application' , 'description' ) ; $ pag -> forced_where = new Pluf_SQL ( 'user_group_id=%s' , array ( $ match [ 'group_id' ] ) ) ; $ pag -> configure ( array ( ) , $ search_fields , $ sort_fields ) ; $ pag -> setFromRequest ( $ request ) ; $ pag -> model_view = 'join_group' ; return $ pag -> render_object ( ) ; }
Returns list of roles of a group . Returned list can be customized with some filter condition and sort .
29,920
public static function get ( $ request , $ match ) { $ group = Pluf_Shortcuts_GetObjectOr404 ( 'User_Group' , $ match [ 'group_id' ] ) ; $ role = new User_Role ( ) ; $ roles = $ role -> getList ( array ( 'view' => 'join_group' , 'filter' => array ( 'user_group_id=' . $ group -> id ) ) ) ; if ( $ roles -> count ( ) == 0 ) { throw new Pluf_Exception_DoesNotExist ( 'Group has not such role' ) ; } return $ roles [ 0 ] ; }
Returns information of a role of a group .
29,921
public static function delete ( $ request , $ match ) { $ group = Pluf_Shortcuts_GetObjectOr404 ( 'User_Group' , $ match [ 'group_id' ] ) ; $ role = Pluf_Shortcuts_GetObjectOr404 ( 'User_Role' , $ match [ 'role_id' ] ) ; $ group -> delAssoc ( $ role ) ; return $ group ; }
Deletes a role from roles of a group .
29,922
public function isAllowed ( RequestInterface $ uri ) { if ( preg_match ( sprintf ( '#^%s$#' , $ this -> regexp ) , $ uri -> getUri ( ) -> getPath ( ) ) ) { if ( isset ( $ this -> assertion ) ) { $ assertion = $ this -> assertion ; return $ assertion ( ) ; } else { return true ; } } return true ; }
Check if the guard applies to the request then apply the assigned assertion .
29,923
public function load ( ) : ResponseInterface { if ( false === mb_strpos ( $ this -> file , '://' ) ) { if ( ! is_file ( $ this -> file ) ) { throw new Exception ( 'The given local file [' . $ this -> file . '] is not a file' , Exception :: LOCAL_FILE_NOT_READABLE ) ; } if ( ! is_readable ( $ this -> file ) ) { throw new Exception ( 'The given local file [' . $ this -> file . '] is not readable' , Exception :: LOCAL_FILE_NOT_READABLE ) ; } } $ stream = fopen ( $ this -> file , 'rb' , false ) ; if ( false === $ stream ) { throw new Exception ( 'could not read content from the given local file [' . $ this -> file . ']' , Exception :: LOCAL_FILE_NOT_READABLE ) ; } return new Response ( 200 , [ ] , new Stream ( $ stream ) ) ; }
loads the ini file from a remote or local location and stores it into the cache dir parses the ini file
29,924
protected function getAdapter ( ) { $ type = strtolower ( $ this -> options [ 'type' ] ) ; if ( ! $ this -> adapter ) { if ( $ this -> options [ 'class' ] ) { $ adapterClass = $ this -> options [ 'class' ] ; } else { $ adapterClass = '\\Wslim\\Security\\Crypt\\' . ucfirst ( $ type ) . 'Adapter' ; } if ( ! class_exists ( $ adapterClass ) ) { throw new Exception ( 'crypt type is not exists: ' . $ type . ' .' ) ; } $ this -> adapter = new $ adapterClass ( ) ; } return $ this -> adapter ; }
get adapter object
29,925
public function orderInlineEditAction ( Request $ request ) { $ value = $ request -> get ( 'value' ) ; $ manager = $ this -> getDoctrine ( ) -> getManager ( ) ; $ repo = $ manager -> getRepository ( 'LibrinfoEcommerceBundle:Order' ) ; $ order = $ repo -> find ( $ request -> get ( 'id' ) ) ; $ propertyAccessor = new PropertyAccessor ( ) ; $ propertyAccessor -> setValue ( $ order , $ request -> get ( 'field' ) , $ value ) ; $ manager -> persist ( $ order ) ; $ manager -> flush ( ) ; return new JsonResponse ( $ value ) ; }
Edit order field .
29,926
public function addToOrderAction ( Request $ request ) { return new JsonResponse ( $ this -> container -> get ( 'librinfo_ecommerce.order.item_updater' ) -> updateItemCount ( $ request -> get ( 'order' ) , $ request -> get ( 'item' ) , true ) ) ; }
Increase order item quantity .
29,927
public function removeFromOrderAction ( Request $ request ) { $ updater = $ this -> container -> get ( 'librinfo_ecommerce.order.item_updater' ) ; $ result = $ updater -> updateItemCount ( $ request -> get ( 'order' ) , $ request -> get ( 'item' ) , false ) ; if ( $ result [ 'lastItem' ] != null ) { $ result [ 'message' ] = $ this -> container -> get ( 'translator' ) -> trans ( 'There must be at least one item left in the order' ) ; } return new JsonResponse ( $ result ) ; }
Decrease order item quantity .
29,928
public function child ( $ name ) { $ file = $ this -> getChild ( $ name ) ; if ( is_dir ( $ file ) ) { return new static ( $ file ) ; } if ( is_file ( $ file ) ) { return new File ( $ file ) ; } return false ; }
GET FILE BY NAME IN THIS DIRECTORY
29,929
public function addFile ( $ name , $ data ) { $ file = new File ( $ this -> getChild ( $ name ) ) ; $ file -> write ( $ data ) ; return $ file ; }
ADD FILE IN DIRECTORY
29,930
public function deleteFile ( $ arg ) { foreach ( func_get_args ( ) as $ name ) { ( new File ( $ this -> getChild ( $ name ) ) ) -> delete ( ) ; } return true ; }
DELETE FILES IN CHILDREN
29,931
public function deleteDirectory ( $ arg ) { foreach ( func_get_args ( ) as $ name ) { ( new static ( $ this -> fullName . '/' . $ name ) ) -> delete ( ) ; } return true ; }
DELETE DIRECTORIES IN CHILDREN
29,932
public function addDirectory ( $ name , $ mode = 0777 ) { if ( is_null ( $ name ) ) { return $ this ; } $ dir = $ this -> getChild ( $ name ) ; if ( ! is_dir ( $ dir ) ) { mkdir ( $ dir , $ mode ) ; } return new Directory ( $ dir ) ; }
ADD DIRECTORY IN DIRECTORY
29,933
public function move ( $ file ) { $ result = true ; $ this -> map ( function ( FileObject $ item ) use ( & $ result , $ file ) { $ result = $ result && $ item -> move ( $ file . '/' . $ item -> getName ( ) ) ; } ) ; return $ result ; }
MOVE TO DIRECTORY
29,934
public function getServersNames ( ) { $ response = array ( ) ; foreach ( $ this -> configuration [ 'connections' ] as $ serverId => $ configuration ) { $ response [ $ serverId ] = $ configuration [ 'name' ] ; } return $ response ; }
Get List of Available Servers
29,935
public function getServerConfiguration ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return array ( ) ; } $ configuration = $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'config' ] ; if ( $ this -> configuration [ 'cache' ] [ 'enabled' ] ) { $ configuration = array_replace_recursive ( $ configuration , $ this -> getConnectorConfigurationFromCache ( $ serverId ) ) ; } return $ configuration ; }
Get Connector Configuration for a Specified Server
29,936
public function getWebserviceId ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'id' ] ; }
Get Webservice Id for a Specified Server
29,937
public function getWebserviceKey ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'key' ] ; }
Get Webservice Key for a Specified Server
29,938
public function getWebserviceHost ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'host' ] ; }
Get Webservice Host for a Specified Server
29,939
public function getServerName ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'name' ] ; }
Get Public Name for a Specified Server
29,940
public function getServerHost ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'server_host' ] ; }
Get Override Host Name for a Specified Server
29,941
public function getConnectorName ( string $ serverId ) { if ( ! $ this -> hasServerConfiguration ( $ serverId ) ) { return null ; } return $ this -> configuration [ 'connections' ] [ $ serverId ] [ 'connector' ] ; }
Get Connector Service Name for a Specified Server
29,942
public function hasWebserviceConfiguration ( string $ webServiceId ) { foreach ( $ this -> configuration [ 'connections' ] as $ serverId => $ configuration ) { if ( $ configuration [ 'id' ] == $ webServiceId ) { return $ serverId ; } } return false ; }
Check if Connector Exists for this WebService Id
29,943
public function getConnectorConfigurations ( string $ connectorName ) { $ response = array ( ) ; foreach ( $ this -> configuration [ 'connections' ] as $ serverId => $ configuration ) { if ( $ configuration [ 'connector' ] != $ connectorName ) { continue ; } $ response [ $ serverId ] = $ configuration ; if ( $ this -> configuration [ 'cache' ] [ 'enabled' ] ) { $ response [ $ serverId ] = array_replace_recursive ( $ configuration , $ this -> getConnectorConfigurationFromCache ( $ serverId ) ) ; } } return $ response ; }
Return List of Servers Using a Connector
29,944
public function onUpdateEvent ( UpdateConfigurationEvent $ event ) { if ( ! $ this -> configuration [ 'cache' ] [ 'enabled' ] ) { Splash :: log ( ) -> war ( '[Splash] Cache is Disabled' ) ; return ; } if ( ! isset ( $ this -> cache ) ) { $ this -> cache = new FilesystemCache ( ) ; } $ serverId = $ this -> hasWebserviceConfiguration ( $ event -> getWebserviceId ( ) ) ; if ( $ serverId ) { $ this -> cache -> set ( static :: $ cacheCfgKey . $ serverId , $ event -> getConfiguration ( ) , $ this -> configuration [ 'cache' ] [ 'lifetime' ] ) ; } $ event -> stopPropagation ( ) ; }
On Connector Configuration Update Event
29,945
protected function getConnectorConfigurationFromCache ( string $ serverId ) { if ( ! $ this -> configuration [ 'cache' ] [ 'enabled' ] ) { return array ( ) ; } if ( ! isset ( $ this -> cache ) ) { $ this -> cache = new FilesystemCache ( ) ; } if ( ! $ this -> cache -> has ( static :: $ cacheCfgKey . $ serverId ) ) { return array ( ) ; } return $ this -> cache -> get ( static :: $ cacheCfgKey . $ serverId ) ; }
Fetch Connector Configuration from System Cache
29,946
protected function getCoreParameter ( $ key , $ default = null , $ domain = null ) { if ( $ domain ) { return isset ( $ this -> configuration [ $ domain ] [ $ key ] ) ? $ this -> configuration [ $ domain ] [ $ key ] : $ default ; } return isset ( $ this -> configuration [ $ key ] ) ? $ this -> configuration [ $ key ] : $ default ; }
Safe Get of A Global Parameter
29,947
public function normalize ( UserAttribute $ userAttribute , UserAttributeValue $ userAttributeValue = null ) { if ( $ userAttributeValue ) { $ originalAttributeValue = $ userAttributeValue -> getValue ( ) ; } else { $ originalAttributeValue = null ; } $ value = [ ] ; $ value [ 'view' ] = $ originalAttributeValue ; if ( $ originalAttributeValue ) { if ( $ userAttribute -> isTranslateable ( ) ) { $ value [ 'view' ] = $ this -> translator -> trans ( $ value [ 'view' ] ) ; } $ printFormat = $ userAttribute -> getPrintFormat ( ) ; if ( $ printFormat ) { $ value [ 'view' ] = $ this -> renderValue ( $ printFormat , [ 'value' => $ value [ 'view' ] , ] ) ; } } $ value [ 'edit' ] = $ originalAttributeValue ; $ normalizedAttributes = [ 'name' => $ userAttribute -> getName ( ) , 'label' => $ this -> translator -> trans ( $ userAttribute -> getName ( ) ) , 'description' => $ this -> translator -> trans ( $ userAttribute -> getDescription ( ) ) , 'type' => $ userAttribute -> getType ( ) , 'value' => $ value , ] ; return $ normalizedAttributes ; }
Get list of user attributes as array
29,948
private function renderValue ( $ printFormat , array $ variables ) { return str_replace ( array_map ( function ( $ variable ) { return '{{' . $ variable . '}}' ; } , array_keys ( $ variables ) ) , array_values ( $ variables ) , $ printFormat ) ; }
Render variables with passed print format
29,949
public function connect ( $ route , $ callable ) { if ( ! is_string ( $ route ) ) { throw new \ InvalidArgumentException ( "Route to connect to callable musts be provided as a string" ) ; } if ( ! is_callable ( $ callable ) ) { throw new \ InvalidArgumentException ( "Provided callable for $route is not valid." ) ; } $ this -> routes [ $ route ] = $ callable ; }
Connect a route to a callable
29,950
public function find ( $ id ) { if ( is_array ( $ id ) ) { $ keys = array_keys ( $ id ) ; $ identifier = $ keys [ 0 ] ; $ id = $ id [ $ identifier ] ; } else { $ identifier = $ this -> _em -> getMetadataFactory ( ) -> getMetadataFor ( ltrim ( $ this -> _entityName , '\\' ) ) -> identifier [ 0 ] ; } return $ this -> createQueryBuilder ( 'a' ) -> leftJoin ( 'a.metas' , 'm' ) -> addSelect ( 'm' ) -> leftJoin ( 'm.meta' , 'meta' ) -> addSelect ( 'meta' ) -> leftJoin ( 'a.menus' , 'me' ) -> addSelect ( 'me' ) -> leftJoin ( 'a.contents' , 'co' ) -> addSelect ( 'co' ) -> leftJoin ( 'co.area' , 'ar' ) -> addSelect ( 'ar' ) -> leftJoin ( 'a.template' , 't' ) -> addSelect ( 't' ) -> where ( sprintf ( 'a.%s = :id' , $ identifier ) ) -> setParameter ( 'id' , $ id ) -> getQuery ( ) -> getOneOrNullResult ( ) ; }
Find an Article from its identifier
29,951
public function findAllPublishedOrdered ( ) { $ builder = $ this -> createQueryBuilder ( 'a' ) -> orderBy ( 'a.startedAt' , 'DESC' ) ; return $ builder -> where ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'a.startedAt' ) , $ builder -> expr ( ) -> lte ( 'a.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'a.endedAt' ) , $ builder -> expr ( ) -> gte ( 'a.endedAt' , ':now' ) ) ) ) -> setParameters ( array ( 'now' => new \ DateTime ( ) ) ) -> getQuery ( ) -> getResult ( ) ; }
Get all published Articles ordered by start publication date DESC
29,952
public function findAllPublishedIndexableOrdered ( ) { $ builder = $ this -> createQueryBuilder ( 'a' ) -> orderBy ( 'a.startedAt' , 'DESC' ) ; $ builder -> where ( $ builder -> expr ( ) -> andX ( $ builder -> expr ( ) -> isNotNull ( 'a.startedAt' ) , $ builder -> expr ( ) -> lte ( 'a.startedAt' , ':now' ) , $ builder -> expr ( ) -> orX ( $ builder -> expr ( ) -> isNull ( 'a.endedAt' ) , $ builder -> expr ( ) -> gte ( 'a.endedAt' , ':now' ) ) ) ) -> innerJoin ( 'a.metas' , 'm' , Join :: WITH , 'm.contents = :value' ) ; return $ builder -> setParameters ( array ( 'now' => new \ DateTime ( ) , 'value' => 'index,follow' , ) ) -> getQuery ( ) -> getResult ( ) ; }
Get all published Articles ordered by start publication date DESC And with index follow meta
29,953
private function finish ( $ list ) { if ( is_array ( $ list ) || ( $ list instanceof ArrayObject ) ) { foreach ( $ list as $ index => $ item ) { $ list [ $ index ] = $ this -> finish ( $ item ) ; } if ( $ list instanceof ArrayObject ) { $ list = $ list -> getArrayCopy ( ) ; } } elseif ( is_object ( $ list ) ) { $ list -> values = $ this -> finish ( $ list -> values ) ; } return $ list ; }
Finishes by converting ArrayObject to array .
29,954
private function startList ( ) { $ list = new ArrayObject ( ) ; if ( null === ( $ key = $ this -> tokens -> getKey ( ) ) ) { $ this -> current [ ] = $ list ; } else { $ this -> current [ $ key ] = $ list ; } $ this -> stack [ ] = $ this -> current ; $ this -> current = $ list ; }
Begins an array of values .
29,955
protected function apiOffsetLimit ( array $ options = null ) { if ( $ options === null ) { $ options = Input :: all ( ) ; } $ offset = null ; if ( isset ( $ options [ 'offset' ] ) ) { $ offset = ( int ) $ options [ 'offset' ] ; $ offset = $ offset < 0 ? 0 : $ offset ; } $ limit = isset ( $ options [ 'limit' ] ) ? ( int ) $ options [ 'limit' ] : 0 ; if ( $ limit < self :: LIMIT_MIN ) { $ limit = self :: LIMIT_DEFAULT ; } elseif ( $ limit > self :: LIMIT_MAX ) { $ limit = self :: LIMIT_MAX ; } if ( $ offset === null && isset ( $ options [ 'page' ] ) ) { $ offset = ( ( int ) $ options [ 'page' ] - 1 ) * $ limit ; $ offset = $ offset < 0 ? 0 : $ offset ; } $ offset ? : 0 ; return array ( $ offset , $ limit ) ; }
Get the offset and limit to apply .
29,956
public function loadPresenter ( $ presenterClassName ) { if ( ! class_exists ( $ presenterClassName ) || ! is_subclass_of ( $ presenterClassName , 'Subbly\\Presenter\\Presenter' ) ) { return ; } $ this -> presenter = call_user_func ( array ( $ presenterClassName , 'create' ) , array ( 'params' => $ this -> getParams ( ) , ) ) ; }
Load the presenter .
29,957
public function processAuthentication ( $ route , $ request ) { if ( \ App :: isDownForMaintenance ( ) ) { return $ this -> jsonErrorResponse ( "We're currently down for maintenance." , 503 ) ; } $ user = null ; try { $ credentials = array ( 'login' => Request :: server ( 'PHP_AUTH_USER' ) , 'password' => Request :: server ( 'PHP_AUTH_PW' ) , ) ; $ user = Subbly :: api ( 'subbly.user' ) -> authenticate ( $ credentials , false ) ; } catch ( \ Exception $ e ) { if ( in_array ( get_class ( $ e ) , array ( 'Cartalyst\\Sentry\\Users\\UserNotActivatedException' , 'Cartalyst\\Sentry\\Users\\UserSuspendedException' , 'Cartalyst\\Sentry\\Users\\UserBannedException' , ) ) ) { return $ this -> jsonErrorResponse ( $ e -> getMessage ( ) ) ; } elseif ( in_array ( get_class ( $ e ) , array ( 'Cartalyst\\Sentry\\Users\\LoginRequiredException' , 'Cartalyst\\Sentry\\Users\\PasswordRequiredException' , 'Cartalyst\\Sentry\\Users\\WrongPasswordException' , 'Cartalyst\\Sentry\\Users\\UserNotFoundException' , ) ) ) { $ httpHeaders = Request :: ajax ( ) ? array ( ) : array ( 'WWW-Authenticate' => 'Basic realm="Subbly authentication"' ) ; return $ this -> jsonErrorResponse ( 'Auth required! Something is wrong with your credentials.' , 401 , $ httpHeaders ) ; } return $ this -> jsonErrorResponse ( 'FATAL ERROR!' , 500 ) ; } if ( ! $ user instanceof User || ! $ user -> hasAccess ( 'subbly.backend.auth' ) ) { return $ this -> jsonErrorResponse ( 'Access refused! You have not the premission to access this page.' , 401 ) ; } }
Controller filter to process to the authentication .
29,958
protected function jsonResponse ( $ data = null , array $ headers = array ( ) , array $ httpHeaders = array ( ) ) { $ headers = array_replace_recursive ( array ( 'status' => array ( 'code' => 200 , 'message' => 'OK' , ) , 'version' => 'v1' , ) , $ headers ) ; $ data = array ( 'headers' => $ headers , 'response' => $ data , ) ; if ( Config :: get ( 'app.debug' , false ) && Input :: get ( 'debug' , false ) == true ) { $ data [ 'debug' ] = $ this -> debugDatas ( ) ; } $ response = Response :: make ( json_encode ( $ data ) , $ headers [ 'status' ] [ 'code' ] ) ; foreach ( $ httpHeaders as $ k => $ v ) { $ response -> header ( $ k , $ v ) ; } $ response -> header ( 'Content-Type' , 'application/json' ) -> setEtag ( md5 ( json_encode ( $ data ) ) ) ; return $ response ; }
Format a json Response .
29,959
public function jsonCollectionResponse ( $ key , Collection $ collection , array $ extras = array ( ) ) { $ key = is_string ( $ key ) ? $ key : 'entries' ; if ( $ this -> presenter instanceof Presenter ) { $ entries = $ this -> presenter -> collection ( $ collection ) ; } return $ this -> jsonResponse ( array_replace ( $ extras , array ( $ key => isset ( $ entries ) ? $ entries : $ collection , 'offset' => $ collection -> offset ( ) , 'limit' => $ collection -> limit ( ) , 'total' => $ collection -> total ( ) , ) ) ) ; }
Format a json collection Response .
29,960
protected function jsonErrorResponse ( $ errorMessage , $ statusCode = 400 , array $ httpHeaders = array ( ) ) { $ statusTexts = \ Symfony \ Component \ HttpFoundation \ Response :: $ statusTexts ; return $ this -> jsonResponse ( array ( 'error' => ( string ) $ errorMessage , ) , array ( 'status' => array ( 'code' => ( int ) $ statusCode , 'message' => $ statusTexts [ $ statusCode ] , ) , ) , $ httpHeaders ) ; }
Format a json error Response .
29,961
public function read ( $ type , $ uuid ) { switch ( $ type ) { case 'contact' : $ type = 'contacts' ; break ; case 'flow' : $ type = 'flows' ; break ; case 'flow_property' : $ type = 'flowproperties' ; break ; case 'process' : $ type = 'processes' ; break ; case 'source' : $ type = 'sources' ; break ; case 'unit_group' : $ type = 'unitgroups' ; break ; } $ this -> setXml ( file_get_contents ( $ this -> dataRootDir . $ type . '/' . $ uuid . '?format=xml' ) ) ; }
Read the file and provide the content
29,962
public function getContactList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/contacts/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 'c:' , 'sapi:' , 'mm:' ) , '' , $ xmlString ) ; $ contacts = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ contacts as $ contact ) { $ result [ ( string ) $ contact -> uuid ] = ( string ) $ contact -> name ; } return $ result ; }
Retrieve the Contact List
29,963
public function getFlowList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/flows/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 'p:' , 'sapi:' , 'mm:' ) , '' , $ xmlString ) ; $ flows = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ flows as $ flow ) { $ result [ ( string ) $ flow -> uuid ] = ( string ) $ flow -> name ; } return $ result ; }
Retrieve the Flow List
29,964
public function getFlowPropertyList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/flowproperties/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 'p:' , 'sapi:' , 'mm:' ) , '' , $ xmlString ) ; $ flowProperties = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ flowProperties as $ flowProperty ) { $ result [ ( string ) $ flowProperty -> uuid ] = ( string ) $ flowProperty -> name ; } return $ result ; }
Retrieve the FlowProperty List
29,965
public function getProcessList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/processes/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 'p:' , 'sapi:' , 'mm:' ) , '' , $ xmlString ) ; $ processes = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ processes as $ process ) { $ result [ ( string ) $ process -> uuid ] = ( string ) $ process -> name ; } return $ result ; }
Retrieve the Process List
29,966
public function getSourceList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/sources/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 's:' , 'sapi:' , 'mm:' , 'xlink:' ) , '' , $ xmlString ) ; $ sources = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ sources as $ source ) { $ result [ ( string ) $ source -> uuid ] = ( string ) $ source -> name ; } return $ result ; }
Retrieve the Source List
29,967
public function getUnitGroupList ( ) { $ url = 'http://www.oekobaudat.de/OEKOBAU.DAT/resource/unitgroups/?pageSize=20000' ; $ xmlString = file_get_contents ( $ url ) ; $ xmlString = str_replace ( array ( 'u:' , 'sapi:' , 'mm:' ) , '' , $ xmlString ) ; $ unitGroups = \ simplexml_load_string ( $ xmlString ) ; $ result = array ( ) ; foreach ( $ unitGroups as $ unitGroup ) { $ result [ ( string ) $ unitGroup -> uuid ] = ( string ) $ unitGroup -> name ; } return $ result ; }
Retrieve the UnitGroup List
29,968
public function directoryLength ( $ directory = '' ) { if ( $ items = glob ( $ this -> rootDir . '/' . trim ( $ directory , '/' ) . '/*' ) ) { return count ( $ items ) ; } return 0 ; }
count directory items
29,969
protected function checkAreaCode ( ) { $ manObj = \ Magento \ Framework \ App \ ObjectManager :: getInstance ( ) ; $ appState = $ manObj -> get ( \ Magento \ Framework \ App \ State :: class ) ; try { $ appState -> getAreaCode ( ) ; } catch ( \ Magento \ Framework \ Exception \ LocalizedException $ e ) { $ areaCode = \ Magento \ Framework \ App \ Area :: AREA_GLOBAL ; $ appState -> setAreaCode ( $ areaCode ) ; $ configLoader = $ manObj -> get ( \ Magento \ Framework \ ObjectManager \ ConfigLoaderInterface :: class ) ; $ config = $ configLoader -> load ( $ areaCode ) ; $ manObj -> configure ( $ config ) ; } }
Check area code in commands that require code to be set .
29,970
protected function execute ( \ Symfony \ Component \ Console \ Input \ InputInterface $ input , \ Symfony \ Component \ Console \ Output \ OutputInterface $ output ) { $ this -> out = $ output ; $ this -> logInfo ( "Command '" . $ this -> getName ( ) . "' is started." ) ; $ this -> conn -> beginTransaction ( ) ; try { $ this -> checkAreaCode ( ) ; $ this -> process ( $ input ) ; $ this -> conn -> commit ( ) ; } catch ( \ Throwable $ e ) { $ this -> logError ( "Command '" . $ this -> getName ( ) . "' failed. Reason: " . $ e -> getMessage ( ) ) ; $ this -> conn -> rollBack ( ) ; } $ this -> logInfo ( "Command '" . $ this -> getName ( ) . "' is completed." ) ; }
Wrap main process function with try - catch & transaction .
29,971
protected function process ( ) { $ this -> result = $ this -> getRequest ( ) -> getResponse ( ) ; $ contentType = $ this -> result -> getContentType ( ) ; if ( preg_match ( '/^\s*(text\/xml|application\/.*xml).*$/' , $ contentType ) ) { $ body = trim ( $ this -> result -> getBody ( true ) ) ; if ( $ body ) { $ xml = new \ SimpleXMLElement ( $ body ) ; $ this -> result = $ xml ; } } if ( preg_match ( '/^\s*(text\/javascript|application\/json|application\/vnd\.rightscale\..*json).*$/' , $ contentType ) ) { $ body = trim ( $ this -> result -> getBody ( true ) ) ; $ this -> result = json_decode ( $ body ) ; } }
Create the result of the command after the request has been completed .
29,972
public static function permissionDirs ( Event $ event ) { $ options = self :: getOptions ( $ event ) ; $ appDir = $ options [ 'ppi-app-dir' ] ; $ logsDir = realpath ( $ appDir ) . '/logs' ; $ cacheDir = realpath ( $ appDir ) . '/cache' ; foreach ( array ( $ logsDir , $ cacheDir ) as $ dir ) { if ( is_dir ( $ dir ) && is_writable ( $ dir ) ) { @ chmod ( $ dir , 0777 ) ; } } }
Apply open writable permissions to logs and cache folders
29,973
function RemoveChannel ( $ idx ) { $ result = array ( ) ; foreach ( $ this -> channels as $ currentIdx => $ channel ) { if ( $ currentIdx != $ idx ) $ result [ ] = $ channel ; } $ this -> channels = $ result ; }
Removes the channel at the specified index position
29,974
private function desoUpdateSql ( $ ar ) { if ( is_array ( $ ar ) && count ( $ ar ) >= 1 ) { foreach ( $ ar as $ filed => $ name ) { if ( $ filed == end ( $ ar ) ) { $ this -> setSql .= $ filed . ' = ' . $ name ; } else { $ this -> setSql .= $ filed . ' = ' . $ name . $ this -> judgeCount ( $ ar ) ; } } } else { $ this -> setSql .= $ ar ; } return $ this -> upSql . $ this -> setSql ; }
desoUpdateSql func is not Prepared statements
29,975
protected function dealDeleteSQL ( $ t , $ w ) { $ this -> delete ( $ t ) ; $ this -> delete .= $ this -> BindWhere ( $ w ) ; return $ this -> delete ; }
deal delete sql function
29,976
protected function __renderIndex ( array $ data ) { $ session = \ Doozr_Loader_Serviceloader :: load ( 'session' ) ; $ fingerprint = $ session -> getIdentifier ( ) ; $ i18nService = \ Doozr_Loader_Serviceloader :: load ( 'i18n' ) ; return $ this -> render ( $ data , $ fingerprint , $ i18nService ) ; }
Renderer for Index .
29,977
protected function beforeAction ( $ actionName ) { if ( ! $ this -> debug ) { InlineCliLogger :: get ( ) -> ignoredClasses = array ( 'mpf\datasources\sql\PDOConnection' ) ; Helper :: get ( ) -> showProgressBar = false ; } return true ; }
You can overwrite this method to add portion of the code to be executed every time before action .
29,978
public function x ( ) { $ file = new \ SplFileObject ( $ this -> storage ( 'finals.all' ) ) ; $ mjdQ = $ this -> mjd ; $ mjd0 = ( int ) substr ( $ file -> getCurrentLine ( ) , 7 , 8 ) ; if ( $ mjdQ < $ mjd0 ) { return false ; } $ p = $ mjdQ - $ mjd0 - 1 ; if ( $ p < static :: INTERP_C && $ p > - static :: INTERP_C ) { $ p = static :: INTERP_C ; } $ ds = [ ] ; for ( $ i = $ p - static :: INTERP_C ; $ i < $ p + static :: INTERP_C ; $ i ++ ) { $ file -> seek ( $ i ) ; $ line = $ file -> getCurrentLine ( ) ; $ mjd = substr ( $ line , 7 , 8 ) ; $ xf = substr ( $ line , 136 , 9 ) ; $ xp = substr ( $ line , 18 , 9 ) ; $ x = trim ( $ xf ) ? $ xf : $ xp ; if ( trim ( $ x ) == '' ) { return false ; } $ ds [ $ i - $ p + static :: INTERP_C ] [ 'x' ] = ( float ) $ mjd ; $ ds [ $ i - $ p + static :: INTERP_C ] [ 'y' ] = ( float ) $ x ; } return $ this -> lagrangeInterp ( $ mjdQ , $ ds ) ; }
Interpolates the celestial pole offset value of x in seconds of arc .
29,979
public function y ( ) { $ file = new \ SplFileObject ( $ this -> storage ( 'finals.all' ) ) ; $ mjdQ = $ this -> mjd ; $ mjd0 = ( int ) substr ( $ file -> getCurrentLine ( ) , 7 , 8 ) ; if ( $ mjdQ < $ mjd0 ) { return false ; } $ p = $ mjdQ - $ mjd0 - 1 ; if ( $ p < static :: INTERP_C && $ p > - static :: INTERP_C ) { $ p = static :: INTERP_C ; } $ ds = [ ] ; for ( $ i = $ p - static :: INTERP_C ; $ i < $ p + static :: INTERP_C ; $ i ++ ) { $ file -> seek ( $ i ) ; $ line = $ file -> getCurrentLine ( ) ; $ mjd = substr ( $ line , 7 , 8 ) ; $ yf = substr ( $ line , 146 , 9 ) ; $ yp = substr ( $ line , 27 , 9 ) ; $ y = trim ( $ yf ) ? $ yf : $ yp ; if ( trim ( $ y ) == '' ) { return false ; } $ ds [ $ i - $ p + static :: INTERP_C ] [ 'x' ] = ( float ) $ mjd ; $ ds [ $ i - $ p + static :: INTERP_C ] [ 'y' ] = ( float ) $ y ; } return $ this -> lagrangeInterp ( $ mjdQ , $ ds ) ; }
Interpolates the celestial pole offset value of y in seconds of arc .
29,980
public function leapSec ( ) { $ file = new \ SplFileObject ( $ this -> storage ( 'tai-utc.dat' ) ) ; $ taiUTC = 0 ; while ( $ file -> valid ( ) ) { $ line = $ file -> getCurrentLine ( ) ; if ( trim ( $ line ) == '' ) { break ; } $ jd = ( float ) substr ( $ line , 17 , 9 ) ; if ( $ jd > $ this -> jd ) { break ; } $ taiUTC = ( float ) substr ( $ line , 38 , 10 ) ; } return $ taiUTC ; }
Finds the number of leap seconds as of the instance s date .
29,981
private function deltaT_lastJD ( ) { $ mLine = count ( file ( $ this -> storage ( 'deltat.data' ) ) ) - 1 ; $ file = new \ SplFileObject ( $ this -> storage ( 'deltat.data' ) ) ; $ file -> seek ( $ mLine ) ; $ line = $ file -> getCurrentLine ( ) ; while ( trim ( $ line ) == '' ) { $ file -> seek ( $ mLine ) ; $ line = $ file -> getCurrentLine ( ) ; $ mLine -- ; } $ mLine -- ; $ file -> seek ( $ mLine ) ; $ line = $ file -> getCurrentLine ( ) ; $ y = ( int ) substr ( $ line , 1 , 4 ) ; $ m = ( int ) substr ( $ line , 6 , 2 ) ; $ d = ( int ) substr ( $ line , 9 , 2 ) ; static :: iauCal2jd ( $ y , $ m , $ d , $ djm0 , $ djm ) ; return $ djm0 + $ djm ; }
Finds the final Julian day count in the deltat . data file
29,982
private function filesExist ( ) { foreach ( static :: FILES as $ file ) { if ( ! file_exists ( $ this -> storage ( $ file ) ) ) { return false ; } } return true ; }
Returns if all needed remote data files defined in FILES exist locally
29,983
private function ftp ( ) { $ servers = static :: SERVERS ; $ ftp ; for ( $ i = 0 ; $ i < count ( $ servers ) ; $ i ++ ) { $ ftpServer = $ servers [ $ i ] [ 'domain' ] ; $ ftp = ftp_connect ( $ ftpServer ) ; if ( $ ftp ) { if ( ftp_login ( $ ftp , 'anonymous' , null ) ) { if ( ftp_chdir ( $ ftp , $ servers [ $ i ] [ 'path' ] ) ) { if ( ftp_pasv ( $ ftp , true ) ) { return $ ftp ; } } } } } throw new \ Exception ( 'Unable to connect to server to download data' ) ; }
Connects to the first available IERS server mirror and returns an FTP connection resource
29,984
private function hoursSinceUpdate ( ) { $ file = $ this -> storage ( '.updated' ) ; if ( ! file_exists ( $ file ) ) { return static :: UPDATE_INTVL_H ; } return ( time ( ) - file_get_contents ( $ file ) ) / 3600 ; }
Returns the number of hours since last updating the local data
29,985
private function lagrangeInterp ( $ x , $ table ) { $ sum = 0 ; for ( $ i = 0 ; $ i < count ( $ table ) ; $ i ++ ) { $ xi = $ table [ $ i ] [ 'x' ] ; $ prod = 1 ; for ( $ j = 0 ; $ j < count ( $ table ) ; $ j ++ ) { if ( $ i != $ j ) { $ xj = $ table [ $ j ] [ 'x' ] ; $ prod *= ( $ x - $ xj ) / ( $ xi - $ xj ) ; } } $ sum += $ table [ $ i ] [ 'y' ] * $ prod ; } return $ sum ; }
Interpolates the y - value at a given x - value within a dataset using the Lagrange interpolation algorithm
29,986
private function log ( $ data ) { $ data = date ( DATE_RSS , time ( ) ) . "\t$data\n" ; file_put_contents ( $ this -> storage ( '.log' ) , $ data , FILE_APPEND ) ; }
Logs activity used for recording remote file updates
29,987
private function storage ( $ file = null ) { $ folder = static :: STORAGE_DIR ; $ path = __DIR__ . "/../../../$folder" ; if ( ! file_exists ( $ path ) ) { mkdir ( $ path ) ; $ this -> initDefaultData ( realpath ( $ path ) ) ; } if ( ! file_exists ( "$path/.gitignore" ) ) { file_put_contents ( "$path/.gitignore" , '*' ) ; } return $ file ? "$path/$file" : "$path" ; }
Returns a file from local storage and creates the directory and initializes default IERS data in the event that it does not exist .
29,988
private function performUpdate ( ) { if ( $ this -> filesExist ( ) ) { if ( $ this -> hoursSinceUpdate ( ) < static :: UPDATE_INTVL_H ) { return false ; } } $ filesUpdated = [ ] ; $ ftp = $ this -> ftp ( ) ; foreach ( static :: FILES as $ file ) { $ lFile = $ this -> storage ( $ file ) ; $ rSize = ftp_size ( $ ftp , $ file ) ; $ lSize = file_exists ( $ lFile ) ? filesize ( $ lFile ) : 0 ; if ( $ lSize != $ rSize ) { ftp_get ( $ ftp , $ lFile , $ file , FTP_ASCII ) ; $ filesUpdated [ ] = $ file ; } } $ this -> setUpdatedNow ( ) ; return $ filesUpdated ; }
Checks if the local files need to be updated and updates them . This occurs if a local file is missing or if the update time interval has been exceeded . While updating local file sizes are compared to remote file sizes and the files are only updated if they differ in size
29,989
private static function iauJd2cal ( $ dj1 , $ dj2 , & $ iy , & $ im , & $ id , & $ fd ) { $ DJMIN = - 68569.5 ; $ DJMAX = 1e9 ; $ jd ; $ l ; $ n ; $ i ; $ k ; $ dj ; $ d1 ; $ d2 ; $ f1 ; $ f2 ; $ f ; $ d ; $ dj = $ dj1 + $ dj2 ; if ( $ dj < $ DJMIN || $ dj > $ DJMAX ) { return - 1 ; } if ( $ dj1 >= $ dj2 ) { $ d1 = $ dj1 ; $ d2 = $ dj2 ; } else { $ d1 = $ dj2 ; $ d2 = $ dj1 ; } $ d2 -= 0.5 ; $ f1 = fmod ( $ d1 , 1.0 ) ; $ f2 = fmod ( $ d2 , 1.0 ) ; $ f = fmod ( $ f1 + $ f2 , 1.0 ) ; if ( $ f < 0.0 ) { $ f += 1.0 ; } $ d = floor ( $ d1 - $ f1 ) + floor ( $ d2 - $ f2 ) + floor ( $ f1 + $ f2 - $ f ) ; $ jd = floor ( $ d ) + 1 ; $ l = $ jd + 68569 ; $ n = intval ( ( 4 * $ l ) / 146097 ) ; $ l -= intval ( ( 146097 * $ n + 3 ) / 4 ) ; $ i = intval ( ( 4000 * ( $ l + 1 ) ) / 1461001 ) ; $ l -= ( ( 1461 * $ i ) / 4 ) - 31 ; $ k = intval ( ( 80 * $ l ) / 2447 ) ; $ id = round ( $ l - ( 2447 * $ k ) / 80 ) ; $ l = intval ( $ k / 11 ) ; $ im = ( int ) ( $ k + 2 - 12 * $ l ) ; $ iy = ( int ) ( 100 * ( $ n - 49 ) + $ i + $ l ) ; $ fd = $ f ; return 0 ; }
Converts a Julian day count to calendar date .
29,990
private static function iauCal2jd ( $ iy , $ im , $ id , & $ djm0 , & $ djm ) { $ j ; $ ly ; $ my ; $ iypmy ; $ IYMIN = - 4799 ; $ mtab = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] ; $ j = 0 ; if ( $ iy < $ IYMIN ) { return - 1 ; } if ( $ im < 1 || $ im > 12 ) { return - 2 ; } $ ly = ( ( $ im == 2 ) && ! ( $ iy % 4 ) && ( $ iy % 100 || ! ( $ iy % 400 ) ) ) ; if ( ( $ id < 1 ) || ( $ id > ( $ mtab [ $ im - 1 ] + $ ly ) ) ) { $ j = - 3 ; } $ my = intval ( ( $ im - 14 ) / 12 ) ; $ iypmy = intval ( $ iy + $ my ) ; $ djm0 = 2400000.5 ; $ djm = ( double ) ( intval ( ( 1461 * ( $ iypmy + 4800 ) ) / 4 ) + intval ( ( 367 * intval ( $ im - 2 - 12 * $ my ) ) / 12 ) - intval ( ( 3 * ( intval ( ( $ iypmy + 4900 ) / 100 ) ) ) / 4 ) + intval ( $ id - 2432076 ) ) ; return $ j ; }
Converts a calendar date to a Julian day count
29,991
public function get ( $ conditions = [ ] , $ requiredField = [ ] , $ page = 0 ) { $ searchParams [ 'index' ] = $ this -> index ; $ searchParams [ 'type' ] = $ this -> type ; $ searchParams [ 'size' ] = $ this -> maxResultsSize ; $ searchParams [ 'from' ] = $ page * $ this -> maxResultsSize ; $ searchParams [ 'body' ] [ 'query' ] [ 'bool' ] [ 'must' ] = [ ] ; $ searchParams [ '_source_exclude' ] = [ 'PAG*' ] ; $ searchParams [ 'body' ] [ 'highlight' ] [ 'order' ] = 'score' ; $ searchParams [ 'body' ] [ 'highlight' ] [ 'fields' ] = [ 'PAGE_*' => [ 'number_of_fragments' => 3 ] , 'PAG_*' => [ 'number_of_fragments' => 3 ] ] ; $ searchParams [ 'body' ] [ 'highlight' ] [ 'pre_tags' ] = [ '<strong>' ] ; $ searchParams [ 'body' ] [ 'highlight' ] [ 'post_tags' ] = [ '</strong>' ] ; foreach ( $ requiredField as $ field ) { $ searchParams [ 'body' ] [ 'query' ] [ 'bool' ] [ 'must' ] [ ] [ 'exists' ] = [ 'field' => $ field ] ; } $ filter = $ this -> makeFilterCondition ( $ conditions ) ; if ( ! empty ( $ filter ) ) $ searchParams [ 'body' ] [ 'query' ] [ 'bool' ] [ 'must' ] [ ] = $ filter ; if ( $ this -> isModel ) return $ this -> model -> hydrateElasticsearchResult ( $ this -> client -> search ( $ searchParams ) ) ; else return $ this -> client -> search ( $ searchParams ) ; }
Search from condition function
29,992
public function cacheAction ( $ filename ) { $ filePath = $ this -> getParameter ( 'kernel.root_dir' ) . '/../var/storage/cache/' . $ filename ; if ( ! file_exists ( $ filePath ) ) { return new Response ( 'File not found.' , 404 ) ; } $ file = file_get_contents ( $ filePath ) ; $ headers = array ( ) ; if ( preg_match ( '/.png$/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'max-age=3600' , 'Content-Type' => 'image/png' , 'Content-Disposition' => 'inline; filename="' . $ filename . '"' , ) ; } elseif ( preg_match ( '/.jpg/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'max-age=3600' , 'Content-Type' => 'image/jpg' , 'Content-Disposition' => 'inline; filename="' . $ filename . '"' , ) ; } elseif ( preg_match ( '/.pdf/' , $ filename ) || preg_match ( '/.xlsx/' , $ filename ) ) { $ headers = array ( 'Cache-Control' => 'private' , 'Content-Type' => mime_content_type ( $ filePath ) , 'Content-length' => filesize ( $ filePath ) , 'Content-Disposition' => 'attachment; filename="' . $ filename . '"' , ) ; } return new Response ( $ file , 200 , $ headers ) ; }
Get the cache file
29,993
public function fileAction ( $ storageId ) { $ fileManager = $ this -> get ( 'beaast.core.manager.file' ) ; $ file = $ fileManager -> findOneBy ( [ 'storageId' => $ storageId ] ) ; if ( ! $ file ) { return new Response ( 'File not found.' , 404 ) ; } $ filePath = $ fileManager -> getFilePath ( $ file ) ; $ headers = array ( ) ; if ( $ file -> getExtension ( ) === 'png' ) { $ headers = array ( 'Content-Type' => 'image/png' , 'Content-Disposition' => 'inline; filename="' . $ file -> getFileName ( ) . '"' , ) ; } elseif ( $ file -> getExtension ( ) === 'jpg' ) { $ headers = array ( 'Content-Type' => 'image/jpg' , 'Content-Disposition' => 'inline; filename="' . $ file -> getFileName ( ) . '"' , ) ; } elseif ( $ file -> getExtension ( ) === 'pdf' || $ file -> getExtension ( ) === 'xlsx' ) { $ headers = array ( 'Cache-Control' => 'private' , 'Content-Type' => $ file -> getMimeType ( ) , 'Content-length' => $ file -> getSize ( ) , 'Content-Disposition' => 'attachment; filename="' . $ file -> getFileName ( ) . '"' , ) ; } return new Response ( file_get_contents ( $ filePath ) , 200 , $ headers ) ; }
Get the storage file
29,994
protected function initAutoloader ( $ service ) { $ autoloaderService = new Doozr_Loader_Autoloader_Spl_Config ( ) ; $ autoloaderService -> _namespace ( 'Doozr_' . $ service ) -> namespaceSeparator ( '_' ) -> addExtension ( 'php' ) -> path ( DOOZR_DOCUMENT_ROOT . 'Service' ) -> description ( 'Doozr\'s ' . $ service . ' service autoloader. Timestamp: ' . time ( ) ) ; $ this -> autoloader = Doozr_Loader_Autoloader_Spl_Facade :: attach ( $ autoloaderService ) ; }
Initialize autoloader for this service .
29,995
public function getJsonResponse ( $ assoc = true ) { Argument :: i ( ) -> test ( 1 , 'bool' ) ; $ this -> meta [ 'response' ] = $ this -> getResponse ( ) ; return json_decode ( $ this -> meta [ 'response' ] , $ assoc ) ; }
Send the curl off and returns the results parsed as JSON
29,996
public function getMeta ( $ key = null ) { Argument :: i ( ) -> test ( 1 , 'string' , 'null' ) ; if ( isset ( $ this -> meta [ $ key ] ) ) { return $ this -> meta [ $ key ] ; } return $ this -> meta ; }
Returns the meta of the last call
29,997
public function getQueryResponse ( ) { $ this -> meta [ 'response' ] = $ this -> getResponse ( ) ; parse_str ( $ this -> meta [ 'response' ] , $ response ) ; return $ response ; }
Send the curl off and returns the results parsed as url query
29,998
protected function addHeaders ( ) { if ( empty ( $ this -> headers ) ) { return $ this ; } $ this -> options [ CURLOPT_HTTPHEADER ] = $ this -> headers ; return $ this ; }
Adds extra headers to the cURL request
29,999
protected function addParameters ( ) { if ( empty ( $ this -> params ) ) { return $ this ; } $ params = http_build_query ( $ this -> params ) ; if ( $ this -> options [ CURLOPT_POST ] ) { $ this -> options [ CURLOPT_POSTFIELDS ] = $ params ; return $ this ; } if ( strpos ( $ this -> options [ CURLOPT_URL ] , '?' ) === false ) { $ params = '?' . $ params ; } else if ( substr ( $ this -> options [ CURLOPT_URL ] , - 1 , 1 ) != '?' ) { $ params = '&' . $ params ; } $ this -> options [ CURLOPT_URL ] .= $ params ; return $ this ; }
Adds extra post parameters to the cURL request