BaseKataoOrderForm.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * KataoOrder form base class.
  4. *
  5. * @package form
  6. * @subpackage katao_order
  7. * @version SVN: $Id: sfPropelFormGeneratedTemplate.php 15484 2009-02-13 13:13:51Z fabien $
  8. */
  9. class BaseKataoOrderForm extends BaseFormPropel
  10. {
  11. public function setup()
  12. {
  13. $this->setWidgets(array(
  14. 'id' => new sfWidgetFormInputHidden(),
  15. 'katao_supplier_id' => new sfWidgetFormPropelSelect(array('model' => 'KataoSupplier', 'add_empty' => false)),
  16. 'katao_period_id' => new sfWidgetFormPropelSelect(array('model' => 'KataoPeriod', 'add_empty' => false)),
  17. 'katao_node_id' => new sfWidgetFormPropelSelect(array('model' => 'KataoNode', 'add_empty' => false)),
  18. 'status' => new sfWidgetFormInput(),
  19. 'is_simulated' => new sfWidgetFormInput(),
  20. 'supplier_name' => new sfWidgetFormInput(),
  21. 'supplier_email' => new sfWidgetFormInput(),
  22. 'supplier_address1' => new sfWidgetFormInput(),
  23. 'supplier_address2' => new sfWidgetFormInput(),
  24. 'supplier_zip' => new sfWidgetFormInput(),
  25. 'supplier_city' => new sfWidgetFormInput(),
  26. 'katao_name' => new sfWidgetFormInput(),
  27. 'katao_address' => new sfWidgetFormTextarea(),
  28. 'katao_siret_number' => new sfWidgetFormInput(),
  29. 'katao_rcs_number' => new sfWidgetFormInput(),
  30. 'katao_capital' => new sfWidgetFormInput(),
  31. 'delivery_address' => new sfWidgetFormTextarea(),
  32. 'created_at' => new sfWidgetFormDateTime(),
  33. 'updated_at' => new sfWidgetFormDateTime(),
  34. 'katao_supplier_invoice_order_list' => new sfWidgetFormPropelSelectMany(array('model' => 'KataoSupplierInvoice')),
  35. ));
  36. $this->setValidators(array(
  37. 'id' => new sfValidatorPropelChoice(array('model' => 'KataoOrder', 'column' => 'id', 'required' => false)),
  38. 'katao_supplier_id' => new sfValidatorPropelChoice(array('model' => 'KataoSupplier', 'column' => 'id')),
  39. 'katao_period_id' => new sfValidatorPropelChoice(array('model' => 'KataoPeriod', 'column' => 'id')),
  40. 'katao_node_id' => new sfValidatorPropelChoice(array('model' => 'KataoNode', 'column' => 'id')),
  41. 'status' => new sfValidatorInteger(),
  42. 'is_simulated' => new sfValidatorInteger(array('required' => false)),
  43. 'supplier_name' => new sfValidatorString(array('max_length' => 255)),
  44. 'supplier_email' => new sfValidatorString(array('max_length' => 255)),
  45. 'supplier_address1' => new sfValidatorString(array('max_length' => 255)),
  46. 'supplier_address2' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  47. 'supplier_zip' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  48. 'supplier_city' => new sfValidatorString(array('max_length' => 255)),
  49. 'katao_name' => new sfValidatorString(array('max_length' => 255)),
  50. 'katao_address' => new sfValidatorString(array('required' => false)),
  51. 'katao_siret_number' => new sfValidatorString(array('max_length' => 14)),
  52. 'katao_rcs_number' => new sfValidatorString(array('max_length' => 255)),
  53. 'katao_capital' => new sfValidatorInteger(),
  54. 'delivery_address' => new sfValidatorString(array('required' => false)),
  55. 'created_at' => new sfValidatorDateTime(array('required' => false)),
  56. 'updated_at' => new sfValidatorDateTime(array('required' => false)),
  57. 'katao_supplier_invoice_order_list' => new sfValidatorPropelChoiceMany(array('model' => 'KataoSupplierInvoice', 'required' => false)),
  58. ));
  59. $this->widgetSchema->setNameFormat('katao_order[%s]');
  60. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  61. parent::setup();
  62. }
  63. public function getModelName()
  64. {
  65. return 'KataoOrder';
  66. }
  67. public function updateDefaultsFromObject()
  68. {
  69. parent::updateDefaultsFromObject();
  70. if (isset($this->widgetSchema['katao_supplier_invoice_order_list']))
  71. {
  72. $values = array();
  73. foreach ($this->object->getKataoSupplierInvoiceOrders() as $obj)
  74. {
  75. $values[] = $obj->getKataoSupplierInvoiceId();
  76. }
  77. $this->setDefault('katao_supplier_invoice_order_list', $values);
  78. }
  79. }
  80. protected function doSave($con = null)
  81. {
  82. parent::doSave($con);
  83. $this->saveKataoSupplierInvoiceOrderList($con);
  84. }
  85. public function saveKataoSupplierInvoiceOrderList($con = null)
  86. {
  87. if (!$this->isValid())
  88. {
  89. throw $this->getErrorSchema();
  90. }
  91. if (!isset($this->widgetSchema['katao_supplier_invoice_order_list']))
  92. {
  93. // somebody has unset this widget
  94. return;
  95. }
  96. if (is_null($con))
  97. {
  98. $con = $this->getConnection();
  99. }
  100. $c = new Criteria();
  101. $c->add(KataoSupplierInvoiceOrderPeer::KATAO_ORDER_ID, $this->object->getPrimaryKey());
  102. KataoSupplierInvoiceOrderPeer::doDelete($c, $con);
  103. $values = $this->getValue('katao_supplier_invoice_order_list');
  104. if (is_array($values))
  105. {
  106. foreach ($values as $value)
  107. {
  108. $obj = new KataoSupplierInvoiceOrder();
  109. $obj->setKataoOrderId($this->object->getPrimaryKey());
  110. $obj->setKataoSupplierInvoiceId($value);
  111. $obj->save();
  112. }
  113. }
  114. }
  115. }