Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
a51e9a5c
Commit
a51e9a5c
authored
11 years ago
by
Bart Visscher
Browse files
Options
Downloads
Plain Diff
Merge pull request #8136 from owncloud/contactsmanager-register
Implement the register function of OC\ContactsManager
parents
339554ae
8749442f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/contactsmanager.php
+68
-33
68 additions, 33 deletions
lib/private/contactsmanager.php
lib/public/contacts.php
+2
-2
2 additions, 2 deletions
lib/public/contacts.php
lib/public/contacts/imanager.php
+1
-2
1 addition, 2 deletions
lib/public/contacts/imanager.php
with
71 additions
and
37 deletions
lib/private/contactsmanager.php
+
68
−
33
View file @
a51e9a5c
...
...
@@ -34,12 +34,13 @@ namespace OC {
* @return array an array of contacts which are arrays of key-value-pairs
*/
public
function
search
(
$pattern
,
$searchProperties
=
array
(),
$options
=
array
())
{
$this
->
loadAddressBooks
();
$result
=
array
();
foreach
(
$this
->
address
_b
ooks
as
$address
_b
ook
)
{
$r
=
$address
_b
ook
->
search
(
$pattern
,
$searchProperties
,
$options
);
foreach
(
$this
->
address
B
ooks
as
$address
B
ook
)
{
$r
=
$address
B
ook
->
search
(
$pattern
,
$searchProperties
,
$options
);
$contacts
=
array
();
foreach
(
$r
as
$c
){
$c
[
'addressbook-key'
]
=
$address
_b
ook
->
getKey
();
$c
[
'addressbook-key'
]
=
$address
B
ook
->
getKey
();
$contacts
[]
=
$c
;
}
$result
=
array_merge
(
$result
,
$contacts
);
...
...
@@ -52,18 +53,20 @@ namespace OC {
* This function can be used to delete the contact identified by the given id
*
* @param object $id the unique identifier to a contact
* @param string $address
_b
ook
_k
ey identifier of the address book in which the contact shall be deleted
* @param string $address
B
ook
K
ey identifier of the address book in which the contact shall be deleted
* @return bool successful or not
*/
public
function
delete
(
$id
,
$address_book_key
)
{
if
(
!
array_key_exists
(
$address_book_key
,
$this
->
address_books
))
public
function
delete
(
$id
,
$addressBookKey
)
{
$addressBook
=
$this
->
getAddressBook
(
$addressBookKey
);
if
(
!
$addressBook
)
{
return
null
;
}
$address_book
=
$this
->
address_books
[
$address_book_key
];
if
(
$address_book
->
getPermissions
()
&
\OCP\PERMISSION_DELETE
)
if
(
$addressBook
->
getPermissions
()
&
\OCP\PERMISSION_DELETE
)
{
return
null
;
}
return
$address
_b
ook
->
delete
(
$id
);
return
$address
B
ook
->
delete
(
$id
);
}
/**
...
...
@@ -71,19 +74,20 @@ namespace OC {
* Otherwise the contact will be updated by replacing the entire data set.
*
* @param array $properties this array if key-value-pairs defines a contact
* @param string $address
_b
ook
_k
ey identifier of the address book in which the contact shall be created or updated
* @return array
an array
representing the contact just created or updated
* @param string $address
B
ook
K
ey identifier of the address book in which the contact shall be created or updated
* @return array representing the contact just created or updated
*/
public
function
createOrUpdate
(
$properties
,
$address
_b
ook
_k
ey
)
{
if
(
!
array_key_exists
(
$address
_b
ook
_key
,
$this
->
address_books
))
public
function
createOrUpdate
(
$properties
,
$address
B
ook
K
ey
)
{
$addressBook
=
$this
->
getAddressBook
(
$addressBookKey
);
if
(
!
$address
B
ook
)
{
return
null
;
}
$address_book
=
$this
->
address_books
[
$address_book_key
];
if
(
$address_book
->
getPermissions
()
&
\OCP\PERMISSION_CREATE
)
if
(
$addressBook
->
getPermissions
()
&
\OCP\PERMISSION_CREATE
)
{
return
null
;
}
return
$address
_b
ook
->
createOrUpdate
(
$properties
);
return
$address
B
ook
->
createOrUpdate
(
$properties
);
}
/**
...
...
@@ -92,30 +96,31 @@ namespace OC {
* @return bool true if enabled, false if not
*/
public
function
isEnabled
()
{
return
!
empty
(
$this
->
address
_b
ooks
);
return
!
empty
(
$this
->
address
B
ooks
)
||
!
empty
(
$this
->
addressBookLoaders
)
;
}
/**
* @param \OCP\IAddressBook $address
_b
ook
* @param \OCP\IAddressBook $address
B
ook
*/
public
function
registerAddressBook
(
\OCP\IAddressBook
$address
_b
ook
)
{
$this
->
address
_b
ooks
[
$address
_b
ook
->
getKey
()]
=
$address
_b
ook
;
public
function
registerAddressBook
(
\OCP\IAddressBook
$address
B
ook
)
{
$this
->
address
B
ooks
[
$address
B
ook
->
getKey
()]
=
$address
B
ook
;
}
/**
* @param \OCP\IAddressBook $address
_b
ook
* @param \OCP\IAddressBook $address
B
ook
*/
public
function
unregisterAddressBook
(
\OCP\IAddressBook
$address
_b
ook
)
{
unset
(
$this
->
address
_b
ooks
[
$address
_b
ook
->
getKey
()]);
public
function
unregisterAddressBook
(
\OCP\IAddressBook
$address
B
ook
)
{
unset
(
$this
->
address
B
ooks
[
$address
B
ook
->
getKey
()]);
}
/**
* @return array
*/
public
function
getAddressBooks
()
{
$this
->
loadAddressBooks
();
$result
=
array
();
foreach
(
$this
->
address
_b
ooks
as
$address
_b
ook
)
{
$result
[
$address
_b
ook
->
getKey
()]
=
$address
_b
ook
->
getDisplayName
();
foreach
(
$this
->
address
B
ooks
as
$address
B
ook
)
{
$result
[
$address
B
ook
->
getKey
()]
=
$address
B
ook
->
getDisplayName
();
}
return
$result
;
...
...
@@ -125,26 +130,56 @@ namespace OC {
* removes all registered address book instances
*/
public
function
clear
()
{
$this
->
address_books
=
array
();
$this
->
addressBooks
=
array
();
$this
->
addressBookLoaders
=
array
();
}
/**
* @var \OCP\IAddressBook[] which holds all registered address books
*/
private
$address_books
=
array
();
private
$addressBooks
=
array
();
/**
* @var \Closure[] to call to load/register address books
*/
private
$addressBookLoaders
=
array
();
/**
* In order to improve lazy loading a closure can be registered which will be called in case
* address books are actually requested
*
* @param string $key
* @param \Closure $callable
*/
function
register
(
$key
,
\Closure
$callable
)
public
function
register
(
\Closure
$callable
)
{
//
//TODO: implement me
//
$this
->
addressBookLoaders
[]
=
$callable
;
}
/**
* Get (and load when needed) the address book for $key
*
* @param string $addressBookKey
* @return \OCP\IAddressBook
*/
protected
function
getAddressBook
(
$addressBookKey
)
{
$this
->
loadAddressBooks
();
if
(
!
array_key_exists
(
$addressBookKey
,
$this
->
addressBooks
))
{
return
null
;
}
return
$this
->
addressBooks
[
$addressBookKey
];
}
/**
* Load all address books registered with 'register'
*/
protected
function
loadAddressBooks
()
{
foreach
(
$this
->
addressBookLoaders
as
$callable
)
{
$callable
(
$this
);
}
$this
->
addressBookLoaders
=
array
();
}
}
}
This diff is collapsed.
Click to expand it.
lib/public/contacts.php
+
2
−
2
View file @
a51e9a5c
...
...
@@ -134,7 +134,7 @@ namespace OCP {
*/
public
static
function
registerAddressBook
(
\OCP\IAddressBook
$address_book
)
{
$cm
=
\OC
::
$server
->
getContactsManager
();
return
$cm
->
registerAddressBook
(
$address_book
);
$cm
->
registerAddressBook
(
$address_book
);
}
/**
...
...
@@ -142,7 +142,7 @@ namespace OCP {
*/
public
static
function
unregisterAddressBook
(
\OCP\IAddressBook
$address_book
)
{
$cm
=
\OC
::
$server
->
getContactsManager
();
return
$cm
->
unregisterAddressBook
(
$address_book
);
$cm
->
unregisterAddressBook
(
$address_book
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
lib/public/contacts/imanager.php
+
1
−
2
View file @
a51e9a5c
...
...
@@ -138,11 +138,10 @@ namespace OCP\Contacts {
* In order to improve lazy loading a closure can be registered which will be called in case
* address books are actually requested
*
* @param string $key
* @param \Closure $callable
* @return void
*/
function
register
(
$key
,
\Closure
$callable
);
function
register
(
\Closure
$callable
);
/**
* @return array
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment