This repository has been archived on 2022-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
socialtree-laravel/src/app/Http/Controllers/PreloadDBController.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']
);
}
}
}