Primary Filter for multi-enum field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • item
    Active Community Member
    • Mar 2017
    • 1476

    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









    If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​
  • yuri
    Member
    • Mar 2014
    • 8442

    #2
    Hi,

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



    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • yuri
      Member
      • Mar 2014
      • 8442

      #3

      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.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment

      • item
        Active Community Member
        • Mar 2017
        • 1476

        #4
        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"
            }
        }
        If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

        Comment

        • esforim
          Active Community Member
          • Jan 2020
          • 2204

          #5
          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.

          Comment

        • emillod
          Active Community Member
          • Apr 2017
          • 1405

          #6
          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

          Comment


          • esforim
            esforim commented
            Editing a comment
            That to create Report isn't it? I'm using to this do Live Filter or Search Filter
        • emillod
          Active Community Member
          • Apr 2017
          • 1405

          #7
          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.

          Comment


          • esforim
            esforim commented
            Editing a comment
            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.
        • SoBeGuy
          Member
          • Jan 2024
          • 62

          #8
          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 )

          Comment

          Working...