Set Sage Filter Data

Merge $this->data with $this->incomingData as Sage filters run before -data class filters
15945
final private function __setDataFromFilter()
    {
        if ($this->template === 'app') {
            // Merge all incoming data from app to allow Sage add_filter support
            $this->data = array_merge($this->data, $this->incomingData);
        }
    }
23398
public function setDataByIndex($line, $data)
    {
        $this->data[$line] = $data;
        $this->filteredData = null;
    }
246853
private void initFilter() {
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass);
        Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(getPersistenceUnit());
        EntityType entityType = metaModel.entity(entityClass);

        if (null == filter) {
            List<String> clauses = new ArrayList<String>();
            addDiscriminatorClause(clauses, entityType);
            return;
        }
        WhereClause whereClause = KunderaQueryUtils.getWhereClause(getJpqlExpression());

        KunderaQueryUtils.traverse(whereClause.getConditionalExpression(), metadata, kunderaMetadata, this, false);

        for (Object filterClause : filtersQueue) {

            if (!(filterClause instanceof String)) {
                onTypedParameter(((FilterClause) filterClause));
            }

        }

        addDiscriminatorClause(null, entityType);
    }
770350
public function applyBrowseSettings()
    {
        $this->loadFilterDependencies(false);

        $yesNo = $this->util->getTranslated()->getYesNo();

        $this->set('gaf_class', 'label', $this->_('Filter type'),
                'description', $this->_('Determines what is filtered how.'),
                'multiOptions', $this->filterOptions
                );
        $this->addColumn('COALESCE(gaf_manual_name, gaf_calc_name)', 'gaf_name');
        $this->set('gaf_name', 'label', $this->_('Name'));
        $this->set('gaf_id_order', 'label', $this->_('Order'),
                'description', $this->_('Execution order of the filters, lower numbers are executed first.')
                );
        $this->set('gaf_active', 'label', $this->_('Active'),
                'multiOptions', $yesNo
                );

        $this->addColumn(new \Zend_Db_Expr(
                "(SELECT COUNT(*) FROM gems__track_appointments WHERE gaf_id = gtap_filter_id)"
                ), 'usetrack');
        $this->set('usetrack', 'label', $this->_('Use in track fields'),
                'description', $this->_('The number of uses of this filter in track fields.'),
                'elementClass', 'Exhibitor'
                );
        $this->addColumn(new \Zend_Db_Expr(
                "(SELECT COUNT(*)
                    FROM gems__appointment_filters AS other
                    WHERE gaf_class IN ('AndAppointmentFilter', 'OrAppointmentFilter') AND
                        (
                            gems__appointment_filters.gaf_id = other.gaf_filter_text1 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text2 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text3 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text4
                        )
                )"
                ), 'usefilter');
        $this->set('usefilter', 'label', $this->_('Use in filters'),
                'description', $this->_('The number of uses of this filter in other filters.'),
                'elementClass', 'Exhibitor'
                );


        return $this;
    }
643608
public function setData()
    {
        $args = func_get_args();
        if (count($args) === 1 && is_array($args[0])) {
            $this->data->replace($args[0]);
        } elseif (count($args) === 2) {
            // Ensure original behavior is maintained. DO NOT invoke stored Closures.
            if (is_object($args[1]) && method_exists($args[1], '__invoke')) {
                $this->data->set($args[0], $this->data->protect($args[1]));
            } else {
                $this->data->set($args[0], $args[1]);
            }
        } else {
            throw new \InvalidArgumentException('Cannot set View data with provided arguments. Usage: `View::setData( $key, $value );` or `View::setData([ key => value, ... ]);`');
        }
    }
1047472
def initialize(self, data):
        
        for item in data:
            if hasattr(self, item):
                setattr(self, item, data[item])
