PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/model/om/BaseStaticPageI18n.php

https://github.com/mikesname/ehri-ica-atom
PHP | 561 lines | 434 code | 107 blank | 20 comment | 62 complexity | 966215ec6b9833762e6ffc171bd9d661 MD5 | raw file
  1. <?php
  2. abstract class BaseStaticPageI18n implements ArrayAccess
  3. {
  4. const
  5. DATABASE_NAME = 'propel',
  6. TABLE_NAME = 'static_page_i18n',
  7. TITLE = 'static_page_i18n.TITLE',
  8. CONTENT = 'static_page_i18n.CONTENT',
  9. ID = 'static_page_i18n.ID',
  10. CULTURE = 'static_page_i18n.CULTURE';
  11. public static function addSelectColumns(Criteria $criteria)
  12. {
  13. $criteria->addSelectColumn(QubitStaticPageI18n::TITLE);
  14. $criteria->addSelectColumn(QubitStaticPageI18n::CONTENT);
  15. $criteria->addSelectColumn(QubitStaticPageI18n::ID);
  16. $criteria->addSelectColumn(QubitStaticPageI18n::CULTURE);
  17. return $criteria;
  18. }
  19. protected static
  20. $staticPageI18ns = array();
  21. protected
  22. $keys = array(),
  23. $row = array();
  24. public static function getFromRow(array $row)
  25. {
  26. $keys = array();
  27. $keys['id'] = $row[2];
  28. $keys['culture'] = $row[3];
  29. $key = serialize($keys);
  30. if (!isset(self::$staticPageI18ns[$key]))
  31. {
  32. $staticPageI18n = new QubitStaticPageI18n;
  33. $staticPageI18n->keys = $keys;
  34. $staticPageI18n->row = $row;
  35. $staticPageI18n->new = false;
  36. self::$staticPageI18ns[$key] = $staticPageI18n;
  37. }
  38. return self::$staticPageI18ns[$key];
  39. }
  40. public static function get(Criteria $criteria, array $options = array())
  41. {
  42. if (!isset($options['connection']))
  43. {
  44. $options['connection'] = Propel::getConnection(QubitStaticPageI18n::DATABASE_NAME);
  45. }
  46. self::addSelectColumns($criteria);
  47. return QubitQuery::createFromCriteria($criteria, 'QubitStaticPageI18n', $options);
  48. }
  49. public static function getAll(array $options = array())
  50. {
  51. return self::get(new Criteria, $options);
  52. }
  53. public static function getOne(Criteria $criteria, array $options = array())
  54. {
  55. $criteria->setLimit(1);
  56. return self::get($criteria, $options)->__get(0, array('defaultValue' => null));
  57. }
  58. public static function getByIdAndCulture($id, $culture, array $options = array())
  59. {
  60. $criteria = new Criteria;
  61. $criteria->add(QubitStaticPageI18n::ID, $id);
  62. $criteria->add(QubitStaticPageI18n::CULTURE, $culture);
  63. if (1 == count($query = self::get($criteria, $options)))
  64. {
  65. return $query[0];
  66. }
  67. }
  68. public static function doDelete(Criteria $criteria, $connection = null)
  69. {
  70. if (!isset($connection))
  71. {
  72. $connection = QubitTransactionFilter::getConnection(QubitStaticPageI18n::DATABASE_NAME);
  73. }
  74. $affectedRows = 0;
  75. $affectedRows += BasePeer::doDelete($criteria, $connection);
  76. return $affectedRows;
  77. }
  78. protected
  79. $tables = array();
  80. public function __construct()
  81. {
  82. $this->tables[] = Propel::getDatabaseMap(QubitStaticPageI18n::DATABASE_NAME)->getTable(QubitStaticPageI18n::TABLE_NAME);
  83. }
  84. protected
  85. $values = array(),
  86. $refFkValues = array();
  87. protected function rowOffsetGet($name, $offset, $options)
  88. {
  89. if (empty($options['clean']) && array_key_exists($name, $this->values))
  90. {
  91. return $this->values[$name];
  92. }
  93. if (array_key_exists($name, $this->keys))
  94. {
  95. return $this->keys[$name];
  96. }
  97. if (!array_key_exists($offset, $this->row))
  98. {
  99. if ($this->new)
  100. {
  101. return;
  102. }
  103. if (!isset($options['connection']))
  104. {
  105. $options['connection'] = Propel::getConnection(QubitStaticPageI18n::DATABASE_NAME);
  106. }
  107. $criteria = new Criteria;
  108. $criteria->add(QubitStaticPageI18n::ID, $this->id);
  109. $criteria->add(QubitStaticPageI18n::CULTURE, $this->culture);
  110. call_user_func(array(get_class($this), 'addSelectColumns'), $criteria);
  111. $statement = BasePeer::doSelect($criteria, $options['connection']);
  112. $this->row = $statement->fetch();
  113. }
  114. return $this->row[$offset];
  115. }
  116. public function __isset($name)
  117. {
  118. $args = func_get_args();
  119. $options = array();
  120. if (1 < count($args))
  121. {
  122. $options = $args[1];
  123. }
  124. $offset = 0;
  125. foreach ($this->tables as $table)
  126. {
  127. foreach ($table->getColumns() as $column)
  128. {
  129. if ($name == $column->getPhpName())
  130. {
  131. return null !== $this->rowOffsetGet($name, $offset, $options);
  132. }
  133. if ("{$name}Id" == $column->getPhpName())
  134. {
  135. return null !== $this->rowOffsetGet("{$name}Id", $offset, $options);
  136. }
  137. $offset++;
  138. }
  139. }
  140. throw new sfException("Unknown record property \"$name\" on \"".get_class($this).'"');
  141. }
  142. public function offsetExists($offset)
  143. {
  144. $args = func_get_args();
  145. return call_user_func_array(array($this, '__isset'), $args);
  146. }
  147. public function __get($name)
  148. {
  149. $args = func_get_args();
  150. $options = array();
  151. if (1 < count($args))
  152. {
  153. $options = $args[1];
  154. }
  155. $offset = 0;
  156. foreach ($this->tables as $table)
  157. {
  158. foreach ($table->getColumns() as $column)
  159. {
  160. if ($name == $column->getPhpName())
  161. {
  162. return $this->rowOffsetGet($name, $offset, $options);
  163. }
  164. if ("{$name}Id" == $column->getPhpName())
  165. {
  166. $relatedTable = $column->getTable()->getDatabaseMap()->getTable($column->getRelatedTableName());
  167. return call_user_func(array($relatedTable->getClassName(), 'getBy'.ucfirst($relatedTable->getColumn($column->getRelatedColumnName())->getPhpName())), $this->rowOffsetGet("{$name}Id", $offset, $options));
  168. }
  169. $offset++;
  170. }
  171. }
  172. throw new sfException("Unknown record property \"$name\" on \"".get_class($this).'"');
  173. }
  174. public function offsetGet($offset)
  175. {
  176. $args = func_get_args();
  177. return call_user_func_array(array($this, '__get'), $args);
  178. }
  179. public function __set($name, $value)
  180. {
  181. $args = func_get_args();
  182. $options = array();
  183. if (2 < count($args))
  184. {
  185. $options = $args[2];
  186. }
  187. $offset = 0;
  188. foreach ($this->tables as $table)
  189. {
  190. foreach ($table->getColumns() as $column)
  191. {
  192. if ($name == $column->getPhpName())
  193. {
  194. $this->values[$name] = $value;
  195. }
  196. if ("{$name}Id" == $column->getPhpName())
  197. {
  198. $relatedTable = $column->getTable()->getDatabaseMap()->getTable($column->getRelatedTableName());
  199. $this->values["{$name}Id"] = $value->__get($relatedTable->getColumn($column->getRelatedColumnName())->getPhpName(), $options);
  200. }
  201. $offset++;
  202. }
  203. }
  204. return $this;
  205. }
  206. public function offsetSet($offset, $value)
  207. {
  208. $args = func_get_args();
  209. return call_user_func_array(array($this, '__set'), $args);
  210. }
  211. public function __unset($name)
  212. {
  213. $offset = 0;
  214. foreach ($this->tables as $table)
  215. {
  216. foreach ($table->getColumns() as $column)
  217. {
  218. if ($name == $column->getPhpName())
  219. {
  220. $this->values[$name] = null;
  221. }
  222. if ("{$name}Id" == $column->getPhpName())
  223. {
  224. $this->values["{$name}Id"] = null;
  225. }
  226. $offset++;
  227. }
  228. }
  229. return $this;
  230. }
  231. public function offsetUnset($offset)
  232. {
  233. $args = func_get_args();
  234. return call_user_func_array(array($this, '__unset'), $args);
  235. }
  236. public function clear()
  237. {
  238. $this->row = $this->values = array();
  239. return $this;
  240. }
  241. protected
  242. $new = true;
  243. protected
  244. $deleted = false;
  245. public function save($connection = null)
  246. {
  247. if ($this->deleted)
  248. {
  249. throw new PropelException('You cannot save an object that has been deleted.');
  250. }
  251. if ($this->new)
  252. {
  253. $this->insert($connection);
  254. }
  255. else
  256. {
  257. $this->update($connection);
  258. }
  259. $offset = 0;
  260. foreach ($this->tables as $table)
  261. {
  262. foreach ($table->getColumns() as $column)
  263. {
  264. if (array_key_exists($column->getPhpName(), $this->values))
  265. {
  266. $this->row[$offset] = $this->values[$column->getPhpName()];
  267. }
  268. $offset++;
  269. }
  270. }
  271. $this->new = false;
  272. $this->values = array();
  273. return $this;
  274. }
  275. protected function param($column)
  276. {
  277. $value = $this->values[$column->getPhpName()];
  278. // Convert to DateTime or SQL zero special case
  279. if (isset($value) && $column->isTemporal() && !$value instanceof DateTime)
  280. {
  281. // Year only: one or more digits. Convert to SQL zero special case
  282. if (preg_match('/^\d+$/', $value))
  283. {
  284. $value .= '-0-0';
  285. }
  286. // Year and month only: one or more digits, plus separator, plus
  287. // one or more digits. Convert to SQL zero special case
  288. else if (preg_match('/^\d+[-\/]\d+$/', $value))
  289. {
  290. $value .= '-0';
  291. }
  292. // Convert to DateTime if not SQL zero special case: year plus
  293. // separator plus zero to twelve (possibly zero padded) plus
  294. // separator plus one or more zeros
  295. if (!preg_match('/^\d+[-\/]0*(?:1[0-2]|\d)[-\/]0+$/', $value))
  296. {
  297. try
  298. {
  299. $value = new DateTime($value);
  300. }
  301. catch (Exception $e)
  302. {
  303. return null;
  304. }
  305. }
  306. }
  307. return $value;
  308. }
  309. protected function insert($connection = null)
  310. {
  311. if (!isset($connection))
  312. {
  313. $connection = QubitTransactionFilter::getConnection(QubitStaticPageI18n::DATABASE_NAME);
  314. }
  315. $offset = 0;
  316. foreach ($this->tables as $table)
  317. {
  318. $criteria = new Criteria;
  319. foreach ($table->getColumns() as $column)
  320. {
  321. if (!array_key_exists($column->getPhpName(), $this->values))
  322. {
  323. if ('createdAt' == $column->getPhpName() || 'updatedAt' == $column->getPhpName())
  324. {
  325. $this->values[$column->getPhpName()] = new DateTime;
  326. }
  327. if ('sourceCulture' == $column->getPhpName())
  328. {
  329. $this->values['sourceCulture'] = sfPropel::getDefaultCulture();
  330. }
  331. }
  332. if (array_key_exists($column->getPhpName(), $this->values))
  333. {
  334. if (null !== $param = $this->param($column))
  335. {
  336. $criteria->add($column->getFullyQualifiedName(), $param);
  337. }
  338. }
  339. $offset++;
  340. }
  341. if (null !== $id = BasePeer::doInsert($criteria, $connection))
  342. {
  343. // Guess that the first primary key of the first table is auto
  344. // incremented
  345. if ($this->tables[0] == $table)
  346. {
  347. $columns = $table->getPrimaryKeyColumns();
  348. $this->values[$columns[0]->getPhpName()] = $this->keys[$columns[0]->getPhpName()] = $id;
  349. }
  350. }
  351. }
  352. return $this;
  353. }
  354. protected function update($connection = null)
  355. {
  356. if (!isset($connection))
  357. {
  358. $connection = QubitTransactionFilter::getConnection(QubitStaticPageI18n::DATABASE_NAME);
  359. }
  360. $offset = 0;
  361. foreach ($this->tables as $table)
  362. {
  363. $criteria = new Criteria;
  364. $selectCriteria = new Criteria;
  365. foreach ($table->getColumns() as $column)
  366. {
  367. if (!array_key_exists($column->getPhpName(), $this->values))
  368. {
  369. if ('updatedAt' == $column->getPhpName())
  370. {
  371. $this->values['updatedAt'] = new DateTime;
  372. }
  373. }
  374. if (array_key_exists($column->getPhpName(), $this->values))
  375. {
  376. if ('serialNumber' == $column->getPhpName())
  377. {
  378. $selectCriteria->add($column->getFullyQualifiedName(), $this->values[$column->getPhpName()]++);
  379. }
  380. $criteria->add($column->getFullyQualifiedName(), $this->param($column));
  381. }
  382. if ($column->isPrimaryKey())
  383. {
  384. $selectCriteria->add($column->getFullyQualifiedName(), $this->keys[$column->getPhpName()]);
  385. }
  386. $offset++;
  387. }
  388. if (0 < $criteria->size())
  389. {
  390. BasePeer::doUpdate($selectCriteria, $criteria, $connection);
  391. }
  392. }
  393. return $this;
  394. }
  395. public function delete($connection = null)
  396. {
  397. if ($this->deleted)
  398. {
  399. throw new PropelException('This object has already been deleted.');
  400. }
  401. $criteria = new Criteria;
  402. $criteria->add(QubitStaticPageI18n::ID, $this->id);
  403. $criteria->add(QubitStaticPageI18n::CULTURE, $this->culture);
  404. self::doDelete($criteria, $connection);
  405. $this->deleted = true;
  406. return $this;
  407. }
  408. /**
  409. * Returns the composite primary key for this object.
  410. * The array elements will be in same order as specified in XML.
  411. * @return array
  412. */
  413. public function getPrimaryKey()
  414. {
  415. $pks = array();
  416. $pks[0] = $this->getid();
  417. $pks[1] = $this->getculture();
  418. return $pks;
  419. }
  420. /**
  421. * Set the [composite] primary key.
  422. *
  423. * @param array $keys The elements of the composite key (order must match the order in XML file).
  424. * @return void
  425. */
  426. public function setPrimaryKey($keys)
  427. {
  428. $this->setid($keys[0]);
  429. $this->setculture($keys[1]);
  430. }
  431. public static function addJoinstaticPageCriteria(Criteria $criteria)
  432. {
  433. $criteria->addJoin(QubitStaticPageI18n::ID, QubitStaticPage::ID);
  434. return $criteria;
  435. }
  436. public function __call($name, $args)
  437. {
  438. if ('get' == substr($name, 0, 3) || 'set' == substr($name, 0, 3))
  439. {
  440. $args = array_merge(array(strtolower(substr($name, 3, 1)).substr($name, 4)), $args);
  441. return call_user_func_array(array($this, '__'.substr($name, 0, 3)), $args);
  442. }
  443. throw new sfException('Call to undefined method '.get_class($this)."::$name");
  444. }
  445. }