initial commit

This commit is contained in:
greggy
2025-10-07 08:26:46 +02:00
parent ba8483bec2
commit d7682e2073
11 changed files with 399 additions and 160 deletions

165
cron-fetch-forcedbanner.php Normal file
View File

@@ -0,0 +1,165 @@
<?php
require_once 'doctrine-config.php';
use Entity\Werbenetzwerk;
use Entity\User;
use Entity\Kampagne;
try {
// Werbenetzwerk-Entity holen
// Werbenetzwerk-User holen
$werbenetzwerkUser = $entityManager->getRepository(User::class)->findByUsername('adcity-eu');
if (!$werbenetzwerkUser) {
echo "werbenetzwerkUser-Daten nicht gefunden.\n";
exit(1);
}
$werbenetzwerk = $entityManager->getRepository(Werbenetzwerk::class)->findByUser($werbenetzwerkUser);
if (!$werbenetzwerk) {
echo "Werbenetzwerk-Daten nicht gefunden.\n";
exit(1);
}
if (!$werbenetzwerkUser) {
echo "Kein Werbenetzwerk-User gefunden.\n";
exit(1);
}
// API-Parameter vorbereiten
$apiUrl = 'https://www.adcity.eu/interface/';
$params = [
'typ' => 'forcedtextlink',
'id' => $werbenetzwerk->getUserId(),
'pw' => $werbenetzwerk->getInterfacepasswort(),
'uebrig' => 20,
'reload' => 99999,
'verguetung' => 0.0001,
'ma' => 99999
];
$fullUrl = $apiUrl . '?' . http_build_query($params);
// API-Anfrage durchführen
$response = file_get_contents($fullUrl);
if ($response === false) {
echo "Fehler beim Abrufen der API-Daten.\n";
exit(1);
}
echo "Response received:\n";
echo $response . "\n\n";
// Flatfile-Response parsen (alle Kampagnen pipe-getrennt in einer Zeile)
$parts = explode('|', trim($response));
$kampagnenCount = 0;
$updatedCount = 0;
$createdCount = 0;
// Durch alle Kampagnen iterieren (je 5, 6 oder 7 Felder pro Kampagne)
$i = 0;
while ($i < count($parts)) {
// Mindestens 5 Felder erforderlich
if ($i + 4 >= count($parts)) {
break;
}
// Erste 5 Felder auslesen
$kid = $parts[$i];
$linktext = $parts[$i + 1];
$reload = (int) $parts[$i + 2];
$uebrig = (int) $parts[$i + 3];
$verdienst = (float) $parts[$i + 4];
// Prüfen ob MA-Feld vorhanden ist (6. Feld)
$ma = 0;
$mailtext = null;
$fieldsConsumed = 5;
// Heuristik: Wenn das nächste Feld numerisch ist und klein, ist es wahrscheinlich MA
if ($i + 5 < count($parts) && is_numeric($parts[$i + 5]) && $parts[$i + 5] < 1000) {
$ma = (int) $parts[$i + 5];
$fieldsConsumed = 6;
// Prüfen ob Nachrichtentext vorhanden ist (7. Feld)
if ($i + 6 < count($parts) && !is_numeric($parts[$i + 6])) {
$mailtext = $parts[$i + 6];
$fieldsConsumed = 7;
}
}
$i += $fieldsConsumed;
$kampagnenCount++;
// Link-URL und Bild-URL generieren (USERID und SEITENID werden später beim Einbau ersetzt)
$destUrl = "https://www.adcity.eu/codes/forcedtextlinkklick.php?id={USERID}&bid=$kid&aid={SEITENID}";
echo "Processing: $linktext (KID: $kid, MA: $ma, Reload: $reload, Uebrig: $uebrig)\n";
// Prüfen ob Kampagne bereits existiert (anhand user_id, KID und is_tr=1)
$existingKampagne = $entityManager->getRepository(Kampagne::class)
->findOneBy([
'user' => $werbenetzwerkUser,
'kid' => $kid,
'is_tr' => true
]);
if ($existingKampagne) {
// Kampagne aktualisieren (verguetung, reload, uebrig)
$existingKampagne->setVerguetung($verdienst);
$existingKampagne->setReload($reload);
$existingKampagne->setUebrig($uebrig);
$existingKampagne->setLinktext($linktext);
$existingKampagne->setMa($ma);
if ($mailtext) {
$existingKampagne->setMailtext($mailtext);
$existingKampagne->setIsMail(true);
}
$entityManager->persist($existingKampagne);
$updatedCount++;
echo " → Updated existing campaign (verguetung: $verdienst, reload: $reload, uebrig: $uebrig)\n";
} else {
// Neue Kampagne erstellen
$kampagne = new Kampagne();
$kampagne->setDestUrl($destUrl);
$kampagne->setKid($kid);
$kampagne->setLinktext($linktext);
$kampagne->setMa($ma);
$kampagne->setReload($reload);
$kampagne->setVerguetung($verdienst);
$kampagne->setUebrig($uebrig);
$kampagne->setIsFb(false);
$kampagne->setIsTr(true);
$kampagne->setIsMail(false);
if ($mailtext) {
$kampagne->setMailtext($mailtext);
$kampagne->setIsMail(true);
}
$kampagne->setUser($werbenetzwerkUser);
$entityManager->persist($kampagne);
$createdCount++;
echo " → Created new campaign\n";
}
}
$entityManager->flush();
echo "\n=== Summary ===\n";
echo "Total campaigns processed: $kampagnenCount\n";
echo "Created: $createdCount\n";
echo "Updated: $updatedCount\n";
echo "\nCron job completed successfully.\n";
} catch (\Exception $e) {
echo "Fehler: " . $e->getMessage() . "\n";
echo $e->getTraceAsString() . "\n";
exit(1);
}

