Overview
  • Package
  • Class
  • Tree
  • Todo

Packages

  • AddonValue
    • Interfaces
  • ApiV2Controllers
  • Category
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Providers
    • Repositories
    • Storages
  • Customer
    • Address
    • Country
    • CountryZone
    • Interfaces
    • Validation
    • ValueObjects
  • Email
    • Collections
    • Entities
    • Exceptions
    • Interfaces
    • Repository
    • ValueObjects
  • Http
    • Collections
    • Exceptions
    • Factories
    • Interfaces
    • ValueObjects
  • Loaders
    • CrossCuttingLoader
    • GXCoreLoader
    • Interfaces
  • None
  • Order
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Repositories
    • Storages
    • ValueObjects
  • Product
    • Collections
    • Entities
    • Factories
    • Interfaces
    • Providers
    • Repositories
    • Storages
  • ProductModule
    • Collections
    • Deleter
    • Entities
    • Factories
    • Interface
    • Interfaces
    • Reader
    • Repositories
    • Writer
  • Shared
    • Exceptions
    • FileSystem
    • Interfaces
    • Storage
    • Types
  • Statistics
    • Interfaces
  • UserConfiguration
    • Interfaces
    • Repository

Classes

  • AbstractAddonValueServiceFactory
  • AbstractAddonValueStorage
  • AbstractApiV2Controller
  • AbstractCategoryServiceFactory
  • AbstractCollection
  • AbstractCustomerFactory
  • AbstractCustomerServiceFactory
  • AbstractFileStorage
  • AbstractHttpContextFactory
  • AbstractHttpViewControllerRegistryFactory
  • AbstractImagesApiV2Controller
  • AbstractOrderServiceFactory
  • AbstractProductAttributeServiceFactory
  • AbstractProductServiceFactory
  • AddonValueService
  • AddonValueServiceFactory
  • AddonValueStorageFactory
  • AddressBlock
  • AddressBookService
  • AddressClass
  • AddressesApiV2Controller
  • AddressFormatProvider
  • AdminHttpViewController
  • AdminPageHttpControllerResponse
  • Asset
  • AssetCollection
  • AttachmentCollection
  • AttachmentName
  • AttachmentPath
  • AttachmentsApiV2Controller
  • AttachmentsHandler
  • BoolType
  • CategoriesApiV2Controller
  • Category
  • CategoryAddonValueStorage
  • CategoryFactory
  • CategoryIconsApiV2Controller
  • CategoryImagesApiV2Controller
  • CategoryListItem
  • CategoryListItemCollection
  • CategoryListProvider
  • CategoryListProviderFactory
  • CategoryObjectService
  • CategoryReadService
  • CategoryRepository
  • CategoryRepositoryDeleter
  • CategoryRepositoryReader
  • CategoryRepositoryWriter
  • CategoryServiceFactory
  • CategorySettings
  • CategorySettingsRepository
  • CategorySettingsRepositoryReader
  • CategorySettingsRepositoryWriter
  • CategoryWriteService
  • ContactCollection
  • ContactName
  • ContactType
  • CountriesApiV2Controller
  • CountryService
  • CrossCuttingLoader
  • CurrencyCode
  • Customer
  • CustomerAccountInputValidator
  • CustomerAddress
  • CustomerAddressDeleter
  • CustomerAddressInputValidator
  • CustomerAddressReader
  • CustomerAddressRepository
  • CustomerAddressWriter
  • CustomerB2BStatus
  • CustomerCallNumber
  • CustomerCity
  • CustomerCompany
  • CustomerCountry
  • CustomerCountryIso2
  • CustomerCountryIso3
  • CustomerCountryName
  • CustomerCountryReader
  • CustomerCountryRepository
  • CustomerCountryZone
  • CustomerCountryZoneIsoCode
  • CustomerCountryZoneName
  • CustomerCountryZoneReader
  • CustomerCountryZoneRepository
  • CustomerDateOfBirth
  • CustomerDeleter
  • CustomerEmail
  • CustomerFactory
  • CustomerFirstname
  • CustomerGender
  • CustomerInputValidator
  • CustomerInputValidatorSettings
  • CustomerLastname
  • CustomerNumber
  • CustomerPassword
  • CustomerPostcode
  • CustomerReader
  • CustomerReadService
  • CustomerRegistrationInputValidatorService
  • CustomerRepository
  • CustomersApiV2Controller
  • CustomerService
  • CustomerServiceFactory
  • CustomerServiceSettings
  • CustomerStatusInformation
  • CustomerStatusProvider
  • CustomerStreet
  • CustomerSuburb
  • CustomerVatNumber
  • CustomerWriter
  • CustomerWriteService
  • DecimalType
  • DefaultApiV2Controller
  • EditableCollection
  • EditableKeyValueCollection
  • Email
  • EmailAddress
  • EmailAttachment
  • EmailCollection
  • EmailContact
  • EmailContent
  • EmailDeleter
  • EmailFactory
  • EmailReader
  • EmailRepository
  • EmailsApiV2Controller
  • EmailService
  • EmailStringType
  • EmailSubject
  • EmailWriter
  • EmptyCurrencyCode
  • EmptyDateTime
  • EmptyLanguageCode
  • EmptyOrderItemDownloadInformation
  • EmptyProductImage
  • EnvCategoryServiceSettings
  • EnvironmentHttpContextFactory
  • EnvironmentHttpViewControllerRegistryFactory
  • EnvProductImageFileStorageSettings
  • ExistingDirectory
  • ExistingFile
  • FilenameStringType
  • GXCoreLoader
  • GXCoreLoaderSettings
  • GXEngineOrder
  • GXEngineProduct
  • HttpApiV2Controller
  • HttpContext
  • HttpContextReader
  • HttpControllerResponse
  • HttpDispatcher
  • HttpResponseProcessor
  • HttpService
  • HttpServiceFactory
  • HttpViewController
  • HttpViewControllerFactory
  • HttpViewControllerRegistry
  • IdCollection
  • IdType
  • ImageFileStorage
  • IntType
  • JsonHttpControllerResponse
  • KeyValueCollection
  • LanguageCode
  • LegacyProductImageProcessing
  • MailerAdapter
  • NonEmptyStringType
  • OrderAddonValueStorage
  • OrderFactory
  • OrderItem
  • OrderItemAddonValueStorage
  • OrderItemAttribute
  • OrderItemAttributeCollection
  • OrderItemAttributeFactory
  • OrderItemAttributeRepository
  • OrderItemAttributeRepositoryDeleter
  • OrderItemAttributeRepositoryFactory
  • OrderItemAttributeRepositoryReader
  • OrderItemAttributeRepositoryWriter
  • OrderItemCollection
  • OrderItemDownloadInformation
  • OrderItemFactory
  • OrderItemProperty
  • OrderItemPropertyFactory
  • OrderItemPropertyRepository
  • OrderItemPropertyRepositoryDeleter
  • OrderItemPropertyRepositoryReader
  • OrderItemPropertyRepositoryWriter
  • OrderItemRepository
  • OrderItemRepositoryDeleter
  • OrderItemRepositoryReader
  • OrderItemRepositoryWriter
  • OrderListGenerator
  • OrderListItem
  • OrderListItemCollection
  • OrderObjectService
  • OrderPaymentType
  • OrderReadService
  • OrderRepository
  • OrderRepositoryDeleter
  • OrderRepositoryReader
  • OrderRepositoryWriter
  • OrdersApiV2Controller
  • OrderServiceFactory
  • OrderServiceSettings
  • OrderShippingType
  • OrdersHistoryApiV2Controller
  • OrdersItemsApiV2Controller
  • OrdersItemsAttributesApiV2Controller
  • OrderStatusHistoryListItem
  • OrderStatusHistoryListItemCollection
  • OrderStatusHistoryStorage
  • OrdersTotalsApiV2Controller
  • OrderTotal
  • OrderTotalCollection
  • OrderTotalFactory
  • OrderTotalRepository
  • OrderTotalRepositoryDeleter
  • OrderTotalRepositoryReader
  • OrderTotalRepositoryWriter
  • OrderWriteService
  • ProductAddonValueStorage
  • ProductAttribute
  • ProductAttributeCollection
  • ProductAttributeFactory
  • ProductAttributeObjectService
  • ProductAttributeRepository
  • ProductAttributeRepositoryDeleter
  • ProductAttributeRepositoryReader
  • ProductAttributeRepositoryWriter
  • ProductAttributeService
  • ProductAttributeServiceFactory
  • ProductCategoryLinker
  • ProductFactory
  • ProductImage
  • ProductImageCollection
  • ProductImageContainer
  • ProductImageContainerRepository
  • ProductImageFileStorage
  • ProductImagesApiV2Controller
  • ProductListItem
  • ProductListItemCollection
  • ProductListProvider
  • ProductListProviderFactory
  • ProductObjectService
  • ProductPermissionSetter
  • ProductReadService
  • ProductRepository
  • ProductRepositoryDeleter
  • ProductRepositoryReader
  • ProductRepositoryWriter
  • ProductsApiV2Controller
  • ProductServiceFactory
  • ProductSettings
  • ProductSettingsRepository
  • ProductSettingsRepositoryReader
  • ProductSettingsRepositoryWriter
  • ProductsLinksApiV2Controller
  • ProductWriteService
  • RedirectHttpControllerResponse
  • StaticCrossCuttingLoader
  • StaticGXCoreLoader
  • StatisticsService
  • StoredCategory
  • StoredOrderItem
  • StoredOrderItemAttribute
  • StoredOrderItemAttributeCollection
  • StoredOrderItemCollection
  • StoredOrderItemProperty
  • StoredOrderTotal
  • StoredOrderTotalCollection
  • StoredProduct
  • StoredProductAttribute
  • StoredProductAttributeCollection
  • StringCollection
  • StringType
  • UserConfigurationReader
  • UserConfigurationService
  • UserConfigurationWriter
  • VatNumberValidator
  • WritableDirectory
  • WritableFile
  • YetAnotherLanguageProvider
  • ZonesApiV2Controller

Interfaces

  • AddonValueContainerInterface
  • AddonValueServiceInterface
  • AddonValueStorageFactoryInterface
  • AddressBlockInterface
  • AddressBookServiceInterface
  • AddressClassInterface
  • AddressFormatProviderInterface
  • AssetCollectionInterface
  • AssetInterface
  • AttachmentCollectionInterface
  • AttachmentNameInterface
  • AttachmentPathInterface
  • AttachmentsHandlerInterface
  • CategoryFactoryInterface
  • CategoryInterface
  • CategoryListProviderFactoryInterface
  • CategoryListProviderInterface
  • CategoryObjectServiceInterface
  • CategoryReadServiceInterface
  • CategoryRepositoryDeleterInterface
  • CategoryRepositoryInterface
  • CategoryRepositoryReaderInterface
  • CategoryRepositoryWriterInterface
  • CategoryServiceSettingsInterface
  • CategorySettingsInterface
  • CategorySettingsRepositoryInterface
  • CategorySettingsRepositoryReaderInterface
  • CategorySettingsRepositoryWriterInterface
  • CategoryWriteServiceInterface
  • ContactCollectionInterface
  • ContactNameInterface
  • ContactTypeInterface
  • ContentViewInterface
  • CountryServiceInterface
  • CrossCuttingLoaderInterface
  • CrossCuttingObjectInterface
  • CustomerAccountInputValidatorInterface
  • CustomerAddressDeleterInterface
  • CustomerAddressInputValidatorInterface
  • CustomerAddressInterface
  • CustomerAddressReaderInterface
  • CustomerAddressRepositoryInterface
  • CustomerAddressWriterInterface
  • CustomerB2BStatusInterface
  • CustomerCallNumberInterface
  • CustomerCityInterface
  • CustomerCompanyInterface
  • CustomerCountryInterface
  • CustomerCountryIso2Interface
  • CustomerCountryIso3Interface
  • CustomerCountryNameInterface
  • CustomerCountryReaderInterface
  • CustomerCountryRepositoryInterface
  • CustomerCountryZoneInterface
  • CustomerCountryZoneIsoCodeInterface
  • CustomerCountryZoneNameInterface
  • CustomerCountryZoneReaderInterface
  • CustomerCountryZoneRepositoryInterface
  • CustomerDeleterInterface
  • CustomerEmailInterface
  • CustomerFirstnameInterface
  • CustomerGenderInterface
  • CustomerInputValidatorInterface
  • CustomerInputValidatorSettingsInterface
  • CustomerInterface
  • CustomerLastnameInterface
  • CustomerNumberInterface
  • CustomerPasswordInterface
  • CustomerPostcodeInterface
  • CustomerReaderInterface
  • CustomerReadServiceInterface
  • CustomerRegistrationInputValidatorServiceInterface
  • CustomerRepositoryInterface
  • CustomerServiceInterface
  • CustomerServiceSettingsInterface
  • CustomerStatusProviderInterface
  • CustomerStreetInterface
  • CustomerSuburbInterface
  • CustomerVatNumberInterface
  • CustomerWriterInterface
  • CustomerWriteServiceInterface
  • EmailAddressInterface
  • EmailAttachmentInterface
  • EmailCollectionInterface
  • EmailContactInterface
  • EmailContentInterface
  • EmailDeleterInterface
  • EmailFactoryInterface
  • EmailInterface
  • EmailReaderInterface
  • EmailRepositoryInterface
  • EmailServiceInterface
  • EmailSubjectInterface
  • EmailWriterInterface
  • GXCoreLoaderInterface
  • GXCoreLoaderSettingsInterface
  • HttpContextInterface
  • HttpContextReaderInterface
  • HttpControllerResponseInterface
  • HttpDispatcherInterface
  • HttpResponseProcessorInterface
  • HttpServiceFactoryInterface
  • HttpServiceInterface
  • HttpViewControllerFactoryInterface
  • HttpViewControllerInterface
  • HttpViewControllerRegistryInterface
  • IdInterface
  • LanguageProviderInterface
  • MailerAdapterInterface
  • OrderFactoryInterface
  • OrderInterface
  • OrderItemAttributeFactoryInterface
  • OrderItemAttributeInterface
  • OrderItemAttributeRepositoryDeleterInterface
  • OrderItemAttributeRepositoryFactoryInterface
  • OrderItemAttributeRepositoryInterface
  • OrderItemAttributeRepositoryReaderInterface
  • OrderItemAttributeRepositoryWriterInterface
  • OrderItemFactoryInterface
  • OrderItemInterface
  • OrderItemPropertyFactoryInterface
  • OrderItemPropertyRepositoryDeleterInterface
  • OrderItemPropertyRepositoryReaderInterface
  • OrderItemPropertyRepositoryWriterInterface
  • OrderItemRepositoryDeleterInterface
  • OrderItemRepositoryInterface
  • OrderItemRepositoryReaderInterface
  • OrderItemRepositoryWriterInterface
  • OrderListGeneratorInterface
  • OrderObjectServiceInterface
  • OrderPaymentTypeInterface
  • OrderReadServiceInterface
  • OrderRepositoryDeleterInterface
  • OrderRepositoryInterface
  • OrderRepositoryReaderInterface
  • OrderRepositoryWriterInterface
  • OrderServiceSettingsInterface
  • OrderShippingTypeInterface
  • OrderStatusHistoryReaderInterface
  • OrderStatusHistoryWriterInterface
  • OrderTotalFactoryInterface
  • OrderTotalInterface
  • OrderTotalRepositoryDeleterInterface
  • OrderTotalRepositoryInterface
  • OrderTotalRepositoryReaderInterface
  • OrderTotalRepositoryWriterInterface
  • OrderWriteServiceInterface
  • ProductAttributeFactoryInterface
  • ProductAttributeInterface
  • ProductAttributeObjectServiceInterface
  • ProductAttributeRepositoryDeleterInterface
  • ProductAttributeRepositoryInterface
  • ProductAttributeRepositoryReaderInterface
  • ProductAttributeRepositoryWriterInterface
  • ProductAttributeServiceInterface
  • ProductCategoryLinkerInterface
  • ProductFactoryInterface
  • ProductImageContainerInterface
  • ProductImageContainerRepositoryInterface
  • ProductImageInterface
  • ProductImagePathsSettingsInterface
  • ProductImageProcessingInterface
  • ProductInterface
  • ProductListProviderFactoryInterface
  • ProductListProviderInterface
  • ProductObjectServiceInterface
  • ProductPermissionSetterInterface
  • ProductReadServiceInterface
  • ProductRepositoryDeleterInterface
  • ProductRepositoryInterface
  • ProductRepositoryReaderInterface
  • ProductRepositoryWriterInterface
  • ProductSettingsInterface
  • ProductSettingsRepositoryInterface
  • ProductSettingsRepositoryReaderInterface
  • ProductSettingsRepositoryWriterInterface
  • ProductWriteServiceInterface
  • StatisticsServiceInterface
  • StoredCategoryInterface
  • StoredOrderItemAttributeInterface
  • StoredOrderItemInterface
  • StoredOrderTotalInterface
  • StoredProductAttributeInterface
  • StoredProductInterface
  • UserConfigurationReaderInterface
  • UserConfigurationServiceInterface
  • UserConfigurationWriterInterface
  • VatNumberValidatorInterface

Exceptions

  • AjaxException
  • AttachmentNotFoundException
  • FileNotFoundException
  • HttpApiV2Exception
  • MissingControllerNameException
  • UnknownEnvironmentException
  1 <?php
  2 /* --------------------------------------------------------------
  3    ProductImageContainerRepository.inc.php 2016-02-15
  4    Gambio GmbH
  5    http://www.gambio.de
  6    Copyright (c) 2016 Gambio GmbH
  7    Released under the GNU General Public License (Version 2)
  8    [http://www.gnu.org/licenses/gpl-2.0.html]
  9    --------------------------------------------------------------
 10 */
 11 
 12 /**
 13  * Class ProductImageContainerRepository
 14  *
 15  * @category   System
 16  * @package    Product
 17  * @subpackage Repositories
 18  */
 19 class ProductImageContainerRepository implements ProductImageContainerRepositoryInterface
 20 {
 21     /**
 22      * Database connection.
 23      *
 24      * @var CI_DB_query_builder
 25      */
 26     protected $db;
 27 
 28 
 29     /**
 30      * ProductImageContainerRepository constructor.
 31      *
 32      * @param CI_DB_query_builder $db Database connection.
 33      */
 34     public function __construct(CI_DB_query_builder $db)
 35     {
 36         $this->db = $db;
 37     }
 38 
 39 
 40     /**
 41      * Stores the product image container.
 42      *
 43      * @param IdType                         $productId      Product ID.
 44      * @param ProductImageContainerInterface $imageContainer Product image container.
 45      *
 46      * @throws InvalidArgumentException On invalid arguments.
 47      *
 48      * @return ProductImageContainerRepository Same instance for method chaining.
 49      */
 50     public function store(IdType $productId, ProductImageContainerInterface $imageContainer)
 51     {
 52         $this->deleteByProductId($productId);
 53 
 54         // Prepare primary image data.
 55         $primaryImageData = array(
 56             'products_image'   => $imageContainer->getPrimary()->getFilename(),
 57             'products_image_w' => 0,
 58             'products_image_h' => 0,
 59             'gm_show_image'    => $imageContainer->getPrimary()->isVisible()
 60         );
 61 
 62         $this->db->where('products_id', $productId->asInt())->update('products', $primaryImageData);
 63 
 64         $this->_savePrimaryImageAltText($imageContainer, $productId);
 65 
 66         $this->_saveAdditionalImagesAltText($imageContainer, $productId);
 67 
 68         return $this;
 69     }
 70 
 71 
 72     /**
 73      * Returns a product image container based on the product ID given.
 74      *
 75      * @param IdType $productId Product ID.
 76      *
 77      * @throws InvalidArgumentException On invalid arguments.
 78      *
 79      * @return ProductImageContainerInterface Product image container.
 80      */
 81     public function getByProductId(IdType $productId)
 82     {
 83         $primaryImageQuery = $this->_queryPrimaryImage($productId);
 84 
 85         $additionalImagesQuery = $this->_queryAdditionalImages($productId);
 86 
 87         $imageContainer = MainFactory::create('ProductImageContainer');
 88 
 89         // Create primary image.
 90         if(!empty($primaryImageQuery['products_image']))
 91         {
 92             $primaryImageFilename  = new FilenameStringType($primaryImageQuery['products_image']);
 93             $primaryImageIsVisible = new BoolType($primaryImageQuery['gm_show_image']);
 94             $primaryImage          = MainFactory::create('ProductImage', $primaryImageFilename);
 95             $primaryImage->setVisible($primaryImageIsVisible);
 96 
 97             // Set alternative texts on primary image.
 98             $this->_getPrimaryImageAltText($primaryImage, $productId);
 99         }
100         else
101         {
102             $primaryImage = MainFactory::create('EmptyProductImage');
103         }
104 
105         $imageContainer->setPrimary($primaryImage);
106 
107         // Create additional images and add them to image container.
108         foreach($additionalImagesQuery as $additionalImageRow)
109         {
110             // Create additional product image.
111             $additionalImageId        = new IdType($additionalImageRow['image_id']);
112             $additionalImageFilename  = new FilenameStringType($additionalImageRow['image_name']);
113             $additionalImageIsVisible = new BoolType($additionalImageRow['gm_show_image']);
114             $additionalImage          = MainFactory::create('ProductImage', $additionalImageFilename);
115             $additionalImage->setVisible($additionalImageIsVisible);
116 
117             // Set alternative texts on additional image.
118             $this->_getAdditionalImagesAltText($additionalImage, $productId, $additionalImageId);
119 
120             $imageContainer->addAdditional($additionalImage);
121         }
122 
123         return $imageContainer;
124     }
125 
126 
127     /**
128      * Deletes a product image container based on the product ID given.
129      *
130      * @param IdType $productId Product ID.
131      *
132      * @return ProductImageContainerRepository Same instance for method chaining.
133      */
134     public function deleteByProductId(IdType $productId)
135     {
136         $this->db->where('products_id', $productId->asInt())->delete('products_images');
137 
138         // Clear primary image fields.
139         $updateData = array(
140             'products_image'   => '',
141             'products_image_w' => 0,
142             'products_image_h' => 0
143         );
144         $this->db->where('products_id', $productId->asInt())->update('products', $updateData);
145 
146         // Delete alternative texts entries for additional images.
147         $this->db->where('products_id', $productId->asInt())->delete('gm_prd_img_alt');
148 
149         return $this;
150     }
151 
152 
153     /**
154      * Saves alternative texts for additional images.
155      *
156      * @param ProductImageContainerInterface $imageContainer Image container.
157      * @param IdType                         $productId      Product ID.
158      *
159      * @throws InvalidArgumentException on invalid arguments.
160      */
161     protected function _saveAdditionalImagesAltText(ProductImageContainerInterface $imageContainer, IdType $productId)
162     {
163         $languages = $this->_getLanguages();
164 
165         // Prepare additional images data and insert entries to database.
166         foreach($imageContainer->getAdditionals()->getArray() as $index => $additionalImage)
167         {
168             // Additional image data.
169             $additionalImageData = array(
170                 'products_id'   => $productId->asInt(),
171                 'image_nr'      => $index + 1,
172                 'image_name'    => $additionalImage->getFilename(),
173                 'gm_show_image' => (bool)$additionalImage->isVisible()
174             );
175 
176             // Insert additional image into database.
177             $this->db->insert('products_images', $additionalImageData);
178         }
179 
180         // Get additional image entries after save.
181         $additionalImagesAfterSave = $this->db->select('*')
182                                               ->from('products_images')
183                                               ->where('products_id', $productId->asInt())
184                                               ->get()
185                                               ->result_array();
186 
187         // Iterate over each additional image fetched from DB.
188         foreach($additionalImagesAfterSave as $additionalImageData)
189         {
190             $imageId    = (int)$additionalImageData['image_id'];
191             $imageIndex = (int)$additionalImageData['image_nr'] - 1;
192 
193             // Iterate over each language
194             foreach($languages as $language)
195             {
196                 $languageId   = new IdType($language['languages_id']);
197                 $languageCode = new LanguageCode(new NonEmptyStringType($language['code']));
198 
199                 // Try to get alternative text of additional image for current language.
200                 // If no value is set for current language, iterate to next.
201                 try
202                 {
203                     // Get alternative text.
204                     // Throws InvalidArgumentException if no value is present.
205                     $altText = $imageContainer->getAdditionals()->getItem($imageIndex)->getAltText($languageCode);
206 
207                     // Data array for insert into `gm_prd_img_alt` table.
208                     $productImageAltData = array(
209                         'image_id'    => $imageId,
210                         'products_id' => $productId->asInt(),
211                         'language_id' => $languageId->asInt(),
212                         'gm_alt_text' => $altText
213                     );
214 
215                     $this->db->insert('gm_prd_img_alt', $productImageAltData);
216                 }
217                 catch(Exception $exception)
218                 {
219                     continue;
220                 }
221             }
222         }
223     }
224 
225 
226     /**
227      * Saves alternative texts for the primary image.
228      *
229      * @param ProductImageContainerInterface $imageContainer Image container.
230      * @param IdType                         $productId      Product ID.
231      *
232      * @throws InvalidArgumentException on invalid arguments.
233      */
234     protected function _savePrimaryImageAltText(ProductImageContainerInterface $imageContainer, IdType $productId)
235     {
236         $languages = $this->_getLanguages();
237 
238         // Iterate over each language and save primary image alternative text.
239         foreach($languages as $language)
240         {
241             $languageId   = new IdType($language['languages_id']);
242             $languageCode = new LanguageCode(new NonEmptyStringType($language['code']));
243 
244             // Try to get alternative text of primary image for current language.
245             // If no value is set for current language, iterate to next.
246             try
247             {
248                 // Get alternative text.
249                 // Throws InvalidArgumentException if no value is present.
250                 $altText = $imageContainer->getPrimary()->getAltText($languageCode);
251 
252                 // Data array for `products_description` table.
253                 $productsDescriptionData = array(
254                     'gm_alt_text' => $altText
255                 );
256 
257                 // Write value to database.
258                 $this->db->where('products_id', $productId->asInt())
259                          ->where('language_id', $languageId->asInt())
260                          ->update('products_description', $productsDescriptionData);
261             }
262             catch(Exception $exception)
263             {
264                 continue;
265             }
266         }
267     }
268 
269 
270     /**
271      * Sets alternative texts for the primary image provided.
272      *
273      * @param ProductImageInterface $primaryImage Product primary image.
274      * @param IdType                $productId    Product ID.
275      *
276      * @throws InvalidArgumentException on invalid arguments.
277      */
278     protected function _getPrimaryImageAltText(ProductImageInterface $primaryImage, IdType $productId)
279     {
280         $languages = $this->_getLanguages();
281 
282         foreach($languages as $language)
283         {
284             $languageId   = new IdType($language['languages_id']);
285             $languageCode = new LanguageCode(new NonEmptyStringType($language['code']));
286 
287             // Get all alternative texts for primary image.
288             $alternativeTextsQuery = $this->db->select('language_id, gm_alt_text')
289                                               ->from('products_description')
290                                               ->where('products_id', $productId->asInt())
291                                               ->where('language_id', $languageId->asInt())
292                                               ->get()
293                                               ->row_array();
294 
295             if(count($alternativeTextsQuery) > 0 && $alternativeTextsQuery['gm_alt_text'] !== null)
296             {
297                 $text = new StringType((string)$alternativeTextsQuery['gm_alt_text']);
298             }
299             else
300             {
301                 $text = new StringType('');
302             }
303             $primaryImage->setAltText($text, $languageCode);
304         }
305     }
306 
307 
308     /**
309      * Sets the alternative texts for an additional image.
310      *
311      * @param ProductImageInterface $additionalImage Additional Image.
312      * @param IdType                $productId       Product ID.
313      * @param IdType                $imageId         Image ID.
314      *
315      * @throws InvalidArgumentException on invalid arguments.
316      */
317     protected function _getAdditionalImagesAltText(ProductImageInterface $additionalImage,
318                                                    IdType $productId,
319                                                    IdType $imageId)
320     {
321         $languages = $this->_getLanguages();
322 
323         foreach($languages as $language)
324         {
325             $languageId   = new IdType($language['languages_id']);
326             $languageCode = new LanguageCode(new NonEmptyStringType($language['code']));
327 
328             // Get all alternative texts for primary image.
329             $alternativeTextsQuery = $this->db->select('*')
330                                               ->from('gm_prd_img_alt')
331                                               ->where('products_id', $productId->asInt())
332                                               ->where('language_id', $languageId->asInt())
333                                               ->where('image_id', $imageId->asInt())
334                                               ->get()
335                                               ->row_array();
336             
337             if(count($alternativeTextsQuery) > 0 && $alternativeTextsQuery['gm_alt_text'] !== null)
338             {
339                 $text = new StringType((string)$alternativeTextsQuery['gm_alt_text']);
340             }
341             else
342             {
343                 $text = new StringType('');
344             }
345             $additionalImage->setAltText($text, $languageCode);
346         }
347     }
348 
349 
350     /**
351      * Get Languages
352      *
353      * Receives and returns all found languages in the database.
354      *
355      * @return array
356      */
357     protected function _getLanguages()
358     {
359         return $this->db->get_where('languages')->result_array();
360     }
361 
362 
363     /**
364      * Perform database query to get primary image.
365      *
366      * @param IdType $productId Product ID.
367      *
368      * @return array Result.
369      */
370     protected function _queryPrimaryImage(IdType $productId)
371     {
372         return $this->db->select('products_image, products_image_w, products_image_h, gm_show_image')
373                         ->from('products')
374                         ->where('products.products_id', $productId->asInt())
375                         ->get()
376                         ->row_array();
377     }
378 
379 
380     /**
381      * Perform database query to get additional images.
382      *
383      * @param IdType $productId Product ID.
384      *
385      * @return array Result.
386      */
387     protected function _queryAdditionalImages(IdType $productId)
388     {
389         return $this->db->select('*')
390                         ->from('products_images')
391                         ->where('products_id', $productId->asInt())
392                         ->get()
393                         ->result_array();
394     }
395 }
API documentation generated by ApiGen