Skip to content

Commit

Permalink
(#10): Added few new ad types and updated few existing ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Ruzak committed Dec 6, 2021
1 parent c680676 commit 2e91435
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 22 deletions.
10 changes: 10 additions & 0 deletions src/AdType.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ public function hasCustomTag($name)
return isset($this->customTags[$name]);
}

public function getPriceTagName()
{
return $this->priceBody->tagName ?? '';
}

public function createObjectHead()
{
$this->createObjectHeadTrait();
Expand Down Expand Up @@ -245,4 +250,9 @@ public function createObjectHead()
}
$this->objectBody->appendChild($this->objectHeadBody);
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
}
}
60 changes: 60 additions & 0 deletions src/AdTypes/BoatMotorXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\PriceTrait;

class BoatMotorXml extends AdType
{
use PriceTrait;

protected $dtd = 'https://www.iad.no/dtd/IADIF-boat_motor23.dtd';

protected $documentType = 'IAD.IF.BOAT_MOTOR';

protected $adBodyTag = 'BOAT_MOTOR';

public function __construct($partner_id, $provider)
{
parent::__construct($partner_id, $provider);
$this->BOATMOTOR_CATEGORY = '';
$this->MOTORTYPE = '';
$this->MOTORMAKE = '';
$this->MOTORSIZE = '';

// Price.
$this->createPriceElements();
$this->priceBody->removeChild($this->priceCurrencyBody);

// Other fields.
$this->DESCRIPTION = '';
$this->VIDEO_URL = '';

// More info.
$this->createMoreInfoElements();

// Contact.
$this->initializeContact();
$this->contactBody->removeAttribute('PHONESALESRESERVATION');
$this->contactBody->removeChild($this->contactFaxBody);
}

public function setSegment($segment)
{
$this->BOATMOTOR_CATEGORY = $segment;
}

public function setMake($make)
{
$this->MOTORTYPE = $make;
}

public function setPhoneSalesReservation($reservation = true)
{
}

public function setContactFax($fax)
{
}
}
22 changes: 16 additions & 6 deletions src/AdTypes/BoatXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\ModelPropertyTrait;
use eiriksm\FinnTransfer\Traits\MotorPriceTrait;
use eiriksm\FinnTransfer\Traits\PriceTrait;

class BoatXml extends AdType
{
use PriceTrait;

protected $dtd = 'http://www.iad.no/dtd/IADIF-boat50.dtd';
protected $dtd = 'https://www.iad.no/dtd/IADIF-boat51.dtd';

protected $documentType = 'IAD.IF.BOAT';

Expand Down Expand Up @@ -39,20 +39,30 @@ public function __construct($partner_id, $provider)
$this->MOTOR_INCLUDED = '';
$this->MAX_SPEED = '';
$this->BOAT_EQUIPMENT = '';
$this->PRICE = '';

// Price.
$this->createPriceElements();

$this->DESCRIPTION = '';

// More info.
$this->createMoreInfoElements();

// Contact.
$this->initializeContact();

$this->LIGHTNUMBER = '';
$this->MOTOR_AD_LOCATION = '';
$this->VIDEO_URL = '';
}

public function setMotorPrice($number, $currency = 'NOK')
public function setSegment($segment)
{
$this->BOAT_CLASS = $segment;
}

public function setIncludingMva($includes)
public function setMake($make)
{
$this->BOAT_MAKE = $make;
}
}
5 changes: 0 additions & 5 deletions src/AdTypes/CarXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public function setAdType($type)
$this->CAR_SALESFORM = $type;
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
}

public function setPhoneSalesReservation($reservation = true)
{
}
Expand Down
7 changes: 1 addition & 6 deletions src/AdTypes/CaravanXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public function createMotorPriceElements($vat_attribute = false)

public function setAdType($type)
{
$this->CAR_SALESFORM = $type;
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
$this->CARAVAN_SALESFORM = $type;
}

public function setSegment($segment)
Expand Down
5 changes: 0 additions & 5 deletions src/AdTypes/McXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ public function setAdType($type)
$this->CAR_SALESFORM = $type;
}

public function setRegistrationNumber($number)
{
$this->REGNO = $number;
}

public function setPhoneSalesReservation($reservation = true)
{
}
Expand Down
107 changes: 107 additions & 0 deletions src/AdTypes/MobileHomeXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\ModelPropertyTrait;
use eiriksm\FinnTransfer\Traits\MotorPriceTrait;