View File

@@ -19,23 +19,81 @@ final class Version20251006214042 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE kampagnen (id INT AUTO_INCREMENT NOT NULL, is_fb TINYINT(1) NOT NULL, is_tr TINYINT(1) NOT NULL, is_mail TINYINT(1) NOT NULL, dest_url VARCHAR(255) NOT NULL, mailtext LONGTEXT DEFAULT NULL, img VARCHAR(255) DEFAULT NULL, linktext VARCHAR(255) DEFAULT NULL, ma SMALLINT NOT NULL, reload SMALLINT NOT NULL, dateCreated DATETIME NOT NULL, dateModified DATETIME NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_37572FC6A76ED395 (user_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE reloadsperre (id INT AUTO_INCREMENT NOT NULL, reload_bis DATETIME NOT NULL, ip VARCHAR(45) NOT NULL, dateCreated DATETIME NOT NULL, kampagne_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_B6A62B2AACE19231 (kampagne_id), INDEX IDX_B6A62B2AA76ED395 (user_id), INDEX idx_kampagne_user (kampagne_id, user_id), INDEX idx_reload_bis (reload_bis), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(100) NOT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\'), createdAt DATETIME NOT NULL, werbenetzwerk_id INT DEFAULT NULL, INDEX IDX_1483A5E948B23AFC (werbenetzwerk_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE werbenetzwerk (id INT AUTO_INCREMENT NOT NULL, umrechnungskurs DOUBLE PRECISION NOT NULL, eigenanteil_prozent SMALLINT UNSIGNED NOT NULL, date_updated DATETIME DEFAULT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT FK_37572FC6A76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E948B23AFC FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id)');
// Werbenetzwerk table
$this->addSql('CREATE TABLE werbenetzwerk (
id INT AUTO_INCREMENT NOT NULL,
umrechnungskurs DOUBLE PRECISION NOT NULL,
eigenanteil_prozent SMALLINT UNSIGNED NOT NULL,
interfacepasswort VARCHAR(255) NOT NULL,
interface_anfragen_pro_tag SMALLINT UNSIGNED NOT NULL,
user_id VARCHAR(50) NOT NULL,
date_updated DATETIME DEFAULT NULL,
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4');
// Users table
$this->addSql('CREATE TABLE users (
id INT AUTO_INCREMENT NOT NULL,
username VARCHAR(100) NOT NULL,
email VARCHAR(255) NULL,
password VARCHAR(255) NULL,
rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\'),
createdAt DATETIME NOT NULL,
werbenetzwerk_id INT DEFAULT NULL,
INDEX IDX_1483A5E948B23AFC (werbenetzwerk_id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4');
// Kampagnen table
$this->addSql('CREATE TABLE kampagnen (
id INT AUTO_INCREMENT NOT NULL,
is_fb TINYINT(1) NOT NULL,
is_tr TINYINT(1) NOT NULL,
is_mail TINYINT(1) NOT NULL,
dest_url VARCHAR(255) NOT NULL,
kid VARCHAR(100) DEFAULT NULL,
mailtext LONGTEXT DEFAULT NULL,
img VARCHAR(255) DEFAULT NULL,
linktext VARCHAR(255) DEFAULT NULL,
ma SMALLINT NOT NULL,
reload SMALLINT NOT NULL,
verguetung DOUBLE PRECISION DEFAULT NULL,
uebrig INT DEFAULT NULL,
dateCreated DATETIME NOT NULL,
dateModified DATETIME NOT NULL,
user_id INT DEFAULT NULL,
INDEX IDX_37572FC6A76ED395 (user_id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4');
// Reloadsperre table
$this->addSql('CREATE TABLE reloadsperre (
id INT AUTO_INCREMENT NOT NULL,
reload_bis DATETIME NOT NULL,
ip INT UNSIGNED NOT NULL,
dateCreated DATETIME NOT NULL,
kampagne_id INT NOT NULL,
user_id INT NOT NULL,
INDEX IDX_B6A62B2AACE19231 (kampagne_id),
INDEX IDX_B6A62B2AA76ED395 (user_id),
INDEX idx_kampagne_user (kampagne_id, user_id),
INDEX idx_reload_bis (reload_bis),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4');
// Foreign keys
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT FK_37572FC6A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE RESTRICT');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E948B23AFC FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id) ON DELETE SET NULL');
// Default data - Werbenetzwerk
$this->addSql('INSERT INTO werbenetzwerk (umrechnungskurs, eigenanteil_prozent, date_updated) VALUES (0.0000000022, 25, NOW())');
$this->addSql('INSERT INTO werbenetzwerk (id, umrechnungskurs, eigenanteil_prozent, interfacepasswort, interface_anfragen_pro_tag, user_id, date_updated) VALUES (1, 0.0000000022, 25, "pAKc34EajovTvsnD6Y6WfhS", 500, "1244", NOW())');
// Default data - Users
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("admin", "admin@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "admin", NOW())');
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("testuser1", "testuser1@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "user", NOW())');
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("testuser2", "testuser2@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "user", NOW())');
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt, werbenetzwerk_id) VALUES ("adcity-eu", "", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "werbenetzwerk", NOW(),1)');
}
public function down(Schema $schema): void

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214520 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change IP column to VARBINARY(16) for efficient storage';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARBINARY(16) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARCHAR(45) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214635 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change IP column to INT UNSIGNED for IPv4 storage (4 bytes)';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARBINARY(16) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

View File

@@ -1,47 +0,0 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214741 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add ON DELETE actions to foreign keys';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE kampagnen DROP FOREIGN KEY `FK_37572FC6A76ED395`');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT FK_37572FC6A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AA76ED395`');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AACE19231`');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users DROP FOREIGN KEY `FK_1483A5E948B23AFC`');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E948B23AFC FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE kampagnen DROP FOREIGN KEY FK_37572FC6A76ED395');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT `FK_37572FC6A76ED395` FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AACE19231');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AA76ED395');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AACE19231` FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AA76ED395` FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE users DROP FOREIGN KEY FK_1483A5E948B23AFC');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
$this->addSql('ALTER TABLE users ADD CONSTRAINT `FK_1483A5E948B23AFC` FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id)');
}
}

View File

@@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214859 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change kampagne FK to RESTRICT (kampagne must exist)';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AACE19231`');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE RESTRICT');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AACE19231');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AACE19231` FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

View File

@@ -26,6 +26,9 @@ class Kampagne
#[ORM\Column(type: 'string', length: 255)]
private string $dest_url;
#[ORM\Column(type: 'string', length: 100, nullable: true)]
private ?string $kid = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $mailtext = null;
@@ -41,6 +44,12 @@ class Kampagne
#[ORM\Column(type: 'smallint')]
private int $reload = 0;
#[ORM\Column(type: 'float', nullable: true)]
private ?float $verguetung = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $uebrig = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?User $user = null;
@@ -114,6 +123,17 @@ class Kampagne
return $this;
}
public function getKid(): ?string
{
return $this->kid;
}
public function setKid(?string $kid): self
{
$this->kid = $kid;
return $this;
}
public function getMailtext(): ?string
{
return $this->mailtext;
@@ -169,6 +189,28 @@ class Kampagne
return $this;
}
public function getVerguetung(): ?float
{
return $this->verguetung;
}
public function setVerguetung(?float $verguetung): self
{
$this->verguetung = $verguetung;
return $this;
}
public function getUebrig(): ?int
{
return $this->uebrig;
}
public function setUebrig(?int $uebrig): self
{
$this->uebrig = $uebrig;
return $this;
}
public function getDateCreated(): \DateTimeInterface
{
return $this->dateCreated;

View File

@@ -3,6 +3,8 @@
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
use Entity\Kampagne;
use Entity\User;
#[ORM\Entity]
#[ORM\Table(name: 'reloadsperre')]

View File

@@ -4,7 +4,7 @@ namespace Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Entity(repositoryClass: 'Repository\WerbenetzwerkRepository')]
#[ORM\Table(name: 'werbenetzwerk')]
#[ORM\HasLifecycleCallbacks]
class Werbenetzwerk
@@ -20,6 +20,15 @@ class Werbenetzwerk
#[ORM\Column(type: 'smallint', options: ['unsigned' => true])]
private int $eigenanteil_prozent;
#[ORM\Column(type: 'string', length: 255)]
private string $interfacepasswort;
#[ORM\Column(type: 'smallint', options: ['unsigned' => true])]
private int $interface_anfragen_pro_tag;
#[ORM\Column(type: 'string', length: 50)]
private string $user_id;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $date_updated = null;
@@ -62,4 +71,37 @@ class Werbenetzwerk
{
return $this->date_updated;
}
public function getInterfacepasswort(): string
{
return $this->interfacepasswort;
}
public function setInterfacepasswort(string $interfacepasswort): self
{
$this->interfacepasswort = $interfacepasswort;
return $this;
}
public function getInterfaceAnfragenProTag(): int
{
return $this->interface_anfragen_pro_tag;
}
public function setInterfaceAnfragenProTag(int $interface_anfragen_pro_tag): self
{
$this->interface_anfragen_pro_tag = $interface_anfragen_pro_tag;
return $this;
}
public function getUserId(): string
{
return $this->user_id;
}
public function setUserId(string $user_id): self
{
$this->user_id = $user_id;
return $this;
}
}

View File

@@ -31,6 +31,14 @@ class UserRepository extends EntityRepository
return $this->findOneBy(['email' => $email]);
}
/**
* Findet einen User anhand des Werbenetzwerks
*/
public function findByWerbenetzwerk(\Entity\Werbenetzwerk $werbenetzwerk): ?User
{
return $this->findOneBy(['werbenetzwerk' => $werbenetzwerk]);
}
/**
* Findet alle User
*/

View File

@@ -0,0 +1,70 @@
<?php
namespace Repository;
use Doctrine\ORM\EntityRepository;
use Entity\Werbenetzwerk;
class WerbenetzwerkRepository extends EntityRepository
{
/**
* Findet ein Werbenetzwerk anhand der ID
*/
public function findById(int $id): ?Werbenetzwerk
{
return $this->find($id);
}
/**
* Findet ein Werbenetzwerk anhand der User-ID
*/
public function findByUserId(string $userId): ?Werbenetzwerk
{
return $this->findOneBy(['user_id' => $userId]);
}
/**
* Findet ein Werbenetzwerk anhand des Users
*/
public function findByUser(\Entity\User $user): ?Werbenetzwerk
{
return $user->getWerbenetzwerk();
}
/**
* Findet alle Werbenetzwerke
*/
public function findAllWerbenetzwerke(): array
{
return $this->findAll();
}
/**
* Zählt alle Werbenetzwerke
*/
public function countWerbenetzwerke(): int
{
return $this->createQueryBuilder('w')
->select('COUNT(w.id)')
->getQuery()
->getSingleScalarResult();
}
/**
* Speichert ein Werbenetzwerk
*/
public function save(Werbenetzwerk $werbenetzwerk): void
{
$this->getEntityManager()->persist($werbenetzwerk);
$this->getEntityManager()->flush();
}
/**
* Löscht ein Werbenetzwerk
*/
public function delete(Werbenetzwerk $werbenetzwerk): void
{
$this->getEntityManager()->remove($werbenetzwerk);
$this->getEntityManager()->flush();
}
}