示例#1
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;
 }