• Stars
    star
    316
  • Rank 132,587 (Top 3 %)
  • Language
    PHP
  • License
    Other
  • Created over 10 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cross database doctrine DQL functions for MySQL and PostgreSQL.

Oro Doctrine Extensions

Build Status

Table of Contents

DQL Functions

This library provides a set of Doctrine DQL functions for MySQL and PostgreSQL.

Available functions:

  • DATE(expr) - Extracts the date part of a date or datetime expression.
  • TIME(expr) - Extracts the time portion of the provided expression.
  • TIMESTAMP(expr) - Converts an expression to TIMESTAMP.
  • TIMESTAMPDIFF(unit, datetime_expr1, datetime_expr2) - Returns datetime_expr2 – datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. The unit parameter can take one of the following values: MICROSECOND (microseconds), SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
  • CONVERT_TZ(expr, from_tz, to_tz) - Converts a datetime value expr from the time zone given by from_tz to the time zone given by to_tz and returns the resulting datetime value.
  • DAY(expr) - Returns the day of the month (0-31).
  • DAYOFWEEK(expr) - Returns the weekday index (1 = Sunday, 2 = Monday, …, 7 = Saturday) for a date expression. These index values correspond to the ODBC standard.
  • DAYOFMONTH(expr) - Returns the day of the month for a date expression, in the range 1 to 31, or 0 for dates such as '0000-00-00' or '2008-00-00' that have a zero day part.
  • DAYOFYEAR(expr) - Returns the day of the year (1-366).
  • HOUR(expr) - Returns the hour from the argument.
  • MD5(expr) - Calculates MD5 checksum.
  • MINUTE(expr) - Returns the minute from the argument.
  • MONTH(expr) - Returns the month from the date passed.
  • QUARTER(expr) - Returns the quarter from the date passed.
  • SECOND(expr) - Returns the second from the argument.
  • WEEK(expr) - Returns the week number of the year that the day is in. By ISO 8601, weeks start on Monday and the first week of a year contains January 4 of that year. In other words, the first Thursday of a year is in week 1 of that year.
  • YEAR(expr) - Returns the year from the date passed.
  • POW(expr, power) - Returns the argument raised to the specified power.
  • ROUND(value, ?precision) - Rounds the value to the specified precision (defaults to 0 precision if not specified).
  • CEIL(value) - Returns the value rounded up.
  • SIGN(expr) - Returns the sign of the argument.
  • CAST(expr as type) - Takes an expression of any type and produces a result value of a specified type. Supported types are: char, string, text, date, datetime, time, int, integer, bigint, decimal, boolean, binary.
  • CONCAT_WS - Concatenate all but the first argument. The first argument is used as the separator string.
  • GROUP_CONCAT - Returns a concatenated string. GROUP_CONCAT full syntax:
GROUP_CONCAT([DISTINCT] expr [,expr ...]
            [ORDER BY {unsigned_integer | col_name | expr}
                [ASC | DESC] [,col_name ...]]
            [SEPARATOR str_val])
  • REPLACE(subject, from, to) - Replaces all occurrences of a string from with to within a string subject.
  • DATE_FORMAT(date, format) - Formats the date value according to the format string. The following specifiers may be used in the format string (the % character is required before format specifier characters):
Specifier Description
%a Abbreviated weekday name (Sun..Sat)
%b Abbreviated month name (Jan..Dec)
%c Month, numeric (0..12)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%f Microseconds (000000..999999)
%H Hour (00..23)
%h Hour (01..12)
%I Hour (01..12)
%i Minutes, numeric (00..59)
%j Day of year (001..366)
%k Hour (0..23)
%l Hour (1..12)
%M Month name (January..December)
%m Month, numeric (00..12)
%p AM or PM
%r Time, 12-hour (hh:mm:ss followed by AM or PM)
%S Seconds (00..59)
%s Seconds (00..59)
%T Time, 24-hour (hh:mm:ss)
%W Weekday name (Sunday..Saturday)
%Y Year, numeric, four digits
%y Year, numeric (two digits)
%% A literal % character

Installation

