<?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\AyalineCategoriesSit;

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 $categories = array();

    /**
     * Construct a new Value object and initialize it with given $data
     *
     * @param array[] $categories
     */
    public function __construct( array $categories = array() )
    {
        $this->categories = $categories;
    }

    /**
     * @see \eZ\Publish\Core\FieldType\Value
     */
    public function __toString()
    {
        return implode(
            ", ",
            array_map(
                function ( $categorie )
                {
                    return $categorie["Name"];
                },
                $this->$categories
            )
        );
    }
}
