PageRenderTime 55ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/map/RelationMap.php

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