1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 
<?php

/* --------------------------------------------------------------
 QuantityUnitController.inc.php 2017-08-08
 Gambio GmbH
 http://www.gambio.de
 Copyright (c) 2017 Gambio GmbH
 Released under the GNU General Public License (Version 2)
 [http://www.gnu.org/licenses/gpl-2.0.html]
 --------------------------------------------------------------
 */

MainFactory::load_class('AdminHttpViewController');

/**
 * Class QuantityUnitController
 *
 * @extends    AdminHttpViewController
 * @category   System
 * @package    AdminHttpViewControllers
 */
class QuantityUnitController extends AdminHttpViewController
{
    /**
     * Default action of the quantity unit controller.
     * Provides necessary data to display the quantity unit listing.
     *
     * @return \AdminLayoutHttpControllerResponse
     */
    public function actionDefault()
    {
        /** @var \QuantityUnitReadService $quantityUnitReadService */
        
        $languageProvider = MainFactory::create('LanguageProvider', StaticGXCoreLoader::getDatabaseQueryBuilder());
        $this->contentView->set_template_dir(DIR_FS_ADMIN . 'html/content/');
        $quantityUnitReadService = StaticGXCoreLoader::getService('QuantityUnitRead');
        $languageTextManager     = MainFactory::create('LanguageTextManager');
        $languageTextManager->init_from_lang_file('products_vpe');
        $languageIds = $languageProvider->getIds()->getIntArray();
        $langIds     = [];
        
        foreach($languageIds as $languageId)
        {
            $data      = [
                'id'   => $languageId,
                'code' => $languageProvider->getCodeById(new IdType($languageId))
            ];
            $langIds[] = $data;
        }
        
        $title = $languageTextManager->get_text($languageTextManager->get_text('HEADING_TITLE', 'quantity_units'));
        $data  = MainFactory::create('KeyValueCollection', [
            'languages'    => $langIds,
            'languageCode' => $languageProvider->getCodeById(new IdType($_SESSION['languages_id'])),
            'quantityUnitEntities'  => $quantityUnitReadService->getAll()->getArray(),
        ]);
        
        return MainFactory::create('AdminLayoutHttpControllerResponse', new NonEmptyStringType($title),
                                   MainFactory::create('ExistingFile', new NonEmptyStringType(DIR_FS_ADMIN
                                                                                              . 'html/content/quantity_units/quantity_units.html')),
                                   $data, MainFactory::create('AssetCollection', [
                MainFactory::create('Asset', 'quantity_units.lang.inc.php')
            ]));
    }
}