/dmCorePlugin/test/project/lib/form/doctrine/base/BaseDmTestCategForm.class.php

https://github.com/ardi-n/diem · PHP · 294 lines · 218 code · 52 blank · 24 comment · 37 complexity · 42df4a60e2f7075674ea9e0e6ee2e387 MD5 · raw file

  1. <?php
  2. /**
  3. * DmTestCateg form base class.
  4. *
  5. * @method DmTestCateg getObject() Returns the current form's model object
  6. *
  7. * @package retest
  8. * @subpackage form
  9. * @author Your name here
  10. * @version SVN: $Id$
  11. * @generator Diem 5.4.0-DEV
  12. */
  13. abstract class BaseDmTestCategForm extends BaseFormDoctrine
  14. {
  15. public function setup()
  16. {
  17. parent::setup();
  18. //column
  19. if($this->needsWidget('id')){
  20. $this->setWidget('id', new sfWidgetFormInputHidden());
  21. $this->setValidator('id', new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)));
  22. }
  23. //column
  24. if($this->needsWidget('created_at')){
  25. $this->setWidget('created_at', new sfWidgetFormDateTime());
  26. $this->setValidator('created_at', new sfValidatorDateTime());
  27. }
  28. //column
  29. if($this->needsWidget('updated_at')){
  30. $this->setWidget('updated_at', new sfWidgetFormDateTime());
  31. $this->setValidator('updated_at', new sfValidatorDateTime());
  32. }
  33. //column
  34. if($this->needsWidget('position')){
  35. $this->setWidget('position', new sfWidgetFormInputText());
  36. $this->setValidator('position', new sfValidatorInteger(array('required' => false)));
  37. }
  38. //many to many
  39. if($this->needsWidget('domains_list')){
  40. $this->setWidget('domains_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmTestDomain', 'expanded' => true)));
  41. $this->setValidator('domains_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmTestDomain', 'required' => false)));
  42. }
  43. //one to many
  44. if($this->needsWidget('dm_test_domain_categ_list')){
  45. $this->setWidget('dm_test_domain_categ_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmTestDomainCateg', 'expanded' => true)));
  46. $this->setValidator('dm_test_domain_categ_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmTestDomainCateg', 'required' => false)));
  47. }
  48. //one to many
  49. if($this->needsWidget('posts_list')){
  50. $this->setWidget('posts_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmTestPost', 'expanded' => true)));
  51. $this->setValidator('posts_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmTestPost', 'required' => false)));
  52. }
  53. if('embed' == sfConfig::get('dm_i18n_form'))
  54. {
  55. $this->embedI18n(sfConfig::get('dm_i18n_cultures'));
  56. }
  57. else
  58. {
  59. $this->mergeI18nForm();
  60. }
  61. $this->widgetSchema->setNameFormat('dm_test_categ[%s]');
  62. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  63. $this->setupInheritance();
  64. parent::setup();
  65. // Unset automatic fields like 'created_at', 'updated_at', 'position'
  66. // override this method in your form to keep them
  67. parent::unsetAutoFields();
  68. }
  69. protected function doBind(array $values)
  70. {
  71. parent::doBind($values);
  72. }
  73. public function processValues($values)
  74. {
  75. $values = parent::processValues($values);
  76. return $values;
  77. }
  78. protected function doUpdateObject($values)
  79. {
  80. parent::doUpdateObject($values);
  81. }
  82. public function getModelName()
  83. {
  84. return 'DmTestCateg';
  85. }
  86. public function updateDefaultsFromObject()
  87. {
  88. parent::updateDefaultsFromObject();
  89. if (isset($this->widgetSchema['domains_list']))
  90. {
  91. $this->setDefault('domains_list', $this->object->Domains->getPrimaryKeys());
  92. }
  93. if (isset($this->widgetSchema['dm_test_domain_categ_list']))
  94. {
  95. $this->setDefault('dm_test_domain_categ_list', $this->object->DmTestDomainCateg->getPrimaryKeys());
  96. }
  97. if (isset($this->widgetSchema['posts_list']))
  98. {
  99. $this->setDefault('posts_list', $this->object->Posts->getPrimaryKeys());
  100. }
  101. if (isset($this->widgetSchema['translation_list']))
  102. {
  103. $this->setDefault('translation_list', $this->object->Translation->getPrimaryKeys());
  104. }
  105. }
  106. protected function doSave($con = null)
  107. {
  108. $this->saveDomainsList($con);
  109. $this->saveDmTestDomainCategList($con);
  110. $this->savePostsList($con);
  111. $this->saveTranslationList($con);
  112. parent::doSave($con);
  113. }
  114. public function saveDomainsList($con = null)
  115. {
  116. if (!$this->isValid())
  117. {
  118. throw $this->getErrorSchema();
  119. }
  120. if (!isset($this->widgetSchema['domains_list']))
  121. {
  122. // somebody has unset this widget
  123. return;
  124. }
  125. if (null === $con)
  126. {
  127. $con = $this->getConnection();
  128. }
  129. $existing = $this->object->Domains->getPrimaryKeys();
  130. $values = $this->getValue('domains_list');
  131. if (!is_array($values))
  132. {
  133. $values = array();
  134. }
  135. $unlink = array_diff($existing, $values);
  136. if (count($unlink))
  137. {
  138. $this->object->unlink('Domains', array_values($unlink));
  139. }
  140. $link = array_diff($values, $existing);
  141. if (count($link))
  142. {
  143. $this->object->link('Domains', array_values($link));
  144. }
  145. }
  146. public function saveDmTestDomainCategList($con = null)
  147. {
  148. if (!$this->isValid())
  149. {
  150. throw $this->getErrorSchema();
  151. }
  152. if (!isset($this->widgetSchema['dm_test_domain_categ_list']))
  153. {
  154. // somebody has unset this widget
  155. return;
  156. }
  157. if (null === $con)
  158. {
  159. $con = $this->getConnection();
  160. }
  161. $existing = $this->object->DmTestDomainCateg->getPrimaryKeys();
  162. $values = $this->getValue('dm_test_domain_categ_list');
  163. if (!is_array($values))
  164. {
  165. $values = array();
  166. }
  167. $unlink = array_diff($existing, $values);
  168. if (count($unlink))
  169. {
  170. $this->object->unlink('DmTestDomainCateg', array_values($unlink));
  171. }
  172. $link = array_diff($values, $existing);
  173. if (count($link))
  174. {
  175. $this->object->link('DmTestDomainCateg', array_values($link));
  176. }
  177. }
  178. public function savePostsList($con = null)
  179. {
  180. if (!$this->isValid())
  181. {
  182. throw $this->getErrorSchema();
  183. }
  184. if (!isset($this->widgetSchema['posts_list']))
  185. {
  186. // somebody has unset this widget
  187. return;
  188. }
  189. if (null === $con)
  190. {
  191. $con = $this->getConnection();
  192. }
  193. $existing = $this->object->Posts->getPrimaryKeys();
  194. $values = $this->getValue('posts_list');
  195. if (!is_array($values))
  196. {
  197. $values = array();
  198. }
  199. $unlink = array_diff($existing, $values);
  200. if (count($unlink))
  201. {
  202. $this->object->unlink('Posts', array_values($unlink));
  203. }
  204. $link = array_diff($values, $existing);
  205. if (count($link))
  206. {
  207. $this->object->link('Posts', array_values($link));
  208. }
  209. }
  210. public function saveTranslationList($con = null)
  211. {
  212. if (!$this->isValid())
  213. {
  214. throw $this->getErrorSchema();
  215. }
  216. if (!isset($this->widgetSchema['translation_list']))
  217. {
  218. // somebody has unset this widget
  219. return;
  220. }
  221. if (null === $con)
  222. {
  223. $con = $this->getConnection();
  224. }
  225. $existing = $this->object->Translation->getPrimaryKeys();
  226. $values = $this->getValue('translation_list');
  227. if (!is_array($values))
  228. {
  229. $values = array();
  230. }
  231. $unlink = array_diff($existing, $values);
  232. if (count($unlink))
  233. {
  234. $this->object->unlink('Translation', array_values($unlink));
  235. }
  236. $link = array_diff($values, $existing);
  237. if (count($link))
  238. {
  239. $this->object->link('Translation', array_values($link));
  240. }
  241. }
  242. }