<?php

class StranasSurveyAnswerComment extends \Phalcon\Mvc\Model
{
    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("stranas_survey_answer_comment");
        $this->belongsTo("id_answer", "StranasSurveyAnswer", "id");
        $this->hasMany("id", "StranasSurveyAnswerCommentAttachment", "id_comment");
        $this->belongsTo("created_by", "UmUser", "um_id", ['alias' => 'creator']);
    }

    public function getDetail()
    {
        $result = $this->toArray();

        $result['attachments'] = [];

        foreach ($this->StranasSurveyAnswerCommentAttachment as $key => $comment_attachment) {
            if (!empty($comment_attachment->attachments)) {
                $result['attachments'][] = $comment_attachment->getDetail();
            }
        }

        $result['creator'] = empty($this->creator) ? null : $this->creator->toArraySimple();

        return $result;
    }
}