Add the following dependency to your composer.json:

{
    "require": {
        "oro/doctrine-extensions": "^2.0"
    }
}

Registering Functions

Doctrine2

Doctrine2 Documentation: "DQL User Defined Functions"

<?php
$config = new \Doctrine\ORM\Configuration();
$config->addCustomStringFunction('group_concat', 'Oro\ORM\Query\AST\Functions\String\GroupConcat');
$config->addCustomNumericFunction('hour', 'Oro\ORM\Query\AST\Functions\SimpleFunction');
$config->addCustomDatetimeFunction('date', 'Oro\ORM\Query\AST\Functions\SimpleFunction');

$em = EntityManager::create($dbParams, $config);

Symfony

In Symfony you can register functions in config.yml

doctrine:
    orm:
        dql:
            datetime_functions:
                date:           Oro\ORM\Query\AST\Functions\SimpleFunction
                time:           Oro\ORM\Query\AST\Functions\SimpleFunction
                timestamp:      Oro\ORM\Query\AST\Functions\SimpleFunction
                convert_tz:     Oro\ORM\Query\AST\Functions\DateTime\ConvertTz
            numeric_functions:
                timestampdiff:  Oro\ORM\Query\AST\Functions\Numeric\TimestampDiff
                dayofyear:      Oro\ORM\Query\AST\Functions\SimpleFunction
                dayofmonth:     Oro\ORM\Query\AST\Functions\SimpleFunction
                dayofweek:      Oro\ORM\Query\AST\Functions\SimpleFunction
                week:           Oro\ORM\Query\AST\Functions\SimpleFunction
                day:            Oro\ORM\Query\AST\Functions\SimpleFunction
                hour:           Oro\ORM\Query\AST\Functions\SimpleFunction
                minute:         Oro\ORM\Query\AST\Functions\SimpleFunction
                month:          Oro\ORM\Query\AST\Functions\SimpleFunction
                quarter:        Oro\ORM\Query\AST\Functions\SimpleFunction
                second:         Oro\ORM\Query\AST\Functions\SimpleFunction
                year:           Oro\ORM\Query\AST\Functions\SimpleFunction
                sign:           Oro\ORM\Query\AST\Functions\Numeric\Sign
                pow:            Oro\ORM\Query\AST\Functions\Numeric\Pow
                round:          Oro\ORM\Query\AST\Functions\Numeric\Round
                ceil:           Oro\ORM\Query\AST\Functions\SimpleFunction
            string_functions:
                md5:            Oro\ORM\Query\AST\Functions\SimpleFunction
                group_concat:   Oro\ORM\Query\AST\Functions\String\GroupConcat
                concat_ws:      Oro\ORM\Query\AST\Functions\String\ConcatWs
                cast:           Oro\ORM\Query\AST\Functions\Cast
                replace:        Oro\ORM\Query\AST\Functions\String\Replace
                date_format:    Oro\ORM\Query\AST\Functions\String\DateFormat

Laminas Project

In Laminas Project (with DoctrineORMModule) you can register functions in config/autoload/doctrine.global.php

return [
    'doctrine' => [
        'configuration' => [
            'orm_default' => [
                'datetime_functions' => [
                    'date'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'time'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'timestamp'     => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'convert_tz'    => \Oro\ORM\Query\AST\Functions\DateTime\ConvertTz::class,
                ],
                'numeric_functions' => [
                    'timestampdiff' => \Oro\ORM\Query\AST\Functions\Numeric\TimestampDiff::class,
                    'dayofyear'     => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'dayofmonth'    => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'dayofweek'     => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'week'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'day'           => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'hour'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'minute'        => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'month'         => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'quarter'       => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'second'        => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'year'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'sign'          => \Oro\ORM\Query\AST\Functions\Numeric\Sign::class,
                    'pow'           => \Oro\ORM\Query\AST\Functions\Numeric\Pow::class,
                    'round'         => \Oro\ORM\Query\AST\Functions\Numeric\Round::class,
                    'ceil'          => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                ],
                'string_functions'  => [
                    'md5'           => \Oro\ORM\Query\AST\Functions\SimpleFunction::class,
                    'group_concat'  => \Oro\ORM\Query\AST\Functions\String\GroupConcat::class,
                    'cast'          => \Oro\ORM\Query\AST\Functions\Cast::class,
                    'concat_ws'     => \Oro\ORM\Query\AST\Functions\String\ConcatWs::class,
                    'replace'       => \Oro\ORM\Query\AST\Functions\String\Replace::class,
                    'date_format'   => \Oro\ORM\Query\AST\Functions\String\DateFormat::class
                ]
            ]
        ]
    ]
];