977879
protected function putRetainedFilterValuesInSession()
    {
        collect($this->filterHandlers)
            // Only filters sent which are declared "retained"
            ->filter(function($handler, $attribute) {
                return request()->has("filter_$attribute")
                    && $this->isRetainedFilter($handler, $attribute);
            })
            ->each(function($handler, $attribute) {
                // Array case: we store a coma separated string
                // (to be consistent and only store strings on filter session)
                $value = is_array(request()->get("filter_$attribute"))
                    ? implode(",", request()->get("filter_$attribute"))
                    : request()->get("filter_$attribute");

                if(strlen(trim($value)) === 0) {
                    // No value, we have to unset the retained value
                    session()->forget("_sharp_retained_filter_$attribute");

                } else {
                    session()->put(
                        "_sharp_retained_filter_$attribute",
                        $value
                    );
                }
            });

        session()->save();
    }
3053
public function set(): TaxonomyInterface
    {
        if (function_exists('current_filter') && 'init' === $hook = current_filter()) {
            $this->register();
        } else {
            $this->action->add('init', [$this, 'register']);
        }

        return $this;
    }
475616
protected function applyFilters(&$propertyData, array $filterClasses)
    {
        /** @var FilterInterface $filter */
        foreach ($filterClasses as $filterClass => $filterClassArguments) {
            $filter = new $filterClass(...$filterClassArguments);
            $propertyData = $filter->apply($propertyData);
        }
        
        return $propertyData;
    }
742379
protected function initFilters()
    {
        if (!empty($this->filters)) {
            foreach ($this->filters as $name => $handler) {
                $this->addFilter($name, $handler);
            }
        }
    }
1064308
protected function doPreGetData()
    {
        foreach ($this->dataTransformers as $dataTransformer) {
            if ($dataTransformer instanceof PreGetDataTransformerInterface) {
                $dataTransformer->preGetData($this->config);
            }
        }
    }
869419
final private function __setDataFromMethods()
    {
        // Get all public methods from class
        $this->methods = $this->class->getMethods(\ReflectionMethod::IS_PUBLIC);

        // Remove __contruct, __init, __finalize and this class methods from $this->methods
        $this->methods = array_filter($this->methods, function ($method) {
            return
                $method->class !== 'Sober\Controller\Controller' &&
                $method->name !== '__construct' &&
                $method->name !== '__before' &&
                $method->name !== '__after';
        });

        // Get all public static methods from class
        $this->staticMethods = $this->class->getMethods(\ReflectionMethod::IS_STATIC);

        // Remove $this->staticMethods from $this->methods using array_diff
        $this->dataMethods = array_diff($this->methods, $this->staticMethods);

        // Filter the remaining data methods
        $this->dataMethods = array_filter($this->dataMethods, function ($method) {
            return $method = $method->name;
        });

        // For each method convert method name to snake case and add to data[key => value]
        foreach ($this->dataMethods as $method) {
            // Convert method name to snake case
            $var = Utils::convertToSnakeCase($method->name);

            // Add var method name to data[]
            $this->data[$var] = $this->{$method->name}();
        }
    }
305486
public function mergeData($data, $overridePrevious = true)
    {
        $oldData = $this->getData();
        if ($oldData === null) {
            $oldData = [];
        }
        if (is_object($data)) {
            $data = get_object_vars($data);
        }
        $this->setData($overridePrevious ? array_merge($oldData, $data) : array_merge($data, $oldData));
        return $this;
    }
233025
private function loadFilterValues()
    {
        $session = new Session();
        $this->filterValues = $session->get($this->getStorageNamespace());
        // Because entities saved into the session are not currently managed,
        // we retrieve the reference id previously set by the storeFilterValues function
        // to load the expected entity
        foreach($this->filters as $datagridFilter) {
            if ($datagridFilter->getType() instanceof DatagridFilterTypeEntity) {
                if (!empty($this->filterValues[$datagridFilter->getName()])) {
                    $filterOptions = $datagridFilter->getOptions();
                    $this->filterValues[$datagridFilter->getName()] = $this->entityManager->getReference(
                        $filterOptions['class'],
                        $this->filterValues[$datagridFilter->getName()]
                    );
                }
            }
        }
    }
1193973
public function applyDetailSettings()
    {
        $this->loadFilterDependencies(true);

        $yesNo = $this->util->getTranslated()->getYesNo();

        $this->resetOrder();

        $this->set('gaf_class', 'label', $this->_('Filter type'),
                'description', $this->_('Determines what is filtered how.'),
                'multiOptions', $this->filterOptions
                );
        $this->set('gaf_manual_name', 'label', $this->_('Manual name'),
                'description', $this->_('A name for this filter. The calculated name is used otherwise.'));
        $this->set('gaf_calc_name', 'label', $this->_('Calculated name'));
        $this->set('gaf_id_order', 'label', $this->_('Order'),
                'description', $this->_('Execution order of the filters, lower numbers are executed first.')
                );

        // Set the order
        $this->set('gaf_filter_text1');
        $this->set('gaf_filter_text2');
        $this->set('gaf_filter_text3');
        $this->set('gaf_filter_text4');

        $this->set('gaf_active', 'label', $this->_('Active'),
                'multiOptions', $yesNo
                );

        $this->addColumn(new \Zend_Db_Expr(sprintf(
                "(SELECT COALESCE(GROUP_CONCAT(gtr_track_name, '%s', gtap_field_name
                                    ORDER BY gtr_track_name, gtap_id_order SEPARATOR '%s'), '%s')
                    FROM gems__track_appointments INNER JOIN gems__tracks ON gtap_id_track = gtr_id_track
                    WHERE gaf_id = gtap_filter_id)",
                $this->_(': '),
                $this->_('; '),
                $this->_('Not used in tracks')
                )), 'usetrack');
        $this->set('usetrack', 'label', $this->_('Use in track fields'),
                'description', $this->_('The use of this filter in track fields.'),
                'elementClass', 'Exhibitor'
                );
        $this->addColumn(new \Zend_Db_Expr(sprintf(
                "(SELECT COALESCE(GROUP_CONCAT(gaf_calc_name ORDER BY gaf_id_order SEPARATOR '%s'), '%s')
                    FROM gems__appointment_filters AS other
                    WHERE gaf_class IN ('AndAppointmentFilter', 'OrAppointmentFilter') AND
                        (
                            gems__appointment_filters.gaf_id = other.gaf_filter_text1 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text2 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text3 OR
                            gems__appointment_filters.gaf_id = other.gaf_filter_text4
                        )
                )",
                $this->_('; '),
                $this->_('Not used in filters')
                )), 'usefilter');
        $this->set('usefilter', 'label', $this->_('Use in filters'),
                'description', $this->_('The use of this filter in other filters.'),
                'elementClass', 'Exhibitor'
                );

        return $this;
    }
907313
protected function initData()
    {
        if (is_null($this->data) && is_null($this->baseModel)) {
            throw new \ErrorException("Error initialize multiple model input. Base model or data not set");
        }

        $attrPart = explode(']', $this->attribute);
        $this->_realAttribute = $this->attribute; //end($attrPart);

        if (is_null($this->data) && $this->model instanceof Model) {
            $this->data = [];
            foreach ((array)$this->model->{$this->_realAttribute} as $index => $value) {
                $this->data[$index] = [];

                $class = $this->baseModel;
                /** @var ActiveRecord|Model $model */
                $model = new $class($value);

                if (method_exists($model, 'setIsNewRecord')) {
                    $pkName = $model->getPrimaryKey(true);
                    $model->setIsNewRecord(count($pkName) == 0);
                }

                foreach ($model->attributes as $_name => $_value) {
                    $this->data[$index][$_name] = $_value;
                }
            }
        }
    }
308055
public function set()
    {
        // Register term meta on Rest API.
        if (function_exists('current_filter') && 'init' === current_filter()) {
            call_user_func($this->register());
        } else {
            $this->action->add('init', $this->register());
        }

        // Display fields.
        $this->action->add($this->taxonomy->getName().'_add_form_fields', $this->outputAddFields());
        $this->action->add($this->taxonomy->getName().'_edit_form_fields', $this->outputEditFields());

        // Save fields values.
        $this->action->add([
            'create_'.$this->taxonomy->getName(),
            'edit_'.$this->taxonomy->getName()
        ], $this->save());
    }