class MobileHomeXml extends AdType
{
use ModelPropertyTrait;
use MotorPriceTrait {
setMotorPrice as protected setMotorPriceTrait;
createMotorPriceElements as protected createMotorPriceElementsTrait;
}

protected $dtd = 'https://www.iad.no/dtd/IADIF-mobilehome-11.dtd';

protected $documentType = 'IAD.IF.MOBILE_HOME';

protected $adBodyTag = 'MOBILE_HOME';

protected $weightBody;
protected $weightNet;
protected $weightTot;

public function __construct($partner_id, $provider)
{
parent::__construct($partner_id, $provider);

$this->CARAVAN_SALESFORM = '';
$this->MOBILE_HOME_SEGMENT = '';
$this->MOBILE_HOME_CHASSIS = '';

// Model.
$this->createModelProperty('CARAVAN_MODEL');
$this->adBody->appendChild($this->modelOuterBody);

// Other fields.
$this->YEAR_MODEL = '';
$this->MILEAGE = '';
$this->NO_OF_BERTHS = '';
$this->BED = '';
$this->WIDTH_CM = '';
$this->LENGTH_CM = '';

// Weight.
$this->weightBody = $this->dom->createElement('CARAVAN_WEIGHT');
$this->weightNet = $this->dom->createElement('WEIGHT_NET');
$this->weightTot = $this->dom->createElement('WEIGHT_TOT');
$this->weightBody->appendChild($this->weightNet);
$this->weightBody->appendChild($this->weightTot);
$this->adBody->appendChild($this->weightBody);

// Motor and price elements.
$this->createMotorPriceElements();

// Registration.
$reg_el = $this->dom->createElement('REGISTRATION', '0');
$this->priceBody->appendChild($reg_el);

// Other fields.
$this->MOBILE_HOME_EQUIPMENT = '';
$this->DESCRIPTION = '';
$this->CARAVAN_CONDITION_REPORT = '';
$this->CAR_CONDITION_DOC = '';
$this->createMoreInfoElements();

// Contact.
$this->initializeContact();
$this->contactBody->removeAttribute('PHONESALESRESERVATION');

// Other fields.
$this->MOBILE_HOME_LOCATION = '';
$this->NO_OF_SEATS = '';

// Engine.
$this->createEngineElements();
$this->engineBody->removeChild($this->engineFuelBody);

// Other fields.
$this->TRANSMISSION = '';
$this->WHEEL_DRIVE = '';
$this->MOBILE_HOME_CONDITION = '';
$this->MOBILE_HOME_WARRANTY = '';
$this->WARRANTY_DISTANCE = '';
$this->REGNO = '';
$this->NO_OF_OWNERS = '';
$this->REGISTRATION_FIRST = '';
$this->VIDEO_URL = '';
}

public function createMotorPriceElements($vat_attribute = false)
{
$this->createMotorPriceElementsTrait($vat_attribute);
$this->priceBody->removeChild($this->priceCurrencyBody);
}

public function setSegment($segment)
{
$this->MOBILE_HOME_SEGMENT = $segment;
}

public function setPhoneSalesReservation($reservation = true)
{
}
}
39 changes: 39 additions & 0 deletions src/AdTypes/MotorMiscXml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace eiriksm\FinnTransfer\AdTypes;

use eiriksm\FinnTransfer\AdType;
use eiriksm\FinnTransfer\Traits\PriceTrait;

class MotorMiscXml extends AdType
{
use PriceTrait;

protected $dtd = 'https://www.iad.no/dtd/IADIF-motor_misc51.dtd';

protected $documentType = 'IAD.IF.MOTORMISC';

protected $adBodyTag = 'MOTORMISC';

public function __construct($partner_id, $provider)
{
parent::__construct($partner_id, $provider);

$this->MOTORMISC_CATEGORY = '';
$this->DESCRIPTION = '';

// More info.
$this->createMoreInfoElements();

// Price.
$this->createPriceElements();

// Contact.
$this->initializeContact();
}

public function setSegment($segment)
{
$this->MOTORMISC_CATEGORY = $segment;
}
}
38 changes: 38 additions & 0 deletions src/Traits/PriceTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace eiriksm\FinnTransfer\Traits;

trait PriceTrait
{

/**
* @var \DOMElement
*/
protected $priceBody;

protected $priceAmountBody;

protected $priceCurrencyBody;


public function setPrice($number, $currency = 'NOK')
{
if (!isset($this->priceBody)) {
$this->createPriceElements();
}
$this->priceAmountBody->nodeValue = $number;
$this->priceCurrencyBody->nodeValue = $currency;
}

protected function createPriceElements()
{
if (!isset($this->priceBody)) {
$this->priceBody = $this->dom->createElement('PRICE');
$this->priceAmountBody = $this->dom->createElement('AMOUNT');
$this->priceBody->appendChild($this->priceAmountBody);
$this->priceCurrencyBody = $this->dom->createElement('CURRENCY');
$this->priceBody->appendChild($this->priceCurrencyBody);
$this->adBody->appendChild($this->priceBody);
}
}
}

0 comments on commit 2e91435

Please sign in to comment.