KataoSupplierProfileForm.class.php 5.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. class KataoSupplierProfileForm extends BaseKataoSupplierForm {
  3. public function configure() {
  4. unset($this->validatorSchema['accounting_code'], $this->validatorSchema['accounting_code_sol'], $this->validatorSchema['katao_supplier_node_list'], $this->validatorSchema['is_global'], $this->validatorSchema['referer_id'], $this->validatorSchema['member_id'], $this->validatorSchema['katao_index'], $this->validatorSchema['url_identifier'], $this->validatorSchema['created_at'], $this->validatorSchema['updated_at']);
  5. unset($this->widgetSchema['accounting_code'], $this->widgetSchema['accounting_code_sol'], $this->widgetSchema['katao_supplier_node_list'], $this->widgetSchema['referer_id'], $this->widgetSchema['member_id'], $this->widgetSchema['katao_index'], $this->widgetSchema['url_identifier'], $this->widgetSchema['created_at'], $this->widgetSchema['updated_at']);
  6. $this->widgetSchema['name'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  7. $this->widgetSchema['email'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  8. $this->widgetSchema['address1'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  9. $this->widgetSchema['address2'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  10. $this->widgetSchema['zip'] = new sfWidgetFormInput(array(), array('style' => 'width: 43px'));
  11. $this->widgetSchema['city'] = new sfWidgetFormInput(array(), array('style' => 'width: 200px'));
  12. $this->widgetSchema['phone'] = new sfWidgetFormInput(array(), array('style' => 'width: 85px'));
  13. $this->widgetSchema['fax'] = new sfWidgetFormInput(array(), array('style' => 'width: 85px'));
  14. $this->widgetSchema['website'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  15. $this->widgetSchema['order_min_amount'] = new sfWidgetFormInput(array(), array('style' => 'width: 50px; text-align: right'));
  16. $this->widgetSchema['presentation'] = new wpWidgetFormRichText();
  17. $this->widgetSchema->setLabels(array(
  18. 'name' => 'Nom',
  19. 'email' => 'Email',
  20. 'phone' => 'Téléphone',
  21. 'fax' => 'Fax',
  22. 'website' => 'Site internet',
  23. 'address1' => 'Adresse',
  24. 'address2' => 'Complément',
  25. 'zip' => 'Code postal',
  26. 'city' => 'Ville',
  27. 'siret_number' => 'N° SIRET',
  28. 'order_min_amount' => 'Montant min. commande',
  29. ));
  30. $katao_supplier = $this->getObject();
  31. $katao_user = KataoUserPeer::retrieveByKataoSupplierId($katao_supplier->getId());
  32. $this->widgetSchema['user_login'] = new sfWidgetFormInput(array(), array('autocomplete' => 'off'));
  33. $this->validatorSchema['user_login'] = new sfValidatorString(array('max_length' => 255));
  34. $this->widgetSchema->setLabel('user_login', 'Login');
  35. $this->setDefault('user_login', $katao_user->getLogin());
  36. $this->widgetSchema['user_password'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  37. $this->validatorSchema['user_password'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  38. $this->widgetSchema->setLabel('user_password', 'Mot de passe');
  39. $this->setDefault('user_password', '');
  40. $this->widgetSchema['user_password_confirmation'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  41. $this->validatorSchema['user_password_confirmation'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  42. $this->widgetSchema->setLabel('user_password_confirmation', 'Confirmation');
  43. $this->setDefault('user_password_confirmation', '');
  44. $this->widgetSchema['update_gmap'] = new wpWidgetFormInputCheckbox();
  45. $this->widgetSchema['update_gmap']->setOption('value_attribute_value', 1);
  46. $this->widgetSchema->setLabel('update_gmap', 'Mettre à jour les coordonnées Google Map automatiquement');
  47. $this->validatorSchema['update_gmap'] = new sfValidatorPass();
  48. $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('user_password', sfValidatorSchemaCompare::EQUAL, 'user_password_confirmation'));
  49. }
  50. protected function doSave($con = null) {
  51. $katao_user = KataoUserPeer::retrieveByKataoSupplierId($this->getObject()->getId());
  52. $katao_user->setLogin($this->getValue('user_login'));
  53. if ($this->getValue('user_password') && $this->getValue('user_password_confirmation') && $this->getValue('user_password') == $this->getValue('user_password_confirmation')) {
  54. $katao_user->setPassword($this->getValue('user_password'));
  55. }
  56. $katao_user->save($con);
  57. $katao_supplier_id = $this->getObject()->getId();
  58. $return = parent::doSave();
  59. if ($this->getValue('update_gmap')) {
  60. $katao_supplier =/*(KataoSupplier)*/ $this->getObject();
  61. $katao_supplier->initGmapCoordinates(true);
  62. $katao_supplier->save($con);
  63. }
  64. $katao_user->setKataoSupplierId($katao_supplier_id);
  65. $katao_user->save($con);
  66. return $return;
  67. }
  68. }