XBase\Table::nextRecord PHP Method

nextRecord() public method

public nextRecord ( )
    public function nextRecord()
    {
        if (!$this->isOpen()) {
            $this->open();
        }
        if ($this->record) {
            $this->record->destroy();
            $this->record = null;
        }
        $valid = false;
        do {
            if ($this->recordPos + 1 >= $this->recordCount) {
                return false;
            }
            $this->recordPos++;
            $this->record = new Record($this, $this->recordPos, $this->readBytes($this->recordByteLength));
            if ($this->record->isDeleted()) {
                $this->deleteCount++;
            } else {
                $valid = true;
            }
        } while (!$valid);
        return $this->record;
    }

Usage Example

Example #1
0
 public function run(CollectionAbstract $filter, AbstractBuilder $builder)
 {
     $table = new Table('files/KLADR.DBF', null, 'CP866');
     $lookOnlyAbbr = false;
     $errors = 0;
     /** @var Scheme $row */
     while ($row = $table->nextRecord()) {
         if ($lookOnlyAbbr && $row->socr != $lookOnlyAbbr) {
             continue;
         }
         try {
             $abbr = new Abbreviation($row->socr);
             $code = new Code($row->code);
             $name = new Name($row->name, $abbr);
             if ($filter->isAllowed($name, $code)) {
                 $builder->buildPart($name, $code);
             }
         } catch (UnknownAbbrException $e) {
             $lookOnlyAbbr = $row->socr;
             $errors++;
             echo $row->code . ' ' . $row->socr . ' ' . $row->name . PHP_EOL;
         }
     }
     if ($errors) {
         echo 'Total items: ' . $errors . PHP_EOL;
     }
     echo $builder->getAsJson();
 }