Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom form field type and user-defined function for it
    text
    copied!<p>This is my first question here, but I hope I will get a lot of help :) So, here's the issue I've faced a few days back.</p> <p>For a project I need a custom form field, which will allow the user to select a numeric range.</p> <p>Example:</p> <pre><code>Number: greater-than 3 and lower-or-equal-than 5 </code></pre> <p>I've managed to create my custom form field type just fine. I've made a custom method into my repository which appends the where clause part and whole thing worked.</p> <p>Recently I needed the very same component on several other places into my project. Now, I hate duplication, so I decided that the logic which modifies the DQL has to reside on a central location. According the features given in Doctrine, this has to be the UDF (user-defined function).</p> <p>I went ahead and tried to implement the UDF, to no avail.</p> <p>I've managed to learn and use the Parser and the Lexer components of the Doctrine ORM package, but it seems to me like this is not enough.</p> <p>To explain in depth, here is the resulting query:</p> <pre><code>SELECT something FROM SomeBundle:Something something WHERE in_range(someProperty, gt, 3, lte, 5) </code></pre> <p>It has to be transformed to:</p> <pre><code>SELECT sometable.* FROM sometable sometable WHERE someProperty &gt; 3 AND someProperty &lt;= 5 </code></pre> <p>I'm fine parsing it, but Doctrine2 requires a condition operator after the UDF, so the syntax should be something like this:</p> <pre><code>SELECT sometable.* FROM sometable sometable WHERE in_range(someProperty, gt, 3, lte, 5) = 1 </code></pre> <p>Using this syntax, one still need to assign values for all the parameters (eg: gt and lte), which will also need a separate function which will track which parameters have been assigned already and which were not. In addition, this solution does not seem to work, as the parser seem to have issues parsing my function arguments :D</p> <p>All I need is simple query modifier.</p> <p>If possible, I would like to achieve better syntax as well. Something like this would be acceptable:</p> <pre><code>someProperty is in_range(gt, 3, lte, 5) </code></pre> <p>Any thoughts? Thanks in advance to all participants!</p> <p><em>P.S According the Doctrine2 site, the UDFs are meant to be used for "implementing vendor specific functions". Perhaps I'm not looking at the right solution for my issue. Any suggestions?</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload