Initialize the product media gallery value with the passed attributes and returns an instance.

@param array $attr The product media gallery value attributes

@return array The initialized product media gallery value
180245
protected function initializeProductMediaGalleryValue(array $attr)
    {

        // load the value/store/parent ID
        $valueId = $attr[MemberNames::VALUE_ID];
        $storeId = $attr[MemberNames::STORE_ID];
        $entityId = $attr[MemberNames::ENTITY_ID];

        // query whether the product media gallery value already exists or not
        if ($entity = $this->loadProductMediaGalleryValue($valueId, $storeId, $entityId)) {
            return $this->mergeEntity($entity, $attr);
        }

        // simply return the attributes
        return $attr;
    }
885435
public function attribute( $attr )
    {
        switch ( $attr )
        {
            case 'element':
                return $this->element();
                break;
            case 'tail':
                return $this->elements();
                break;
            case 'base':
                return $this->base();
                break;
            case 'index':
                return $this->index();
                break;
            case 'uri':
                return $this->uriString();
                break;
            case 'original_uri':
                return $this->originalURIString();
                break;
            case 'query_string':
                return eZSys::queryString();
                break;
            default:
            {
                eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
                return null;
            } break;
        }
    }
1222155
function attribute( $attr )
    {
        if ( isset( $this->Attributes[$attr] ) )
        {
            return $this->Attributes[$attr];
        }

        eZDebug::writeError( "Attribute '$attr' does not exist", __METHOD__ );
        $attributeData = null;
        return $attributeData;
    }
567213
public function attributes(array $attr)
    {
        $attr_string = '';
        foreach ($attr as $name => $value) {
            if (is_array($value)) {
                $attr_string .= ' '.$name.'="'.implode(' ', $value).'"';
            } else {
                $attr_string .= ' '.$name.'="'.$value.'"';
            }
        }

        return $attr_string;
    }
189356
protected function initializeProductSuperAttributeLabel(array $attr)
    {

        // load product super attribute/store ID
        $storeId = $attr[MemberNames::STORE_ID];
        $productSuperAttributeId = $attr[MemberNames::PRODUCT_SUPER_ATTRIBUTE_ID];

        // query whether or not, the product super attribute label already exists
        if ($entity = $this->loadProductSuperAttributeLabel($productSuperAttributeId, $storeId)) {
            return $this->mergeEntity($entity, $attr);
        }

        // simply return the attributes
        return $attr;
    }
1030619
public function addAttributes(array $attr)
    {
        foreach ($attr as $name => $value) {
            $this->setAttribute($name, $value);
        }

        return $this;
    }
1076352
protected function initializeCustomerAddress(array $attr)
    {

        // try to load the customer address with the given entity ID
        if ($entity = $this->loadCustomerAddress($attr[MemberNames::ENTITY_ID])) {
            return $this->mergeEntity($entity, $attr);
        }

        // remove the entity ID
        unset($attr[MemberNames::ENTITY_ID]);

        // simply return the attributes
        return $attr;
    }
1061939
public function getAttribute($attr)
    {
        switch($attr)
        {
        case \PDO::ATTR_AUTOCOMMIT:
            return $this->_autocommit;
        case \PDO::ATTR_DRIVER_NAME:
            return 'oci';
        case \PDO::ATTR_CASE:
            return $this->_case;
        }
        return null;
    }
1071851
protected function getCategoryIdFromMetadata(array $attr)
    {

        // load the metadata of the passed URL rewrite entity
        $metadata = $this->getMetadata($attr);

        // return the category ID from the metadata
        return (integer) $metadata[UrlRewriteObserver::CATEGORY_ID];
    }
1329459
protected function createPicturesFor($product, $attr)
    {
        $pictures = Images::parse($attr->get('pictures'))
            ->on($this->basePath. '/' . $product->id)
            ->store();

        $product->pictures()->createMany($pictures);
    }
