Exemplo n.º 1
0
 /**
  * Donations 
  */
 public function executeDons(sfWebRequest $r)
 {
     $this->dons = array(5, 10, 15, 20, 30, 50);
     // TODO : needs a little more control if the payment has really passed.
     if ($r->hasParameter("hash")) {
         $sesDons = $this->getUser()->getAttribute("donations");
         foreach ($sesDons as $id => $don) {
             if ($r->getUrlParameter("hash") == $don['hash']) {
                 // Save donation
                 $d = new Donations();
                 $d->setAmount($sesDons[$id]['amount']);
                 $d->setDonor($this->getUser()->getAttribute("id"));
                 $d->save();
                 // Shout
                 /*sfProjectConfiguration::getActive()->loadHelpers('Number');
                   $sh = Doctrine::getTable("Shoutbox")->ecrireShout(array(
                     "img" => "money_add",
                     "msg" => $this->getContext()->getI18N()->__("has just made a donation of %amount% !", 
                             array("%amount%" => format_currency($don['amount'], 'EUR'))),
                     "url" => $this->getContext()->getController()->genUrl('membres/dons'),
                     "titre" => $this->getContext()->getI18N()->__("Go to donations page !"),
                   ));*/
                 // On confirme
                 $this->getUser()->setFlash("notice", $this->getContext()->getI18N()->__("Thanks for your donation !"));
                 // On redirige
                 $this->redirect("@homepage");
             }
         }
     } else {
         // Generating hash for each donation
         foreach ($this->dons as $id => $don) {
             $amount = $don;
             $hash = md5(sfConfig::get("sf_csrf_secret") . $don);
             $this->dons[$id] = array("hash" => $hash, "amount" => $amount);
         }
         $this->getUser()->setAttribute("donations", $this->dons);
     }
     $this->donations = Doctrine::getTable("Donations")->getAmount();
     $this->donationsPercentage = $this->donations / sfConfig::get('app_dons_objectif') * 100;
     if ($this->donationsPercentage > 100) {
         $this->donationsPercentage = 100;
     }
     $this->bestDonors = Doctrine::getTable("Donations")->getBestDonors(10);
     $this->lastDonations = Doctrine::getTable("Donations")->getLastDonations(10);
     $this->r = $r;
     return $this->renderText(json_encode(array("right" => array("donations" => $this->getTab("Donations", "money_add.png", $this->getPartial($this->getModuleName() . '/donate_choices')), "goal" => $this->getTab("Objective", "credit.png", $this->getPartial($this->getModuleName() . '/donate_goal'))))));
 }