Property classes and mysql-schema

This commit is contained in:
RainLoop Team 2013-11-28 04:52:50 +04:00
parent 103c6efb85
commit 98cc5c0fe6
5 changed files with 353 additions and 14 deletions

View file

@ -0,0 +1,110 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook\Classes;
class Contact
{
/**
* @var int
*/
public $IdContact;
/**
* @var int
*/
public $IdUser;
/**
* @var string
*/
public $DisplayName;
/**
* @var string
*/
public $DisplayEmail;
/**
* @var string
*/
public $DisplayInList;
/**
* @var bool
*/
public $IsAuto;
/**
* @var bool
*/
public $IsShare;
/**
* @var int
*/
public $Created;
/**
* @var int
*/
public $Updated;
/**
* @var array
*/
public $Tags;
/**
* @var array
*/
public $Properties;
public function __construct()
{
$this->Clear();
}
public function Clear()
{
$this->IdContact = 0;
$this->IdUser = 0;
$this->DisplayName = '';
$this->DisplayEmail = '';
$this->DisplayInList = '';
$this->IsAuto = false;
$this->IsShare = false;
$this->Changed = \time();
$this->Tags = array();
$this->Properties = array();
}
public function InitBeforeWrite()
{
$sDisplayName = '';
$sDisplayEmail = '';
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ $oProperty)
{
if ($oProperty)
{
$oProperty->InitBeforeWrite();
if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type)
{
$sDisplayName = $oProperty->Value;
}
if ('' === $sDisplayEmail && $oProperty->IsEmail())
{
$sDisplayEmail = $oProperty->Value;
}
}
}
$this->DisplayName = $sDisplayName;
$this->DisplayEmail = $sDisplayEmail;
$this->DisplayInList = 0 < \strlen($this->DisplayName) ? $this->DisplayName : (!empty($this->DisplayEmail) ? $this->DisplayEmail : '');
$this->Changed = \time();
}
}

View file

@ -0,0 +1,110 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook\Classes;
use RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
class Property
{
/**
* @var int
*/
public $IdContact;
/**
* @var int
*/
public $IdUser;
/**
* @var int
*/
public $Type;
/**
* @var string
*/
public $TypeCustom;
/**
* @var string
*/
public $Value;
/**
* @var string
*/
public $ValueClear;
/**
* @var int
*/
public $Frec;
public function __construct()
{
$this->Clear();
}
public function Clear()
{
$this->IdContact = 0;
$this->IdUser = 0;
$this->Type = PropertyType::UNKNOWN;
$this->TypeCustom = '';
$this->Value = '';
$this->ValueClear = '';
$this->Frec = 0;
}
/**
* @return bool
*/
public function IsEmail()
{
return \in_array($this->Type, array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
));
}
/**
* @return bool
*/
public function IsPhone()
{
return \in_array($this->Type, array(
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER,
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER,
PropertyType::FAX_BUSSINES, PropertyType::FAX_OTHER
));
}
public function InitBeforeWrite()
{
// trimer
$this->Value = \trim($this->Value);
$this->ValueClear = \trim($this->ValueClear);
$this->TypeCustom = \trim($this->TypeCustom);
if (0 < \strlen($this->Value))
{
// lower
if ($this->IsEmail())
{
$this->Value = \strtolower($this->Value);
}
// phones clear value for searching
if ($this->IsPhone())
{
$sPhone = $this->Value;
$sPhone = \preg_replace('^[+]+', '', $sPhone);
$sPhone = \preg_replace('[^\d]', '', $sPhone);
$this->ValueClear = $sPhone;
}
}
}
}