265215
protected function prepareProductMediaGalleryAttributes()
    {

        // load the attribute ID of the media gallery EAV attribute
        $mediaGalleryAttribute = $this->getEavAttributeByAttributeCode(MediaGalleryObserver::ATTRIBUTE_CODE);
        $attributeId = $mediaGalleryAttribute[MemberNames::ATTRIBUTE_ID];

        // initialize the gallery data
        $disabled = 0;
        $mediaType = 'image';
        $image = $this->getValue(ColumnKeys::IMAGE_PATH_NEW);

        // initialize and return the entity
        return $this->initializeEntity(
            array(
                MemberNames::ATTRIBUTE_ID => $attributeId,
                MemberNames::VALUE        => $image,
                MemberNames::MEDIA_TYPE   => $mediaType,
                MemberNames::DISABLED     => $disabled
            )
        );
    }
1179893
public function getClient($attr = '')
    {
        if ($attr == '') {
            return $this->client;
        }

        if (!isset($this->client[$attr])) {
            return self::UNKNOWN;
        }

        return $this->client[$attr];
    }
804172
public function setPicturesAttribute(array $attr)
    {
        $current = $this->image;
        $image = Images::parse($attr)->on($this->storageFolder());

        if ($image->wantsDeletion()) {
            $image->delete($current);
            return $this->attributes['image'] = null;
        }

        $picture = $image->update($current);

        return $this->attributes['image'] = $picture['path'];
    }
24533
protected function initializeProductSuperLink(array $attr)
    {

        // laod parent/product ID
        $parentId = $attr[MemberNames::PARENT_ID];
        $productId = $attr[MemberNames::PRODUCT_ID];

        // query whether or not the product super link already exists
        if ($this->loadProductSuperLink($productId, $parentId)) {
            return;
        }

        // simply return the attributes
        return $attr;
    }
1125740
public function attribute( $attr )
    {
        switch( $attr )
        {
            case 'responseHeader':
            {
                return $this->ResultArray['responseHeader'];
            } break;

            case 'hasError':
            {
                return !empty( $this->ResultArray['error'] );
            } break;

            case 'error':
            {
                if ( !empty( $this->ResultArray['error'] ) )
                {
                    return $this->ResultArray['error'];
                }
            } break;

            case 'facet_queries':
            {
                if ( !empty( $this->FacetQueries ) )
                {
                    return $this->FacetQueries;
                }

                // If the facets count is empty, an error has occured.
                if ( empty( $this->ResultArray['facet_counts'] ) )
                {
                    return null;
                }

                $facetArray = array();
                foreach ( $this->ResultArray['facet_counts']['facet_queries'] as $query => $count )
                {
                    list( $field, $fieldValue ) = explode( ':', $query );
                    $fieldInfo = array( 'field' => $field,
                                        'count' => $count,
                                        'queryLimit' => $query,
                                        'fieldValue' => $fieldValue );
                    $facetArray[] = $fieldInfo;
                }

                $this->FacetQueries = $facetArray;
                return $this->FacetQueries;
            } break;

            case 'facet_fields':
            {
                if ( !empty( $this->FacetFields ) )
                {
                    return $this->FacetFields;
                }

                // If the facets count is empty, an error has occured.
                if ( empty( $this->ResultArray['facet_counts'] ) )
                {
                    return null;
                }

                $facetArray = array();
                foreach ( $this->ResultArray['facet_counts']['facet_fields'] as $field => $facetField )
                {
                    switch( $field )
                    {
                        // class facet field
                        case eZSolr::getMetaFieldName( 'contentclass_id' ):
                        {
                            $fieldInfo = array( 'field' => 'class',
                                                'count' => count( $facetField ),
                                                'nameList' => array(),
                                                'queryLimit' => array(),
                                                'fieldList' => array(),
                                                'countList' => array() );
                            foreach ( $facetField as $contentClassID => $count )
                            {
                                if ( $contentClass = eZContentClass::fetch( $contentClassID ) )
                                {
                                    $fieldInfo['nameList'][$contentClassID] = $contentClass->attribute( 'name' );
                                    $fieldInfo['queryLimit'][$contentClassID] = 'contentclass_id:' . $contentClassID;
                                    $fieldInfo['countList'][$contentClassID] = $count;
                                    $fieldInfo['fieldList'][$contentClassID] = 'contentclass_id';
                                }
                                else
                                {
                                    eZDebug::writeWarning( 'Could not fetch eZContentClass: ' . $contentClassID, __METHOD__ );
                                }
                            }
                            $facetArray[] = $fieldInfo;
                        } break;

                        // instalaltion facet field
                        case eZSolr::getMetaFieldName( 'installation_id' ):
                        {
                            $findINI = eZINI::instance( 'ezfind.ini' );
                            $siteNameMapList = $findINI->variable( 'FacetSettings', 'SiteNameList' );
                            $fieldInfo = array( 'field' => 'installation',
                                                'count' => count( $facetField ),
                                                'nameList' => array(),
                                                'queryLimit' => array(),
                                                'fieldList' => array(),
                                                'countList' => array() );
                            foreach ( $facetField as $installationID => $count )
                            {
                                $fieldInfo['nameList'][$installationID] = isset( $siteNameMapList[$installationID] ) ?
                                    $siteNameMapList[$installationID] : $installationID;
                                $fieldInfo['queryLimit'][$installationID] = 'installation_id:' . $installationID;
                                $fieldInfo['countList'][$installationID] = $count;
                                $fieldInfo['fieldList'][$installationID] = 'installation_id';
                            }
                            $facetArray[] = $fieldInfo;
                        } break;

                        // author facet field
                        case eZSolr::getMetaFieldName( 'owner_id' ):
                        {
                            $fieldInfo = array( 'field' => 'author',
                                                'count' => count( $facetField ),
                                                'nameList' => array(),
                                                'queryLimit' => array(),
                                                'fieldList' => array(),
                                                'countList' => array() );
                            foreach ( $facetField as $ownerID => $count )
                            {
                                if ( $owner = eZContentObject::fetch( $ownerID ) )
                                {
                                    $fieldInfo['nameList'][$ownerID] = $owner->attribute( 'name' );
                                    $fieldInfo['queryLimit'][$ownerID] = 'owner_id:' . $ownerID;
                                    $fieldInfo['countList'][$ownerID] = $count;
                                    $fieldInfo['fieldList'][$ownerID] = 'owner_id';
                                }
                                else
                                {
                                    eZDebug::writeWarning( 'Could not fetch owner ( eZContentObject ): ' . $ownerID, __METHOD__ );
                                }
                            }
                            $facetArray[] = $fieldInfo;
                        } break;

                        // translation facet field
                        case eZSolr::getMetaFieldName( 'language_code' ):
                        {
                            $fieldInfo = array( 'field' => 'translation',
                                                'count' => count( $facetField ),
                                                'nameList' => array(),
                                                'queryLimit' => array(),
                                                'fieldList' => array(),
                                                'countList' => array() );
                            foreach ( $facetField as $languageCode => $count )
                            {
                                $fieldInfo['nameList'][$languageCode] = $languageCode;
                                $fieldInfo['queryLimit'][$languageCode] = 'language_code:' . $languageCode;
                                $fieldInfo['fieldList'][$languageCode] = 'language_code';
                                $fieldInfo['countList'][$languageCode] = $count;
                            }
                            $facetArray[] = $fieldInfo;
                        } break;

                        default:
                        {
                            $fieldInfo = array( 'field' => $field,
                                                'count' => count( $facetField ),
                                                'queryLimit' => array(),
                                                'fieldList' => array(),
                                                'nameList' => array(),
                                                'countList' => array() );
                            foreach ( $facetField as $value => $count )
                            {
                                $fieldInfo['nameList'][$value] = $value;
                                $fieldInfo['fieldList'][$value] = $field;
                                $fieldInfo['queryLimit'][$value] = $field . ':' . $value;
                                $fieldInfo['countList'][$value] = $count;
                            }
                            $facetArray[] = $fieldInfo;
                        } break;
                    }
                }

                $this->FacetFields = $facetArray;
                return $this->FacetFields;
            } break;

            case 'engine':
            {
                return eZSolr::engineText();
            } break;


            //may or may not be active, so returns false if not present
            case 'spellcheck':
            {
                if ( isset( $this->ResultArray['spellcheck'] ) && $this->ResultArray['spellcheck']['suggestions'] > 0 )
                {
                    return $this->ResultArray['spellcheck']['suggestions'];
                }
                else
                {
                    return false;
                }
            } break;

            case 'spellcheck_collation':
            {
                if ( isset( $this->ResultArray['spellcheck']['suggestions']['collation'] ) )
                {
                    // work around border case if 'collation' is searched for but does not exist in the spell check index
                    // the collation string is the last element of the suggestions array
                    return end( $this->ResultArray['spellcheck']['suggestions'] );

                }
                else
                {
                    return false;
                }
            } break;

            //only relevant for MoreLikeThis queries
            case 'interestingTerms':
            {
                if ( isset( $this->ResultArray['interestingTerms'] ) )
                {
                    return $this->ResultArray['interestingTerms'];
                }
                else
                {
                    return false;
                }
            } break;
            case 'facet_dates':
            {
                if ( isset( $this->ResultArray['facet_dates'] ) )
                {
                    return $this->ResultArray['facet_dates'];
                }
                else
                {
                    return false;
                }
            } break;

            case 'facet_ranges':
            {
                if ( isset( $this->ResultArray['facet_counts']['facet_ranges'] ) )
                {
                    return $this->ResultArray['facet_counts']['facet_ranges'];
                }
                else
                {
                    return false;
                }
            } break;
            case 'clusters':
            {
                if ( isset( $this->ResultArray['clusters'] ) )
                {
                    return $this->ResultArray['clusters'];
                }
                else
                {
                    return false;
                }
            } break;
            case 'highlighting':
            {
                if ( isset( $this->ResultArray['highlighting'] ) )
                {
                    return $this->ResultArray['highlighting'];
                }
                else
                {
                    return false;
                }
            } break;

            default:
            {
            } break;
        }
        return null;
    }
