Skip to content
Merged
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
61 changes: 11 additions & 50 deletions library/DataFixtures/ORM/ProviderCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DataFixtures\ORM;

use DataFixtures\Stub\Provider\CompanyStub;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
Expand All @@ -14,6 +15,11 @@ class ProviderCompany extends Fixture implements DependentFixtureInterface
{
use \DataFixtures\FixtureHelperTrait;

public function __construct(
private CompanyStub $companyStub,
) {
}

/**
* {@inheritDoc}
*/
Expand All @@ -23,55 +29,11 @@ public function load(ObjectManager $manager)
$this->disableLifecycleEvents($manager);
$manager->getClassMetadata(Company::class)->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);

/** @var CompanyInterface $item1 */
$item1 = $this->createEntityInstance(Company::class);
(function () use ($fixture) {

$invoicing = new Invoicing(
nif: '12345678A',
postalAddress: 'Company Address',
postalCode: '54321',
town: 'Company Town',
province: 'Company Province',
countryName: 'Company Country',
);

$this->setName("DemoCompany");
$this->setDomainUsers("127.0.0.1");
$this->setMaxCalls(0);
$this->setIpfilter(false);
$this->setOnDemandRecord(0);
$this->setOnDemandRecordCode("");
$this->setExternallyextraopts("");
$this->setRecordingsLimitEmail("");
$this->setBillingMethod("prepaid");
$this->setBalance(1.2);
$this->setMaxDailyUsageEmail('[email protected]');
$this->setMaxDailyUsage(2);
$this->setCurrentDayUsage(1);
$this->setShowInvoices(true);
$this->setMaxDailyUsageNotificationTemplate(
$fixture->getReference('_reference_ProviderNotificationTemplate2')
);
$this->invoicing = $invoicing;
$this->setLanguage($fixture->getReference('_reference_ProviderLanguage1'));
$this->setDefaultTimezone($fixture->getReference('_reference_ProviderTimezone145'));
$this->setBrand($fixture->getReference('_reference_ProviderBrand1'));
$this->setDomain($fixture->getReference('_reference_ProviderDomain3'));
$this->setCountry($fixture->getReference('_reference_ProviderCountry70'));
$this->setTransformationRuleSet($fixture->getReference('_reference_ProviderTransformationRuleSet70'));
$this->setVoicemailNotificationTemplate($fixture->getReference('_reference_ProviderNotificationTemplate1'));
$this->setAccessCredentialNotificationTemplate($fixture->getReference('_reference_ProviderNotificationTemplate5'));
$this->setCorporation($fixture->getReference('_reference_Corporation1'));
$this->setApplicationServerSet($fixture->getReference('_reference_ProviderApplicationServerSet1'));
$this->setMediaRelaySet($fixture->getReference('_reference_ProviderMediaRelaySet0'));
$this->setLocation($fixture->getReference('_reference_ProviderLocation1'));
})->call($item1);

$this->addReference('_reference_ProviderCompany1', $item1);

$this->sanitizeEntityValues($item1);
$manager->persist($item1);
$entities = $this->companyStub->getAll();
foreach ($entities as $entity) {
$this->addReference('_reference_ProviderCompany' . $entity->getId(), $entity);
$manager->persist($entity);
}

$item2 = $this->createEntityInstance(Company::class);
(function () use ($fixture) {
Expand Down Expand Up @@ -277,7 +239,6 @@ public function getDependencies()
ProviderCorporation::class,
ProviderApplicationServerSet::class,
ProviderMediaRelaySet::class,
ProviderLocation::class,
);
}
}
12 changes: 9 additions & 3 deletions library/DataFixtures/ORM/ProviderLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use DataFixtures\Stub\Provider\LocationStub;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use Ivoz\Provider\Domain\Model\Location\Location;
use Ivoz\Provider\Domain\Model\Location\EncodedFile;
use Ivoz\Provider\Domain\Model\Location\OriginalFile;

class ProviderLocation extends Fixture
class ProviderLocation extends Fixture implements DependentFixtureInterface
{
use \DataFixtures\FixtureHelperTrait;

Expand Down Expand Up @@ -43,4 +42,11 @@ public function load(ObjectManager $manager)

$manager->flush();
}

