MetaModels\BackendIntegration\InputScreen\InputScreen::transformConditions PHP Method

transformConditions() protected method

Transform the given condition array into real conditions.
protected transformConditions ( array $conditions ) : void
$conditions array The property condition information.
return void
    protected function transformConditions($conditions)
    {
        // First pass, sort them into pid.
        $sorted = array();
        $byPid = array();
        foreach ($conditions as $i => $condition) {
            $sorted[$condition['id']] = $conditions[$i];
            $byPid[$condition['pid']][] = $condition['id'];
        }
        $instances = array();
        // Second pass, handle them.
        foreach ($sorted as $id => $condition) {
            $instances[$id] = $this->transformCondition($condition);
        }
        // Sort all conditions into their parents.
        foreach ($byPid as $pid => $ids) {
            foreach ($ids as $id) {
                $settingId = $sorted[$id]['settingId'];
                if (!isset($this->conditions[$settingId])) {
                    $this->conditions[$settingId] = new PropertyConditionChain();
                }
                $result = $this->conditions[$settingId];
                $condition = $instances[$id];
                $parent = $pid == 0 ? $result : $instances[$pid];
                // TODO: this is better to be done with a new event to sort conditions into their parents as we might
                // have other classes in the future.
                if ($parent instanceof ConditionChainInterface) {
                    $parent->addCondition($condition);
                } elseif ($parent instanceof NotCondition) {
                    $parent->setCondition($condition);
                }
            }
        }
    }