Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 *  $Id: RelationMap.php 1153 2009-09-20 18:08:53Z francois $
5
 *
6
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
7
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
9
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
10
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
11
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
12
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
13
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
14
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
16
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
 *
18
 * This software consists of voluntary contributions made by many individuals
19
 * and is licensed under the LGPL. For more information please see
20
 * <http://propel.phpdb.org>.
21
 */
22
 
23
/**
24
 * RelationMap is used to model a database relationship.
25
 *
26
 * GENERAL NOTE
27
 * ------------
28
 * The propel.map classes are abstract building-block classes for modeling
29
 * the database at runtime.  These classes are similar (a lite version) to the
30
 * propel.engine.database.model classes, which are build-time modeling classes.
31
 * These classes in themselves do not do any database metadata lookups.
32
 *
33
 * @author     Francois Zaninotto
34
 * @version    $Revision: 1153 $
35
 * @package    propel.map
36
 */
37
class RelationMap {
38
 
39
  const
40
    MANY_TO_ONE = 1,
41
    ONE_TO_MANY = 2,
42
    ONE_TO_ONE = 3;
43
 
44
  protected
45
    $name,
46
    $type,
47
    $localTable,
48
    $foreignTable,
49
    $localColumns = array(),
50
    $foreignColumns = array(),
51
    $onUpdate, $onDelete;
52
 
53
  /**
54
   * Constructor.
55
   *
56
   * @param      string $name Name of the database.
57
   */
58
  public function __construct($name)
59
  {
60
    $this->name = $name;
61
  }
62
 
63
  /**
64
   * Get the name of this database.
65
   *
66
   * @return     string The name of the database.
67
   */
68
  public function getName()
69
  {
70
    return $this->name;
71
  }
72
 
73
  /**
74
   * Set the type
75
   *
76
   * @param      integer $type The relation type (either self::HAS_ONE, or self::HAS_MANY)
77
   */
78
  public function setType($type)
79
  {
80
    $this->type = $type;
81
  }
82
 
83
  /**
84
   * Get the type
85
   *
86
   * @return      integer the relation type
87
   */
88
  public function getType()
89
  {
90
    return $this->type;
91
  }
92
 
93
  /**
94
   * Set the local table
95
   *
96
   * @param      TableMap $table The local table for this relationship
97
   */
98
  public function setLocalTable($table)
99
  {
100
    $this->localTable = $table;
101
  }
102
 
103
  /**
104
   * Get the local table
105
   *
106
   * @return      TableMap The local table for this relationship
107
   */
108
  public function getLocalTable()
109
  {
110
    return $this->localTable;
111
  }
112
 
113
  /**
114
   * Set the foreign table
115
   *
116
   * @param      TableMap $table The foreign table for this relationship
117
   */
118
  public function setForeignTable($table)
119
  {
120
    $this->foreignTable = $table;
121
  }
122
 
123
  /**
124
   * Get the foreign table
125
   *
126
   * @return      TableMap The foreign table for this relationship
127
   */
128
  public function getForeignTable()
129
  {
130
    return $this->foreignTable;
131
  }
132
 
133
  /**
134
   * Add a column mapping
135
   *
136
   * @param   ColumnMap $local The local column
137
   * @param   ColumnMap $foreign The foreign column
138
   */
139
  public function addColumnMapping(ColumnMap $local, ColumnMap $foreign)
140
  {
141
    $this->localColumns[] = $local;
142
    $this->foreignColumns[] = $foreign;
143
  }
144
 
145
  /**
146
   * Get an associative array mapping local column names to foreign column names
147
   *
148
   * @return Array Associative array (local => foreign) of fully qualified column names
149
   */
150
  public function getColumnMappings()
151
  {
152
    $h = array();
153
    for ($i=0, $size=count($this->localColumns); $i < $size; $i++) {
154
      $h[$this->localColumns[$i]->getFullyQualifiedName()] = $this->foreignColumns[$i]->getFullyQualifiedName();
155
    }
156
    return $h;
157
  }
158
 
159
  /**
160
   * Get the local columns
161
   *
162
   * @return      Array list of ColumnMap objects
163
   */
164
  public function getLocalColumns()
165
  {
166
    return $this->localColumns;
167
  }
168
 
169
  /**
170
   * Get the foreign columns
171
   *
172
   * @return      Array list of ColumnMap objects
173
   */
174
  public function getForeignColumns()
175
  {
176
    return $this->foreignColumns;
177
  }
178
 
179
  /**
180
   * Set the onUpdate behavior
181
   *
182
   * @param      string $onUpdate
183
   */
184
  public function setOnUpdate($onUpdate)
185
  {
186
    $this->onUpdate = $onUpdate;
187
  }
188
 
189
  /**
190
   * Get the onUpdate behavior
191
   *
192
   * @return      integer the relation type
193
   */
194
  public function getOnUpdate()
195
  {
196
    return $this->onUpdate;
197
  }
198
 
199
  /**
200
   * Set the onDelete behavior
201
   *
202
   * @param      string $onDelete
203
   */
204
  public function setOnDelete($onDelete)
205
  {
206
    $this->onDelete = $onDelete;
207
  }
208
 
209
  /**
210
   * Get the onDelete behavior
211
   *
212
   * @return      integer the relation type
213
   */
214
  public function getOnDelete()
215
  {
216
    return $this->onDelete;
217
  }
218
}