Commit 0d88c7bc authored by Emiliano Balbuena's avatar Emiliano Balbuena

(feat): Hydrate logo and background from channel

1 merge request!281WIP: (feat): Minds Pro
Pipeline #72980888 passed with stages
in 9 minutes and 51 seconds
<?php
/**
* HydrateSettingsDelegate
* @author edgebal
*/
namespace Minds\Core\Pro\Delegates;
use Minds\Core\Config;
use Minds\Core\Di\Di;
use Minds\Core\EntitiesBuilder;
use Minds\Core\Pro\Settings;
use Minds\Entities\Object\Carousel;
use Minds\Entities\User;
class HydrateSettingsDelegate
{
/** @var EntitiesBuilder */
protected $entitiesBuilder;
/** @var Config */
protected $config;
/**
* HydrateSettingsDelegate constructor.
* @param EntitiesBuilder $entitiesBuilder
* @param Config $config
*/
public function __construct(
$entitiesBuilder = null,
$config = null
)
{
$this->entitiesBuilder = $entitiesBuilder ?: Di::_()->get('EntitiesBuilder');
$this->config = $config ?: Di::_()->get('Config');
}
/**
* @param User $user
* @param Settings $settings
* @return Settings
*/
public function onGet(User $user, Settings $settings)
{
try {
$avatarUrl = $user->getIconURL('large');
if ($avatarUrl) {
$settings
->setLogoImage($avatarUrl);
}
} catch (\Exception $e) {
error_log($e);
}
try {
$carousels = $this->entitiesBuilder->get(['subtype' => 'carousel', 'owner_guid' => (string) $user->guid]);
$carousel = $carousels[0] ?? null;
if ($carousel) {
$settings
->setBackgroundImage(sprintf(
'%sfs/v1/banners/%s/fat/%s',
$this->config->get('cdn_url'),
$carousel->guid,
$carousel->last_updated
));
}
} catch (\Exception $e) {
error_log($e);
}
return $settings;
}
}
......@@ -21,6 +21,9 @@ class Manager
/** @var Delegates\InitializeSettingsDelegate */
protected $initializeSettingsDelegate;
/** @var Delegates\HydrateSettingsDelegate */
protected $hydrateSettingsDelegate;
/** @var User */
protected $user;
......@@ -29,16 +32,19 @@ class Manager
* @param Repository $repository
* @param Save $saveAction
* @param Delegates\InitializeSettingsDelegate $initializeSettingsDelegate
* @param Delegates\HydrateSettingsDelegate $hydrateSettingsDelegate
*/
public function __construct(
$repository = null,
$saveAction = null,
$initializeSettingsDelegate = null
$initializeSettingsDelegate = null,
$hydrateSettingsDelegate = null
)
{
$this->repository = $repository ?: new Repository();
$this->saveAction = $saveAction ?: new Save();
$this->initializeSettingsDelegate = $initializeSettingsDelegate ?: new Delegates\InitializeSettingsDelegate();
$this->hydrateSettingsDelegate = $hydrateSettingsDelegate ?: new Delegates\HydrateSettingsDelegate();
}
/**
......@@ -120,9 +126,16 @@ class Manager
throw new Exception('Invalid user');
}
return $this->repository->getList([
$settings = $this->repository->getList([
'user_guid' => $this->user->guid
])->first();
if (!$settings) {
return null;
}
return $this->hydrateSettingsDelegate
->onGet($this->user, $settings);
}
/**
......
......@@ -26,6 +26,10 @@ use Minds\Traits\MagicAttributes;
* @method Settings setPrimaryColor(string $primaryColor)
* @method string getPlainBackgroundColor()
* @method Settings setPlainBackgroundColor(string $plainBackgroundColor)
* @method string getBackgroundImage()
* @method Settings setBackgroundImage(string $backgroundImage)
* @method string getLogoImage()
* @method Settings setLogoImage(string $logoImage)
*/
class Settings implements JsonSerializable
{
......@@ -52,6 +56,12 @@ class Settings implements JsonSerializable
/** @var string */
protected $plainBackgroundColor;
/** @var string */
protected $backgroundImage;
/** @var string */
protected $logoImage;
/**
* @return array
*/
......@@ -65,6 +75,8 @@ class Settings implements JsonSerializable
'text_color' => $this->textColor,
'primary_color' => $this->primaryColor,
'plain_background_color' => $this->plainBackgroundColor,
'background_image' => $this->backgroundImage,
'logo_image' => $this->logoImage,
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment