Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Model - customValidator: EntityInterface $model

I cannot see how can i make $model->field object request to be more customizable:

    class DbBetweenValidator extends Validator implements ValidatorInterface
    {
        public function validate(EntityInterface $model)
        {
            $field = $this->getOption('field');

            $newStart   = $this->getOption('startTime');
            $newEnd   = $this->getOption('endTime');

            $value = $model->$field;

The field is an event time and there can be multiple events for a particular day. So i would like to get all event times for a distinct date. Is it possible to do it with object model or i need to use phql or something like that?

Thank you.

What you want to achieve ? If the events are just some related field in day then you can juast access htis field.

edited Apr '16

You can pass whole model in validator options and do what you want with it, but its good from v 2.1, where the model validation is deprecated, UniquenessValidator is using it

    new DbBetweenValidator(
        array(
            "model" => $this,
            ...
        )
    );


6.8k

I want to create one validation class, that will gather all events(their times) for a particular day and compare the new event time with the old ones, to make sure there is no collision between them.

What you want to achieve ? If the events are just some related field in day then you can juast access htis field.



6.9k
Accepted
answer

Use phql to query events which are not the same event as current and have times between interval startTime and endTime. All necessary info you can gather from $model.



6.8k

Yes, this is what i have done exactly. Thank you.