public function getDependencies()
{
return array(
ProviderCompany::class,
);
}
}
4 changes: 2 additions & 2 deletions library/DataFixtures/ORM/ProviderSurvivalDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function load(ObjectManager $manager)
$this->setTlsPort(5063);
$this->setWssPort(10083);
$this->setDescription("new survival device 3");
$this->setCompany($fixture->getReference('_reference_ProviderCompany3'));
$this->setCompany($fixture->getReference('_reference_ProviderCompany1'));
})->call($item3);
$this->addReference('__reference_SurvivalDevice3', $item3);
$this->sanitizeEntityValues($item3);
Expand All @@ -78,7 +78,7 @@ public function load(ObjectManager $manager)
$this->setTlsPort(5064);
$this->setWssPort(10084);
$this->setDescription("new survival device 4");
$this->setCompany($fixture->getReference('_reference_ProviderCompany4'));
$this->setCompany($fixture->getReference('_reference_ProviderCompany1'));
})->call($item4);
$this->addReference('__reference_SurvivalDevice4', $item4);
$this->sanitizeEntityValues($item4);
Expand Down
57 changes: 57 additions & 0 deletions library/DataFixtures/Stub/Provider/CompanyStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace DataFixtures\Stub\Provider;

use DataFixtures\Stub\StubTrait;
use Ivoz\Provider\Domain\Model\Company\Company;
use Ivoz\Provider\Domain\Model\Company\CompanyDto;

class CompanyStub
{
use StubTrait;

protected function getEntityName(): string
{
return Company::class;
}

protected function load()
{
$dto = (new CompanyDto(1))
->setName("DemoCompany")
->setDomainUsers("127.0.0.1")
->setMaxCalls(0)
->setIpfilter(false)
->setOnDemandRecord(0)
->setOnDemandRecordCode("")
->setExternallyextraopts("")
->setRecordingsLimitEmail("")
->setBillingMethod("prepaid")
->setBalance(1.2)
->setMaxDailyUsageEmail('[email protected]')
->setMaxDailyUsage(2)
->setCurrentDayUsage(1)
->setShowInvoices(true)
->setInvoicingNif('12345678A')
->setInvoicingPostalAddress('Company Address')
->setInvoicingPostalCode('54321')
->setInvoicingTown('Company Town')
->setInvoicingProvince('Company Province')
->setInvoicingCountryName('Company Country')
->setLanguageId(1)
->setDefaultTimezoneId(145)
->setBrandId(1)
->setDomainId(3)
->setCountryId(68)
->setTransformationRuleSetId(1)
->setVoicemailNotificationTemplateId(1)
->setAccessCredentialNotificationTemplateId(5)
->setCorporationId(1)
->setApplicationServerSetId(1)
->setMediaRelaySetId(0)
->setMaxDailyUsageNotificationTemplateId(2)
->setLocationId(1);

$this->append($dto);
}
}
10 changes: 10 additions & 0 deletions library/Ivoz/Provider/Domain/Model/Calendar/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ivoz\Provider\Domain\Model\Calendar;

use Ivoz\Core\Infrastructure\Persistence\Doctrine\Model\Helper\CriteriaHelper;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;

/**
* Calendar
Expand Down Expand Up @@ -66,4 +67,13 @@ public function getHolidayDate(\DateTimeInterface $dateTime)

return array_shift($holidayDates);
}

protected function setCompany(CompanyInterface $company): static
{
if ($company->getType() !== CompanyInterface::TYPE_VPBX) {
throw new \DomainException('Calendar can only be associated with vpbx companies');
}

return parent::setCompany($company);
}
}
10 changes: 10 additions & 0 deletions library/Ivoz/Provider/Domain/Model/CallAcl/CallAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\Common\Collections\Criteria;
use Ivoz\Provider\Domain\Model\CallAclRelMatchList\CallAclRelMatchListInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;

/**
* CallAcl
Expand Down Expand Up @@ -60,4 +61,13 @@ public function dstIsCallable($dst)

return 'allow' === $defaultPolicy;
}

protected function setCompany(CompanyInterface $company): static
{
if ($company->getType() !== CompanyInterface::TYPE_VPBX) {
throw new \DomainException('CallAcl can only be associated with vpbx companies');
}

return parent::setCompany($company);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ivoz\Provider\Domain\Model\CompanyRelCodec;

use Ivoz\Provider\Domain\Model\Company\CompanyInterface;

/**
* CompanyRelCodec
* @codeCoverageIgnore
Expand All @@ -28,4 +30,22 @@ public function getId(): ?int
{
return $this->id;
}

public function setCompany(CompanyInterface $company = null): static
{
if (is_null($company)) {
return parent::setCompany(null);
}

$companyType = $company->getType();
$isValidCompanyType =
$companyType === CompanyInterface::TYPE_RETAIL ||
$companyType === CompanyInterface::TYPE_WHOLESALE;

if (!$isValidCompanyType) {
throw new \DomainException('CompanyRelCodec can only be associated with retail or wholesale companies');
}

return parent::setCompany($company);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Ivoz\Provider\Domain\Model\CompanyRelCodec;

use Ivoz\Core\Domain\Model\LoggableEntityInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Core\Domain\Model\EntityInterface;
use Ivoz\Core\Domain\DataTransferObjectInterface;
use Ivoz\Core\Domain\ForeignKeyTransformerInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Model\Codec\CodecInterface;

/**
Expand All @@ -27,6 +27,8 @@ public function getChangeSet(): array;
*/
public function getId(): ?int;

