Beispiel #1
0
 /**
  * Updates this events money raised value.
  * @return void
  */
 public function updateMoneyRaised()
 {
     $total = 0;
     //get the event and look through all its pages.
     foreach ($this->JustGivingEvent as $jgEvent) {
         $pages = Doctrine_Core::getTable('Page')->findByJustGivingEventId($jgEvent->id);
         //get and save the amount raised for each page.
         foreach ($pages as $page) {
             $resp = JustGivingAPI::retrievePage($page->short_name);
             $moneyRaised = (string) $resp->grandTotalRaisedExcludingGiftAid;
             $page->money_raised = $moneyRaised;
             $page->save();
             if ($moneyRaised > 0) {
                 $total += $moneyRaised;
             }
         }
     }
     //save the events total.
     $this->total_money = $total;
     $this->save();
 }
Beispiel #2
0
 /**
  * A form to create a page on JustGiving that will be tracked by the system.
  *
  * @param sfRequest $request A request object
  */
 public function executeForm(sfWebRequest $request)
 {
     $this->charityName = '';
     $this->charityCodeArray = array();
     //find the Just Giving Event Id.
     $eventCode = $request->getParameter('event_code');
     $this->event = Doctrine_Core::getTable('Event')->findOneByCode($eventCode);
     $firstJGEvent = $this->event->JustGivingEvent[0];
     $firstJGEventId = $firstJGEvent->id;
     $this->eventCode = $request->getParameter('event_code');
     $this->form = new PageCreationForm();
     $this->error = '';
     $this->form->setDefault('just_giving_event_id', $firstJGEventId);
     //$this->form->setDefault('charity_code', '2357');
     if ($request->isMethod(sfWebRequest::POST)) {
         $params = $request->getParameter($this->form->getName());
         $this->form->bind($params);
         if ($this->form->isValid()) {
             $existingShortPage = $params['existing_short_name'];
             if ($existingShortPage != '') {
                 $resp = JustGivingAPI::retrievePage($existingShortPage);
                 $title = (string) $resp->eventName;
                 if ($title != '') {
                     $page = new Page();
                     $page->title = $title;
                     $page->short_name = $existingShortPage;
                     $page->target_amount = (string) $resp->fundraisingTarget;
                     $page->charity_name = (string) $resp->charity->name;
                     $page->charity_code = (string) $resp->charity->registrationNumber;
                     $page->money_raised = (string) $resp->grandTotalRaisedExcludingGiftAid;
                     $page->user = (string) $resp->owner;
                     $page->just_giving_event_id = $firstJGEventId;
                     $page->save();
                     $this->getUser()->setFlash('message', 'The page with the title "' . $page->title . '" was found and added.');
                 } else {
                     $this->getUser()->setFlash('message', 'The page was not found.');
                 }
             } else {
                 $title = $params['title'];
                 $shortName = $params['short_name'];
                 $targetAmount = $params['target_amount'];
                 $charityCode = $params['charity_code'];
                 $charityName = $params['charity_name'];
                 $charitySearch = $params['charity_search'];
                 $jgEventId = $params['just_giving_event_id'];
                 //if searching for a charity, find it first.
                 if ($charitySearch != '' && $charityCode == '') {
                     $charityResp = JustGivingAPI::charitySearch($charitySearch);
                     if ($charityResp->error == '') {
                         $charityName = (string) $charityResp->charitySearchResults->charitySearchResult[0]->name;
                         $charityCode = (string) $charityResp->charitySearchResults->charitySearchResult[0]->charityId;
                         $this->form->setDefault('charity_code', $charityCode);
                         $this->charityName = $charityName;
                         $this->charityCodeArray = array('value' => $charityCode);
                         $this->form->setDefaults(array('charity_name' => $charityName));
                         $this->getUser()->setFlash('message', 'We have found a charity, click submit again to use this, or clear the charity id and try again.');
                         return;
                     } else {
                         $this->getUser()->setFlash('message', (string) $charityResp->error->desc);
                         return;
                     }
                 }
                 $response = JustGivingAPI::createPage('false', $charityCode, 'false', $jgEventId, $title, 'false', $shortName, $title, null, $targetAmount);
                 if (!is_null($response)) {
                     $uri = (string) $response->next->uri;
                     if ($uri != '') {
                         $page = Doctrine_Core::getTable('Page')->create(array('title' => $title, 'short_name' => $shortName, 'target_amount' => $targetAmount, 'charity_code' => $charityCode, 'charity_name' => $charityName, 'just_giving_event_id' => $jgEventId));
                         $page->save();
                         $this->redirect($uri);
                     } else {
                         $errors = '';
                         foreach ($response->error as $error) {
                             $errors .= ", " . (string) $error->desc;
                         }
                         $this->getUser()->setFlash('message', 'Not able to create this JustGiving page' . $errors);
                     }
                 }
             }
         } else {
             $this->getUser()->setFlash('message', "Form is invalid.");
         }
     }
 }