KataoSubscribeForm.class.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. class KataoSubscribeForm extends BaseKataoMemberForm {
  3. public function configure() {
  4. unset($this->validatorSchema['is_anonymous'], $this->validatorSchema['katao_node_id'], $this->validatorSchema['accounting_code'], $this->validatorSchema['accounting_code_sol'], $this->validatorSchema['initial_amount'], $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'],$this->validatorSchema['user_birthday'],$this->validatorSchema['user_situation'],$this->validatorSchema['parrain_name']);
  5. unset($this->widgetSchema['is_anonymous'], $this->widgetSchema['katao_node_id'], $this->widgetSchema['accounting_code'], $this->widgetSchema['accounting_code_sol'], $this->widgetSchema['initial_amount'], $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'], $this->widgetSchema['user_birthday'], $this->widgetSchema['user_situation'], $this->widgetSchema['parrain_name']);
  6. $this->widgetSchema->setLabels(array(
  7. 'first_name' => 'Prénom',
  8. 'last_name' => 'Nom',
  9. ));
  10. $katao_member = new KataoMember();
  11. $katao_user = new KataoUser();
  12. $this->widgetSchema['user_email'] = new sfWidgetFormInput();
  13. $this->validatorSchema['user_email'] = new sfValidatorString(array('max_length' => 255));
  14. $this->widgetSchema->setLabel('user_email', 'Email');
  15. $this->widgetSchema['user_phone'] = new sfWidgetFormInput();
  16. $this->validatorSchema['user_phone'] = new sfValidatorString(array('max_length' => 255));
  17. $this->widgetSchema->setLabel('user_phone', 'Téléphone');
  18. $this->widgetSchema['user_fax'] = new sfWidgetFormInput();
  19. $this->validatorSchema['user_fax'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  20. $this->widgetSchema->setLabel('user_fax', 'Fax');
  21. $this->widgetSchema['user_address1'] = new sfWidgetFormInput();
  22. $this->validatorSchema['user_address1'] = new sfValidatorString(array('max_length' => 255));
  23. $this->widgetSchema->setLabel('user_address1', 'Adresse');
  24. $this->widgetSchema['user_address2'] = new sfWidgetFormInput();
  25. $this->validatorSchema['user_address2'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  26. $this->widgetSchema->setLabel('user_address2', 'Complément');
  27. $this->widgetSchema['user_zip'] = new sfWidgetFormInput();
  28. $this->validatorSchema['user_zip'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  29. $this->widgetSchema->setLabel('user_zip', 'Code postal');
  30. $this->widgetSchema['user_city'] = new sfWidgetFormInput();
  31. $this->validatorSchema['user_city'] = new sfValidatorString(array('max_length' => 255));
  32. $this->widgetSchema->setLabel('user_city', 'Ville');
  33. $this->widgetSchema['user_login'] = new sfWidgetFormInput();
  34. $this->validatorSchema['user_login'] = new sfValidatorString(array('max_length' => 255));
  35. $this->widgetSchema->setLabel('user_login', 'Login');
  36. $this->widgetSchema['user_password'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  37. $this->validatorSchema['user_password'] = new sfValidatorString(array('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('required' => false));
  42. $this->widgetSchema->setLabel('user_password_confirmation', 'Confirmation');
  43. $this->setDefault('user_password_confirmation', '');
  44. $this->widgetSchema['no_spam'] = new sfWidgetFormInputHidden();
  45. $this->setDefault('no_spam', '');
  46. $this->validatorSchema->setPostValidator(new sfValidatorSchemaCompare('user_password', sfValidatorSchemaCompare::EQUAL, 'user_password_confirmation'));
  47. }
  48. protected function doSave($con = null) {
  49. $katao_user = new KataoUser();
  50. $katao_user->setStatus(KataoUser::STATUS_PENDING);
  51. $katao_user->setEmail($this->getValue('user_email'));
  52. $katao_user->setPhone($this->getValue('user_phone'));
  53. $katao_user->setFax($this->getValue('user_fax'));
  54. $katao_user->setAddress1($this->getValue('user_address1'));
  55. $katao_user->setAddress2($this->getValue('user_address2'));
  56. $katao_user->setZip($this->getValue('user_zip'));
  57. $katao_user->setCity($this->getValue('user_city'));
  58. $katao_user->setLogin($this->getValue('user_login'));
  59. if ($this->getValue('user_password') && $this->getValue('user_password_confirmation') && $this->getValue('user_password') == $this->getValue('user_password_confirmation')) {
  60. $katao_user->setPassword($this->getValue('user_password'));
  61. }
  62. $katao_user->save($con);
  63. $this->getObject()->setKataoNodeRelatedByKataoNodeId(sfContext::getInstance()->getUser()->getActiveNode()?sfContext::getInstance()->getUser()->getActiveNode():KataoNodePeer::getDefaultOne());
  64. $this->getObject()->setIsMember(false);
  65. $return = parent::doSave($con);
  66. $katao_user->setKataoMember($this->getObject());
  67. $katao_user->save();
  68. return $return;
  69. }
  70. }