Return attribute values by ajax request.

@param $attributeId
@return string
@throws NotFoundHttpException
761806
public function actionGetAttributeValues($attributeId)
    {
        if (\Yii::$app->request->isAjax) {
            $attributeValues = ShopAttributeValue::find()
                ->where(['attribute_id' => $attributeId])->all();

            $attributeValuesArray = ArrayHelper::toArray($attributeValues, [
                'bl\cms\shop\common\entities\ShopAttributeValue' => [
                    'id',
                    'attribute_id',
                    'translation' => 'translation'
                ]
            ]);

            $shopAttribute = ShopAttribute::findOne($attributeId);
            if ($shopAttribute->type_id == ShopAttribute::TYPE_TEXTURE || $shopAttribute->type_id == ShopAttribute::TYPE_COLOR) {
                $newArray = [];
                foreach ($attributeValuesArray as $attributeValuesItem) {

                    $texture = ShopAttributeValueColorTexture::findOne($attributeValuesItem['translation']['value']);
                    if ($shopAttribute->type_id == ShopAttribute::TYPE_TEXTURE) {
                        $texture = $texture->attributeTexture . Html::tag('p', $texture->title);
                    } else if ($shopAttribute->type_id == ShopAttribute::TYPE_COLOR) {
                        $texture = $texture->attributeColor . Html::tag('p', $texture->title);
                    }

                    $attributeValuesItem['translation'] =
                        array_replace($attributeValuesItem['translation'], ['value' => $texture]);
                    $newArray[] = $attributeValuesItem;
                }
                $attributeValuesArray = $newArray;
            }
            return json_encode($attributeValuesArray);
        } else throw new NotFoundHttpException();
    }
766140
public function find($id, $attributes = ['*'])
    {
        return $this->executeCallback(get_called_class(), __FUNCTION__, func_get_args(), function () use ($id, $attributes) {
            return $this->prepareQuery($this->createModel())->find($id, $attributes);
        });
    }
926695
public function getBasicTagData($tagId)
    {
        $query = $this->handler->createSelectQuery();
        $query
            ->select('*')
            ->from($this->handler->quoteTable('eztags'))
            ->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('id'),
                    $query->bindValue($tagId, null, PDO::PARAM_INT)
                )
            );

        $statement = $query->prepare();
        $statement->execute();

        if ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
            return $row;
        }

        throw new NotFoundException('tag', $tagId);
    }
1034398
private function getAttributeValueAlias($attributeCode, $storeId = null)
    {
        $returnValue = $attributeCode;
        if ($storeId !== null) {
            $returnValue .= '_' . $storeId;
        }
        return $returnValue;
    }
1079572
public function get($ajaxWidgetId)
    {
        $ajaxWidgetId = (int) $ajaxWidgetId;
        if (!isset($this->widgetContexts[$ajaxWidgetId])) {
            throw new WidgetContextNotFoundException('No widget context was found for the Ajax Widget Identifier "' . $ajaxWidgetId . '". This only happens if AJAX URIs are called without including the widget on a page.', 1284793775);
        }
        return $this->widgetContexts[$ajaxWidgetId];
    }
485411
public function getAttributeValuesAction(/** @noinspection PhpUnusedParameterInspection */ $productId, $attributeId)
    {
        $result = array();

        // Get attribute for this product
        $attribute = AttributeQuery::create()->findPk($attributeId);

        if ($attribute !== null) {
            $values = AttributeAvQuery::create()
                ->joinWithI18n($this->getCurrentEditionLocale())
                ->filterByAttribute($attribute)
                ->find();
            ;

            if ($values !== null) {
                /** @var AttributeAv $value */
                foreach ($values as $value) {
                    $result[] = array('id' => $value->getId(), 'title' => $value->getTitle());
                }
            }
        }

        return $this->jsonResponse(json_encode($result));
    }
23371
public function getForFrontend($pageId)
    {
        return $this->find()
            ->contain(['Current', 'Attributes'])
            ->formatResults([$this, 'formatAttributes'])
            ->where([$this->aliasField('id') => $pageId])
            ->first();
    }
