<?php

namespace Modules;

class CMultiple {

    public $elements=array();
    public $first_element="";
    public $last_element="";
    public $ids=array();
    
    function __construct($elements,$IDs=false) {
        $this->elements = $elements;
        if (!$IDs) {
            $keys=array_keys($this->elements);
            foreach($this->elements as $k=>$v) {
                $this->ids[] = $this->elements[$k]->id;
            }
        } else {
            $this->ids = $IDs;
        }
        //foreach ($this->ids as $k=>$v) {
            //var_dump($this->elements[$k]);
            //$this->elements[$k]->id = $v;
        //}
    }


    function __toString() {
        return sprintf("<div>%s<div>%s</div>%s</div>",
                       $this->first_element,
                       implode("\n", $this->elements),
                       $this->last_element
        );
    }

    function set_layout($new,$target="") {
        switch ($target) {
        case "first":
            break;
        case "last":
            break;
        default:
            foreach($this->elements as $el) {
                $el->set_layout($new);
            }
            break;
        }
    }

    function set_first($element,$layout="") {
        $this->first_element=$element;
        if ($layout) {
            $this->first_element->set_layout($layout);
        }
    }

    function set_last($element,$layout="") {
        $this->last_element=$element;
        if ($layout) {
            $this->last_element->set_layout($layout);
        }
    }
}
