327 lines
8.0 KiB
PHP
327 lines
8.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Subclass for representing a row from the 'st_invoice_user_customer' table.
|
|
*
|
|
*
|
|
*
|
|
* @package plugins.stInvoicePlugin.lib.model
|
|
*/
|
|
class InvoiceUserCustomer extends BaseInvoiceUserCustomer
|
|
{
|
|
public function getFullName()
|
|
{
|
|
$fullname = parent::getFullName();
|
|
|
|
if (empty($fullname))
|
|
{
|
|
if ($this->getName() != "" || $this->getSurname() != "")
|
|
{
|
|
$fullname = $this->getName() . ' ' . $this->getSurname();
|
|
}
|
|
}
|
|
|
|
return $fullname;
|
|
}
|
|
|
|
public function getAddress()
|
|
{
|
|
$address = parent::getAddress();
|
|
|
|
if (empty($address))
|
|
{
|
|
if ($this->getStreet() != "" || $this->getHouse() != "" || $this->getFlat() != "")
|
|
{
|
|
$old_address = $this->getStreet() . ' ' . $this->getHouse();
|
|
|
|
if ($this->getFlat() != "")
|
|
{
|
|
|
|
$old_address .= '/' . $this->getFlat();
|
|
}
|
|
|
|
$address = $old_address;
|
|
}
|
|
}
|
|
|
|
return $address;
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
$name = parent::getName();
|
|
if (empty($name))
|
|
{
|
|
$fullname_array = explode(' ', parent::getFullName());
|
|
$name = $fullname_array[0];
|
|
}
|
|
|
|
return $name;
|
|
}
|
|
|
|
public function getSurname()
|
|
{
|
|
$surname = parent::getSurname();
|
|
if (empty($surname))
|
|
{
|
|
$fullname_array = explode(' ', parent::getFullName());
|
|
|
|
foreach ($fullname_array as $key => $array)
|
|
{
|
|
if ($key != 0)
|
|
{
|
|
$surname .= $array;
|
|
$surname .= " ";
|
|
}
|
|
}
|
|
$surname = substr($surname, 0, strlen($surname) - 1);
|
|
}
|
|
|
|
return $surname;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
* @deprecated use getAddress method
|
|
*/
|
|
public function getStreet()
|
|
{
|
|
$street = parent::getStreet();
|
|
if (empty($street))
|
|
{
|
|
$aparser = new stAddressParser(parent::getAddress());
|
|
$result = $aparser->getAddress();
|
|
$street = $result['s1'];
|
|
}
|
|
|
|
return $street;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
* @deprecated use getAddress method
|
|
*/
|
|
public function getHouse()
|
|
{
|
|
$house = parent::getHouse();
|
|
if (empty($house))
|
|
{
|
|
$aparser = new stAddressParser(parent::getAddress());
|
|
$result = $aparser->getAddress();
|
|
$house = $result['n1'];
|
|
}
|
|
|
|
return $house;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
* @deprecated use getAddress method
|
|
*/
|
|
public function getFlat()
|
|
{
|
|
$flat = parent::getFlat();
|
|
if (empty($flat))
|
|
{
|
|
$aparser = new stAddressParser(parent::getAddress());
|
|
$result = $aparser->getAddress();
|
|
$flat = $result['n2'];
|
|
}
|
|
|
|
return $flat;
|
|
}
|
|
|
|
public function isCompany()
|
|
{
|
|
return null !== $this->getCompany() && !empty($this->getCompany());
|
|
}
|
|
|
|
public function hydrate(ResultSet $rs, $startcol = 1)
|
|
{
|
|
$ret = parent::hydrate($rs, $startcol);
|
|
|
|
$crypt = Crypt::getInstance();
|
|
|
|
if ($crypt->isEncrypted($this->crypt))
|
|
{
|
|
$this->address = $crypt->Decrypt($this->address, $this->crypt);
|
|
|
|
$this->address_more = $crypt->Decrypt($this->address_more, $this->crypt);
|
|
|
|
$this->region = $crypt->Decrypt($this->region, $this->crypt);
|
|
|
|
$this->pesel = $crypt->Decrypt($this->pesel, $this->crypt);
|
|
|
|
$this->street = $crypt->Decrypt($this->street, $this->crypt);
|
|
|
|
$this->house = $crypt->Decrypt($this->house, $this->crypt);
|
|
|
|
$this->flat = $crypt->Decrypt($this->flat, $this->crypt);
|
|
|
|
$this->code = $crypt->Decrypt($this->code, $this->crypt);
|
|
|
|
$this->town = $crypt->Decrypt($this->town, $this->crypt);
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|
|
public function save($con = null, $forced = false)
|
|
{
|
|
$crypt = Crypt::getInstance();
|
|
|
|
$address_more = $this->getAddressMore();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS_MORE))
|
|
{
|
|
$address_more_crypt = $crypt->Encrypt($this->getAddressMore());
|
|
|
|
$this->setAddressMore($address_more_crypt);
|
|
}
|
|
|
|
$region = $this->getRegion();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::REGION))
|
|
{
|
|
$region_crypt = $crypt->Encrypt($this->getRegion());
|
|
|
|
$this->setRegion($region_crypt);
|
|
}
|
|
|
|
$pesel = $this->getPesel();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::PESEL))
|
|
{
|
|
$pesel_crypt = $crypt->Encrypt($this->getPesel());
|
|
|
|
$this->setPesel($pesel_crypt);
|
|
}
|
|
|
|
//new format addresss
|
|
|
|
$address = $this->getAddress();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
$address_crypt = $crypt->Encrypt($this->getAddress());
|
|
|
|
$this->setAddress($address_crypt);
|
|
}
|
|
|
|
//old format addresss ******************
|
|
|
|
if (!$address)
|
|
{
|
|
$street = $this->getStreet();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::STREET) || $this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
|
|
$street_crypt = $crypt->Encrypt($this->getStreet());
|
|
|
|
if ($this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
|
|
$aparser = new stAddressParser($address);
|
|
$result = $aparser->getAddress();
|
|
$street_crypt = $crypt->Encrypt($result['s1']);
|
|
|
|
$street = $street_crypt;
|
|
}
|
|
|
|
$this->setStreet($street_crypt);
|
|
}
|
|
|
|
$house = $this->getHouse();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::HOUSE) || $this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
$house_crypt = $crypt->Encrypt($this->getHouse());
|
|
|
|
if ($this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
|
|
$aparser = new stAddressParser($address);
|
|
$result = $aparser->getAddress();
|
|
$house_crypt = $crypt->Encrypt($result['n1']);
|
|
|
|
$house = $house_crypt;
|
|
}
|
|
|
|
$this->setHouse($house_crypt);
|
|
}
|
|
|
|
$flat = $this->getFlat();
|
|
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::FLAT) || $this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
$flat_crypt = $crypt->Encrypt($this->getFlat());
|
|
|
|
if ($this->isColumnModified(InvoiceUserCustomerPeer::ADDRESS))
|
|
{
|
|
|
|
$aparser = new stAddressParser($address);
|
|
$result = $aparser->getAddress();
|
|
$flat_crypt = $crypt->Encrypt(isset($result['n2']) ? $result['n2'] : '');
|
|
|
|
$flat = $flat_crypt;
|
|
}
|
|
|
|
$this->setFlat($flat_crypt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$this->setFlat(null);
|
|
$this->setHouse(null);
|
|
$this->setStreet(null);
|
|
}
|
|
|
|
$code = $this->getCode();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::CODE))
|
|
{
|
|
$code_crypt = $crypt->Encrypt($this->getCode());
|
|
|
|
$this->setCode($code_crypt);
|
|
}
|
|
|
|
$town = $this->getTown();
|
|
|
|
if (!$crypt->checkVersion($this->crypt) || $this->isColumnModified(InvoiceUserCustomerPeer::TOWN))
|
|
{
|
|
$town_crypt = $crypt->Encrypt($this->getTown());
|
|
|
|
$this->setTown($town_crypt);
|
|
}
|
|
|
|
$this->setCrypt(Crypt::VERSION);
|
|
|
|
$ret = parent::save($con);
|
|
|
|
$this->setAddress($address);
|
|
|
|
$this->setAddressMore($address_more);
|
|
|
|
$this->setRegion($region);
|
|
|
|
$this->setPesel($pesel);
|
|
|
|
if (!$address)
|
|
{
|
|
$this->setStreet($street);
|
|
|
|
$this->setHouse($house);
|
|
|
|
$this->setFlat($flat);
|
|
}
|
|
|
|
$this->setCode($code);
|
|
|
|
$this->setTown($town);
|
|
|
|
return $ret;
|
|
}
|
|
}
|