BaseKataoProductCategoryForm.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * KataoProductCategory form base class.
  4. *
  5. * @package form
  6. * @subpackage katao_product_category
  7. * @version SVN: $Id: sfPropelFormGeneratedTemplate.php 15484 2009-02-13 13:13:51Z fabien $
  8. */
  9. class BaseKataoProductCategoryForm extends BaseFormPropel
  10. {
  11. public function setup()
  12. {
  13. $this->setWidgets(array(
  14. 'id' => new sfWidgetFormInputHidden(),
  15. 'name' => new sfWidgetFormInput(),
  16. 'url_identifier' => new sfWidgetFormInput(),
  17. 'accounting_code_suffix' => new sfWidgetFormInput(),
  18. 'sort_order' => new sfWidgetFormInput(),
  19. 'created_at' => new sfWidgetFormDateTime(),
  20. 'updated_at' => new sfWidgetFormDateTime(),
  21. 'katao_supplier_product_category_list' => new sfWidgetFormPropelSelectMany(array('model' => 'KataoSupplier')),
  22. ));
  23. $this->setValidators(array(
  24. 'id' => new sfValidatorPropelChoice(array('model' => 'KataoProductCategory', 'column' => 'id', 'required' => false)),
  25. 'name' => new sfValidatorString(array('max_length' => 255)),
  26. 'url_identifier' => new sfValidatorString(array('max_length' => 255)),
  27. 'accounting_code_suffix' => new sfValidatorString(array('max_length' => 12)),
  28. 'sort_order' => new sfValidatorInteger(array('required' => false)),
  29. 'created_at' => new sfValidatorDateTime(array('required' => false)),
  30. 'updated_at' => new sfValidatorDateTime(array('required' => false)),
  31. 'katao_supplier_product_category_list' => new sfValidatorPropelChoiceMany(array('model' => 'KataoSupplier', 'required' => false)),
  32. ));
  33. $this->widgetSchema->setNameFormat('katao_product_category[%s]');
  34. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  35. parent::setup();
  36. }
  37. public function getModelName()
  38. {
  39. return 'KataoProductCategory';
  40. }
  41. public function updateDefaultsFromObject()
  42. {
  43. parent::updateDefaultsFromObject();
  44. if (isset($this->widgetSchema['katao_supplier_product_category_list']))
  45. {
  46. $values = array();
  47. foreach ($this->object->getKataoSupplierProductCategorys() as $obj)
  48. {
  49. $values[] = $obj->getKataoSupplierId();
  50. }
  51. $this->setDefault('katao_supplier_product_category_list', $values);
  52. }
  53. }
  54. protected function doSave($con = null)
  55. {
  56. parent::doSave($con);
  57. $this->saveKataoSupplierProductCategoryList($con);
  58. }
  59. public function saveKataoSupplierProductCategoryList($con = null)
  60. {
  61. if (!$this->isValid())
  62. {
  63. throw $this->getErrorSchema();
  64. }
  65. if (!isset($this->widgetSchema['katao_supplier_product_category_list']))
  66. {
  67. // somebody has unset this widget
  68. return;
  69. }
  70. if (is_null($con))
  71. {
  72. $con = $this->getConnection();
  73. }
  74. $c = new Criteria();
  75. $c->add(KataoSupplierProductCategoryPeer::KATAO_PRODUCT_CATEGORY_ID, $this->object->getPrimaryKey());
  76. KataoSupplierProductCategoryPeer::doDelete($c, $con);
  77. $values = $this->getValue('katao_supplier_product_category_list');
  78. if (is_array($values))
  79. {
  80. foreach ($values as $value)
  81. {
  82. $obj = new KataoSupplierProductCategory();
  83. $obj->setKataoProductCategoryId($this->object->getPrimaryKey());
  84. $obj->setKataoSupplierId($value);
  85. $obj->save();
  86. }
  87. }
  88. }
  89. }