Commit d42a4973 authored by Patrick Müller's avatar Patrick Müller

feat: custom data for addresses #698

parent 1b1bea23
......@@ -145,6 +145,28 @@
<primary>id</primary>
<auto_increment>id</auto_increment>
</table>
<!-- Addresses -->
<table name="users_address">
<field type="INT(11) NOT NULL">id</field>
<field type="INT(11) NOT NULL">uid</field>
<field type="VARCHAR(10)">salutation</field>
<field type="VARCHAR(40)">firstname</field>
<field type="VARCHAR(40)">lastname</field>
<field type="TEXT NULL">phone</field>
<field type="TEXT NULL">mail</field>
<field type="VARCHAR(100)">company</field>
<field type="TEXT NULL">delivery</field>
<field type="TEXT NULL">street_no</field>
<field type="TEXT NULL">zip</field>
<field type="TEXT NULL">city</field>
<field type="TEXT NULL">country</field>
<field type="TEXT NULL">custom_data</field>
<primary>id</primary>
<auto_increment>id</auto_increment>
</table>
</global>
<projects>
......
......@@ -31,6 +31,13 @@ class Address extends QUI\QDOM
*/
protected $id = false;
/**
* Custom address data
*
* @var array
*/
protected $customData = [];
/**
* constructor
*
......@@ -66,10 +73,16 @@ class Address extends QUI\QDOM
);
}
unset($result[0]['id']);
unset($result[0]['uid']);
$data = current($result);
unset($data['id']);
unset($data['uid']);
$this->setAttributes($result[0]);
if (!empty($data['custom_data'])) {
$this->setCustomData(json_decode($data['custom_data'], true));
}
$this->setAttributes($data);
}
/**
......@@ -380,17 +393,18 @@ class Address extends QUI\QDOM
QUI::getDataBase()->update(
Manager::tableAddress(),
[
'salutation' => Orthos::clear($this->getAttribute('salutation')),
'firstname' => Orthos::clear($this->getAttribute('firstname')),
'lastname' => Orthos::clear($this->getAttribute('lastname')),
'company' => Orthos::clear($this->getAttribute('company')),
'delivery' => Orthos::clear($this->getAttribute('delivery')),
'street_no' => Orthos::clear($this->getAttribute('street_no')),
'zip' => Orthos::clear($this->getAttribute('zip')),
'city' => Orthos::clear($this->getAttribute('city')),
'country' => Orthos::clear($this->getAttribute('country')),
'mail' => $mail,
'phone' => $phone
'salutation' => Orthos::clear($this->getAttribute('salutation')),
'firstname' => Orthos::clear($this->getAttribute('firstname')),
'lastname' => Orthos::clear($this->getAttribute('lastname')),
'company' => Orthos::clear($this->getAttribute('company')),
'delivery' => Orthos::clear($this->getAttribute('delivery')),
'street_no' => Orthos::clear($this->getAttribute('street_no')),
'zip' => Orthos::clear($this->getAttribute('zip')),
'city' => Orthos::clear($this->getAttribute('city')),
'country' => Orthos::clear($this->getAttribute('country')),
'mail' => $mail,
'phone' => $phone,
'custom_data' => json_encode($this->getCustomData())
],
[
'id' => $this->id
......@@ -431,7 +445,7 @@ class Address extends QUI\QDOM
'Countries' => new QUI\Countries\Manager()
]);
return $Engine->fetch(SYS_DIR.'template/users/address/display.html');
return $Engine->fetch(SYS_DIR . 'template/users/address/display.html');
}
/**
......@@ -542,6 +556,57 @@ class Address extends QUI\QDOM
return $result;
}
/**
* Set custom data entry
*
* @param string $key
* @param mixed $value
* @return void
*/
public function setCustomDataEntry($key, $value)
{
$this->customData[$key] = $value;
$this->setAttribute('customData', $this->customData);
}
/**
* Get custom data entry
*
* @param string $key
* @return mixed|null - Null if no entry set
*/
public function getCustomDataEntry($key)
{
if (array_key_exists($key, $this->customData)) {
return $this->customData[$key];
}
return null;
}
/**
* Set multiple custom data entries
*
* @param array $entries
* @return void
*/
public function setCustomData($entries)
{
foreach ($entries as $k => $v) {
$this->setCustomDataEntry($k, $v);
}
}
/**
* Get all custom data entries
*
* @return array
*/
public function getCustomData()
{
return $this->customData;
}
/**
* Return the address as json
*
......
......@@ -128,31 +128,6 @@ class Manager
} catch (\PDOException $Exception) {
}
// Addresses
$DataBase->table()->addColumn(self::tableAddress(), array(
'id' => 'INT(11)',
'uid' => 'INT(11)',
'salutation' => 'VARCHAR(10)',
'firstname' => 'VARCHAR(40)',
'lastname' => 'VARCHAR(40)',
'phone' => 'TEXT NULL',
'mail' => 'TEXT NULL',
'company' => 'VARCHAR(100)',
'delivery' => 'TEXT NULL',
'street_no' => 'TEXT NULL',
'zip' => 'TEXT NULL',
'city' => 'TEXT NULL',
'country' => 'TEXT NULL'
));
$DataBase->table()->setIndex(self::tableAddress(), 'id');
$tableAddress = self::tableAddress();
$DataBase->getPDO()->exec(
"ALTER TABLE `{$tableAddress}` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT"
);
// uuid extrem indexes patch
$Stmt = $DataBase->getPDO()->prepare(
"SHOW INDEXES FROM `{$table}`
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment