Sabre\CardDAV\Backend\PDO::getMultipleCards PHP Méthode

getMultipleCards() public méthode

This method should work identical to getCard, but instead return all the cards in the list as an array. If the backend supports this, it may allow for some speed-ups.
public getMultipleCards ( mixed $addressBookId, array $uris ) : array
$addressBookId mixed
$uris array
Résultat array
    function getMultipleCards($addressBookId, array $uris)
    {
        return array_map(function ($uri) use($addressBookId) {
            return $this->getCard($addressBookId, $uri);
        }, $uris);
        $query = 'SELECT id, uri, lastmodified, etag, size FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = IN (';
        // Inserting a whole bunch of question marks
        $query .= implode(',', array_fill(0, count($uris), '?'));
        $query .= ')';
        $stmt = $this->pdo->prepare($query);
        $stmt->execute(array_merge([$addressBookId], $uris));
        $result = [];
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            $row['etag'] = '"' . $row['etag'] . '"';
            $result[] = $row;
        }
        return $result;
    }

Usage Example

 /**
  * @depends testCreateCard
  */
 function testGetMultiple()
 {
     $result = $this->backend->createCard(1, 'card2', 'data2');
     $result = $this->backend->createCard(1, 'card3', 'data3');
     $check = [['id' => 1, 'uri' => 'card1', 'carddata' => 'card1', 'lastmodified' => 0], ['id' => 2, 'uri' => 'card2', 'carddata' => 'data2', 'lastmodified' => time()], ['id' => 3, 'uri' => 'card3', 'carddata' => 'data3', 'lastmodified' => time()]];
     $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
     foreach ($check as $index => $node) {
         foreach ($node as $k => $v) {
             $expected = $v;
             $actual = $result[$index][$k];
             switch ($k) {
                 case 'lastmodified':
                     $this->assertInternalType('int', $actual);
                     break;
                 case 'carddata':
                     if (is_resource($actual)) {
                         $actual = stream_get_contents($actual);
                     }
                     // No break intended.
                 // No break intended.
                 default:
                     $this->assertEquals($expected, $actual);
                     break;
             }
         }
     }
 }
All Usage Examples Of Sabre\CardDAV\Backend\PDO::getMultipleCards