<?php

class DetailAlokasiBOPTN extends Phalcon\Mvc\Model
{
    /**
     *
     * @var integer
     */
    public $id;
    /**
     *
     * @var integer
     */
    public $alokasi_id;
    /**
     *
     * @var integer
     */
    public $info_alokasi_boptn_id;
    /**
     *
     * @var float
     */
    public $nilai_alokasi;
    /**
     *
     * @var datetime
     */
    public $created_at;
    /**
     *
     * @var datetime
     */
    public $updated_at;
    /**
     *
     * @var datetime
     */
    public $deleted_at;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->setSchema('jaga');
        $this->setSource('detail_alokasi_boptn');
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'detail_alokasi_boptn';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return DetailAlokasiBOPTN[]|DetailAlokasiBOPTN|\Phalcon\Mvc\Model\ResultSetInterface
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return DetailAlokasiBOPTN|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }
    public function toArrayDetail()
    {
        $result = $this->toArray();

        $result['alokasi'] = [];
        if(!empty($this->alokasi_id)) {
            $alokasi = AlokasiBOPTNBPPTNBH::findFirstById($this->alokasi_id);

            if(!empty($alokasi)) {
                $result['alokasi'] = $alokasi->toArrayDetail();
            }
        }   

        $result['info_alokasi'] = [];
        if(!empty($this->info_alokasi_boptn_id)) {
            $info = InfoAlokasiBOPTN::findFirst(
                [
                    'id = :id: and deleted_at is null',
                    'bind' => [
                        'id' => $this->info_alokasi_boptn_id
                    ]
                ]
            );

            if(!empty($info)) {
                $result['info_alokasi'] = $info->toArray();
            }
        }

        return $result;
    }
}

?>