Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/packages/easy_admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ easy_admin:
- { property: matchingContexts, label: notices.matchingContexts }
- { property: expires, label: notices.expires }
- { property: unpublishedOnExpiration, label: notices.unpublishedOnExpiration }
- { property: badgedRatingCount, label: notices.badgedRatingCount }
- { property: displayedRatingCount, label: notices.displayedRatingCount, css_class: 'graphable column-displayedRatingCount' }
- { property: unfoldedRatingCount, label: notices.unfoldedRatingCount, css_class: 'graphable column-unfoldedRatingCount' }
- { property: clickedRatingCount, label: notices.clickedRatingCount, css_class: 'graphable column-clickedRatingCount' }
- { property: likedRatingCount, label: notices.likedRatingCount, css_class: 'graphable column-likedRatingCount' }
- { property: dislikedRatingCount, label: notices.dislikedRatingCount, css_class: 'graphable column-dislikedRatingCount' }
- { property: dismissedRatingCount, label: notices.dismissedRatingCount, css_class: 'graphable column-dismissedRatingCount' }
form: &noticeForm
fields:
- { type: group, label: notices.groups.publication, icon: comments, columns: 8 }
Expand Down
12 changes: 12 additions & 0 deletions src/DataFixtures/DomainFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public function load(ObjectManager $manager): void
$manager->persist($okinawa);
$this->addReference('okinawa_domain', $okinawa);

$testsMenantDomain = new DomainName('tests.menant-benjamin.fr');
$manager->persist($testsMenantDomain);
$this->addReference('tests_menant_domain', $testsMenantDomain);

$lbcDomain = new DomainName('leboncoin.fr');
$manager->persist($lbcDomain);
$this->addReference('lbc_domain', $lbcDomain);

$lequipe = new DomainName('lequipe.fr');
$manager->persist($lequipe);
$this->addReference('lequipe_domain', $lequipe);

$manager->flush();
}

Expand Down
82 changes: 82 additions & 0 deletions src/DataFixtures/NoticeMatchingContextFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace App\DataFixtures;

use App\Domain\Factory\MatchingContextFactory;
use App\Entity\Contributor;
use App\Entity\Notice;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;

class NoticeMatchingContextFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager): void
{
/** @var Contributor $famousContributor */
$famousContributor = $this->getReference('famous_contributor');

$notice = new Notice();
$notice->setContributor($famousContributor);
$notice->setMessage('This notice has two matching contexts on same domain');
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('tests_menant_domain'),
'.*',
"//text()[contains(.,'Not Found')]"
));
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('tests_menant_domain'),
'.*',
"//text()[contains(.,'was not found on this server')]"
));
$manager->persist($notice);

$notice = new Notice();
$notice->setContributor($famousContributor);
$notice->setMessage('This notice on the same domain of others notices.');
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('tests_menant_domain'),
'.*',
"//text()[contains(.,'This is not an error!')]"
));
$manager->persist($notice);

$notice = new Notice();
$notice->setContributor($famousContributor);
$notice->setMessage('This notice appear on lbc when the word "location" is found.');
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('lbc_domain'),
'.*',
"//text()[contains(.,'location')]"
));
$manager->persist($notice);

$notice = new Notice();
$notice->setContributor($famousContributor);
$notice->setMessage('This notice appear on lbc when the word "piscine" is found.');
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('lbc_domain'),
'.*',
"//text()[contains(.,'piscine')]"
));
$manager->persist($notice);

$notice = new Notice();
$notice->setContributor($famousContributor);
$notice->setMessage("Accès gratuit aux notes des joueurs sur d'autres sites...");
$notice->addMatchingContext(MatchingContextFactory::create(
$this->getReference('lequipe_domain'),
'.*((football.*article.*notes)|(football.*notes.*match))'
));
$manager->persist($notice);

$manager->flush();
}

public function getDependencies()
{
return [ContributorFixtures::class, DomainFixtures::class];
}
}
26 changes: 26 additions & 0 deletions src/Domain/Factory/MatchingContextFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Domain\Factory;

use App\Entity\DomainName;
use App\Entity\MatchingContext;

class MatchingContextFactory
{
public static function create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put this static function create inside MatchingContext class ?

DomainName $domainName,
string $urlRegex = '.*',
string $xpath = null
): MatchingContext {
$matchingContext = new MatchingContext();
$matchingContext->addDomainName($domainName);
$matchingContext->setUrlRegex($urlRegex);
if ($xpath) {
$matchingContext->setXpath($xpath);
}

return $matchingContext;
}
}