Primary Filter for multi-enum field

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • SoBeGuy
    replied
    Originally posted by yuri

    PHP Code:
    use Espo\Entities\ArrayValue;
    use Espo\ORM\Query\SelectBuilder;
    
    $subQuery = SelectBuilder::create()
        ->select('entityId')
        ->from(ArrayValue::ENTITY_TYPE)
        ->where([
            'entityType' => 'Contact',
            'attribute' => 'cmmTypes',
            'value' => ['1', '6'],
        ])->build();
    
    $queryBuilder->where(['id' => $subQuery]);
    (as of v7.4)
    I tried this and got the following error:

    Code:
    DEBUG: API (21000) SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row; GET /Contact; Route pattern: /{controller}; Route params: Array (     [controller] => Contact     [action] => index )

    Leave a comment:


  • esforim
    commented on 's reply
    Thank you. Guess I just stick with mass file for now. I will grab that DAV extension you recently release though! Been waiting too long.

  • emillod
    replied
    esforim
    You have to create report with proper conditions and then point it in Report Filters settings for specific entity. It'll show up on list of filters. You can go to Report filters and click on rebuild filters to make sure everything is ok.

    Leave a comment:


  • esforim
    commented on 's reply
    That to create Report isn't it? I'm using to this do Live Filter or Search Filter

  • emillod
    replied
    esforim
    if you have a lot of filters i would recommend to use Advanced Pack report filters feature. How to use Report Filters in EspoCRM - YouTube

    Leave a comment:


  • esforim
    commented on 's reply
    emillod if you have free time

  • esforim
    replied
    Hi item,

    I used devCRM/dubas tutorial and create a filter https://www.youtube.com/watch?v=BYllS-6_xdE

    And I'm slowly adding more and more filter, but look like there is many file now. Reaching about 30 php files.

    If there any method to reduce this using the "Class" or some other method, for example one PHP file but each filter use a different filter Class in here.

    Here is an example of the current PHP file:

    Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\CaseObj\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    
    class DocumentID implements Filter
    {
    public function apply(SelectBuilder $queryBuilder): void
    {
    $queryBuilder->where([
    'type=' => ['ID']
    ]);
    }
    }​
    Can we somehow make it like this example:

    Code:
    class DocumentID implements Filter
    {
    public function apply(SelectBuilder $queryBuilder): void
    {
    $queryBuilder->where([
    'type=' => ['ID']
    ]);
    }
    }​
    
    class DocumentInvoice implements Filter
    ...
    'type=' => ['Invoice']
    
    
    class DocumentAgreement implements Filter
    ...
    'type=' => ['Agreement']​
    Is this a dumb idea or it is doable?
    Last edited by esforim; 06-08-2023, 07:50 AM.

    Leave a comment:


  • item
    replied
    Thanks Yuri to point me to the solution .. best regard.
    for other :

    Espo\Custom\Classes\Select\Epidemio\PrimaryFilters \Adult

    PHP Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\Epidemio\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    use Espo\Entities\ArrayValue;
    use Espo\ORM\Query\Part\Condition as Cond;
    use Espo\Core\Select\Where\ConverterFactory;
    use Espo\Entities\User;
    use Espo\Core\Select\Where\ItemBuilder;
    
    
    class Adult implements Filter
    {
        private $converterFactory;
        private $user;
        public function __construct(ConverterFactory $converterFactory, User $user){
            $this->converterFactory = $converterFactory;
            $this->user = $user;
    }
    
        public function apply(SelectBuilder $queryBuilder): void
        {
            $converter = $this->converterFactory->create('Epidemio', $this->user);
            $whereClause = $converter->convert(
                $queryBuilder,
                (new \Espo\Core\Select\Where\ItemBuilder)
                ->setAttribute('target')
                ->setType('arrayAllOf')
                ->setValue(['Adult'])
                ->build()
            );
            $queryBuilder->where($whereClause);
        }
    }
    Espo\Custom\Resources\metadat\selectDefs\Epidemio. json

    PHP Code:
    {
        "primaryFilterClassNameMap": {
            "adult": "Espo\\Custom\\Classes\\Select\\Epidemio\\PrimaryFilters\\Adult"
        },
        "boolFilterClassNameMap": {
            "active": "Espo\\Custom\\Classes\\Select\\Epidemio\\BoolFilters\\Active"
        }
    }

    Leave a comment:


  • yuri
    replied

    PHP Code:
    
    use Espo\Entities\ArrayValue;
    use Espo\ORM\Query\SelectBuilder;
    
                $subQuery = SelectBuilder::create()
                    ->select('entityId')
                    ->from(ArrayValue::ENTITY_TYPE)
                    ->where([
                        'entityType' => 'YourEntityType',
                        'attribute' => 'yourField',
                        'value' => $valueList,
                    ])
                    ->build();
    
                $queryBuilder->where(['id' => $subQuery]);
    (as of v7.4)
    Last edited by yuri; 05-12-2023, 07:19 AM.

    Leave a comment:


  • yuri
    replied
    Hi,

    It's covered here https://forum.espocrm.com/forum/deve...for-multi-enum.



    Leave a comment:


  • item
    started a topic Primary Filter for multi-enum field

    Primary Filter for multi-enum field

    Hello,
    can someone help me with a primary filter on multi-enum field ?
    just the function :
    PHP Code:
    <?php
    
    namespace Espo\Custom\Classes\Select\Epidemio\PrimaryFilters;
    
    use Espo\Core\Select\Primary\Filter;
    use Espo\ORM\Query\SelectBuilder;
    use Espo\ORM\Query\Part\Condition as Cond;
    
    
    class MultiEnumField implements Filter
    {
        public function __construct()
        {
    
        }
    
        public function apply(SelectBuilder $queryBuilder): void
        {
            $queryBuilder->where([
                'MultiEnumField' => ['value1', 'value2'],
            ]);
        }
    }
    If i understand, i need something like item::fromRaw or item converter ?

    it's crazy, we can do this in 3 click with advanced pack report, report filter !

    Thanks









Working...