luxifer / doctrine-functions

📚 Set of DQL Function for MySQL
http://luxifer.github.io/doctrine-functions/
MIT License
88 stars 14 forks source link

DayOfYear not working #11

Closed arcovoltaico closed 10 years ago

arcovoltaico commented 10 years ago

As I can't find documentation explaining how to use the functions, I'm not able of running ->andWhere("(DateOfYear(u.birthday)-DateOfYear(:today)) >0")

The error I'm getting is: ClassNotFoundException: Attempted to load class "DateOfYear" from namespace "Luxifer\DQL\Datetime" in /Users/a77/Documents/DEV/UVox Com/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php line 3096. Do you need to "use" it from another namespace?

So which use sentence I need to include on my repository file? Thanks in advance

luxifer commented 10 years ago

Hey, The function loaded is DAYOFYEAR() and not DATEOFYEAR() :wink:

arcovoltaico commented 10 years ago

Still getting an error. [Syntax Error] line 0, col 423: Error: Expected known function, got 'DAYOFYEAR'

luxifer commented 10 years ago

By looking at the issue #10, you didn't register DAYOFYEAR but DATEOFYEAR

arcovoltaico commented 10 years ago

Thanks, I have updated to datetime_functions: date: Luxifer\DQL\Datetime\Date datediff: Luxifer\DQL\Datetime\DateDiff dateofmonth: Luxifer\DQL\Datetime\DateOfMonth dateofweek: Luxifer\DQL\Datetime\DateOfWeek dateofyear: Luxifer\DQL\Datetime\DayOfYear

But still getting the same error while executing ->andWhere("(DAYOFYEAR(u.birthday)-DAYOFYEAR(:today)) >0")

luxifer commented 10 years ago

Please, can you paste the stack trace?

arcovoltaico commented 10 years ago
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
INFO - Matched route "mailing" (parameters: "_controller": "Acme\DemoBundle\Controller\MailingController::sendAction", "_locale": "es", "id": "20", "_route": "mailing")
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
INFO - Populated SecurityContext with an anonymous Token
DEBUG - Notified event "kernel.request" to listener "RaulFraile\Bundle\LadybugBundle\EventListener\LadybugConfigListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
DEBUG - SELECT t0.ID AS ID1, t0.Title AS Title2, t0.Subtitle AS Subtitle3, t0.Date AS Date4, t0.Body AS Body5, t0.Start AS Start6, t0.End AS End7, t0.Released AS Released8, t0.Venue AS Venue9, t0.Type AS Type10, t0.Target AS Target11, t0.Messagestyle AS Messagestyle12 FROM Messages t0 WHERE t0.ID = ? 
Context: ["20"]
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException".
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".
DEBUG - Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException".
CRITICAL - Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Syntax Error] line 0, col 423: Error: Expected known function, got 'DAYOFYEAR'" at /Users/a77/Documents/DEV/UVox Com/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 44 
Context: {"exception":"Object(Doctrine\\ORM\\Query\\QueryException)"}
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "RaulFraile\Bundle\LadybugBundle\EventListener\LadybugConfigListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\Security\Http\Firewall::onKernelFinishRequest".
DEBUG - Listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException" stopped propagation of the event "kernel.exception".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\Firewall\ContextListener::onKernelResponse".
DEBUG - Write SecurityContext in the session
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse".
DEBUG - Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelFinishRequest".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelFinishRequest".
DEBUG - Notified event "kernel.finish_request" to listener "Symfony\Component\Security\Http\Firewall::onKernelFinishRequest".
DEBUG - Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate".
DEBUG - Notified event "kernel.terminate" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelTerminate".
luxifer commented 10 years ago

The DQL seems to not be registered. did you try to load them according to the configuration reference ? http://symfony.com/doc/current/reference/configuration/doctrine.html

luxifer commented 10 years ago

You have an example in the cookbook http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html

arcovoltaico commented 10 years ago

I installed it via composer and then modifying the config.yml. Should I also use the Doctrine only directions on your readme.md?

luxifer commented 10 years ago

No, you have to follow the symfony directive in the documentation of this repo. What I mean is, it seems that your app/config/config.yml is not correct. You have to register the functions you want under the dql node like shown in the readme:

doctrine:
    orm:
        entity_managers:
            default:
                dql:
                    datetime_functions:
                        dayofmonth: Luxifer\DQL\Datetime\DayOfMonth

You must have at least one entity_manager registered.

arcovoltaico commented 10 years ago

Yes I have just tried different things like but no luck

dql: datetime_functions: date: Luxifer\DQL\Datetime\Date datediff: Luxifer\DQL\Datetime\DateDiff dateofmonth: Luxifer\DQL\Datetime\DateOfMonth dateofweek: Luxifer\DQL\Datetime\DateOfWeek dateofyear: Acme\DemoBundle\Luxifer\DQL\Datetime\DayOfYearFunction

arcovoltaico commented 10 years ago

Great, now it’s working it seems. orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true

    dql:
      datetime_functions:
             dayofyear: Luxifer\DQL\Datetime\DayOfYear

Thanks so much for your patience and for your really helpful extension ;) Cheers!

El 06/06/2014, a las 14:26, Florent VIEL notifications@github.com escribió:

doctrine: orm: entity_managers: default: dql: datetime_functions: dayofmonth: Luxifer\DQL\Datetime\DayOfMonth

luxifer commented 10 years ago

You're welcome :wink: Cheers!