Page 1 of 1

OO PHP assigning values

Posted: Fri Oct 02, 2009 12:34 pm
by dgkindy
Having a go at OO PHP making progress until I got stumped on this little problem.

I run this bit of code to print out the object:

Code: Select all

           print_r($material[$part_cnt++]); echo "<br />";
 
and this is what I got.

Material Object ( [project] => 33176434 [skid] => [skid_descr] => [part] => [part_Descr] => [status] => [ddate] => [rdate] => [qty] => [pr] => [po] => [line] => [plant] => [error] => [prod] => )

I managed to create the object and assign the project to it but when I did the same for other parts of the object, it did not seem to save them??

What have I missed?

Code: Select all

       $material[$part_cnt] = new Material;
        $material[$part_cnt]->project = $project;

Code: Select all

           $material[$part_cnt]->skid = (explode(" ",substr($sLBL,($pos - strlen($sLBL)))));
            $material[$part_cnt]->skid_descr = substr($sLBL,($pos - strlen($sLBL)),40);
 

Code: Select all

class Material  {
        Public $project;
        Public $skid;
        Public $skid_descr;
        Public $part;
        Public $part_descr;
        Public $status;
        Public $ddate;
        Public $rdate;
        Public $qty;
        Public $pr;
        Public $po;
        Public $line;
        Public $plant;
        Public $error;
        Public $prod;
        }

Re: OO PHP assigning values

Posted: Fri Oct 02, 2009 12:42 pm
by requinix
Posting small snippets of code rarely ever helps. Need MORE.

Code: Select all

$material[$part_cnt] = new Material;
$material[$part_cnt]->project = $project;

Code: Select all

$material[$part_cnt]->skid = (explode(" ",substr($sLBL,($pos - strlen($sLBL)))));
$material[$part_cnt]->skid_descr = substr($sLBL,($pos - strlen($sLBL)),40);
What's the code with these parts? Particularly interested in what's between them.

Re: OO PHP assigning values

Posted: Fri Oct 02, 2009 1:58 pm
by dgkindy
Here is the whole thing

Code: Select all

<?php
 
