mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Implementation of share contacts (begin)
This commit is contained in:
parent
5198dcfa20
commit
026839d864
17 changed files with 469 additions and 50 deletions
|
|
@ -29,6 +29,11 @@ class Contact
|
|||
*/
|
||||
public $ScopeType;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ScopeValue;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
@ -44,6 +49,11 @@ class Contact
|
|||
*/
|
||||
public $Properties;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $ReadOnly;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->Clear();
|
||||
|
|
@ -57,9 +67,11 @@ class Contact
|
|||
$this->DisplayName = '';
|
||||
$this->DisplayEmail = '';
|
||||
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
||||
$this->ScopeValue = '';
|
||||
$this->Changed = \time();
|
||||
$this->IdPropertyFromSearch = 0;
|
||||
$this->Properties = array();
|
||||
$this->ReadOnly = false;
|
||||
}
|
||||
|
||||
public function UpdateDependentValues()
|
||||
|
|
@ -72,6 +84,7 @@ class Contact
|
|||
if ($oProperty)
|
||||
{
|
||||
$oProperty->ScopeType = $this->ScopeType;
|
||||
$oProperty->ScopeValue = $this->ScopeValue;
|
||||
$oProperty->UpdateDependentValues();
|
||||
|
||||
if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type &&
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ class Property
|
|||
*/
|
||||
public $ScopeType;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ScopeValue;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
@ -52,6 +57,7 @@ class Property
|
|||
|
||||
$this->Type = PropertyType::UNKNOWN;
|
||||
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
||||
$this->ScopeValue = '';
|
||||
$this->TypeCustom = '';
|
||||
|
||||
$this->Value = '';
|
||||
|
|
|
|||
|
|
@ -6,5 +6,7 @@ class ScopeType
|
|||
{
|
||||
const DEFAULT_ = 0;
|
||||
const AUTO = 1;
|
||||
const SHARE = 2;
|
||||
const SHARE_ALL = 2;
|
||||
const SHARE_DOMAIN = 3;
|
||||
const SHARE_EMAIL = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class PdoPersonalAddressBook
|
|||
$aFreq = $this->getContactFreq($iUserID, $iIdContact);
|
||||
|
||||
$sSql = 'UPDATE rainloop_pab_contacts SET display = :display, display_name = :display_name, display_email = :display_email, '.
|
||||
'scope_type = :scope_type, changed = :changed WHERE id_user = :id_user AND id_contact = :id_contact';
|
||||
'scope_type = :scope_type, scope_value = :scope_value, changed = :changed WHERE id_user = :id_user AND id_contact = :id_contact';
|
||||
|
||||
$this->prepareAndExecute($sSql,
|
||||
array(
|
||||
|
|
@ -121,6 +121,7 @@ class PdoPersonalAddressBook
|
|||
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
|
||||
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
|
||||
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
|
||||
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
|
||||
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
|
||||
)
|
||||
);
|
||||
|
|
@ -137,8 +138,8 @@ class PdoPersonalAddressBook
|
|||
else
|
||||
{
|
||||
$sSql = 'INSERT INTO rainloop_pab_contacts '.
|
||||
'( id_user, display, display_name, display_email, scope_type, changed) VALUES '.
|
||||
'(:id_user, :display, :display_name, :display_email, :scope_type, :changed)';
|
||||
'( id_user, display, display_name, display_email, scope_type, scope_value, changed) VALUES '.
|
||||
'(:id_user, :display, :display_name, :display_email, :scope_type, :scope_value, :changed)';
|
||||
|
||||
$this->prepareAndExecute($sSql,
|
||||
array(
|
||||
|
|
@ -147,6 +148,7 @@ class PdoPersonalAddressBook
|
|||
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
|
||||
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
|
||||
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
|
||||
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
|
||||
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
|
|
@ -174,6 +176,7 @@ class PdoPersonalAddressBook
|
|||
':id_contact' => array($iIdContact, \PDO::PARAM_INT),
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
|
||||
':scope_value' => array($oContact->ScopeValue, \PDO::PARAM_STR),
|
||||
':prop_type' => array($oProp->Type, \PDO::PARAM_INT),
|
||||
':prop_type_custom' => array($oProp->TypeCustom, \PDO::PARAM_STR),
|
||||
':prop_value' => array($oProp->Value, \PDO::PARAM_STR),
|
||||
|
|
@ -183,8 +186,8 @@ class PdoPersonalAddressBook
|
|||
}
|
||||
|
||||
$sSql = 'INSERT INTO rainloop_pab_properties '.
|
||||
'( id_contact, id_user, prop_type, prop_type_custom, prop_value, prop_value_custom, scope_type, prop_frec) VALUES '.
|
||||
'(:id_contact, :id_user, :prop_type, :prop_type_custom, :prop_value, :prop_value_custom, :scope_type, :prop_frec)';
|
||||
'( id_contact, id_user, prop_type, prop_type_custom, prop_value, prop_value_custom, scope_type, scope_value, prop_frec) VALUES '.
|
||||
'(:id_contact, :id_user, :prop_type, :prop_type_custom, :prop_value, :prop_value_custom, :scope_type, :scope_value, :prop_frec)';
|
||||
|
||||
$this->prepareAndExecute($sSql, $aParams, true);
|
||||
}
|
||||
|
|
@ -286,7 +289,10 @@ class PdoPersonalAddressBook
|
|||
$iLimit = 0 < $iLimit ? (int) $iLimit : 20;
|
||||
$sSearch = \trim($sSearch);
|
||||
|
||||
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||
$sEmail = $oAccount->ParentEmailHelper();
|
||||
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
||||
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$iCount = 0;
|
||||
$aSearchIds = array();
|
||||
|
|
@ -294,15 +300,24 @@ class PdoPersonalAddressBook
|
|||
|
||||
if (0 < \strlen($sSearch))
|
||||
{
|
||||
$sSql = 'SELECT id_prop, id_contact FROM rainloop_pab_properties WHERE id_user = :id_user'.
|
||||
' AND scope_type = :scope_type AND prop_value LIKE :search ESCAPE \'=\' GROUP BY id_contact, id_prop';
|
||||
|
||||
$sSql = 'SELECT id_user, id_prop, id_contact FROM rainloop_pab_properties '.
|
||||
'WHERE ('.
|
||||
'(id_user = :id_user)'.
|
||||
' OR (scope_type = :scope_type_share_all)'.
|
||||
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
|
||||
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
|
||||
') AND prop_value LIKE :search ESCAPE \'=\' GROUP BY id_contact, id_prop';
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':scope_type' => array($iScopeType, \PDO::PARAM_INT),
|
||||
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
|
||||
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
|
||||
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
|
||||
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
|
||||
':scope_value_email' => array($sEmail, \PDO::PARAM_STR),
|
||||
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
|
||||
);
|
||||
|
||||
|
||||
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||
if ($oStmt)
|
||||
{
|
||||
|
|
@ -325,10 +340,22 @@ class PdoPersonalAddressBook
|
|||
}
|
||||
else
|
||||
{
|
||||
$sSql = 'SELECT COUNT(DISTINCT id_contact) as contact_count FROM rainloop_pab_properties WHERE id_user = :id_user AND scope_type = :scope_type';
|
||||
$sSql = 'SELECT COUNT(DISTINCT id_contact) as contact_count FROM rainloop_pab_properties '.
|
||||
'WHERE ('.
|
||||
'(id_user = :id_user)'.
|
||||
' OR (scope_type = :scope_type_share_all)'.
|
||||
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
|
||||
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
|
||||
')'
|
||||
;
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':scope_type' => array($iScopeType, \PDO::PARAM_INT)
|
||||
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
|
||||
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
|
||||
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
|
||||
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
|
||||
':scope_value_email' => array($sEmail, \PDO::PARAM_STR)
|
||||
);
|
||||
|
||||
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||
|
|
@ -346,10 +373,22 @@ class PdoPersonalAddressBook
|
|||
|
||||
if (0 < $iCount)
|
||||
{
|
||||
$sSql = 'SELECT * FROM rainloop_pab_contacts WHERE id_user = :id_user AND scope_type = :scope_type';
|
||||
$sSql = 'SELECT * FROM rainloop_pab_contacts '.
|
||||
'WHERE ('.
|
||||
'(id_user = :id_user)'.
|
||||
' OR (scope_type = :scope_type_share_all)'.
|
||||
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
|
||||
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
|
||||
')'
|
||||
;
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':scope_type' => array($iScopeType, \PDO::PARAM_INT)
|
||||
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
|
||||
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
|
||||
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
|
||||
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
|
||||
':scope_value_email' => array($sEmail, \PDO::PARAM_STR)
|
||||
);
|
||||
|
||||
if (0 < \count($aSearchIds))
|
||||
|
|
@ -384,7 +423,9 @@ class PdoPersonalAddressBook
|
|||
$oContact->DisplayEmail = isset($aItem['display_email']) ? (string) $aItem['display_email'] : '';
|
||||
$oContact->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
|
||||
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
||||
$oContact->ScopeValue = isset($aItem['scope_value']) ? (string) $aItem['scope_value'] : '';
|
||||
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
|
||||
$oContact->ReadOnly = $iUserID !== (isset($aItem['id_user']) ? (int) $aItem['id_user'] : 0);
|
||||
|
||||
$oContact->IdPropertyFromSearch = isset($aPropertyFromSearchIds[$iIdContact]) &&
|
||||
0 < $aPropertyFromSearchIds[$iIdContact] ? $aPropertyFromSearchIds[$iIdContact] : 0;
|
||||
|
|
@ -400,10 +441,8 @@ class PdoPersonalAddressBook
|
|||
{
|
||||
$oStmt->closeCursor();
|
||||
|
||||
$sSql = 'SELECT * FROM rainloop_pab_properties WHERE id_user = :id_user AND id_contact IN ('.\implode(',', $aIdContacts).')';
|
||||
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||
));
|
||||
$sSql = 'SELECT * FROM rainloop_pab_properties WHERE id_contact IN ('.\implode(',', $aIdContacts).')';
|
||||
$oStmt = $this->prepareAndExecute($sSql);
|
||||
|
||||
if ($oStmt)
|
||||
{
|
||||
|
|
@ -421,6 +460,7 @@ class PdoPersonalAddressBook
|
|||
$oProperty->IdProperty = (int) $aItem['id_prop'];
|
||||
$oProperty->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
|
||||
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
||||
$oProperty->ScopeValue = isset($aItem['scope_value']) ? (string) $aItem['scope_value'] : '';
|
||||
$oProperty->Type = (int) $aItem['prop_type'];
|
||||
$oProperty->TypeCustom = isset($aItem['prop_type_custom']) ? (string) $aItem['prop_type_custom'] : '';
|
||||
$oProperty->Value = (string) $aItem['prop_value'];
|
||||
|
|
@ -467,18 +507,32 @@ class PdoPersonalAddressBook
|
|||
}
|
||||
|
||||
$this->Sync();
|
||||
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||
|
||||
$sEmail = $oAccount->ParentEmailHelper();
|
||||
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
||||
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$sTypes = implode(',', array(
|
||||
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
|
||||
));
|
||||
|
||||
$sSql = 'SELECT id_contact, id_prop, prop_type, prop_value FROM rainloop_pab_properties '.
|
||||
'WHERE id_user = :id_user AND prop_type IN ('.$sTypes.') AND prop_value LIKE :search ESCAPE \'=\'';
|
||||
'WHERE ('.
|
||||
'(id_user = :id_user)'.
|
||||
' OR (scope_type = :scope_type_share_all)'.
|
||||
' OR (scope_type = :scope_type_share_domain AND scope_value = :scope_value_domain)'.
|
||||
' OR (scope_type = :scope_type_share_email AND scope_value = :scope_value_email)'.
|
||||
') AND prop_type IN ('.$sTypes.') AND prop_value LIKE :search ESCAPE \'=\'';
|
||||
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':limit' => array($iLimit, \PDO::PARAM_INT),
|
||||
':scope_type_share_all' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_ALL, \PDO::PARAM_INT),
|
||||
':scope_type_share_domain' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_DOMAIN, \PDO::PARAM_INT),
|
||||
':scope_type_share_email' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::SHARE_EMAIL, \PDO::PARAM_INT),
|
||||
':scope_value_domain' => array($sDomain, \PDO::PARAM_STR),
|
||||
':scope_value_email' => array($sEmail, \PDO::PARAM_STR),
|
||||
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
|
||||
);
|
||||
|
||||
|
|
@ -537,11 +591,9 @@ class PdoPersonalAddressBook
|
|||
));
|
||||
|
||||
$sSql = 'SELECT id_prop, id_contact, prop_type, prop_value FROM rainloop_pab_properties '.
|
||||
'WHERE id_user = :id_user AND prop_type IN ('.$sTypes.') AND id_contact IN ('.\implode(',', $aIdContacts).')';
|
||||
'WHERE prop_type IN ('.$sTypes.') AND id_contact IN ('.\implode(',', $aIdContacts).')';
|
||||
|
||||
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||
));
|
||||
$oStmt = $this->prepareAndExecute($sSql);
|
||||
if ($oStmt)
|
||||
{
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
|
@ -990,15 +1042,27 @@ SQLITEINITIAL;
|
|||
{
|
||||
case 'mysql':
|
||||
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
|
||||
1 => $this->getInitialTablesArray($this->sDsnType)
|
||||
1 => $this->getInitialTablesArray($this->sDsnType),
|
||||
2 => array(
|
||||
'ALTER TABLE rainloop_pab_contacts ADD scope_value varchar(128) NOT NULL DEFAULT \'\' AFTER scope_type',
|
||||
'ALTER TABLE rainloop_pab_properties ADD scope_value varchar(128) NOT NULL DEFAULT \'\' AFTER scope_type'
|
||||
)
|
||||
));
|
||||
case 'pgsql':
|
||||
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
|
||||
1 => $this->getInitialTablesArray($this->sDsnType)
|
||||
1 => $this->getInitialTablesArray($this->sDsnType),
|
||||
2 => array(
|
||||
'ALTER TABLE rainloop_pab_contacts ADD scope_value varchar(128) NOT NULL DEFAULT \'\'',
|
||||
'ALTER TABLE rainloop_pab_properties ADD scope_value varchar(128) NOT NULL DEFAULT \'\''
|
||||
)
|
||||
));
|
||||
case 'sqlite':
|
||||
return $this->dataBaseUpgrade($this->sDsnType.'-pab-version', array(
|
||||
1 => $this->getInitialTablesArray($this->sDsnType)
|
||||
1 => $this->getInitialTablesArray($this->sDsnType),
|
||||
2 => array(
|
||||
'ALTER TABLE rainloop_pab_contacts ADD scope_value text NOT NULL default \'\'',
|
||||
'ALTER TABLE rainloop_pab_properties ADD scope_value text NOT NULL default \'\''
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue