KataoSupplierForm.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * KataoSupplier form.
  4. *
  5. * @package katao
  6. * @subpackage form
  7. * @author Your name here
  8. * @version SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
  9. */
  10. class KataoSupplierForm extends BaseKataoSupplierForm {
  11. public function configure() {
  12. unset($this->validatorSchema['gmap_lng'], $this->validatorSchema['gmap_lat'], $this->validatorSchema['accounting_code'], $this->validatorSchema['accounting_code_sol'], $this->validatorSchema['katao_index'], $this->validatorSchema['presentation'], $this->validatorSchema['url_identifier'], $this->validatorSchema['created_at'], $this->validatorSchema['updated_at']);
  13. unset($this->widgetSchema['gmap_lng'], $this->widgetSchema['gmap_lat'], $this->widgetSchema['accounting_code'], $this->widgetSchema['accounting_code_sol'], $this->widgetSchema['katao_index'], $this->widgetSchema['presentation'], $this->widgetSchema['url_identifier'], $this->widgetSchema['created_at'], $this->widgetSchema['updated_at']);
  14. $sf_user = sfContext::getInstance()->getUser();
  15. $members = array('' => '&mdash;&nbsp;aucun&nbsp;&mdash;');
  16. foreach (KataoMemberPeer::getAllGroupedByNode() as $member_id => $member_name) {
  17. $members[$member_id] = $member_name;
  18. }
  19. $referers = array('' => '&mdash;&nbsp;aucun&nbsp;&mdash;');
  20. foreach (KataoMemberPeer::getAllReferers() as $referer_id => $referer_name) {
  21. $referers[$referer_id] = $referer_name;
  22. }
  23. $this->widgetSchema['member_id'] = new sfWidgetFormSelect(array('choices' => $members));
  24. $this->widgetSchema['referer_id'] = new sfWidgetFormSelect(array('choices' => $referers));
  25. $this->widgetSchema['is_global'] = new sfWidgetFormSelect(array('choices' => array(0 => 'Local', 1 => 'National')), array('onchange' => 'if("0" == $("katao_supplier_is_global").value) { $("katao_supplier_node_list_row").show(); } else { $("katao_supplier_node_list_row").hide(); }'));
  26. $this->widgetSchema['katao_supplier_node_list'] = new sfWidgetFormPropelSelectMany(array('model' => 'KataoNode'));
  27. $this->widgetSchema['katao_supplier_product_category_list'] = new sfWidgetFormPropelSelectMany(array('model' => 'KataoProductCategory', 'order_by' => array('SortOrder', 'ASC')));
  28. $this->widgetSchema['siret_number'] = new sfWidgetFormInput(array(), array('maxlength' => 14, 'onchange' => $sf_user->isJustDelegate()?'checkSiretNumberAvailability();':''));
  29. $this->widgetSchema['name'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  30. $this->widgetSchema['email'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  31. $this->widgetSchema['address1'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  32. $this->widgetSchema['address2'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  33. $this->widgetSchema['zip'] = new sfWidgetFormInput(array(), array('style' => 'width: 43px'));
  34. $this->widgetSchema['city'] = new sfWidgetFormInput(array(), array('style' => 'width: 200px'));
  35. $this->widgetSchema['phone'] = new sfWidgetFormInput(array(), array('style' => 'width: 85px'));
  36. $this->widgetSchema['fax'] = new sfWidgetFormInput(array(), array('style' => 'width: 85px'));
  37. $this->widgetSchema['website'] = new sfWidgetFormInput(array(), array('style' => 'width: 250px'));
  38. $this->widgetSchema['order_min_amount'] = new sfWidgetFormInput(array(), array('style' => 'width: 50px; text-align: right'));
  39. $this->widgetSchema->setLabels(array(
  40. 'member_id' => 'Compte adhérent lié',
  41. 'referer_id' => 'Référent',
  42. 'name' => 'Nom',
  43. 'email' => 'Email',
  44. 'address1' => 'Adresse',
  45. 'address2' => 'Complément',
  46. 'zip' => 'Code postal',
  47. 'city' => 'Ville',
  48. 'phone' => 'Téléphone',
  49. 'fax' => 'Fax',
  50. 'website' => 'Site internet',
  51. 'siret_number' => 'N° SIRET',
  52. 'is_global' => 'Type',
  53. 'order_min_amount' => 'Montant min. commande',
  54. 'katao_supplier_node_list' => 'Noeuds autorisés',
  55. 'katao_supplier_product_category_list' => 'Rayons proposés',
  56. ));
  57. $katao_supplier = $this->getObject();
  58. $katao_user = null;
  59. if (!$katao_supplier->isNew()) {
  60. $katao_user = KataoUserPeer::retrieveByKataoSupplierId($katao_supplier->getId());
  61. }
  62. if (is_null($katao_user)) {
  63. $katao_user = new KataoUser();
  64. }
  65. $this->widgetSchema['user_status'] = new sfWidgetFormSelect(array('choices' => KataoUserPeer::getAllStatuses(true)));
  66. $this->validatorSchema['user_status'] = new sfValidatorInteger();
  67. $this->widgetSchema->setLabel('user_status', 'Etat');
  68. $this->setDefault('user_status', $katao_user->getStatus());
  69. $this->widgetSchema['user_login'] = new sfWidgetFormInput();
  70. $this->validatorSchema['user_login'] = new sfValidatorString(array('max_length' => 255));
  71. $this->widgetSchema->setLabel('user_login', 'Login');
  72. $this->setDefault('user_login', $katao_user->getLogin());
  73. $this->widgetSchema['user_password'] = new sfWidgetFormInput();
  74. $this->validatorSchema['user_password'] = new sfValidatorString(array('max_length' => 255));
  75. $this->widgetSchema->setLabel('user_password', 'Mot de passe');
  76. $this->setDefault('user_password', $katao_user->getPassword());
  77. $this->widgetSchema['update_gmap'] = new wpWidgetFormInputCheckbox();
  78. $this->widgetSchema['update_gmap']->setOption('value_attribute_value', 1);
  79. $this->widgetSchema->setLabel('update_gmap', 'Mettre à jour les coordonnées Google Map automatiquement');
  80. $this->validatorSchema['update_gmap'] = new sfValidatorPass();
  81. if ($sf_user->isJustDelegate()) {
  82. $this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback' => array($this, 'checkSiretNumber')), array('invalid' => 'Un fournisseur national existe déjà avec ce n° SIRET.')));
  83. }
  84. }
  85. public function checkSiretNumber($validator, $value) {
  86. $sf_request = sfContext::getInstance()->getRequest();
  87. $id = $sf_request->getParameter('katao_supplier[id]');
  88. $siret_number = $sf_request->getParameter('katao_supplier[siret_number]');
  89. if (null != $katao_supplier = KataoSupplierPeer::retrieveBySiretNumber($siret_number, $id)) {
  90. if ($katao_supplier->getIsGlobal()) {
  91. throw new sfValidatorError($validator, 'invalid');
  92. }
  93. }
  94. return $value;
  95. }
  96. protected function doSave($con = null) {
  97. $katao_user =/*(KataoUser)*/ $this->getObject()->isNew()?new KataoUser():KataoUserPeer::retrieveByKataoSupplierId($this->getObject()->getId());
  98. $katao_user->setStatus($this->getValue('user_status'));
  99. $katao_user->setLogin($this->getValue('user_login'));
  100. $katao_user->setPassword($this->getValue('user_password'));
  101. $katao_user->save($con);
  102. $return = parent::doSave($con);
  103. if ($this->getValue('update_gmap')) {
  104. $katao_supplier =/*(KataoSupplier)*/ $this->getObject();
  105. $katao_supplier->initGmapCoordinates(true);
  106. $katao_supplier->save($con);
  107. }
  108. $katao_user->setKataoSupplier($this->getObject());
  109. $katao_user->save();
  110. return $return;
  111. }
  112. }