//$file = @fopen("Hamma.txt", "r") or exit("Unable to open file!");
//$file = @fopen("text2.txt", "r") or exit("Unable to open file!");
$file = @fopen("Text.txt", "r") or exit("Unable to open file!");
 
 
if ($file) {
    $sLBL=fgets($file);
    //Isolates project number
    $pos=0;
    $project=(explode(" ",$sLBL));
    while (substr($project[1],$pos,1) == 0) {
        $pos++;
    }
    if ($pos !== false) {
        $project=substr($project[1], ($pos - strlen($project[1])));
    } 
    //Skips through blank lines in file
    For ($count=0; $count <=6; ++$count) {
        $sLBL=fgets($file);
    }
    //Loops through the material status lines until end of file
    $part_cnt = 0;
    while (!feof($file)) {
        $pos=0;
        $material[$part_cnt] = new Material;
        $material[$part_cnt]->project = $project;
        while (substr($sLBL,$pos,1) == '|') {
            $pos++;
        }
        $level = $pos;
        If (substr($sLBL,$pos,4) == '----') {
            echo $level." Package part <br />";
        }
        elseIf (substr($sLBL,$pos,2) == '--' && $level==1) {
            $pos=$pos+2;
            $material[$part_cnt]->skid = (explode(" ",substr($sLBL,($pos - strlen($sLBL)))));
            $skid_number = (explode(" ",substr($sLBL,($pos - strlen($sLBL)))));
            $pos = $pos + strlen($skid_number[0]);
            while (substr($sLBL,$pos,1) == ' ') {
                $pos++;
            }
            $material[$part_cnt]->factory = substr($sLBL,($pos - strlen($sLBL)),4);
            $factory = substr($sLBL,($pos - strlen($sLBL)),4);
            $pos=$pos+7;
            $material[$part_cnt]->skid_descr = substr($sLBL,($pos - strlen($sLBL)),40);
            $skid_description = substr($sLBL,($pos - strlen($sLBL)),40);
            echo $level."*Skid*".$skid_number[0]."-".$skid_description." % ".$factory."<br />";
        }
        elseIf (substr($sLBL,$pos,2) == '--') {
            $pos=$pos+2;
            $part_number = (explode(" ",substr($sLBL,($pos - strlen($sLBL)))));
            $pos = $pos + strlen($part_number[0]);
            while (substr($sLBL,$pos,1) == ' ') {
                $pos++;
            }
            $factory = substr($sLBL,($pos - strlen($sLBL)),4);
            $pos=$pos+7;
            $description = substr($sLBL,($pos - strlen($sLBL)),40);
            echo $level."*Part*".$part_number[0]." @ ".$description." % ".$factory." ! <br />";
        }
        elseIf (substr($sLBL,$pos,6) == '      ') {
            echo $level."part count".$part_cnt." LF<br />";
            print_r($material[$part_cnt++]); echo "<br />";
        }
        elseIf (!$level) {
            echo $level."*Start New Skid*<br />";
        }
        else{   
            $sfragment = explode(" ",ltrim(substr($sLBL,($pos - strlen($sLBL)))));
            echo "*".$sfragment[1]."*<br />";
        //    if(rank($sfragment[1])<rank($rank)) {
          //      $rank=$sfragment[1];
           // }
            switch (rank($sfragment[1])) {
                case 1:  //Plan.order
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    break;
                case 2:  //PurRequist
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    list($po, $line) = purchase_order($sfragment[2]);
                    echo " Purchase Order: ".$po." Line: ".$line." <br />";    
                    break;
                case 3:  //Sim.reqmts
                    //No action to take
                    break;
                case 4:  //POSched.ln
                    echo "Error Code: ".error_code($sLBL)." <br />";    
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    list($po, $line) = purchase_order($sfragment[2]);
                    echo " Purchase Order: ".$po." Line: ".$line." <br />";    
                    break;
                case 5:  //Ship.note
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    list($po, $line) = purchase_order($sfragment[2]);
                    echo " Purchase Order: ".$po." Line: ".$line." <br />";    
                    break;
                case 6:  //Sched.agr.
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    list($po, $line) = purchase_order($sfragment[2]);
                    echo " Purchase Order: ".$po." Line: ".$line." <br />";    
                    break;
                case 7:  //QM InspLot
                    //No action to take
                    break;
                case 8:  //Prod.order
                    error_code($sLBL);
                    echo "Production Order: ".production_order($sfragment[2])." <br />";    
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    break;
                case 9:  //Plant Stck
                    break;
                case 10:  //Depend.req
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    list($d1,$d2,$d3) = expected_date($sfragment[0]);
                    echo "Expected Date :".$d1."-".$d2."-".$d3." <br />";
                    break;
                case 11:  //Order.res.
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    //quantity($sLBL);
                    list($rd1, $rd2, $rd3) = required_date($sfragment[0]);
                    echo "Required Date :".$rd1."-".$rd2."-".$rd3." <br />";
                    break;
                case 12:  //SubctctReq
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    list($rd1, $rd2, $rd3) = required_date($sfragment[0]);
                    echo "Required Date :".$rd1."-".$rd2."-".$rd3." <br />";
                    break;
                case 13:  //SalesOrder
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    list($rd1, $rd2, $rd3) = required_date($sfragment[0]);
                    echo "Required Date :".$rd1."-".$rd2."-".$rd3." <br />";
                    break;
                case 14:  //ReleaseOrd
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    list($rd1, $rd2, $rd3) = required_date($sfragment[0]);
                    echo "Required Date :".$rd1."-".$rd2."-".$rd3." <br />";
                    echo " Purchase Order: ".$po." Line: ".$line." <br />";    
                    purchase_order($sfragment[2]);
                    break;
                case 15:  //PldOrdRelO
                    echo "Production Order: ".production_order($sfragment[0])." <br />";    
                    echo "Required Quantity: ".quantity($sLBL)." <br />";    
                    list($rd1, $rd2, $rd3) = required_date($sfragment[0]);
                    echo "Required Date :".$rd1."-".$rd2."-".$rd3." <br />";
                    break;
                case 16:  //ProjectOrd
                    //confirm variable
                    break;
                case 17:  //Free deliv
                    //confirm variable
                    break;
                default:
                    echo "No action for ".$sfragment[1]."<br />";
            } 
        }
    $sLBL=fgets($file);
    }
    fclose($file);
}
 
class Material  {
        Public $project;
        Public $skid;
        Public $skid_descr;
        Public $part;
        Public $part_descr;
        Public $status;
        Public $ddate;
        Public $rdate;
        Public $qty;
        Public $pr;
        Public $po;
        Public $line;
        Public $plant;
        Public $error;
        Public $prod;
        }
 
Function production_order($string) {
        $prod_order = explode("/",$string);   
        return $prod_order[0];
    }
 
Function error_code($string) {
        return $errord = trim(substr($string,-68,10));   
    }
 
Function quantity($string) {
        $qty = explode("-",trim(substr($string,-50,10)));   
        return $qty[0];
    }
 
Function purchase_request($string) {
        return explode("/",$string);   
    }
 
Function purchase_order($string) {
        return explode("/",$string);   
    }
    
Function expected_date($date) {
        return explode("-",$date);
    }
 
Function required_date($date) {
        return explode("-",$date);
    }
 
Function rank($status) {
    switch ($status) {
        case "Plan.order":
          $rank=1;
          break;
        case "PurRequist":
          $rank=2;
          break;
        case "Sim.reqmts":
          $rank=3;
          break;
        case "POSched.ln":
          $rank=4;
          break;
        case "Ship.note":
          $rank=5;
          break;
        case "Sched.agr.":
          $rank=6;
          break;
        case "QM InspLot":
          $rank=7;
          break;
        case "Prod.order":
          $rank=8;
          break;
        case "Plant":  //Plant Stck
          $rank=9;
          break;
        case "Depend.req":
          $rank=10;
          break;
        case "Order.res.":
          $rank=11;
          break;
        case "SubctctReq":
          $rank=12;
          break;
        case "SalesOrder":
          $rank=13;
          break;
        case "ReleaseOrd":
          $rank=14;
          break;
        case "PldOrdRelO":
          $rank=15;
          break;
        case "ProjectOrd":
          $rank=16;
          break;
        case "Free deliv":
          $rank=17;
          break;
        default:
          $rank=25;
    } 
    return $rank;
} 
 
?>