Listeners and/or Subscribes which listen for sub-properties

Viewed 67

SelectorListInterface represents a list of user-selectable options, and I have multiple concrete classes which implement it (i.e. Industry, ProjectStage, DocumentType).

I also have multiple "parent" entities (i.e. EntityWithSelectorLists1, EntityWithSelectorLists2) which have SelectorListInterface objects as properties.

I wish to have a listener or subscriber listen for all GET/POST/etc requests for parent entities that have properties that implement SelectorListInterface.

Is this possible, or will I need to also add some interface to the parent classes (i.e. HasSelectorListInterface) and listen for that?

Could/should annotations or attributes be used to better implement this?

<?php

#[ORM\Entity]
class EntityWithSelectorLists1
{
    #[ORM\ManyToOne(targetEntity: 'Industry')]
    private SelectorListInterface $industry;

    #[ORM\ManyToOne(targetEntity: 'ProjectStage')]
    private SelectorListInterface $projectStage;
}
#[ORM\Entity]
class EntityWithSelectorLists2
{
    #[ORM\ManyToOne(targetEntity: 'DocumentType')]
    private SelectorListInterface $documentType;

    #[ORM\ManyToOne(targetEntity: 'Industry')]
    private SelectorListInterface $industry;

}

EDIT - Why I wish to do this.

While some of the lists of user-selectable options might be just a few, others can be many, and it is expected that each individual user will typically select the same options each time using the application. Instead of requiring the user to scroll down the list to select their desired choice, I wish to show their common selections at the top. To determine their typical selections, I plan on increasing their preference based on whether they make a request which includes a given list option or they search for records that contain a given option. I haven't thought it totally through, but thinking of using a super-table that is joined to User and sub-tables for each individual list. Somehow duration in the past will need to be taken into account, and will need to use some cron job to daily recalculate each option's weight so that I could query the results without some mathematical formula is the WHERE statement so that indexes could be utilized.

0 Answers
Related