<?php

class ListPTNBH extends Phalcon\Mvc\Model
{
    /**
     *
     * @var integer
     */
    public $id;
    /**
     *
     * @var integer
     */
    public $perguruan_tinggi_id;
    /**
     *
     * @var string
     */
    public $url_report;
    /**
     *
     * @var datetime
     */
    public $created_at;
    /**
     *
     * @var integer
     */
    public $created_by;
    /**
     *
     * @var datetime
     */
    public $updated_at;
    /**
     *
     * @var integer
     */
    public $updated_by;
    /**
     *
     * @var datetime
     */
    public $deleted_at;
    /**
     *
     * @var integer
     */
    public $deleted_by;

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

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

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return ListPTNBH[]|ListPTNBH|\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 ListPTNBH|\Phalcon\Mvc\Model\ResultInterface
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    public function toArrayDetail()
    {
        $result = $this->toArray();
        $result['nama_perguruan_tinggi'] = '';
        if(!empty($this->perguruan_tinggi_id)) {
            $pt = PerguruanTinggi::findFirst(
                [
                    "id_pt = :id:",
                    "bind" => [
                        "id" => $this->perguruan_tinggi_id
                    ]
                ]
            );

            if(!empty($pt)) {
                $result['nama_perguruan_tinggi'] = $pt->nama;
            }
        }

        return $result;
    }
}

?>