<?php namespace Eae\Transformation\Transformer;

use League\Fractal;
use Entry;

class PageTransformer extends Fractal\TransformerAbstract {  
    protected $availableIncludes = ['pageSections', 'archives'];
    protected $defaultIncludes = ['pageSections', 'archives'];
    
    public function transform(Entry $page){
        return array(
            'id' => (int) $page->id,
            'title' => $page->title,
            'content' => $page->content,
            'headerTemplate' => $page->header_template
        ); 
    }

    public function includePageSections(Entry $page)
    {
		if (!$page->pageSections) {
			return [];
		} 
		return $this->collection($page->pageSections, new PageSectionTransformer());
    }
    
    public function includeArchives(Entry $page)
    {
		if (!$page->archives) {
			return [];
		} 
		return $this->collection($page->archives, new ArchiveTransformer());
	}
}