/**
  * This method is called ONLY after ALL validation has
  * passed.  This is the method that allows you to 
  * do something with the data, say insert/update records
  * in the DB.
  */
 function form_action()
 {
     $success = true;
     $result = new SwimResult();
     $result->PurgeResults();
     $this->set_action_message(html_div(sprintf('ft-%s-msg', $result->getAffectedRows() == 0 ? 'warning' : 'note'), sprintf('%d record%s purged from Results database.', $result->getAffectedRows(), $result->getAffectedRows() == 1 ? '' : 's')));
     unset($result);
     return $success;
 }
示例#2
0
 /**
  * Process D0 SDIF records from the Queue
  *
  * @return int number of records processed
  */
 function ProcessQueueD0Records()
 {
     //  Processing D0 records is trickier than B1 or C1
     //  records because each D0 record is associated with
     //  a C1 record prior to it and D0 and C1 records are
     //  associated with the B1 record.
     $this->setQuery(sprintf('SELECT sdifrecord FROM %s WHERE recordtype="B1"', FT_SDIFQUEUE_TABLE));
     $this->runSelectQuery(true);
     $rslt = $this->getQueryResult();
     $rsltscnt = $this->getQueryCount();
     $b1_record = new SwimMeet();
     $b1_record->setSDIFRecord($rslt["sdifrecord"]);
     $b1_record->ParseRecord();
     $swimmeetid = $b1_record->GetSwimMeetIdByName();
     //  Need D0 record to add or update the swim meet BUT
     //  need to select the C1 records as well to ensure that
     //  D0 records are associated with the proper team.
     $this->setQuery(sprintf('SELECT recordtype, sdifrecord, linenumber
         FROM %s WHERE recordtype="D0" OR recordtype="C1" ORDER BY
         linenumber', FT_SDIFQUEUE_TABLE));
     $this->runSelectQuery(true);
     $swimmer = new Swimmer();
     $c1_record = new SwimTeam();
     $d0_record = new SwimResult();
     $rslts = $this->getQueryResults();
     $rsltscnt = $this->getQueryCount();
     //  Process each C1 and D0 record in the file.
     foreach ($rslts as $rslt) {
         //  Look for C1 records to set swim team
         if ($rslt['recordtype'] == 'C1') {
             $c1_record->setSDIFRecord($rslt["sdifrecord"]);
             $c1_record->ParseRecord();
             $swimteamid = $c1_record->GetSwimTeamIdByName();
             //  Need to select swim team id based on C1 record
         } else {
             $d0_record->setSDIFRecord($rslt["sdifrecord"]);
             $d0_record->ParseRecord();
             $d0_record->setSwimMeetId($swimmeetid['swimmeetid']);
             $d0_record->setSwimTeamId($swimteamid['swimteamid']);
             //  Does the swimmer exist?  If not, the swimmer
             //  record needs to be created.  The USS ID can be
             //  used to determine uniqueness BUT there is a chance
             //  that more than one swimmer id could be returned.
             $swimmer->setUSSNew($d0_record->getUSSNew());
             $swimmer->setSwimTeamId($d0_record->getSwimTeamId());
             if ($swimmer->SwimmerExistsByUSSNewAndSwimTeamId()) {
                 $swimmerid = $swimmer->GetSwimmerIdByUSSNewAndSwimTeamId();
             } else {
                 //print '<h1>' . basename(__FILE__) . '::' . __LINE__ . '</h1>' ;
                 $swimmer->setSwimTeamId($d0_record->getSwimTeamId());
                 $swimmer->setBirthDate($d0_record->getBirthDate(true), true);
                 $name = $d0_record->getSwimmerName();
                 list($last, $first, $middle) = explode(',', $name . ',,', 3);
                 if ($first == ',') {
                     $first = '';
                 }
                 if ($middle == ',') {
                     $middle = '';
                 }
                 $swimmer->setSwimmerLastName($last);
                 $swimmer->setSwimmerFirstName($first);
                 $swimmer->setSwimmerMiddleName($middle);
                 $swimmer->setUSS($d0_record->getUSS());
                 $swimmer->setUSSNew($d0_record->getUSSNew());
                 $swimmer->setGender($d0_record->getGender());
                 $swimmer->AddSwimmer();
                 $swimmerid = $swimmer->getSwimmerId();
                 if ($swimmerid == null) {
                     $this->add_status_message(sprintf('Unable to add swimmer "%s" from line %d to the database, result record skipped.', $d0_record->getSwimmerName(), $rslt['linenumber']), FT_WARNING);
                 }
             }
             //  The Swimmer Id may be in an array so need to extract it if it is.
             if (is_array($swimmerid)) {
                 $swimmerid = $swimmerid['swimmerid'];
             }
             //  Try and add the result
             if ($swimmerid != null) {
                 $d0_record->setSwimmerId($swimmerid);
                 if (!$d0_record->ResultExistsByMeetTeamAndSwimmer()) {
                     $d0_record->AddResult();
                 } else {
                     $this->add_status_message(sprintf('Result for "%s" from line %d is already stored in the database, ignored.', $d0_record->getSwimmerName(), $rslt['linenumber']), FT_WARNING);
                 }
             }
         }
     }
     //return $this->getAffectedRows() ;
     return $rsltscnt;
 }
示例#3
0
 /**
  * Construct a summary of the active season.
  *
  */
 function BuildInfoTable($eventid = null)
 {
     //  Alternate the row colors
     $this->set_alt_color_flag(true);
     $result = new SwimResult();
     if (is_null($eventid)) {
         $eventid = $this->getEventId();
     }
     if (!is_null($eventid) || $event->EventExistsById($eventid)) {
         $event = explode($eventid, '-');
         $result->setEventCode($event[0]);
         $result->setAgeGroupCode($event[1]);
         $result->setEventCode($event[2]);
         //$event->LoadEventById($eventid) ;
         $this->add_row("Event details available.");
         //$this->add_row(html_b("Organization"), SDIFCodeTables::GetOrgCode($event->getOrgCode())) ;
         //$this->add_row(html_b("Event Code"), $event->getEventCode()) ;
         //$this->add_row(html_b("Event Name"), $event->getEventName()) ;
         //$this->add_row(html_b("Event Name Abbreviation"), $event->getEventNameAbrv()) ;
         //$this->add_row(html_b("Event Addresss 1"), $event->getEventAddress1()) ;
         //$this->add_row(html_b("Event Addresss 2"), $event->getEventAddress2()) ;
         //$this->add_row(html_b("City"), $event->getEventCity()) ;
         //$this->add_row(html_b("State"), $event->getEventState()) ;
         //$this->add_row(html_b("Postal Code"), $event->getEventPostalCode()) ;
         //$this->add_row(html_b("Country"), SDIFCodeTables::GetCountryCode($event->getEventCountryCode())) ;
         //$this->add_row(html_b("Region"), SDIFCodeTables::GetRegionCode($event->getRegionCode())) ;
         //$this->add_row(html_b("Event Code 5th Character"), $event->getEventCode5()) ;
     } else {
         $this->add_row("No event details available.");
     }
 }