Sabre\CardDAV\Backend\PDO::updateAddressBook PHP 메소드

updateAddressBook() 공개 메소드

The list of mutations is stored in a Sabre\DAV\PropPatch object. To do the actual updates, you must tell this object which properties you're going to process with the handle() method. Calling the handle method is like telling the PropPatch object "I promise I can handle updating this property". Read the PropPatch documenation for more info and examples.
public updateAddressBook ( string $addressBookId, Sabre\DAV\PropPatch $propPatch ) : void
$addressBookId string
$propPatch Sabre\DAV\PropPatch
리턴 void
    function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch)
    {
        $supportedProperties = ['{DAV:}displayname', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description'];
        $propPatch->handle($supportedProperties, function ($mutations) use($addressBookId) {
            $updates = [];
            foreach ($mutations as $property => $newValue) {
                switch ($property) {
                    case '{DAV:}displayname':
                        $updates['displayname'] = $newValue;
                        break;
                    case '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description':
                        $updates['description'] = $newValue;
                        break;
                }
            }
            $query = 'UPDATE ' . $this->addressBooksTableName . ' SET ';
            $first = true;
            foreach ($updates as $key => $value) {
                if ($first) {
                    $first = false;
                } else {
                    $query .= ', ';
                }
                $query .= ' `' . $key . '` = :' . $key . ' ';
            }
            $query .= ' WHERE id = :addressbookid';
            $stmt = $this->pdo->prepare($query);
            $updates['addressbookid'] = $addressBookId;
            $stmt->execute($updates);
            $this->addChange($addressBookId, "", 2);
            return true;
        });
    }

Usage Example

예제 #1
0
 public function testUpdateAddressBookSuccess()
 {
     $result = $this->backend->updateAddressBook(1, array('{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated'));
     $this->assertTrue($result);
     $result = $this->backend->getAddressBooksForUser('principals/user1');
     $expected = array(array('id' => 1, 'uri' => 'book1', 'principaluri' => 'principals/user1', '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', '{http://calendarserver.org/ns/}getctag' => 2, '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData()));
     $this->assertEquals($expected, $result);
 }
All Usage Examples Of Sabre\CardDAV\Backend\PDO::updateAddressBook