singletonIf('svc.service.icon', function () { return new static(); }); /** @var static $i */ $i = bff('svc.service.icon'); $i->setRecordID($svcID); return $i; } public function initSettings() { $this->path = $this->app->path('svc', 'images'); $this->pathTmp = $this->app->path('tmp', 'images'); $this->url = $this->app->url('svc', 'images'); $this->urlTmp = $this->app->url('tmp', 'images'); $this->table = Svc::TABLE_SERVICES; $this->fieldID = 'id'; $this->filenameLetters = 4; $variants = $this->getVariants(); if (!empty($variants)) { $this->setVariant(key($variants)); } } /** * Build service icon URL * @param string $svcID * @param string $fileName * @param string $variantKey * @return string */ public function url($svcID, string $fileName, string $variantKey = self::BIG): string { $this->setRecordID($svcID); if (empty($fileName)) { # default return $this->url . 'default-' . $variantKey . '.png'; } else { return $this->getURL($fileName, static::szOriginal); } } /** * Список доступных вариантов размеров * @return array */ public function getVariants() { return $this->app->filter('svc.service.icon.variants', [ 'icon_' . static::BIG => [ 'title' => _t('svc', 'Icon (large)'), 'key' => static::BIG, 'sizes' => [ static::szOriginal => ['width' => 128, 'height' => 128, 'o' => true], ], ], 'icon_' . static::SMALL => [ 'title' => _t('svc', 'Icon (small)'), 'key' => static::SMALL, 'sizes' => [ static::szOriginal => ['width' => 32, 'height' => 32, 'o' => true], ], ], ]); } /** * @param string $key * @return void */ public function setVariant(string $key) { $list = $this->getVariants(); if (isset($list[$key])) { $this->fieldImage = $key; $this->sizes = $list[$key]['sizes']; } } }