<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File: error.class.php
 * @Description:  
 
      Ein kleine Error mini Datenbank. Damit kann man 
      Error Meldungen Speichern innerhalb einer Instance und wieder
      ausgeben.

      Die ErrorList muss zuerst Initialisiert werden.
      $error = new ErrorList();
      
	  //Input
	  $error->addError(1,"Error1");
      $error->addError(2,"Error2");

	  //Output 
	  $error->getMessage(1);
      $error->getMessage(2);

     Die KLasse ist im CMS Intigriert und kann mit getErrorList() 
     initialisiert werden. In Modulen ist es auch automatisch dabei.	   
 */
 
 
class Error
{
   protected $ErrorNumber = null;
   protected $ErrorText   = null;
   public    $NextError   = null;
   
   public function Error($ErrorNumber,$ErrorText)
   {
      $this->ErrorNumber = $ErrorNumber;
	  $this->ErrorText   = $ErrorText;
   }
   
   public function getError()
   {
     return $this->ErrorText;
   }
   
   public function getErrorNumber()
   { 
     return $this->ErrorNumber;
   }

}

class ErrorList
{
   protected $Error  = null;
   protected $Start  = null;
   protected $n_list = null; 
   
   public function ErrorList()
   {
      $this->Error = new Error(0,"");
	  $this->Start = $this->Error;  
	  $this->n_list = array();
   }
   
   public function addError($Number,$Text)
   {
       $this->Start->NextError = new Error($Number,$Text);
	   $this->Start = $this->Start->NextError;
	   array_push($this->n_list,$Number);
   }
   
   public function getMessage($Number)
   {
     $list = $this->search($this->Error,$Number);
	 return $list->getError();
   }
   
   public function getSize()
   {
     return count($this->n_list);
   }
   
   public function getIndexList()
   {
     return $this->n_list;
   }
      
   private function search($error,$Number)
   {
      if($error != null)
	  {
         if(strcmp($Number,$error->getErrorNumber()) != false){
		   if($error->NextError != null){
		       return $this->search($error->NextError,$Number);
		   }
		 }
        		 
	  }
      return $error;
   }


}

?>