BaseKataoSupplierForm.class.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * KataoSupplier form base class.
  4. *
  5. * @package form
  6. * @subpackage katao_supplier
  7. * @version SVN: $Id: sfPropelFormGeneratedTemplate.php 15484 2009-02-13 13:13:51Z fabien $
  8. */
  9. class BaseKataoSupplierForm extends BaseFormPropel
  10. {
  11. public function setup()
  12. {
  13. $this->setWidgets(array(
  14. 'id' => new sfWidgetFormInputHidden(),
  15. 'katao_index' => new sfWidgetFormInput(),
  16. 'member_id' => new sfWidgetFormPropelSelect(array('model' => 'KataoMember', 'add_empty' => true)),
  17. 'referer_id' => new sfWidgetFormPropelSelect(array('model' => 'KataoMember', 'add_empty' => true)),
  18. 'name' => new sfWidgetFormInput(),
  19. 'url_identifier' => new sfWidgetFormInput(),
  20. 'presentation' => new sfWidgetFormTextarea(),
  21. 'email' => new sfWidgetFormInput(),
  22. 'address1' => new sfWidgetFormInput(),
  23. 'address2' => new sfWidgetFormInput(),
  24. 'zip' => new sfWidgetFormInput(),
  25. 'city' => new sfWidgetFormInput(),
  26. 'phone' => new sfWidgetFormInput(),
  27. 'fax' => new sfWidgetFormInput(),
  28. 'website' => new sfWidgetFormInput(),
  29. 'gmap_lng' => new sfWidgetFormInput(),
  30. 'gmap_lat' => new sfWidgetFormInput(),
  31. 'accounting_code' => new sfWidgetFormInput(),
  32. 'accounting_code_sol' => new sfWidgetFormInput(),
  33. 'siret_number' => new sfWidgetFormInput(),
  34. 'is_global' => new sfWidgetFormInput(),
  35. 'order_min_amount' => new sfWidgetFormInput(),
  36. 'created_at' => new sfWidgetFormDateTime(),
  37. 'updated_at' => new sfWidgetFormDateTime(),
  38. 'katao_supplier_node_list' => new sfWidgetFormPropelSelectMany(array('model' => 'KataoNode')),
  39. 'katao_supplier_product_category_list' => new sfWidgetFormPropelSelectMany(array('model' => 'KataoProductCategory')),
  40. ));
  41. $this->setValidators(array(
  42. 'id' => new sfValidatorPropelChoice(array('model' => 'KataoSupplier', 'column' => 'id', 'required' => false)),
  43. 'katao_index' => new sfValidatorInteger(),
  44. 'member_id' => new sfValidatorPropelChoice(array('model' => 'KataoMember', 'column' => 'id', 'required' => false)),
  45. 'referer_id' => new sfValidatorPropelChoice(array('model' => 'KataoMember', 'column' => 'id', 'required' => false)),
  46. 'name' => new sfValidatorString(array('max_length' => 255)),
  47. 'url_identifier' => new sfValidatorString(array('max_length' => 255)),
  48. 'presentation' => new sfValidatorString(array('required' => false)),
  49. 'email' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  50. 'address1' => new sfValidatorString(array('max_length' => 255)),
  51. 'address2' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  52. 'zip' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  53. 'city' => new sfValidatorString(array('max_length' => 255)),
  54. 'phone' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  55. 'fax' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  56. 'website' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
  57. 'gmap_lng' => new sfValidatorNumber(array('required' => false)),
  58. 'gmap_lat' => new sfValidatorNumber(array('required' => false)),
  59. 'accounting_code' => new sfValidatorString(array('max_length' => 6)),
  60. 'accounting_code_sol' => new sfValidatorString(array('max_length' => 6)),
  61. 'siret_number' => new sfValidatorString(array('max_length' => 14)),
  62. 'is_global' => new sfValidatorInteger(array('required' => false)),
  63. 'order_min_amount' => new sfValidatorNumber(array('required' => false)),
  64. 'created_at' => new sfValidatorDateTime(array('required' => false)),
  65. 'updated_at' => new sfValidatorDateTime(array('required' => false)),
  66. 'katao_supplier_node_list' => new sfValidatorPropelChoiceMany(array('model' => 'KataoNode', 'required' => false)),
  67. 'katao_supplier_product_category_list' => new sfValidatorPropelChoiceMany(array('model' => 'KataoProductCategory', 'required' => false)),
  68. ));
  69. $this->validatorSchema->setPostValidator(
  70. new sfValidatorPropelUnique(array('model' => 'KataoSupplier', 'column' => array('siret_number')))
  71. );
  72. $this->widgetSchema->setNameFormat('katao_supplier[%s]');
  73. $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
  74. parent::setup();
  75. }
  76. public function getModelName()
  77. {
  78. return 'KataoSupplier';
  79. }
  80. public function updateDefaultsFromObject()
  81. {
  82. parent::updateDefaultsFromObject();
  83. if (isset($this->widgetSchema['katao_supplier_node_list']))
  84. {
  85. $values = array();
  86. foreach ($this->object->getKataoSupplierNodes() as $obj)
  87. {
  88. $values[] = $obj->getKataoNodeId();
  89. }
  90. $this->setDefault('katao_supplier_node_list', $values);
  91. }
  92. if (isset($this->widgetSchema['katao_supplier_product_category_list']))
  93. {
  94. $values = array();
  95. foreach ($this->object->getKataoSupplierProductCategorys() as $obj)
  96. {
  97. $values[] = $obj->getKataoProductCategoryId();
  98. }
  99. $this->setDefault('katao_supplier_product_category_list', $values);
  100. }
  101. }
  102. protected function doSave($con = null)
  103. {
  104. parent::doSave($con);
  105. $this->saveKataoSupplierNodeList($con);
  106. $this->saveKataoSupplierProductCategoryList($con);
  107. }
  108. public function saveKataoSupplierNodeList($con = null)
  109. {
  110. if (!$this->isValid())
  111. {
  112. throw $this->getErrorSchema();
  113. }
  114. if (!isset($this->widgetSchema['katao_supplier_node_list']))
  115. {
  116. // somebody has unset this widget
  117. return;
  118. }
  119. if (is_null($con))
  120. {
  121. $con = $this->getConnection();
  122. }
  123. $c = new Criteria();
  124. $c->add(KataoSupplierNodePeer::KATAO_SUPPLIER_ID, $this->object->getPrimaryKey());
  125. KataoSupplierNodePeer::doDelete($c, $con);
  126. $values = $this->getValue('katao_supplier_node_list');
  127. if (is_array($values))
  128. {
  129. foreach ($values as $value)
  130. {
  131. $obj = new KataoSupplierNode();
  132. $obj->setKataoSupplierId($this->object->getPrimaryKey());
  133. $obj->setKataoNodeId($value);
  134. $obj->save();
  135. }
  136. }
  137. }
  138. public function saveKataoSupplierProductCategoryList($con = null)
  139. {
  140. if (!$this->isValid())
  141. {
  142. throw $this->getErrorSchema();
  143. }
  144. if (!isset($this->widgetSchema['katao_supplier_product_category_list']))
  145. {
  146. // somebody has unset this widget
  147. return;
  148. }
  149. if (is_null($con))
  150. {
  151. $con = $this->getConnection();
  152. }
  153. $c = new Criteria();
  154. $c->add(KataoSupplierProductCategoryPeer::KATAO_SUPPLIER_ID, $this->object->getPrimaryKey());
  155. KataoSupplierProductCategoryPeer::doDelete($c, $con);
  156. $values = $this->getValue('katao_supplier_product_category_list');
  157. if (is_array($values))
  158. {
  159. foreach ($values as $value)
  160. {
  161. $obj = new KataoSupplierProductCategory();
  162. $obj->setKataoSupplierId($this->object->getPrimaryKey());
  163. $obj->setKataoProductCategoryId($value);
  164. $obj->save();
  165. }
  166. }
  167. }
  168. }