439268
protected function initializeProductLink(array $attr)
    {

        // load the product/linked product/link type ID
        $productId = $attr[MemberNames::PRODUCT_ID];
        $linkTypeId = $attr[MemberNames::LINK_TYPE_ID];
        $linkedProductId = $attr[MemberNames::LINKED_PRODUCT_ID];

        // try to load the link with the passed product/linked product/link type ID
        if ($entity = $this->loadProductLink($productId, $linkedProductId, $linkTypeId)) {
            return $this->mergeEntity($entity, $attr);
        }

        // simply return the attributes
        return $attr;
    }
250123
protected function initializeUrlRewrite(array $attr)
    {

        // load store ID and request path
        $categoryId = $attr[MemberNames::ENTITY_ID];
        $requestPath = $attr[MemberNames::REQUEST_PATH];

        // iterate over the available URL rewrites to find the one that matches the category ID
        foreach ($this->existingUrlRewrites as $urlRewrite) {
            // compare the category IDs AND the request path
            if ($categoryId === $urlRewrite[MemberNames::ENTITY_ID] &&
                $requestPath === $urlRewrite[MemberNames::REQUEST_PATH]
            ) {
                // if a URL rewrite has been found, do NOT create a redirect
                $this->removeExistingUrlRewrite($urlRewrite);

                // if the found URL rewrite has been created manually
                if ((integer) $urlRewrite[MemberNames::IS_AUTOGENERATED] === 0 && (integer) $urlRewrite[MemberNames::REDIRECT_TYPE] === 0) {
                    // do NOT update it nor create a another redirect
                    return false;
                }

                // if the found URL rewrite has been autogenerated, then update it
                return $this->mergeEntity($urlRewrite, $attr);
            }
        }

        // simple return the attributes
        return $attr;
    }