Changeset 1441
- Timestamp:
- Sep 26, 2010, 9:59:08 PM (10 years ago)
- Location:
- cpc/trunk/project
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpc/trunk/project/apps/frontend/config/routing.yml
r1439 r1441 394 394 url: /alerte/delete/:verif 395 395 param: {module: alerte, action: delete} 396 alerte_confirmation: 397 url: /alerte/confirmation/:verif 398 param: {module: alerte, action: confirmation} 396 399 397 400 parlementaire: -
cpc/trunk/project/apps/frontend/modules/alerte/actions/actions.class.php
r1437 r1441 66 66 } 67 67 68 public function executeConfirmation(sfWebRequest $request) 69 { 70 $this->forward404Unless($alerte = Doctrine::getTable('Alerte')->createQuery('a')->where('verif = ?', $request->getParameter('verif'))->fetchOne()); 71 $alerte->confirmed = 1; 72 $alerte->save(); 73 $this->getUser()->setFlash('notice', 'Merci d\'avoir confirmé votre alerte'); 74 return $this->redirect("@homepage"); 75 } 68 76 private function redirectPostSave($alerte = null) { 69 77 if ($citoyen_id = $this->getUser()->getAttribute('user_id')) 70 78 return $this->redirect('alerte/list'); 71 else if ($alerte _id)72 return $this->redirect('alerte/edit? id='.$alerte_id);79 else if ($alerte) 80 return $this->redirect('alerte/edit?verif='.$alerte->verif); 73 81 else 74 82 return $this->redirect('@homepage'); … … 83 91 $form->bind($request->getParameter($form->getName())); 84 92 if ($form->isValid()) { 85 $form->save(); 93 try { 94 if (!$form->save()) { 95 throw new Exception(); 96 } 97 }catch(Exception $e) { 98 $this->getUser()->setFlash('error', 'Désolé nous n\'avons pu créer votre alerte, vous y étiez sans doute déjà abonné'); 99 return $this->redirect('@homepage'); 100 } 86 101 if ($this->submit == 'Créer') { 87 $this->getUser()->setFlash('notice', 'Votre alerte email a été créée'); 102 if ($alerte->confirmed) 103 $this->getUser()->setFlash('notice', 'Votre alerte email a été créée'); 104 else { 105 $this->confirmeAlerte($alerte); 106 $this->getUser()->setFlash('notice', 'Votre alerte email a été créée, merci de confirmer votre abonnement par email'); 107 } 88 108 }else { 89 109 $this->getUser()->setFlash('notice', 'Votre alerte email a été modifiée'); 90 110 } 91 return $this->redirectPostSave($form->getObject() ->id);111 return $this->redirectPostSave($form->getObject()); 92 112 } 93 113 } 94 114 return $form; 95 115 } 116 private function confirmeAlerte($alerte) { 117 $message = $this->getMailer()->compose(array('no-reply@nosdeputes.fr' => 'Regards Citoyens (ne pas répondre)'), 118 $alerte->email, 119 '[NosDeputes.fr] Confirmation d\'Alerte email - '.$alerte->titre); 120 $text = $this->getPartial('mail/sendConfirmationAlerte', array('alerte' => $alerte)); 121 $message->setBody($text, 'text/plain'); 122 try { 123 $this->getMailer()->send($message); 124 }catch(Exception $e) { 125 echo "Oups could not send email ($text)\n"; 126 } 127 } 96 128 } -
cpc/trunk/project/config/doctrine/schema.yml
r1432 r1441 674 674 relations: 675 675 Citoyen: 676 class: Citoyen677 676 foreignAlias: Alertes 677 indexes: 678 index_uniq: 679 fields: [email, citoyen_id, query, filter] 680 type: unique 678 681 -
cpc/trunk/project/lib/model/doctrine/Alerte.class.php
r1438 r1441 14 14 { 15 15 public function getEmail() { 16 if ($ c = $this->Citoyen) {17 return $ c->email;16 if ($this->citoyen_id) { 17 return $this->getCitoyen()->email; 18 18 } 19 19 return $this->_get('email'); … … 31 31 } 32 32 33 public function save(Doctrine_Connection $c = null) {33 public function save(Doctrine_Connection $c = null) { 34 34 if (!$this->last_mail) 35 35 $this->last_mail = date('Y-m-d H:i:s'); 36 36 if (!$this->verif) 37 37 $this->generateVerif(); 38 if ($this->citoyen_id) 39 $this->confirmed = 1; 38 40 return parent::save($c); 39 41 }
Note: See TracChangeset
for help on using the changeset viewer.