243 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			243 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
class RecordLine
 | 
						|
{
 | 
						|
    private $debug                      = false;
 | 
						|
    private $hash                       = '';
 | 
						|
 | 
						|
    private $originalContent            = array();
 | 
						|
    private $lineCount                  = 0;
 | 
						|
 | 
						|
    private $composedContent            = "";
 | 
						|
 | 
						|
    private $composedData               = array();
 | 
						|
 | 
						|
    private $type                       = '';
 | 
						|
    private $sub_type                   = '';
 | 
						|
 | 
						|
    private $reportMatrix               = null;
 | 
						|
 | 
						|
    function __construct($type)
 | 
						|
    {
 | 
						|
        $this->type = $type;
 | 
						|
        //$this->hash = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
 | 
						|
    }
 | 
						|
 | 
						|
    function setOriginalContent($line,$refresh=false)
 | 
						|
    {
 | 
						|
        if($refresh)
 | 
						|
        {
 | 
						|
            $this->originalContent = array();
 | 
						|
        }
 | 
						|
        $this->originalContent[] = trim($line);
 | 
						|
        $this->lineCount = count($this->originalContent);
 | 
						|
        $this->composedContent = implode(" ",$this->originalContent);
 | 
						|
    }
 | 
						|
 | 
						|
    function setComposedData($key,$value)
 | 
						|
    {
 | 
						|
        $this->composedData[$key] = $value;
 | 
						|
    }
 | 
						|
 | 
						|
    function getType()
 | 
						|
    {
 | 
						|
        return $this->type;
 | 
						|
    }
 | 
						|
 | 
						|
    function getComposedData()
 | 
						|
    {
 | 
						|
        return $this->composedData;
 | 
						|
    }
 | 
						|
 | 
						|
    function getReportMatrix()
 | 
						|
    {
 | 
						|
        return $this->reportMatrix;
 | 
						|
    }
 | 
						|
    
 | 
						|
    function process()
 | 
						|
    {
 | 
						|
        
 | 
						|
        switch($this->type)
 | 
						|
        {
 | 
						|
            case 'license-header':
 | 
						|
                if($this->debug) echo "<br><b style='color:blue;'>  Top Label(lh) - </b> Parsing -> ".$this->composedContent;
 | 
						|
                $this->__processLicenseHeader();
 | 
						|
                break;
 | 
						|
            case 'school-report-head':
 | 
						|
                if($this->debug) echo "<br><b style='color:blue;'>  Top Label(rh) - </b> Parsing -> ".$this->composedContent;
 | 
						|
                $this->__processSchoolReportHead();
 | 
						|
                break;
 | 
						|
            case 'school-name-head':
 | 
						|
                if($this->debug) echo "<br><b style='color:blue;'>  Top Label(sh) - </b> Parsing -> ".$this->composedContent;
 | 
						|
                $this->__processSchoolNameHead();
 | 
						|
                break;
 | 
						|
            case 'result-label':
 | 
						|
                if($this->debug) echo "<br><b style='color:blue;'>  Top Label(rl) - </b> Parsing -> ".$this->composedContent;
 | 
						|
                $this->__processResultLabel();
 | 
						|
                break;
 | 
						|
            case 'line-break':
 | 
						|
                if($this->debug) echo "<br><b style='color:blue;'>  Content - </b> Parsing -> Blank Line";
 | 
						|
                $this->__processLineBreak();
 | 
						|
                break;
 | 
						|
            case 'report-data':
 | 
						|
                $this->__processReportData();
 | 
						|
                break;
 | 
						|
                      
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    function __processLicenseHeader()
 | 
						|
    {
 | 
						|
        $info_divider = "-";
 | 
						|
        
 | 
						|
        $words = ParserUtility::getWords($this->composedContent);
 | 
						|
        
 | 
						|
        $licenseToPart = array();
 | 
						|
        $subLicencePart = array();
 | 
						|
        $subLicenceToPart = array();
 | 
						|
        $subLicenceDatePart = array();
 | 
						|
        
 | 
						|
        $foundDivider = false;
 | 
						|
        
 | 
						|
        foreach($words as $word)
 | 
						|
        {
 | 
						|
            if( !$foundDivider && trim($word)===$info_divider)
 | 
						|
            {
 | 
						|
                $foundDivider = true;
 | 
						|
                continue;
 | 
						|
            }
 | 
						|
 | 
						|
            if(!$foundDivider)
 | 
						|
            {
 | 
						|
                $licenseToPart[] = trim($word);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                $subLicencePart[] = trim($word);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        $foundDivider = false;
 | 
						|
        foreach($subLicencePart as $word)
 | 
						|
        {
 | 
						|
            if(preg_match("/^(((0)[0-9])|((1)[0-2]))(\/)([0-2][0-9]|(3)[0-1])(\/)\d{4}$/i", $word) 
 | 
						|
                || preg_match("/^\d{1,2}(\/)\d{1,2}(\/)\d{4}$/i", $word)  ) {
 | 
						|
                $foundDivider = true; 
 | 
						|
               
 | 
						|
            }
 | 
						|
 | 
						|
            if(!$foundDivider)
 | 
						|
            {
 | 
						|
                $subLicenceToPart[] = trim($word);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                $subLicenceDatePart[] = trim($word);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        $this->composedData["LICENCE TO"] = implode(" ",$licenseToPart);
 | 
						|
        $this->composedData["SUB-LICENSE"] = implode(" ",$subLicenceToPart);
 | 
						|
        $this->composedData["LICENSE DATE"] = implode(" ",$subLicenceDatePart);
 | 
						|
    }
 | 
						|
 | 
						|
    function __processSchoolReportHead()
 | 
						|
    {
 | 
						|
        $info_divider = "-";
 | 
						|
        
 | 
						|
        $words = ParserUtility::getWords($this->composedContent);
 | 
						|
 | 
						|
        $eventNamePart = array();
 | 
						|
        $datePart = array();
 | 
						|
 | 
						|
        $foundDivider = false;
 | 
						|
        
 | 
						|
        foreach($words as $word)
 | 
						|
        {
 | 
						|
            if( !$foundDivider && trim($word)===$info_divider)
 | 
						|
            {
 | 
						|
                $foundDivider = true;
 | 
						|
                continue;
 | 
						|
            }
 | 
						|
 | 
						|
            if(!$foundDivider)
 | 
						|
            {
 | 
						|
                $eventNamePart[] = trim($word);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                $datePart[] = trim($word);
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        $this->composedData["EVENT NAME"] = implode(" ",$eventNamePart);
 | 
						|
        $this->composedData["EVENT DATE"] = implode(" ",$datePart);
 | 
						|
    }
 | 
						|
 | 
						|
    function __processSchoolNameHead()
 | 
						|
    {        
 | 
						|
        $words = ParserUtility::getWords($this->composedContent);
 | 
						|
 | 
						|
        $schoolNamePart = array();
 | 
						|
        
 | 
						|
        foreach($words as $word)
 | 
						|
        {
 | 
						|
            $schoolNamePart[] = trim($word);
 | 
						|
        }
 | 
						|
 | 
						|
        $this->composedData["SCHOOL NAME"] = implode(" ",$schoolNamePart);
 | 
						|
    }
 | 
						|
 | 
						|
    function __processResultLabel()
 | 
						|
    {        
 | 
						|
        $words = ParserUtility::getWords($this->composedContent);
 | 
						|
 | 
						|
        $resultLabelPart = array();
 | 
						|
        
 | 
						|
        foreach($words as $word)
 | 
						|
        {
 | 
						|
            $resultLabelPart[] = trim($word);
 | 
						|
        }
 | 
						|
 | 
						|
        $this->composedData["LABEL"] = implode(" ",$resultLabelPart);
 | 
						|
    }
 | 
						|
 | 
						|
    function __processLineBreak()
 | 
						|
    {     
 | 
						|
        $this->composedData["LINE-COUNT"] = count($this->originalContent);
 | 
						|
    }
 | 
						|
 | 
						|
    function __processReportData()
 | 
						|
    {        
 | 
						|
        $this->__processReportHeaderLabel();        
 | 
						|
        $this->reportMatrix = new ReportMatrix(@$this->composedData["SPORT-GROUP"], @$this->composedData["SPORT"]);
 | 
						|
        $this->reportMatrix->setSportsLevel(@$this->composedData["SPORT-ROUND"]);        
 | 
						|
    }
 | 
						|
   
 | 
						|
    function __processReportHeaderLabel()
 | 
						|
    {
 | 
						|
        if($this->debug) echo "<br><b>LINE - </b> Parsing -> ".$this->composedContent;
 | 
						|
        $words = ParserUtility::getWords($this->composedContent);
 | 
						|
 | 
						|
        $labelPart = array();
 | 
						|
        
 | 
						|
        foreach($words as $word)
 | 
						|
        {
 | 
						|
            $labelPart[] = trim($word);
 | 
						|
        }
 | 
						|
 | 
						|
        $this->composedData["HEADER"] = implode(" ",$labelPart);
 | 
						|
 | 
						|
        $hAnalysis = new Lexicon($this->composedData["HEADER"]);
 | 
						|
        $hAnalysis->analyse();
 | 
						|
 | 
						|
        $this->composedData["HEADER-ANALYSIS"] = $hAnalysis;
 | 
						|
 | 
						|
        $this->composedData["GENDER"]       = $hAnalysis->getGender();
 | 
						|
        $this->composedData["SPORT-GROUP"]  = $hAnalysis->getSportsType();
 | 
						|
        $this->composedData["SPORT"]        = $hAnalysis->getSports();
 | 
						|
        $this->composedData["SPORT-ROUND"]  = $hAnalysis->getSportsRound();   
 | 
						|
        
 | 
						|
        if($this->debug) { echo '<br><b>LINE - </b> Parsed -> <div style="max-height:100px; overflow:auto; border:thin solid #00ff00;  margin-left:60px; margin-right:60px;">';print_r($this->composedData); echo '</div>'; }
 | 
						|
    }
 | 
						|
}
 | 
						|
?>
 |