fipamo/app/Services/SettingsService.php

95 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Services;
class SettingsService
{
protected $settings;
protected $folks;
protected $tags;
protected $docs;
public function __construct(DocService $docService)
{
$this->folks = json_decode(file_get_contents(env('FOLKS_PATH')), true);
$this->tags = json_decode(file_get_contents(env('TAGS_PATH')), true);
$this->docs = $docService;
}
protected function loadSettings()
{
return json_decode(file_get_contents(env('SETTINGS_PATH')), true);
}
public function getSettings()
{
return $this->loadSettings();
}
public function getGlobal()
{
$this->settings = $this->loadSettings();
return $this->settings['global'];
}
public function getEmail()
{
$this->settings = $this->loadSettings();
return $this->settings['email'];
}
public function getMenu()
{
$this->settings = $this->loadSettings();
return $this->settings['menu'];
}
public function getTags()
{
return $this->tags;
}
public function getFolks()
{
return $this->folks;
}
public function updatePageIndex()
{
$this->settings = $this->loadSettings();
$this->settings['library_stats']['current_index']++;
$this->docs->writeSettings($this->settings);
}
public function updateGlobalData($key, $value)
{
$this->settings = $this->loadSettings();
$this->settings['global'][$key] = $data;
$this->docs->writeSettings($this->settings);
}
public function sync($data)
{
//dd($data->global->renderOnSave);
$settings = $this->getSettings();
$settings['global']['base_url'] = $data->global->base_url;
$settings['global']['title'] = $data->global->title;
$settings['global']['descriptions'] = $data->global->descriptions;
$settings['global']['private'] = $data->global->private;
$settings['global']['renderOnSave'] = $data->global->renderOnSave;
$settings['global']['theme'] = $data->global->theme;
$settings['global']['externalAPI'] = $data->global->externalAPI;
$settings['global']['dynamicRender'] = $data->global->dynamicRender;
//TODO: This is for to be created MemberServices
//Member::updateData('handle', $data['member']['handle']);
//Member::updateData('email', $data['member']['email']);
$settings['email']['active'] = $data->email->active;
$settings['email']['smtp'] = $data->email->smtp;
$settings['email']['mailgun'] = $data->email->mailgun;
return $this->docs->writeSettings($settings);
}
}