<?php

namespace app\models;

use app\models\ReportPhoto;
use Yii;

/**
 * This is the model class for table "report_topic".
 *
 * @property int $id
 * @property int|null $parent_id
 * @property string $date
 * @property string|null $title
 * @property string $body
 * @property string $folder
 * @property int $sort
 * @property int $active
 */
class ReportTopic extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'report_topic';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['parent_id', 'sort', 'active'], 'integer'],
            [['date'], 'safe'],
            [['title', 'body'], 'string'],
            [['body'], 'required'],
            [['folder'], 'string', 'max' => 250],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => 'Parent ID',
            'date' => 'Date',
            'title' => 'Title',
            'body' => 'Body',
            'folder' => 'Folder',
            'sort' => 'Sort',
            'active' => 'Active',
        ];
    }

    public function getUrl(){
		return "/photo/".$this->id;
	}

    public function getReport()
    {
        return $this->hasMany(ReportPhoto::className(), ['topic_id' => 'id'])->all();
    }

}
