SolVioletteSubscribeForm.class.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. class SolVioletteSubscribeForm extends BaseKataoMemberForm {
  3. public function configure() {
  4. parent::configure();
  5. 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']);
  6. 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']);
  7. $this->widgetSchema->setLabels(array(
  8. 'first_name' => 'Prénom <sup>*</sup>',
  9. 'last_name' => 'Nom <sup>*</sup>',
  10. ));
  11. $katao_member = new KataoMember();
  12. $katao_user = new KataoUser();
  13. $this->validatorSchema['first_name'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre prénom'));
  14. $this->validatorSchema['last_name'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre nom'));
  15. $this->widgetSchema['user_email'] = new sfWidgetFormInput();
  16. $this->validatorSchema['user_email'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre email'));
  17. $this->widgetSchema->setLabel('user_email', 'Email <sup>*</sup>');
  18. $this->widgetSchema['user_phone'] = new sfWidgetFormInput();
  19. $this->validatorSchema['user_phone'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre numéro de téléphone'));
  20. $this->widgetSchema->setLabel('user_phone', 'Téléphone <sup>*</sup>');
  21. $this->widgetSchema['user_fax'] = new sfWidgetFormInput();
  22. $this->validatorSchema['user_fax'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  23. $this->widgetSchema->setLabel('user_fax', 'Fax');
  24. $this->widgetSchema['user_address1'] = new sfWidgetFormInput();
  25. $this->validatorSchema['user_address1'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre adresse'));
  26. $this->widgetSchema->setLabel('user_address1', 'Adresse <sup>*</sup>');
  27. $this->widgetSchema['user_address2'] = new sfWidgetFormInput();
  28. $this->validatorSchema['user_address2'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  29. $this->widgetSchema->setLabel('user_address2', 'Complément');
  30. $this->widgetSchema['user_zip'] = new sfWidgetFormInput();
  31. $this->validatorSchema['user_zip'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  32. $this->widgetSchema->setLabel('user_zip', 'Code postal');
  33. $this->widgetSchema['user_city'] = new sfWidgetFormInput();
  34. $this->validatorSchema['user_city'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre ville'));
  35. $this->widgetSchema->setLabel('user_city', 'Ville <sup>*</sup>');
  36. $this->widgetSchema['user_login'] = new sfWidgetFormInput();
  37. $this->validatorSchema['user_login'] = new sfValidatorString(array('max_length' => 255), array('required' => 'Veuillez entrer votre identifiant'));
  38. $this->widgetSchema->setLabel('user_login', 'Identifiant <sup>*</sup>');
  39. $this->widgetSchema['user_situation'] = new sfWidgetFormSelectRadio(array('choices' => sfConfig::get('app_solviolette_situation')));
  40. $this->validatorSchema['user_situation'] = new sfValidatorString(array('max_length' => 255));
  41. $this->widgetSchema->setLabel('user_situation', 'Situation <sup>*</sup>');
  42. $this->setDefault('user_situation', 'etudiant');
  43. $years = range(date('Y', strtotime('- 100 year')), date('Y'));
  44. $this->widgetSchema['user_birthday'] = new sfWidgetFormI18nDate(array('culture' => 'fr', 'years' => array_combine($years, $years)));
  45. $this->validatorSchema['user_birthday'] = new sfValidatorDate(array('required' => false), array('invalid' => "Veuillez entrer une date valide"));
  46. $this->widgetSchema->setLabel('user_birthday', 'Date de naissance');
  47. $this->widgetSchema['user_adhesion'] = new sfWidgetFormSelectRadio(array('choices' => sfConfig::get('app_solviolette_adhesion')));
  48. $this->validatorSchema['user_adhesion'] = new sfValidatorString(array('max_length' => 255));
  49. $this->widgetSchema->setLabel('user_adhesion', 'Situation');
  50. $this->setDefault('user_adhesion', 'todo');
  51. // $this->widgetSchema['user_solde'] = new sfWidgetFormInputCheckbox();
  52. // $this->validatorSchema['user_solde'] = new sfValidatorBoolean();
  53. // $this->widgetSchema->setLabel('user_solde', 'Je souhaite changer des euros pour un montant de :');
  54. $this->widgetSchema['user_amount'] = new sfWidgetFormInput();
  55. $this->validatorSchema['user_amount'] = new sfValidatorInteger(array('required' => false), array('invalid' => 'Le montant doit etre un nombre entier positf.'));
  56. $this->widgetSchema->setLabel('user_amount', 'Montant');
  57. $this->widgetSchema['user_payment_mode'] = new sfWidgetFormSelect(array('choices' => array('' => '&mdash;&nbsp;aucun&nbsp;&mdash;', KataoMemberDeposit::PAYMENT_MODE_OTHER => 'Carte Bleue', KataoMemberDeposit::PAYMENT_MODE_CHECK => 'Chèque', KataoMemberDeposit::PAYMENT_MODE_CASH => 'Espèces')));
  58. $this->validatorSchema['user_payment_mode'] = new sfValidatorPass();
  59. $this->widgetSchema->setLabel('user_payment_mode', 'Mon moyen de paiement :');
  60. $this->setDefault('user_payment_mode', KataoMemberDeposit::PAYMENT_MODE_OTHER);
  61. $this->widgetSchema['parrain_name'] = new sfWidgetFormInput();
  62. $this->validatorSchema['parrain_name'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  63. $this->widgetSchema->setLabel('parrain_name', 'Nom du parrain');
  64. $this->widgetSchema['card_number_sol'] = new sfWidgetFormInput();
  65. $this->validatorSchema['card_number_sol'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
  66. $this->widgetSchema->setLabel('card_number_sol', 'N° de carte d\'adhérent sol<br /><small>si vous en avez une</small>');
  67. $this->widgetSchema['no_spam'] = new sfWidgetFormInputHidden();
  68. $this->setDefault('no_spam', '');
  69. $this->widgetSchema['user_password'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  70. $this->validatorSchema['user_password'] = new sfValidatorString(array('required' => false));
  71. $this->widgetSchema->setLabel('user_password', 'Mot de passe');
  72. $this->setDefault('user_password', '');
  73. $this->widgetSchema['user_password_confirmation'] = new sfWidgetFormInputPassword(array(), array('autocomplete' => 'off'));
  74. $this->validatorSchema['user_password_confirmation'] = new sfValidatorString(array('required' => false));
  75. $this->widgetSchema->setLabel('user_password_confirmation', 'Confirmation');
  76. $this->setDefault('user_password_confirmation', '');
  77. $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(new sfValidatorSchemaCompare('user_password', sfValidatorSchemaCompare::EQUAL, 'user_password_confirmation', array(), array('invalid' => 'le mot de passe et la confirmation doivent etre les mêmes')),
  78. new wpValidatorSolVioletteSubscribe(),
  79. )));
  80. }
  81. protected function doSave($con = null) {
  82. $katao_member = /*(KataoMember)*/$this->getObject();
  83. $katao_member->setIsMember(false);
  84. $katao_member->setIsAnonymous(true);
  85. $katao_member->setKataoNodeId(sfConfig::get('app_solviolette_adhesion_node'));
  86. $katao_user = new KataoUser();
  87. $katao_user->setStatus(KataoUser::STATUS_PENDING);
  88. $katao_user->setEmail($this->getValue('user_email'));
  89. $katao_user->setPhone($this->getValue('user_phone'));
  90. $katao_user->setFax($this->getValue('user_fax'));
  91. $katao_user->setAddress1($this->getValue('user_address1'));
  92. $katao_user->setAddress2($this->getValue('user_address2'));
  93. $katao_user->setZip($this->getValue('user_zip'));
  94. $katao_user->setCity($this->getValue('user_city'));
  95. $katao_user->setLogin($this->slug($this->getValue('user_login')));
  96. if ($this->getValue('user_password') && $this->getValue('user_password_confirmation') && $this->getValue('user_password') == $this->getValue('user_password_confirmation')) {
  97. $katao_user->setPassword($this->getValue('user_password'));
  98. }
  99. $katao_user->save($con);
  100. // $katao_member->setKataoNodeRelatedByKataoNodeId(sfContext::getInstance()->getUser()->getActiveNode()?sfContext::getInstance()->getUser()->getActiveNode():KataoNodePeer::getDefaultOne());
  101. $katao_member->setIsMember(false);
  102. $return = parent::doSave($con);
  103. $katao_user->setKataoMember($katao_member);
  104. $katao_user->save();
  105. return $return;
  106. }
  107. protected function slug($text, $default = '-') {
  108. $text = preg_replace('~[^\\pL\d]+~u', '-', $text);
  109. $text = trim($text, '-');
  110. if (function_exists('iconv')) {
  111. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  112. }
  113. $text = strtolower($text);
  114. $text = preg_replace('~[^-a-zA-Z0-9]+~', '', $text);
  115. if (empty($text) || ('-' == $text)) {
  116. $text = $default;
  117. }
  118. return $text;
  119. }
  120. }