<?php

class StranasNewReportLog extends \Phalcon\Mvc\Model
{

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema("jaga");
        $this->setSource("str_target_log");
        $this->hasMany("id", "StranasNewReportLogAttachments", "id_log");
        $this->hasMany("id", "StranasNewReportLogComments", "id_log");
        $this->hasOne("id_triwulan", "StranasNewPeriodeTriwulan", "id", ['alias' => 'triwulan']);
        $this->hasOne("id_master", "StranasNewTargetSpecialLog", "id_master", ['alias' => 'special']);
        $this->belongsTo("created_by", "UmUser", "um_id", ['alias' => 'creator']);
        $this->belongsTo("updated_by", "UmUser", "um_id", ['alias' => 'updater']);
        $this->belongsTo("verified_by", "UmUser", "um_id", ['alias' => 'verificator']);
    }

    public function getDetail($columns = null)
    {
        $result = parent::toArray($columns);
        $result['is_submit'] = is_null($this->nilai) ? 0 : 1;
        $result['is_verify'] = (empty($this->nilai_verification) || $this->nilai_verification ==0) ? 0 : 1;
        $result['triwulan'] = empty($this->triwulan) ? null : $this->triwulan->label;
        $result['comments'] = $this->StranasNewReportLogComments;
        $result['special'] = $this->StranasNewTargetSpecialLog;
        $result['attachments'] = $this->StranasNewReportLogAttachments;

        return $result;
    }
    
    public function toArray($columns = null)
    {
        $result = parent::toArray($columns);
        $result['is_submit'] = is_null($this->nilai) ? 0 : 1;
        $result['is_verify'] = (empty($this->nilai_verification) || $this->nilai_verification ==0) ? 0 : 1;

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

        $result['triwulan'] = empty($this->triwulan) ? null : $this->triwulan->label;
        $result['special'] = empty($this->special) ? null : $this->special->getValueTriwulan($this->id_master, $this->id_triwulan);
        $result['comments'] = $this->StranasNewReportLogComments;
        $result['attachments'] = $this->StranasNewReportLogAttachments;

        return $result;
    }

    public function toDetail($columns = null)
    {
        $result = parent::toArray($columns);
        $result['is_submit'] = is_null($this->nilai) ? 0 : 1;
        $result['is_verify'] = (empty($this->nilai_verification) || $this->nilai_verification ==0) ? 0 : 1;
        $result['triwulan'] = empty($this->triwulan) ? null : $this->triwulan->label;
        $result['special'] = $this->StranasNewTargetSpecialLog;
        $result['comments'] = $this->StranasNewReportLogComments;
        $result['attachments'] = $this->StranasNewReportLogAttachments;

        return $result;
    }
}