Contributing

Architecture

DQL Function Parsing

Most of that functions that require only one ArithmeticPrimary argument may be parsed with Oro\ORM\Query\AST\Functions\SimpleFunction. This class is responsible for parsing a function definition and saving the parsed data to the parameters. It extends Oro\ORM\Query\AST\Functions\AbstractPlatformAwareFunctionNode.

SQL Generation

SQL generation is the responsibility of the platform-specific functions that extend PlatformFunctionNode. AbstractPlatformAwareFunctionNode creates an appropriate instance of a platform function based on the database platform instance name used in the current connection, and the DQL function name.

The naming rule for the platform function classes:

Oro\ORM\Query\AST\Platform\Functions\$platformName\$functionName

Adding a New Platform

To add support of a new platform you just need to create a new folder Oro\ORM\Query\AST\Platform\Functions\$platformName and add implementations of all the required functions there (using the naming rules as specified above).

Adding a New Function

In case when your function is a function with only one ArithmeticPrimary argument you do not need a custom DQL function parser and may use Oro\ORM\Query\AST\Functions\SimpleFunction for this. Then only the platform specific SQL implementation of your function is required.

In case when you are implementing more complex functions like GROUP_CONCAT, both the DQL parser and the SQL implementations are required.

If you want to add a new function to this library feel free to fork it and create a pull request with your implementation. Please remember to update the documentation (this README.md file) with your new function description and add the necessary tests (and/or test fixtures). All new functions MUST be implemented for both supported platforms (MySQL and PostgreSQL).

Field Types

This library also provides the following field types:

  • MoneyType
  • PercentType
  • ObjectType
  • ArrayType

ObjectType and ArrayType use Base64 encoded strings to store values in the database instead of storing serialized strings. For backward compatibility the values that are already stored in the database will be unserialized without Base64 encoding. The new values will be Base64 encoded before saving to the database and Base64 decoded before unserialization.

More Repositories

1

crm-application

OroCRM - an open-source Customer Relationship Management application.
PHP
935
star
2

crm

Main OroCRM package with core functionality.
PHP
648
star
3

platform

Main OroPlatform package with core functionality.
PHP
628
star
4

orocommerce-application

OroCommerce - an open-source Business to Business Commerce platform.
PHP
320
star
5

platform-application

OroPlatform - business application framework that is a backbone of the OroCRM and OroCommerce.
PHP
231
star
6

orocommerce

Main OroCommerce package with core functionality.
PHP
193
star
7

twig-inspector

PHP
48
star
8

documentation

Oro products documentation.
CSS
38
star
9

environment

Please follow https://doc.oroinc.com/backend/setup/dev-environment/ for development environment setup.
Shell
32
star
10

oro-phpstorm-plugin

PhpStorm plugin, enables autocomplete for OroPlatform configuration files.
Java
22
star
11

magento-orocrm-bridge

Magento extension, extends SOAP API for OroCRM integration.
PHP
16
star
12

phpstan-rules

A set of additional PHPStan rules used in Oro products.
PHP
12
star
13

customer-portal

OroCommerce package with customer portal and non authenticated visitor website base features.
PHP
11
star
14

OroMessageQueueBundle

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
9
star
15

OroCRMMailChimpBundle

OroCRM package, integrates marketing functionality with MailChimp.
PHP
9
star
16

magento-orocrm-tracking

Magento extension, enables OroCRM web tracking integration on Magento store.
PHP
8
star
17

trainings

PHP
8
star
18

orocommerce-sample-extensions

