<?php
/**
 * File containing the Categorie SIT Value class
 *
 * @copyright Copyright (C) 1999-2014 eZ Systems AS. All rights reserved.
 * @license http://ez.no/licenses/gnu_gpl GNU General Public License v2.0
 * @version 
 */

namespace Ayaline\Bundle\EzSitBundle\eZ\Publish\FieldType\AyalineEzMatrix;

use eZ\Publish\Core\FieldType\Value as BaseValue;

/**
 * Value for Categorie SIT field type
 */
class Value extends BaseValue
{
    /**
     * Associative array with Alpha2 codes as keys and categories SIT data as values.
     *
     *
     * @var array[]
     */
    public $matrix = array();

    /**
     * Construct a new Value object and initialize it with given $data
     *
     * @param array[] $categories
     */
    public function __construct( array $matrix = array() )
    {
        $xmlToString = "";
        $xmlToString .= isset($matrix[0]) ? $matrix[0] : "";
        $xmlToString .= isset($matrix[1]) ? $matrix[1] : "";
        /*
        $xmlObject = simplexml_load_string($xmlToString);

        if (isset($xmlObject->rows) && isset($xmlObject->c)) {
            for ($i = 0; $i < count($xmlObject->c); $i += 2) {
                echo $xmlObject->c[$i] . " ==> " . $xmlObject->c[$i + 1] . "<br />";
            }
        }*/

        $this->matrix = $xmlToString;
    }

    /**
     * @see \eZ\Publish\Core\FieldType\Value
     */
    public function __toString()
    {
        $xmlToString = "";
        $xmlToString .= isset($this->matrix[0]) ? $this->matrix[0] : "";
        $xmlToString .= isset($this->matrix[1]) ? $this->matrix[1] : "";
        return $xmlToString;
    }
}
