public function registerChain($section, QueryChain $chain, $opt_key = null) { $alias = $chain->getAlias(); if (isset($this->global_chains[$alias])) { $reg_chain = $this->global_chains[$alias]; } else { $reg_chain = $chain; $def = $reg_chain->getDefinition(); $this->global_chains[$alias] = $chain; $this->global_chains[$def] = $chain; } $storage_name = $section . '_chains'; $this->{$storage_name}[$alias] = $reg_chain; if (!is_null($opt_key)) { $this->{$storage_name}[$opt_key] = $reg_chain; } // get default options from expressions if ($chain->getLastElement()->getValue() instanceof ExpressionField) { $options = $chain->getLastElement()->getValue()->getOptions(); if (!empty($options)) { foreach ($options as $option => $value) { if (!isset($this->options[$option])) { $this->options[$option] = $value; } } } } return $reg_chain; }
protected function collectExprChains(QueryChain $chain, $storages = array('hidden')) { $last_elem = $chain->getLastElement(); $bf_chains = $last_elem->getValue()->getBuildFromChains(); $pre_chain = clone $chain; //$pre_chain->removeLastElement(); foreach ($bf_chains as $bf_chain) { // collect hidden chain $tmp_chain = clone $pre_chain; // exclude init entity $bf_elements = array_slice($bf_chain->getAllElements(), 1); // add elements foreach ($bf_elements as $bf_element) { $tmp_chain->addElement($bf_element); } foreach ($storages as $storage) { $reg_chain = $this->registerChain($storage, $tmp_chain); } // replace "build_from" chain end by registered chain end // actually it's better and more correctly to replace the whole chain $bf_chain->removeLastElement(); $bf_chain->addElement($reg_chain->getLastElement()); // check elements to recursive collect hidden chains foreach ($bf_elements as $bf_element) { if ($bf_element->getValue() instanceof ExpressionField) { $this->collectExprChains($tmp_chain); } } } }