src/searchOld/elastic/Watch.php
private static function prepareStatic($props, $modelId, $workingProps, $index, $type, $languages)
    {
        $res = $valIds = [];
        //leave only applicable properties with according values
        $workingProps = array_intersect_key($workingProps, $props);
        $workingProps = array_flip($workingProps);
        $values = (new Query())->from(StaticValueTranslation::tableName())
            ->select(['model_id', 'language_id', 'name', 'slug'])
            ->where(['model_id' => array_keys($workingProps)])
            ->all();
        $propertyValues = [];
        foreach ($values as $value) {
            if (false === isset($propertyValues[$value['model_id']])) {
                $propId = isset($workingProps[$value['model_id']]) ? $workingProps[$value['model_id']] : null;
                $propKey = isset($props[$propId]) ? $props[$propId] : null;
                $propertyValues[$value['model_id']] = [
                    'static_value_id' => $value['model_id'],
                    'prop_id' => $propId,
                    'prop_key' => $propKey,
                    'value_' . $languages[$value['language_id']] => $value['name'],
                    'slug_' . $languages[$value['language_id']] => $value['slug'],
                ];
            } else {
                $propertyValues[$value['model_id']]['value_' . $languages[$value['language_id']]] = $value['name'];
                $propertyValues[$value['model_id']]['slug_' . $languages[$value['language_id']]] = $value['slug'];
            }
        }
        if (false === empty($propertyValues)) {
            $res['body'][] = ['index' => [
                '_id' => $modelId,
                '_index' => $index,
                '_type' => $type,
            ]];
            $res['body'][] = [
                'model_id' => $modelId,
                Search::STATIC_VALUES_FILED => array_values($propertyValues),
            ];
        }
        return $res;
    }
private static function prepareStatic($props, $modelId, $workingProps, $index, $type, $languages)
    {
        $res = $valIds = [];
        //leave only applicable properties with according values
        $workingProps = array_intersect_key($workingProps, $props);
        $workingProps = array_flip($workingProps);
        $values = (new Query())->from(StaticValueTranslation::tableName())
            ->select(['model_id', 'language_id', 'name', 'slug'])
            ->where(['model_id' => array_keys($workingProps)])
            ->all();
        $propertyValues = [];
        foreach ($values as $value) {
            if (false === isset($propertyValues[$value['model_id']])) {
                $propId = isset($workingProps[$value['model_id']]) ? $workingProps[$value['model_id']] : null;
                $propKey = isset($props[$propId]) ? $props[$propId] : null;
                $propertyValues[$value['model_id']] = [
                    'static_value_id' => $value['model_id'],
                    'prop_id' => $propId,
                    'prop_key' => $propKey,
                    'value_' . $languages[$value['language_id']] => $value['name'],
                    'slug_' . $languages[$value['language_id']] => $value['slug'],
                ];
            } else {
                $propertyValues[$value['model_id']]['value_' . $languages[$value['language_id']]] = $value['name'];
                $propertyValues[$value['model_id']]['slug_' . $languages[$value['language_id']]] = $value['slug'];
            }
        }
        if (false === empty($propertyValues)) {
            $res['body'][] = ['index' => [
                '_id' => $modelId,
                '_index' => $index,
                '_type' => $type,
            ]];
            $res['body'][] = [
                'model_id' => $modelId,
                Search::STATIC_VALUES_FILED => array_values($propertyValues),
            ];
        }
        return $res;
    }
private static function prepareStatic ( $ props , $ modelId , $ workingProps , $ index , $ type , $ languages ) { $ res = $ valIds = [ ] ; //leave only applicable properties with according values $ workingProps = array_intersect_key ( $ workingProps , $ props ) ; $ workingProps = array_flip ( $ workingProps ) ; $ values = ( new Query ( ) ) -> from ( StaticValueTranslation :: tableName ( ) ) -> select ( [ 'model_id' , 'language_id' , 'name' , 'slug' ] ) -> where ( [ 'model_id' => array_keys ( $ workingProps ) ] ) -> all ( ) ; $ propertyValues = [ ] ; foreach ( $ values as $ value ) { if ( false === isset ( $ propertyValues [ $ value [ 'model_id' ] ] ) ) { $ propId = isset ( $ workingProps [ $ value [ 'model_id' ] ] ) ? $ workingProps [ $ value [ 'model_id' ] ] : null ; $ propKey = isset ( $ props [ $ propId ] ) ? $ props [ $ propId ] : null ; $ propertyValues [ $ value [ 'model_id' ] ] = [ 'static_value_id' => $ value [ 'model_id' ] , 'prop_id' => $ propId , 'prop_key' => $ propKey , 'value_' . $ languages [ $ value [ 'language_id' ] ] => $ value [ 'name' ] , 'slug_' . $ languages [ $ value [ 'language_id' ] ] => $ value [ 'slug' ] , ] ; } else { $ propertyValues [ $ value [ 'model_id' ] ] [ 'value_' . $ languages [ $ value [ 'language_id' ] ] ] = $ value [ 'name' ] ; $ propertyValues [ $ value [ 'model_id' ] ] [ 'slug_' . $ languages [ $ value [ 'language_id' ] ] ] = $ value [ 'slug' ] ; } } if ( false === empty ( $ propertyValues ) ) { $ res [ 'body' ] [ ] = [ 'index' => [ '_id' => $ modelId , '_index' => $ index , '_type' => $ type , ] ] ; $ res [ 'body' ] [ ] = [ 'model_id' => $ modelId , Search :: STATIC_VALUES_FILED => array_values ( $ propertyValues ) , ] ; } return $ res ; }
Prepares bulk data to store in elasticsearch index for model properties static values

@param array $props
@param integer $modelId
@param array $workingProps
@param string $index index name i.e.: page
@param string $type index type i.e.: static_values
@param array $languages
@return array
Prepares bulk data to store in elasticsearch index for model properties static values