PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/oiclient/lib/model/om/BaseComputerPeer.php

http://openirudi.googlecode.com/
PHP | 386 lines | 277 code | 109 blank | 0 comment | 32 complexity | 6f986f2e953772e71a285002abeaa732 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0
  1. <?php
  2. abstract class BaseComputerPeer {
  3. const DATABASE_NAME = 'propel';
  4. const TABLE_NAME = 'computer';
  5. const CLASS_DEFAULT = 'lib.model.Computer';
  6. const NUM_COLUMNS = 5;
  7. const NUM_LAZY_LOAD_COLUMNS = 0;
  8. const ID = 'computer.ID';
  9. const NAME = 'computer.NAME';
  10. const MAC = 'computer.MAC';
  11. const GROUPS = 'computer.GROUPS';
  12. const HW = 'computer.HW';
  13. private static $phpNameMap = null;
  14. private static $fieldNames = array (
  15. BasePeer::TYPE_PHPNAME => array ('Id', 'Name', 'Mac', 'Groups', 'Hw', ),
  16. BasePeer::TYPE_COLNAME => array (ComputerPeer::ID, ComputerPeer::NAME, ComputerPeer::MAC, ComputerPeer::GROUPS, ComputerPeer::HW, ),
  17. BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'mac', 'groups', 'hw', ),
  18. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
  19. );
  20. private static $fieldKeys = array (
  21. BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'Name' => 1, 'Mac' => 2, 'Groups' => 3, 'Hw' => 4, ),
  22. BasePeer::TYPE_COLNAME => array (ComputerPeer::ID => 0, ComputerPeer::NAME => 1, ComputerPeer::MAC => 2, ComputerPeer::GROUPS => 3, ComputerPeer::HW => 4, ),
  23. BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'mac' => 2, 'groups' => 3, 'hw' => 4, ),
  24. BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
  25. );
  26. public static function getMapBuilder()
  27. {
  28. return BasePeer::getMapBuilder('lib.model.map.ComputerMapBuilder');
  29. }
  30. public static function getPhpNameMap()
  31. {
  32. if (self::$phpNameMap === null) {
  33. $map = ComputerPeer::getTableMap();
  34. $columns = $map->getColumns();
  35. $nameMap = array();
  36. foreach ($columns as $column) {
  37. $nameMap[$column->getPhpName()] = $column->getColumnName();
  38. }
  39. self::$phpNameMap = $nameMap;
  40. }
  41. return self::$phpNameMap;
  42. }
  43. static public function translateFieldName($name, $fromType, $toType)
  44. {
  45. $toNames = self::getFieldNames($toType);
  46. $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null;
  47. if ($key === null) {
  48. throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true));
  49. }
  50. return $toNames[$key];
  51. }
  52. static public function getFieldNames($type = BasePeer::TYPE_PHPNAME)
  53. {
  54. if (!array_key_exists($type, self::$fieldNames)) {
  55. throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.');
  56. }
  57. return self::$fieldNames[$type];
  58. }
  59. public static function alias($alias, $column)
  60. {
  61. return str_replace(ComputerPeer::TABLE_NAME.'.', $alias.'.', $column);
  62. }
  63. public static function addSelectColumns(Criteria $criteria)
  64. {
  65. $criteria->addSelectColumn(ComputerPeer::ID);
  66. $criteria->addSelectColumn(ComputerPeer::NAME);
  67. $criteria->addSelectColumn(ComputerPeer::MAC);
  68. $criteria->addSelectColumn(ComputerPeer::GROUPS);
  69. $criteria->addSelectColumn(ComputerPeer::HW);
  70. }
  71. const COUNT = 'COUNT(computer.ID)';
  72. const COUNT_DISTINCT = 'COUNT(DISTINCT computer.ID)';
  73. public static function doCount(Criteria $criteria, $distinct = false, $con = null)
  74. {
  75. $criteria = clone $criteria;
  76. $criteria->clearSelectColumns()->clearOrderByColumns();
  77. if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
  78. $criteria->addSelectColumn(ComputerPeer::COUNT_DISTINCT);
  79. } else {
  80. $criteria->addSelectColumn(ComputerPeer::COUNT);
  81. }
  82. foreach($criteria->getGroupByColumns() as $column)
  83. {
  84. $criteria->addSelectColumn($column);
  85. }
  86. $rs = ComputerPeer::doSelectRS($criteria, $con);
  87. if ($rs->next()) {
  88. return $rs->getInt(1);
  89. } else {
  90. return 0;
  91. }
  92. }
  93. public static function doSelectOne(Criteria $criteria, $con = null)
  94. {
  95. $critcopy = clone $criteria;
  96. $critcopy->setLimit(1);
  97. $objects = ComputerPeer::doSelect($critcopy, $con);
  98. if ($objects) {
  99. return $objects[0];
  100. }
  101. return null;
  102. }
  103. public static function doSelect(Criteria $criteria, $con = null)
  104. {
  105. return ComputerPeer::populateObjects(ComputerPeer::doSelectRS($criteria, $con));
  106. }
  107. public static function doSelectRS(Criteria $criteria, $con = null)
  108. {
  109. if ($con === null) {
  110. $con = Propel::getConnection(self::DATABASE_NAME);
  111. }
  112. if (!$criteria->getSelectColumns()) {
  113. $criteria = clone $criteria;
  114. ComputerPeer::addSelectColumns($criteria);
  115. }
  116. $criteria->setDbName(self::DATABASE_NAME);
  117. return BasePeer::doSelect($criteria, $con);
  118. }
  119. public static function populateObjects(ResultSet $rs)
  120. {
  121. $results = array();
  122. $cls = ComputerPeer::getOMClass();
  123. $cls = sfPropel::import($cls);
  124. while($rs->next()) {
  125. $obj = new $cls();
  126. $obj->hydrate($rs);
  127. $results[] = $obj;
  128. }
  129. return $results;
  130. }
  131. static public function getUniqueColumnNames()
  132. {
  133. return array();
  134. }
  135. public static function getTableMap()
  136. {
  137. return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME);
  138. }
  139. public static function getOMClass()
  140. {
  141. return ComputerPeer::CLASS_DEFAULT;
  142. }
  143. public static function doInsert($values, $con = null)
  144. {
  145. if ($con === null) {
  146. $con = Propel::getConnection(self::DATABASE_NAME);
  147. }
  148. if ($values instanceof Criteria) {
  149. $criteria = clone $values; } else {
  150. $criteria = $values->buildCriteria(); }
  151. $criteria->remove(ComputerPeer::ID);
  152. $criteria->setDbName(self::DATABASE_NAME);
  153. try {
  154. $con->begin();
  155. $pk = BasePeer::doInsert($criteria, $con);
  156. $con->commit();
  157. } catch(PropelException $e) {
  158. $con->rollback();
  159. throw $e;
  160. }
  161. return $pk;
  162. }
  163. public static function doUpdate($values, $con = null)
  164. {
  165. if ($con === null) {
  166. $con = Propel::getConnection(self::DATABASE_NAME);
  167. }
  168. $selectCriteria = new Criteria(self::DATABASE_NAME);
  169. if ($values instanceof Criteria) {
  170. $criteria = clone $values;
  171. $comparison = $criteria->getComparison(ComputerPeer::ID);
  172. $selectCriteria->add(ComputerPeer::ID, $criteria->remove(ComputerPeer::ID), $comparison);
  173. } else { $criteria = $values->buildCriteria(); $selectCriteria = $values->buildPkeyCriteria(); }
  174. $criteria->setDbName(self::DATABASE_NAME);
  175. return BasePeer::doUpdate($selectCriteria, $criteria, $con);
  176. }
  177. public static function doDeleteAll($con = null)
  178. {
  179. if ($con === null) {
  180. $con = Propel::getConnection(self::DATABASE_NAME);
  181. }
  182. $affectedRows = 0; try {
  183. $con->begin();
  184. $affectedRows += BasePeer::doDeleteAll(ComputerPeer::TABLE_NAME, $con);
  185. $con->commit();
  186. return $affectedRows;
  187. } catch (PropelException $e) {
  188. $con->rollback();
  189. throw $e;
  190. }
  191. }
  192. public static function doDelete($values, $con = null)
  193. {
  194. if ($con === null) {
  195. $con = Propel::getConnection(ComputerPeer::DATABASE_NAME);
  196. }
  197. if ($values instanceof Criteria) {
  198. $criteria = clone $values; } elseif ($values instanceof Computer) {
  199. $criteria = $values->buildPkeyCriteria();
  200. } else {
  201. $criteria = new Criteria(self::DATABASE_NAME);
  202. $criteria->add(ComputerPeer::ID, (array) $values, Criteria::IN);
  203. }
  204. $criteria->setDbName(self::DATABASE_NAME);
  205. $affectedRows = 0;
  206. try {
  207. $con->begin();
  208. $affectedRows += BasePeer::doDelete($criteria, $con);
  209. $con->commit();
  210. return $affectedRows;
  211. } catch (PropelException $e) {
  212. $con->rollback();
  213. throw $e;
  214. }
  215. }
  216. public static function doValidate(Computer $obj, $cols = null)
  217. {
  218. $columns = array();
  219. if ($cols) {
  220. $dbMap = Propel::getDatabaseMap(ComputerPeer::DATABASE_NAME);
  221. $tableMap = $dbMap->getTable(ComputerPeer::TABLE_NAME);
  222. if (! is_array($cols)) {
  223. $cols = array($cols);
  224. }
  225. foreach($cols as $colName) {
  226. if ($tableMap->containsColumn($colName)) {
  227. $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
  228. $columns[$colName] = $obj->$get();
  229. }
  230. }
  231. } else {
  232. }
  233. $res = BasePeer::doValidate(ComputerPeer::DATABASE_NAME, ComputerPeer::TABLE_NAME, $columns);
  234. if ($res !== true) {
  235. $request = sfContext::getInstance()->getRequest();
  236. foreach ($res as $failed) {
  237. $col = ComputerPeer::translateFieldname($failed->getColumn(), BasePeer::TYPE_COLNAME, BasePeer::TYPE_PHPNAME);
  238. $request->setError($col, $failed->getMessage());
  239. }
  240. }
  241. return $res;
  242. }
  243. public static function retrieveByPK($pk, $con = null)
  244. {
  245. if ($con === null) {
  246. $con = Propel::getConnection(self::DATABASE_NAME);
  247. }
  248. $criteria = new Criteria(ComputerPeer::DATABASE_NAME);
  249. $criteria->add(ComputerPeer::ID, $pk);
  250. $v = ComputerPeer::doSelect($criteria, $con);
  251. return !empty($v) > 0 ? $v[0] : null;
  252. }
  253. public static function retrieveByPKs($pks, $con = null)
  254. {
  255. if ($con === null) {
  256. $con = Propel::getConnection(self::DATABASE_NAME);
  257. }
  258. $objs = null;
  259. if (empty($pks)) {
  260. $objs = array();
  261. } else {
  262. $criteria = new Criteria();
  263. $criteria->add(ComputerPeer::ID, $pks, Criteria::IN);
  264. $objs = ComputerPeer::doSelect($criteria, $con);
  265. }
  266. return $objs;
  267. }
  268. }
  269. if (Propel::isInit()) {
  270. try {
  271. BaseComputerPeer::getMapBuilder();
  272. } catch (Exception $e) {
  273. Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR);
  274. }
  275. } else {
  276. Propel::registerMapBuilder('lib.model.map.ComputerMapBuilder');
  277. }