57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\Links\LinksService;
|
|
use App\Services\LoadDBService;
|
|
use App\Services\Userdatas\UserdatasService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PreloadDBController extends Controller
|
|
{
|
|
private $userdatasService;
|
|
private $linksService;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->userdatasService = new UserdatasService();
|
|
$this->linksService = new LinksService();
|
|
}
|
|
|
|
public function setInitialUserData(string $username, string $theme, string $profilepicture)
|
|
{
|
|
$userdatas = $this->userdatasService->getAllUserdatas();
|
|
$userdataslenght = count($userdatas);
|
|
if ($userdataslenght > 0)
|
|
{
|
|
for ($userdata = 0; $userdata < $userdataslenght; $userdata++)
|
|
{
|
|
$this->userdatasService->deleteUserdataByID($userdatas[$userdata]['id']);
|
|
}
|
|
}
|
|
$this->userdatasService->setNewUserdata($username, $theme, $profilepicture);
|
|
}
|
|
|
|
public function setInitialLinks(array $newlinks)
|
|
{
|
|
$links = $this->linksService->getAllLinks();
|
|
$linkslenght = count($links);
|
|
if ($linkslenght > 0)
|
|
{
|
|
for ($link = 0; $link < $linkslenght; $link++)
|
|
{
|
|
$this->linksService->deleteLinkById($links[$link]['id']);
|
|
}
|
|
}
|
|
for ($link = 0; $link < count($newlinks); $link++)
|
|
{
|
|
$this->linksService->setNewLink(
|
|
$newlinks[$link]['platform'],
|
|
$newlinks[$link]['link'],
|
|
$newlinks[$link]['linktext'],
|
|
$newlinks[$link]['brandcolors']
|
|
);
|
|
}
|
|
}
|
|
}
|