Ejemplo n.º 1
0
 public function getRegisteredChain($key, $force_create = false)
 {
     if (isset($this->global_chains[$key])) {
         return $this->global_chains[$key];
     }
     if ($force_create) {
         $chain = QueryChain::getChainByDefinition($this->init_entity, $key);
         $this->registerChain('global', $chain);
         return $chain;
     }
     return false;
 }
Ejemplo n.º 2
0
 public static function appendHrefSelectElements(&$elem, $fList, $entity, $helper_class, &$select, &$runtime)
 {
     // default href assign
     if (empty($elem['href'])) {
         $href = call_user_func(array($helper_class, 'getDefaultElemHref'), $elem, $fList);
         if (!empty($href)) {
             $elem['href'] = $href;
         }
     }
     // user defined or default href
     if (!empty($elem['href'])) {
         $matches = array();
         preg_match_all('/#([a-zA-Z0-9_\\.:\\\\]+)#/', $elem['href']['pattern'], $matches);
         if (!empty($matches[1])) {
             foreach ($matches[1] as $match) {
                 // by default get definition from href
                 $fieldDefinition = $match;
                 $fieldAggr = null;
                 // try to find extended info about href element
                 if (!empty($elem['href']['elements'][$fieldDefinition])) {
                     $fieldDefinition = $elem['href']['elements'][$match]['name'];
                     if (!empty($elem['href']['elements'][$match]['aggr'])) {
                         $fieldAggr = $elem['href']['elements'][$match]['aggr'];
                     } else {
                         // normalize
                         $elem['href']['elements'][$match]['aggr'] = null;
                     }
                 } else {
                     // normalize
                     $elem['href']['elements'][$fieldDefinition] = array('name' => $fieldDefinition, 'aggr' => null);
                 }
                 $fieldAlias = Entity\QueryChain::getAliasByDefinition($entity, $fieldDefinition);
                 // add to select
                 if (empty($fieldAggr) && !in_array($fieldDefinition, $select, true)) {
                     $select[$fieldAlias] = $fieldDefinition;
                 } elseif (!empty($fieldAggr)) {
                     $fieldAlias = $fieldAggr . '_' . $fieldAlias;
                     // add if not exists
                     if (!array_key_exists($fieldAlias, $select)) {
                         // get field object
                         $chain = Entity\QueryChain::getChainByDefinition($entity, $fieldDefinition);
                         $field = $chain->getLastElement()->getValue();
                         // add to select
                         if ($fieldAggr == 'COUNT_DISTINCT') {
                             $runtime[$fieldAlias] = array('data_type' => 'integer', 'expression' => array('COUNT(DISTINCT %s)', $fieldDefinition));
                         } else {
                             $runtime[$fieldAlias] = array('data_type' => call_user_func(array($helper_class, 'getFieldDataType'), $field), 'expression' => array($fieldAggr . '(%s)', $fieldDefinition));
                         }
                         $select[] = $fieldAlias;
                     }
                 }
             }
             // href pattern and elements saved
         }
     }
 }
Ejemplo n.º 3
0
 CReport::appendHrefSelectElements($elem, $fList, $entity, $arParams['REPORT_HELPER_CLASS'], $grcSelect, $runtime);
 if (!empty($elem['href'])) {
     $viewColumns[$num]['href'] = $elem['href'];
 }
 list($alias, $selElem) = CReport::prepareSelectViewElement($elem, $settings['select'], $is_init_entity_aggregated, $fList, $fChainList, $arParams['REPORT_HELPER_CLASS'], $entity);
 if (is_array($selElem) && !empty($selElem['expression'])) {
     $runtime[$alias] = $selElem;
     $grcSelect[] = $alias;
 } else {
     // normal field
     $alias = Entity\QueryChain::getAliasByDefinition($entity, $elem['name']);
     $grcSelect[$alias] = $selElem;
 }
 CReport::rewriteUserShortName($grcSelect, $runtime, $arParams['USER_NAME_FORMAT'], $entity, true);
 // add primary of grc entity field
 $grcChain = Entity\QueryChain::getChainByDefinition($entity, $elem['name']);
 $grc_field = $grcChain->getLastElement()->getValue();
 if (is_array($grc_field)) {
     $grc_field = end($grc_field);
 }
 $grc_primary = end($grc_field->getEntity()->getPrimaryArray());
 $grc_marker = substr($elem['name'], 0, strrpos($elem['name'], '.')) . '.' . $grc_primary;
 $grc_marker_alias = Entity\QueryChain::getAliasByDefinition($entity, $grc_marker);
 $grcSelect[$grc_marker_alias] = $grc_marker;
 // select
 $resultName = $viewColumns[$num]['resultName'];
 $grcData[$resultName] = array();
 $grc_query = new Entity\Query($entity);
 $grc_query->setSelect($grcSelect);
 $grc_query->setFilter($grcFilter);
 foreach ($runtime as $k => $v) {
Ejemplo n.º 4
0
 public function getBuildFromChains()
 {
     if (is_null($this->buildFromChains)) {
         $this->buildFromChains = array();
         foreach ($this->buildFrom as $elem) {
             // validate if build from scalar or expression
             $chain = QueryChain::getChainByDefinition($this->entity, $elem);
             $field = $chain->getLastElement()->getValue();
             if ($field instanceof ScalarField || $field instanceof ExpressionField) {
                 $this->buildFromChains[] = $chain;
             } else {
                 throw new SystemException(sprintf('Expected ScalarField or ExpressionField in `%s` build_from, but `%s` was given.', $this->name, is_object($field) ? get_class($field) . ':' . $field->getName() : gettype($field)));
             }
         }
     }
     return $this->buildFromChains;
 }