KataoMemberProfileForm.class.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. class KataoMemberProfileForm extends BaseKataoMemberForm {
  3. public function configure() {
  4. parent::configure();
  5. unset($this->validatorSchema['katao_assoc_member_group_list'], $this->validatorSchema['katao_node_id'], $this->validatorSchema['accounting_code'], $this->validatorSchema['accounting_code_sol'], $this->validatorSchema['initial_amount_euro'], $this->validatorSchema['initial_amount_sol'], $this->validatorSchema['is_referer'], $this->validatorSchema['is_delegate'], $this->validatorSchema['katao_member_id'], $this->validatorSchema['user_status'], $this->validatorSchema['katao_index'], $this->validatorSchema['created_at'], $this->validatorSchema['updated_at']);
  6. unset($this->widgetSchema['katao_assoc_member_group_list'], $this->widgetSchema['katao_node_id'], $this->widgetSchema['accounting_code'], $this->widgetSchema['accounting_code_sol'], $this->widgetSchema['initial_amount_euro'], $this->widgetSchema['initial_amount_sol'], $this->widgetSchema['is_referer'], $this->widgetSchema['is_delegate'], $this->widgetSchema['katao_member_id'], $this->widgetSchema['user_status'], $this->widgetSchema['katao_index'], $this->widgetSchema['created_at'], $this->widgetSchema['updated_at']);
  7. $this->widgetSchema->setLabels(array(
  8. 'first_name' => 'Prénom',
  9. 'last_name' => 'Nom',
  10. 'is_anonymous' => 'Anonyme ?',
  11. 'card_number_sol' => 'N° carte ' . wpConfig::getAdditionalCurrencyName(),
  12. ));
  13. $this->widgetSchema['is_anonymous'] = new wpWidgetFormInputCheckbox();
  14. $this->widgetSchema['is_anonymous']->setOption('value_attribute_value', 1);
  15. if ((bool)$this->getObject()->getIsAnonymous()) {
  16. $this->widgetSchema['is_anonymous']->setAttribute('checked', 'checked');
  17. }
  18. $katao_member = $this->getObject();
  19. $katao_user = KataoUserPeer::retrieveByKataoMemberId($katao_member->getId());
  20. $this->widgetSchema['user_email'] = new sfWidgetFormInput();
  21. $this->validatorSchema['user_email'] = new sfValidatorString(array('max_length' => 255));
  22. $this->widgetSchema->setLabel('user_email', 'Email');
  23. $this->setDefault('user_email', $katao_user->getEmail());
  24. $this->widgetSchema['user_phone'] = new sfWidgetFormInput();
  25. $this->validatorSchema['user_phone'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  26. $this->widgetSchema->setLabel('user_phone', 'Téléphone');
  27. $this->setDefault('user_phone', $katao_user->getPhone());
  28. $this->widgetSchema['user_fax'] = new sfWidgetFormInput();
  29. $this->validatorSchema['user_fax'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  30. $this->widgetSchema->setLabel('user_fax', 'Fax');
  31. $this->setDefault('user_fax', $katao_user->getFax());
  32. $this->widgetSchema['user_address1'] = new sfWidgetFormInput();
  33. $this->validatorSchema['user_address1'] = new sfValidatorString(array('max_length' => 255));
  34. $this->widgetSchema->setLabel('user_address1', 'Adresse');
  35. $this->setDefault('user_address1', $katao_user->getAddress1());
  36. $this->widgetSchema['user_address2'] = new sfWidgetFormInput();
  37. $this->validatorSchema['user_address2'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  38. $this->widgetSchema->setLabel('user_address2', 'Complément');
  39. $this->setDefault('user_address2', $katao_user->getAddress2());
  40. $this->widgetSchema['user_zip'] = new sfWidgetFormInput();
  41. $this->validatorSchema['user_zip'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  42. $this->widgetSchema->setLabel('user_zip', 'Code postal');
  43. $this->setDefault('user_zip', $katao_user->getZip());
  44. $this->widgetSchema['user_city'] = new sfWidgetFormInput();
  45. $this->validatorSchema['user_city'] = new sfValidatorString(array('max_length' => 255));
  46. $this->widgetSchema->setLabel('user_city', 'Ville');
  47. $this->setDefault('user_city', $katao_user->getCity());
  48. $this->widgetSchema['user_login'] = new sfWidgetFormInput(array(), array('autocomplete' => 'off'));
  49. $this->validatorSchema['user_login'] = new sfValidatorString(array('max_length' => 255));
  50. $this->widgetSchema->setLabel('user_login', 'Login');
  51. $this->setDefault('user_login', $katao_user->getLogin());
  52. $this->widgetSchema['user_password'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  53. $this->validatorSchema['user_password'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  54. $this->widgetSchema->setLabel('user_password', 'Mot de passe');
  55. $this->setDefault('user_password', '');
  56. $this->widgetSchema['user_password_confirmation'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  57. $this->validatorSchema['user_password_confirmation'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  58. $this->widgetSchema->setLabel('user_password_confirmation', 'Confirmation');
  59. $this->setDefault('user_password_confirmation', '');
  60. $this->widgetSchema['update_gmap'] = new wpWidgetFormInputCheckbox();
  61. $this->widgetSchema['update_gmap']->setOption('value_attribute_value', 1);
  62. $this->widgetSchema->setLabel('update_gmap', 'Mettre à jour les coordonnées Google Map automatiquement');
  63. $this->validatorSchema['update_gmap'] = new sfValidatorPass();
  64. $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('user_password', sfValidatorSchemaCompare::EQUAL, 'user_password_confirmation'));
  65. }
  66. protected function doSave($con = null) {
  67. $katao_user = KataoUserPeer::retrieveByKataoMemberId($this->getObject()->getId());
  68. $katao_user->setEmail($this->getValue('user_email'));
  69. $katao_user->setPhone($this->getValue('user_phone'));
  70. $katao_user->setFax($this->getValue('user_fax'));
  71. $katao_user->setAddress1($this->getValue('user_address1'));
  72. $katao_user->setAddress2($this->getValue('user_address2'));
  73. $katao_user->setZip($this->getValue('user_zip'));
  74. $katao_user->setCity($this->getValue('user_city'));
  75. $katao_user->setLogin($this->getValue('user_login'));
  76. if ($this->getValue('user_password') && $this->getValue('user_password_confirmation') && $this->getValue('user_password') == $this->getValue('user_password_confirmation')) {
  77. $katao_user->setPassword($this->getValue('user_password'));
  78. }
  79. if ($this->getValue('update_gmap')) {
  80. $katao_user->initGmapCoordinates(true);
  81. }
  82. $katao_user->save($con);
  83. $katao_member_id = $this->getObject()->getId();
  84. $return = parent::doSave($con);
  85. $katao_user->setKataoMemberId($katao_member_id);
  86. $katao_user->save($con);
  87. return $return;
  88. }
  89. }