Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
--TEST--
2
XML_Query2XML::getXML(): using the callback interface for an idColumn specification
3
--SKIPIF--
4
<?php require_once dirname(dirname(__FILE__)) . '/skipif.php'; ?>
5
--FILE--
6
<?php
7
    require_once 'XML/Query2XML.php';
8
    require_once 'XML/Query2XML/Callback.php';
9
    require_once dirname(dirname(__FILE__)) . '/db_init.php';
10
    class MyCallback implements XML_Query2XML_Callback
11
    {
12
        private $_columnName = '';
13
 
14
        public function __construct($columnName)
15
        {
16
            $this->_columnName = $columnName;
17
        }
18
 
19
        public function execute(array $record)
20
        {
21
            return $record[$this->_columnName];
22
        }
23
    }
24
 
25
    $query2xml = XML_Query2XML::factory($db);
26
    $dom =& $query2xml->getXML(
27
        "SELECT
28
            *
29
         FROM
30
            artist",
31
        array(
32
            'rootTag' => 'music_store',
33
            'rowTag' => 'artist',
34
            'idColumn' => 'artistid',
35
            'elements' => array(
36
                'artistid',
37
                'name',
38
                'albums' => array(
39
                    'idColumn' => 'albumid',
40
                    'sql' => array(
41
                        'data' => array(
42
                            new MyCallback('artistid')
43
                        ),
44
                        'query' => 'SELECT * FROM album WHERE artist_id = ?'
45
                    ),
46
                    'elements' => array(
47
                        'title'
48
                    )
49
                )
50
            )
51
        )
52
    );
53
    $dom->formatOutput = true;
54
    print $dom->saveXML();
55
?>
56
--EXPECT--
57
<?xml version="1.0" encoding="UTF-8"?>
58
<music_store>
59
  <artist>
60
    <artistid>1</artistid>
61
    <name>Curtis Mayfield</name>
62
    <albums>
63
      <title>New World Order</title>
64
    </albums>
65
    <albums>
66
      <title>Curtis</title>
67
    </albums>
68
  </artist>
69
  <artist>
70
    <artistid>2</artistid>
71
    <name>Isaac Hayes</name>
72
    <albums>
73
      <title>Shaft</title>
74
    </albums>
75
  </artist>
76
  <artist>
77
    <artistid>3</artistid>
78
    <name>Ray Charles</name>
79
  </artist>
80
</music_store>