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

/dmCorePlugin/test/project/lib/form/doctrine/dmUserPlugin/base/BaseDmPermissionForm.class.php

https://github.com/xdade/diem
PHP | 299 lines | 221 code | 52 blank | 26 comment | 37 complexity | fb4fc632d9d0c7d1b745d587d87a06be MD5 | raw file
  1. <?php
  2. /**
  3. * DmPermission form base class.
  4. *
  5. * @method DmPermission 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 BaseDmPermissionForm 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('name')){
  25. $this->setWidget('name', new sfWidgetFormInputText());
  26. $this->setValidator('name', new sfValidatorString(array('max_length' => 255, 'required' => false)));
  27. }
  28. //column
  29. if($this->needsWidget('description')){
  30. $this->setWidget('description', new sfWidgetFormTextarea());
  31. $this->setValidator('description', new sfValidatorString(array('max_length' => 5000, 'required' => false)));
  32. }
  33. //column
  34. if($this->needsWidget('created_at')){
  35. $this->setWidget('created_at', new sfWidgetFormDateTime());
  36. $this->setValidator('created_at', new sfValidatorDateTime());
  37. }
  38. //column
  39. if($this->needsWidget('updated_at')){
  40. $this->setWidget('updated_at', new sfWidgetFormDateTime());
  41. $this->setValidator('updated_at', new sfValidatorDateTime());
  42. }
  43. //many to many
  44. if($this->needsWidget('users_list')){
  45. $this->setWidget('users_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmUser', 'expanded' => true)));
  46. $this->setValidator('users_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmUser', 'required' => false)));
  47. }
  48. //many to many
  49. if($this->needsWidget('groups_list')){
  50. $this->setWidget('groups_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmGroup', 'expanded' => true)));
  51. $this->setValidator('groups_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmGroup', 'required' => false)));
  52. }
  53. //one to many
  54. if($this->needsWidget('dm_user_permission_list')){
  55. $this->setWidget('dm_user_permission_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmUserPermission', 'expanded' => true)));
  56. $this->setValidator('dm_user_permission_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmUserPermission', 'required' => false)));
  57. }
  58. //one to many
  59. if($this->needsWidget('dm_group_permission_list')){
  60. $this->setWidget('dm_group_permission_list', new sfWidgetFormDmPaginatedDoctrineChoice(array('multiple' => true, 'model' => 'DmGroupPermission', 'expanded' => true)));
  61. $this->setValidator('dm_group_permission_list', new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'DmGroupPermission', 'required' => false)));
  62. }
  63. $this->validatorSchema->setPostValidator(
  64. new sfValidatorDoctrineUnique(array('model' => 'DmPermission', 'column' => array('name')))
  65. );
  66. $this->widgetSchema->setNameFormat('dm_permission[%s]');
  67. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  68. $this->setupInheritance();
  69. parent::setup();
  70. // Unset automatic fields like 'created_at', 'updated_at', 'position'
  71. // override this method in your form to keep them
  72. parent::unsetAutoFields();
  73. }
  74. protected function doBind(array $values)
  75. {
  76. parent::doBind($values);
  77. }
  78. public function processValues($values)
  79. {
  80. $values = parent::processValues($values);
  81. return $values;
  82. }
  83. protected function doUpdateObject($values)
  84. {
  85. parent::doUpdateObject($values);
  86. }
  87. public function getModelName()
  88. {
  89. return 'DmPermission';
  90. }
  91. public function updateDefaultsFromObject()
  92. {
  93. parent::updateDefaultsFromObject();
  94. if (isset($this->widgetSchema['users_list']))
  95. {
  96. $this->setDefault('users_list', array_merge((array)$this->getDefault('users_list'),$this->object->Users->getPrimaryKeys()));
  97. }
  98. if (isset($this->widgetSchema['groups_list']))
  99. {
  100. $this->setDefault('groups_list', array_merge((array)$this->getDefault('groups_list'),$this->object->Groups->getPrimaryKeys()));
  101. }
  102. if (isset($this->widgetSchema['dm_user_permission_list']))
  103. {
  104. $this->setDefault('dm_user_permission_list', array_merge((array)$this->getDefault('dm_user_permission_list'),$this->object->DmUserPermission->getPrimaryKeys()));
  105. }
  106. if (isset($this->widgetSchema['dm_group_permission_list']))
  107. {
  108. $this->setDefault('dm_group_permission_list', array_merge((array)$this->getDefault('dm_group_permission_list'),$this->object->DmGroupPermission->getPrimaryKeys()));
  109. }
  110. }
  111. protected function doSave($con = null)
  112. {
  113. $this->saveUsersList($con);
  114. $this->saveGroupsList($con);
  115. $this->saveDmUserPermissionList($con);
  116. $this->saveDmGroupPermissionList($con);
  117. parent::doSave($con);
  118. }
  119. public function saveUsersList($con = null)
  120. {
  121. if (!$this->isValid())
  122. {
  123. throw $this->getErrorSchema();
  124. }
  125. if (!isset($this->widgetSchema['users_list']))
  126. {
  127. // somebody has unset this widget
  128. return;
  129. }
  130. if (null === $con)
  131. {
  132. $con = $this->getConnection();
  133. }
  134. $existing = $this->object->Users->getPrimaryKeys();
  135. $values = $this->getValue('users_list');
  136. if (!is_array($values))
  137. {
  138. $values = array();
  139. }
  140. $unlink = array_diff($existing, $values);
  141. if (count($unlink))
  142. {
  143. $this->object->unlink('Users', array_values($unlink));
  144. }
  145. $link = array_diff($values, $existing);
  146. if (count($link))
  147. {
  148. $this->object->link('Users', array_values($link));
  149. }
  150. }
  151. public function saveGroupsList($con = null)
  152. {
  153. if (!$this->isValid())
  154. {
  155. throw $this->getErrorSchema();
  156. }
  157. if (!isset($this->widgetSchema['groups_list']))
  158. {
  159. // somebody has unset this widget
  160. return;
  161. }
  162. if (null === $con)
  163. {
  164. $con = $this->getConnection();
  165. }
  166. $existing = $this->object->Groups->getPrimaryKeys();
  167. $values = $this->getValue('groups_list');
  168. if (!is_array($values))
  169. {
  170. $values = array();
  171. }
  172. $unlink = array_diff($existing, $values);
  173. if (count($unlink))
  174. {
  175. $this->object->unlink('Groups', array_values($unlink));
  176. }
  177. $link = array_diff($values, $existing);
  178. if (count($link))
  179. {
  180. $this->object->link('Groups', array_values($link));
  181. }
  182. }
  183. public function saveDmUserPermissionList($con = null)
  184. {
  185. if (!$this->isValid())
  186. {
  187. throw $this->getErrorSchema();
  188. }
  189. if (!isset($this->widgetSchema['dm_user_permission_list']))
  190. {
  191. // somebody has unset this widget
  192. return;
  193. }
  194. if (null === $con)
  195. {
  196. $con = $this->getConnection();
  197. }
  198. $existing = $this->object->DmUserPermission->getPrimaryKeys();
  199. $values = $this->getValue('dm_user_permission_list');
  200. if (!is_array($values))
  201. {
  202. $values = array();
  203. }
  204. $unlink = array_diff($existing, $values);
  205. if (count($unlink))
  206. {
  207. $this->object->unlink('DmUserPermission', array_values($unlink));
  208. }
  209. $link = array_diff($values, $existing);
  210. if (count($link))
  211. {
  212. $this->object->link('DmUserPermission', array_values($link));
  213. }
  214. }
  215. public function saveDmGroupPermissionList($con = null)
  216. {
  217. if (!$this->isValid())
  218. {
  219. throw $this->getErrorSchema();
  220. }
  221. if (!isset($this->widgetSchema['dm_group_permission_list']))
  222. {
  223. // somebody has unset this widget
  224. return;
  225. }
  226. if (null === $con)
  227. {
  228. $con = $this->getConnection();
  229. }
  230. $existing = $this->object->DmGroupPermission->getPrimaryKeys();
  231. $values = $this->getValue('dm_group_permission_list');
  232. if (!is_array($values))
  233. {
  234. $values = array();
  235. }
  236. $unlink = array_diff($existing, $values);
  237. if (count($unlink))
  238. {
  239. $this->object->unlink('DmGroupPermission', array_values($unlink));
  240. }
  241. $link = array_diff($values, $existing);
  242. if (count($link))
  243. {
  244. $this->object->link('DmGroupPermission', array_values($link));
  245. }
  246. }
  247. }