<?php

class StranasSurvey extends \Phalcon\Mvc\Model
{

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("stranas_survey");
        $this->belongsTo("id_periode", "StranasPeriode", "id");
        $this->belongsTo("id_instansi_satker", "Instansi", "id");
        $this->belongsTo("id_survey_template", "StranasSurveyTemplate", "id");
        $this->hasMany("id", "StranasSurveyAnswer", "id_survey");
    }

    public function getDetail()
    {
        $result = $this->toArray();
        $result['survey_template'] = $this->stranasSurveyTemplate->getDetail();
        $result['periode'] = $this->stranasPeriode;
        $result['instansi_satker'] = $this->instansi;
        $result['answers'] = [];

        foreach ($this->stranasSurveyAnswer as $key => $answer) {
            $result['answers'][] = $answer->getDetail();
        }

        return $result;
    }

    public function overview()
    {
        $result = $this->toArray();
        $result['instansi_satker'] = $this->instansi;
        $result['periode'] = $this->stranasPeriode;

        return $result;
    }
}