1312141
public function getAttributeKeyByID($akID)
    {
        $cache = $this->application->make('cache/request');
        $class = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
        $category = strtolower(substr($class, 0, strpos($class, 'Category')));
        $item = $cache->getItem(sprintf('/attribute/%s/id/%s', $category, $akID));
        if (!$item->isMiss()) {
            $key = $item->get();
        } else {
            $key = $this->getAttributeKeyRepository()->findOneBy([
                'akID' => $akID,
            ]);
            $cache->save($item->set($key));
        }

        return $key;
    }
283601
private function getIdsWithAttributes($id, $attributes = [])
    {
        $ids = [];

        if ($id instanceof Model) {
            $ids[$id->getKey()] = $attributes;
        } elseif ($id instanceof Collection) {
            foreach ($id as $model) {
                $ids[$model->getKey()] = $attributes;
            }
        } elseif (is_array($id)) {
            foreach ($id as $key => $attributesArray) {
                if (is_array($attributesArray)) {
                    $ids[$key] = array_merge($attributes, $attributesArray);
                } else {
                    $ids[$attributesArray] = $attributes;
                }
            }
        } elseif (is_int($id) || is_string($id)) {
            $ids[$id] = $attributes;
        }

        $idsOnly = array_keys($ids);

        return [$idsOnly, $ids];
    }
940864
protected function getAttributeId($attribute)
	{
		return isset($this->htmlOptions['id'])
			? $this->htmlOptions['id']
			: CHtml::getIdByName(CHtml::resolveName($this->model, $attribute));
	}
452373
public function getAttributeValueByName($attributeValueName)
    {
        /** @var AttributeValueInterface $attributeValue */
        foreach ($this->attributeValues as $attributeValue) {
            if ($attributeValue->getAttributeName() == $attributeValueName) {
                return $attributeValue;
            }
        }

        return null;
    }
1359315
function attribute( $attributeName )
    {
        if ( isset( $this->Parameters[$attributeName] ) )
        {
            return $this->Parameters[$attributeName];
        }

        eZDebug::writeError( "Attribute '$attributeName' does not exist", __METHOD__ );
        return null;
    }
887735
public function getQuestion($id)
    {
        /** @var TemplateInterface $template */
        foreach ($this->data as $template) {
            if ($template->getQuestion()->getId() == $id) {
                return $template;
            }
        }

        throw new NotFoundHttpException(sprintf('Id question %s not found', $id));
    }
1249834
public function getCustomerAddressAttributesByEntityId($entityId)
    {

        // initialize the array for the attributes
        $attributes = array();

        // load the datetime attributes
        foreach ($this->customerAddressDatetimeRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the decimal attributes
        foreach ($this->customerAddressDecimalRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the integer attributes
        foreach ($this->customerAddressIntRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the text attributes
        foreach ($this->customerAddressTextRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // load the varchar attributes
        foreach ($this->customerAddressVarcharRepository->findAllByEntityId($entityId) as $attribute) {
            $attributes[$attribute[MemberNames::ATTRIBUTE_ID]] = $attribute;
        }

        // return the array with the attributes
        return $attributes;
    }
752033
public function getValueData(AttributeInterface $attribute, array $context = null)
    {
        $valuesData = $this->getValuesData($attribute, $context);

        return 0 === \count($valuesData) ? null : $valuesData->first();
    }
588914
private function getStoreData($productId, $storeId, $attributeCode)
    {
        if (array_key_exists($productId, $this->attributeData)
            && array_key_exists($storeId, $this->attributeData[$productId])
            && array_key_exists($attributeCode, $this->attributeData[$productId][$storeId])
        ) {
            return $this->attributeData[$productId][$storeId][$attributeCode];
        }

        return null;
    }
49871
protected function getValuesByAttribute(AttributeInterface $attribute)
    {
        if (null === $this->valuesByAttributes) {
            $this->valuesByAttributes = [];
        }

        if (!array_key_exists($attribute->getCode(), $this->valuesByAttributes)) {
            $this->valuesByAttributes[$attribute->getCode()] = [];
            foreach ($this->values as $value) {
                if ($value->getAttributeCode() === $attribute->getCode()) {
                    $this->addValueByAttribute($value);
                }
            }
        }

        return $this->valuesByAttributes[$attribute->getCode()];
    }