Various extension and customization examples referenced in OroCommerce documentation.
PHP
7
star
19

OroCRMMagentoContactUsBundle

[DEPRECATED] This repository is no longer maintained.
PHP
7
star
20

OroCalendarBundle

OroPlatform package, enables system and user calendars management.
PHP
7
star
21

redis-config

OroPlatform package, enables Redis storage support for application cache.
PHP
6
star
22

OroAkeneoBundle

Connector between OroCommerce Enterprise and Akeneo PIM Enterprise
PHP
6
star
23

OroMessageQueueComponent

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
6
star
24

docker-demo

5
star
25

OroCRMZendeskBundle

OroCRM package, integrates cases with ZenDesk tickets.
PHP
5
star
26

maker

PHP
5
star
27

paypal-express

PHP
4
star
28

upgrade

PHP
4
star
29

orocommerce-orocrm

OroCommerce package, integrates customer and sales data with OroCRM.
PHP
4
star
30

OroCRMCallBundle

OroPlatform package, enables calls management.
PHP
4
star
31

OroCRMTaskBundle

OroPlatform package, enables user tasks management.
PHP
3
star
32

OroHealthCheckBundle

PHP
3
star
33

OroCRMDotmailerBundle

OroCRM package, integrates marketing functionality with dotmailer.
PHP
3
star
34

OroEntitySerializedFieldsBundle

OroPlatform package, enables entity extended fields support without updating DB schema.
PHP
3
star
35

OroCRMAbandonedCartBundle

OroCRM package, allows to run MailChimp campaigns for Magento abandoned carts.
PHP
3
star
36

OroCommerceStorefrontStyleGuide

OroCommerce storefront style guide in a Sketch file.
3
star
37

OroLayoutBundle

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
3
star
38

OroCRMMarketingBundle

OroCRM package with marketing features.
PHP
2
star
39

orocloud-training

Repository to store code snippets related to OroCloud training
2
star
40

oauth2-server

PHP
2
star
41

orocrm-magento1-connector

OroCRM connector to Magento 1
PHP
2
star
42

sphinxdoc-integrity-check-ext

Sphinx extension allows to control content of rst document
Python
2
star
43

RequireJSBundle

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
2
star
44

OroInfinitePayBundle

OroCommerce package, integration with InfinitePay payment service.
PHP
2
star
45

OroChainProcessorComponent

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
2
star
46

OroApruveBundle

OroCommerce package, integration with Apruve credit network.
PHP
2
star
47

OroCRMHangoutsCallBundle

OroPlatform package, allows to make calls using Google Hangouts.
JavaScript
1
star
48

zray

Oro Extension for Z-Ray
PHP
1
star
49

json2

JavaScript
1
star
50

commerce-consents

An extension for OroCommerce 2.6 that provides ability to manage various consents (optional and required) to be accepted by the storefront customers during registration, RFQ submission and checkout.
PHP
1
star
51

platform-documentation

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/documentation repository.
CSS
1
star
52

OroWirecardBundle

This repository is no longer maintained!!! OroCommerce package, integration with Wirecard payment provider.
PHP
1
star
53

google-tag-manager

OroCommerce package, adds integration with Google Tag Manager.
PHP
1
star
54

orocommerce-application-de

German localized version of OroCommerce application.
PHP
1
star
55

german-localization

OroCommerce package, enables German localization.
PHP
1
star
56

flotr2

JavaScript
1
star
57

OroLayoutComponent

[DEPRECATED] This repository is no longer maintained. Please use the main https://github.com/oroinc/platform/ repository.
PHP
1
star
58

moment-timezone

Composer package for http://momentjs.com/timezone/ JS library, used by OroPlatform 1.10/1.12
JavaScript
1
star
59

resource-library

Sample code to demonstrate how new web catalog content variant types can be created, organized and used.
PHP
1
star
60

OroAuthorizeNetBundle

OroCommerce package, integration with Authorize.net payment provider.
PHP
1
star
61

OroDpdBundle

OroCommerce package, integration with Dynamic Parcel Distribution service provider.
PHP
1
star