public function setCompany(?CompanyInterface $company = null): static;

/**
* @param int | null $id
*/
Expand All @@ -50,8 +52,6 @@ public static function fromDto(DataTransferObjectInterface $dto, ForeignKeyTrans
*/
public function toDto(int $depth = 0): CompanyRelCodecDto;

public function setCompany(?CompanyInterface $company = null): static;

public function getCompany(): ?CompanyInterface;

public function getCodec(): CodecInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Ivoz\Provider\Domain\Model\ConditionalRoute;

use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Traits\RoutableTrait;

/**
Expand Down Expand Up @@ -69,4 +70,13 @@ public function getNumberValueE164()
$this->getNumberCountry()->getCountryCode() .
$this->getNumberValue();
}

protected function setCompany(CompanyInterface $company): static
{
if ($company->getType() !== CompanyInterface::TYPE_VPBX) {
throw new \DomainException('ConditionalRoute can only be associated with vpbx companies');
}

return parent::setCompany($company);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ivoz\Provider\Domain\Model\ConferenceRoom;

use Ivoz\Provider\Domain\Model\Company\CompanyInterface;

/**
* ConferenceRoom
*/
Expand Down Expand Up @@ -51,4 +53,13 @@ protected function sanitizeValues(): void
$this->setPinCode(null);
}
}

protected function setCompany(CompanyInterface $company): static
{
if ($company->getType() !== CompanyInterface::TYPE_VPBX) {
throw new \DomainException('ConferenceRoom can only be associated with vpbx companies');
}

return parent::setCompany($company);
}
}
10 changes: 10 additions & 0 deletions library/Ivoz/Provider/Domain/Model/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Ivoz\Provider\Domain\Model\Contact;

use Ivoz\Core\Domain\Assert\Assertion;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;

/**
* Contact
Expand Down Expand Up @@ -57,4 +58,13 @@ protected function setEmail(?string $email = null): static

return parent::setEmail($email);
}

public function setCompany(CompanyInterface $company): static
{
if ($company->getType() !== CompanyInterface::TYPE_VPBX) {
throw new \DomainException('Contact can only be associated with vpbx companies');
}

return parent::setCompany($company);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Ivoz\Provider\Domain\Model\Contact;

use Ivoz\Core\Domain\Model\LoggableEntityInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Core\Domain\Model\EntityInterface;
use Ivoz\Core\Domain\DataTransferObjectInterface;
use Ivoz\Core\Domain\ForeignKeyTransformerInterface;
use Ivoz\Provider\Domain\Model\User\UserInterface;
use Ivoz\Provider\Domain\Model\Company\CompanyInterface;
use Ivoz\Provider\Domain\Model\Country\CountryInterface;

/**
Expand All @@ -28,6 +28,8 @@ public function getChangeSet(): array;
*/
public function getId(): ?int;

public function setCompany(CompanyInterface $company): static;

/**
* @param int | null $id
*/
Expand Down Expand Up @@ -71,8 +73,6 @@ public function setUser(?UserInterface $user = null): static;

public function getUser(): ?UserInterface;

public function setCompany(CompanyInterface $company): static;

public function getCompany(): CompanyInterface;

public function getWorkPhoneCountry(): ?CountryInterface;
Expand Down
Loading