<?php
/**
* This file is part of the easy-CMS project.
* easy-CMS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* 
* easy-CMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with easy-CMS; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

include_once('config.inc.php');

/**
* Allows references operations and outputs.
*
* @access   private
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	Reference.class, Sun Nov 28 13:29:42 CET 2004
* @package	Types
*/
class Reference {

  var $typeName;
  var $id;

  function Reference($value = "") {
		//struct : integer_id_element;name_of_type_referenced
    list($id, $name) = explode(";", $value);		    		
    $this->setValue($id, $name);
  }

  function getType() {
    return EASY_CMS_TYPE_REFERENCE;
  }
		
	function compareTo(&$referenceObj){
    if ($referenceObj->getValue() == $this->getValue()) {
      return 0;
    }
    if ($referenceObj->getValue() > $this->getValue()) {
      return -1;
    }
    return 1;
	}
	
  function setValue($id, $typeName='') {
    $this->id = $id;
    $this->typeName = $typeName;
  }

  function &getValue() {
    return $this->id.";".$this->typeName;
  }

  function toString() {
    return $this->getValue();
  }

  function toXML() {
    return "<id>".$this->id."</id>\n<type>".$this->typeName."</type>\n";		
  }

  function toSQL() {
    return $this->getValue();
  }
}
?>